GRINS-0.8.0
stokes.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2017 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // This class
27 #include "grins/stokes.h"
28 
29 // GRINS
30 #include "grins_config.h"
32 #include "grins/assembly_context.h"
34 #include "grins/multiphysics_sys.h"
35 
36 // libMesh
37 #include "libmesh/fem_context.h"
38 #include "libmesh/quadrature.h"
39 
40 namespace GRINS
41 {
42 
43  template<class Mu>
44  Stokes<Mu>::Stokes(const std::string& physics_name, const GetPot& input )
45  : IncompressibleNavierStokesBase<Mu>(physics_name,
46  PhysicsNaming::stokes(), /* "core" Physics name */
47  input),
48  _p_pinning(input,physics_name),
49  _pin_pressure( input("Physics/"+PhysicsNaming::stokes()+"/pin_pressure", false ) )
50  {
51  this->_ic_handler = new GenericICHandler( physics_name, input );
52  }
53 
54  template<class Mu>
56  {
57  return;
58  }
59 
60  template<class Mu>
62  {
63  if( _pin_pressure )
64  _p_pinning.check_pin_location(system.get_mesh());
65  }
66 
67  template<class Mu>
69  ( bool compute_jacobian, AssemblyContext & context )
70  {
71  // The number of local degrees of freedom in each variable.
72  const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
73  const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).size();
74 
75  // Check number of dofs is same for this->_flow_vars.u(), v_var and w_var.
76  libmesh_assert (n_u_dofs == context.get_dof_indices(this->_flow_vars.v()).size());
77 
78  if (this->_flow_vars.dim() == 3)
79  libmesh_assert (n_u_dofs == context.get_dof_indices(this->_flow_vars.w()).size());
80 
81  // We get some references to cell-specific data that
82  // will be used to assemble the linear system.
83 
84  // Element Jacobian * quadrature weights for interior integration.
85  const std::vector<libMesh::Real> &JxW =
86  context.get_element_fe(this->_flow_vars.u())->get_JxW();
87 
88  // The velocity shape function gradients (in global coords.)
89  // at interior quadrature points.
90  const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
91  context.get_element_fe(this->_flow_vars.u())->get_dphi();
92 
93  // The pressure shape functions at interior quadrature points.
94  const std::vector<std::vector<libMesh::Real> >& p_phi =
95  context.get_element_fe(this->_press_var.p())->get_phi();
96 
97  // The subvectors and submatrices we need to fill:
98  //
99  // K_{\alpha \beta} = R_{\alpha},{\beta} = \partial{ R_{\alpha} } / \partial{ {\beta} } (where R denotes residual)
100  // e.g., for \alpha = v and \beta = u we get: K{vu} = R_{v},{u}
101  // Note that Kpu, Kpv, Kpw and Fp comes as constraint.
102 
103  libMesh::DenseSubMatrix<libMesh::Number> &Kuu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u()); // R_{u},{u}
104  libMesh::DenseSubMatrix<libMesh::Number> &Kvv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v()); // R_{v},{v}
105  libMesh::DenseSubMatrix<libMesh::Number>* Kww = NULL;
106 
107  libMesh::DenseSubMatrix<libMesh::Number> &Kup = context.get_elem_jacobian(this->_flow_vars.u(), this->_press_var.p()); // R_{u},{p}
108  libMesh::DenseSubMatrix<libMesh::Number> &Kvp = context.get_elem_jacobian(this->_flow_vars.v(), this->_press_var.p()); // R_{v},{p}
109  libMesh::DenseSubMatrix<libMesh::Number>* Kwp = NULL;
110 
111  libMesh::DenseSubVector<libMesh::Number> &Fu = context.get_elem_residual(this->_flow_vars.u()); // R_{u}
112  libMesh::DenseSubVector<libMesh::Number> &Fv = context.get_elem_residual(this->_flow_vars.v()); // R_{v}
113  libMesh::DenseSubVector<libMesh::Number>* Fw = NULL;
114 
115  if( this->_flow_vars.dim() == 3 )
116  {
117  Kww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w()); // R_{w},{w}
118  Kwp = &context.get_elem_jacobian(this->_flow_vars.w(), this->_press_var.p()); // R_{w},{p}
119  Fw = &context.get_elem_residual(this->_flow_vars.w()); // R_{w}
120  }
121 
122  // Now we will build the element Jacobian and residual.
123  // Constructing the residual requires the solution and its
124  // gradient from the previous timestep. This must be
125  // calculated at each quadrature point by summing the
126  // solution degree-of-freedom values by the appropriate
127  // weight functions.
128  unsigned int n_qpoints = context.get_element_qrule().n_points();
129 
130  for (unsigned int qp=0; qp != n_qpoints; qp++)
131  {
132  // Compute the solution & its gradient at the old Newton iterate.
133  libMesh::Number p, u, v, w;
134  p = context.interior_value(this->_press_var.p(), qp);
135  u = context.interior_value(this->_flow_vars.u(), qp);
136  v = context.interior_value(this->_flow_vars.v(), qp);
137  if (this->_flow_vars.dim() == 3)
138  w = context.interior_value(this->_flow_vars.w(), qp);
139 
140  libMesh::Gradient grad_u, grad_v, grad_w;
141  grad_u = context.interior_gradient(this->_flow_vars.u(), qp);
142  grad_v = context.interior_gradient(this->_flow_vars.v(), qp);
143  if (this->_flow_vars.dim() == 3)
144  grad_w = context.interior_gradient(this->_flow_vars.w(), qp);
145 
146  libMesh::NumberVectorValue Uvec (u,v);
147  if (this->_flow_vars.dim() == 3)
148  Uvec(2) = w;
149 
150  // Compute the viscosity at this qp
151  libMesh::Real _mu_qp = this->_mu(context, qp);
152 
153  // First, an i-loop over the velocity degrees of freedom.
154  // We know that n_u_dofs == n_v_dofs so we can compute contributions
155  // for both at the same time.
156  for (unsigned int i=0; i != n_u_dofs; i++)
157  {
158  Fu(i) += JxW[qp] *
159  ( p*u_gradphi[i][qp](0) // pressure term
160  -_mu_qp*(u_gradphi[i][qp]*grad_u) ); // diffusion term
161 
162  Fv(i) += JxW[qp] *
163  ( p*u_gradphi[i][qp](1) // pressure term
164  -_mu_qp*(u_gradphi[i][qp]*grad_v) ); // diffusion term
165  if (this->_flow_vars.dim() == 3)
166  {
167  (*Fw)(i) += JxW[qp] *
168  ( p*u_gradphi[i][qp](2) // pressure term
169  -_mu_qp*(u_gradphi[i][qp]*grad_w) ); // diffusion term
170  }
171 
172  if (compute_jacobian)
173  {
174  for (unsigned int j=0; j != n_u_dofs; j++)
175  {
176  // TODO: precompute some terms like:
177  // (Uvec*vel_gblgradphivec[j][qp]),
178  // vel_phi[i][qp]*vel_phi[j][qp],
179  // (vel_gblgradphivec[i][qp]*vel_gblgradphivec[j][qp])
180 
181  Kuu(i,j) += JxW[qp] * context.get_elem_solution_derivative() *
182  (-_mu_qp*(u_gradphi[i][qp]*u_gradphi[j][qp])); // diffusion term
183 
184  Kvv(i,j) += JxW[qp] * context.get_elem_solution_derivative() *
185  (-_mu_qp*(u_gradphi[i][qp]*u_gradphi[j][qp])); // diffusion term
186 
187  if (this->_flow_vars.dim() == 3)
188  {
189  (*Kww)(i,j) += JxW[qp] * context.get_elem_solution_derivative() *
190  (-_mu_qp*(u_gradphi[i][qp]*u_gradphi[j][qp])); // diffusion term
191  }
192  } // end of the inner dof (j) loop
193 
194  // Matrix contributions for the up, vp and wp couplings
195  for (unsigned int j=0; j != n_p_dofs; j++)
196  {
197  Kup(i,j) += context.get_elem_solution_derivative() * JxW[qp]*u_gradphi[i][qp](0)*p_phi[j][qp];
198  Kvp(i,j) += context.get_elem_solution_derivative() * JxW[qp]*u_gradphi[i][qp](1)*p_phi[j][qp];
199  if (this->_flow_vars.dim() == 3)
200  (*Kwp)(i,j) += context.get_elem_solution_derivative() * JxW[qp]*u_gradphi[i][qp](2)*p_phi[j][qp];
201  } // end of the inner dof (j) loop
202 
203  } // end - if (compute_jacobian && context.get_elem_solution_derivative())
204 
205  } // end of the outer dof (i) loop
206  } // end of the quadrature point (qp) loop
207  }
208 
209  template<class Mu>
211  ( bool compute_jacobian, AssemblyContext & context )
212  {
213  // The number of local degrees of freedom in each variable.
214  const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
215  const unsigned int n_p_dofs = context.get_dof_indices(this->_press_var.p()).size();
216 
217  // We get some references to cell-specific data that
218  // will be used to assemble the linear system.
219 
220  // Element Jacobian * quadrature weights for interior integration.
221  const std::vector<libMesh::Real> &JxW =
222  context.get_element_fe(this->_flow_vars.u())->get_JxW();
223 
224  // The velocity shape function gradients (in global coords.)
225  // at interior quadrature points.
226  const std::vector<std::vector<libMesh::RealGradient> >& u_gradphi =
227  context.get_element_fe(this->_flow_vars.u())->get_dphi();
228 
229  // The pressure shape functions at interior quadrature points.
230  const std::vector<std::vector<libMesh::Real> >& p_phi =
231  context.get_element_fe(this->_press_var.p())->get_phi();
232 
233  // The subvectors and submatrices we need to fill:
234  //
235  // Kpu, Kpv, Kpw, Fp
236 
237  libMesh::DenseSubMatrix<libMesh::Number> &Kpu = context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.u()); // R_{p},{u}
238  libMesh::DenseSubMatrix<libMesh::Number> &Kpv = context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.v()); // R_{p},{v}
239  libMesh::DenseSubMatrix<libMesh::Number>* Kpw = NULL;
240 
241  libMesh::DenseSubVector<libMesh::Number> &Fp = context.get_elem_residual(this->_press_var.p()); // R_{p}
242 
243 
244  if( this->_flow_vars.dim() == 3 )
245  {
246  Kpw = &context.get_elem_jacobian(this->_press_var.p(), this->_flow_vars.w()); // R_{p},{w}
247  }
248 
249  // Add the constraint given by the continuity equation.
250  unsigned int n_qpoints = context.get_element_qrule().n_points();
251  for (unsigned int qp=0; qp != n_qpoints; qp++)
252  {
253  // Compute the velocity gradient at the old Newton iterate.
254  libMesh::Gradient grad_u, grad_v, grad_w;
255  grad_u = context.interior_gradient(this->_flow_vars.u(), qp);
256  grad_v = context.interior_gradient(this->_flow_vars.v(), qp);
257  if (this->_flow_vars.dim() == 3)
258  grad_w = context.interior_gradient(this->_flow_vars.w(), qp);
259 
260  // Now a loop over the pressure degrees of freedom. This
261  // computes the contributions of the continuity equation.
262  for (unsigned int i=0; i != n_p_dofs; i++)
263  {
264  Fp(i) += JxW[qp] * p_phi[i][qp] *
265  (grad_u(0) + grad_v(1));
266  if (this->_flow_vars.dim() == 3)
267  Fp(i) += JxW[qp] * p_phi[i][qp] *
268  (grad_w(2));
269 
270  if (compute_jacobian)
271  {
272  for (unsigned int j=0; j != n_u_dofs; j++)
273  {
274  Kpu(i,j) += context.get_elem_solution_derivative() * JxW[qp]*p_phi[i][qp]*u_gradphi[j][qp](0);
275  Kpv(i,j) += context.get_elem_solution_derivative() * JxW[qp]*p_phi[i][qp]*u_gradphi[j][qp](1);
276  if (this->_flow_vars.dim() == 3)
277  (*Kpw)(i,j) += context.get_elem_solution_derivative() * JxW[qp]*p_phi[i][qp]*u_gradphi[j][qp](2);
278  } // end of the inner dof (j) loop
279 
280  } // end - if (compute_jacobian && context.get_elem_solution_derivative())
281 
282  } // end of the outer dof (i) loop
283  } // end of the quadrature point (qp) loop
284 
285 
286  // Pin p = p_value at p_point
287  if( _pin_pressure )
288  {
289  _p_pinning.pin_value( context, compute_jacobian, this->_press_var.p() );
290  }
291  }
292 
293  template<class Mu>
295  ( bool compute_jacobian, AssemblyContext & context )
296  {
297  // Element Jacobian * quadrature weights for interior integration
298  // We assume the same for each flow variable
299  const std::vector<libMesh::Real> &JxW =
300  context.get_element_fe(this->_flow_vars.u())->get_JxW();
301 
302  // The shape functions at interior quadrature points.
303  // We assume the same for each flow variable
304  const std::vector<std::vector<libMesh::Real> >& u_phi =
305  context.get_element_fe(this->_flow_vars.u())->get_phi();
306 
307  // The number of local degrees of freedom in each variable
308  const unsigned int n_u_dofs = context.get_dof_indices(this->_flow_vars.u()).size();
309 
310  // The subvectors and submatrices we need to fill:
311  libMesh::DenseSubVector<libMesh::Real> &F_u = context.get_elem_residual(this->_flow_vars.u());
312  libMesh::DenseSubVector<libMesh::Real> &F_v = context.get_elem_residual(this->_flow_vars.v());
313  libMesh::DenseSubVector<libMesh::Real>* F_w = NULL;
314 
315  libMesh::DenseSubMatrix<libMesh::Real> &M_uu = context.get_elem_jacobian(this->_flow_vars.u(), this->_flow_vars.u());
316  libMesh::DenseSubMatrix<libMesh::Real> &M_vv = context.get_elem_jacobian(this->_flow_vars.v(), this->_flow_vars.v());
317  libMesh::DenseSubMatrix<libMesh::Real>* M_ww = NULL;
318 
319  if( this->_flow_vars.dim() == 3 )
320  {
321  F_w = &context.get_elem_residual(this->_flow_vars.w()); // R_{w}
322  M_ww = &context.get_elem_jacobian(this->_flow_vars.w(), this->_flow_vars.w());
323  }
324 
325  unsigned int n_qpoints = context.get_element_qrule().n_points();
326 
327  for (unsigned int qp = 0; qp != n_qpoints; ++qp)
328  {
329  // For the mass residual, we need to be a little careful.
330  // The time integrator is handling the time-discretization
331  // for us so we need to supply M(u_fixed)*u' for the residual.
332  // u_fixed will be given by the fixed_interior_value function
333  // while u' will be given by the interior_rate function.
334  libMesh::Real u_dot, v_dot, w_dot = 0.0;
335  context.interior_rate(this->_flow_vars.u(), qp, u_dot);
336  context.interior_rate(this->_flow_vars.v(), qp, v_dot);
337 
338  if( this->_flow_vars.dim() == 3 )
339  context.interior_rate(this->_flow_vars.w(), qp, w_dot);
340 
341  for (unsigned int i = 0; i != n_u_dofs; ++i)
342  {
343  F_u(i) -= JxW[qp]*this->_rho*u_dot*u_phi[i][qp];
344  F_v(i) -= JxW[qp]*this->_rho*v_dot*u_phi[i][qp];
345 
346  if( this->_flow_vars.dim() == 3 )
347  (*F_w)(i) -= JxW[qp]*this->_rho*w_dot*u_phi[i][qp];
348 
349  if( compute_jacobian )
350  {
351  for (unsigned int j=0; j != n_u_dofs; j++)
352  {
353  // Assuming rho is constant w.r.t. u, v, w
354  // and T (if Boussinesq added).
355  libMesh::Real value = context.get_elem_solution_derivative() * JxW[qp]*this->_rho*u_phi[i][qp]*u_phi[j][qp];
356 
357  M_uu(i,j) -= value;
358  M_vv(i,j) -= value;
359 
360  if( this->_flow_vars.dim() == 3)
361  {
362  (*M_ww)(i,j) -= value;
363  }
364 
365  } // End dof loop
366  } // End Jacobian check
367  } // End dof loop
368  } // End quadrature loop
369 
370  return;
371  }
372 
373 } // namespace GRINS
374 
375 // Instantiate
GRINS::ICHandlingBase * _ic_handler
Definition: physics.h:258
Physics class for Incompressible Navier-Stokes.
INSTANTIATE_INC_NS_SUBCLASS(Stokes)
virtual void mass_residual(bool compute_jacobian, AssemblyContext &context)
Mass matrix part(s) for element interiors. All boundary terms lie within the time_derivative part...
Definition: stokes.C:295
Base class for reading and handling initial conditions for physics classes.
GRINS namespace.
virtual void auxiliary_init(MultiphysicsSystem &system)
Any auxillary initialization a Physics class may need.
Definition: stokes.C:61
Interface with libMesh for solving Multiphysics problems.
virtual void element_constraint(bool compute_jacobian, AssemblyContext &context)
Constraint part(s) of physics for element interiors.
Definition: stokes.C:211
virtual void element_time_derivative(bool compute_jacobian, AssemblyContext &context)
Time dependent part(s) of physics for element interiors.
Definition: stokes.C:69

Generated on Tue Dec 19 2017 12:47:28 for GRINS-0.8.0 by  doxygen 1.8.9.1