www.mooseframework.org
INSBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "INSBase.h"
11 #include "Assembly.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<Kernel>();
18 
19  params.addClassDescription("This class computes various strong and weak components of the "
20  "incompressible navier stokes equations which can then be assembled "
21  "together in child classes.");
22  // Coupled variables
23  params.addRequiredCoupledVar("u", "x-velocity");
24  params.addCoupledVar("v", 0, "y-velocity"); // only required in 2D and 3D
25  params.addCoupledVar("w", 0, "z-velocity"); // only required in 3D
26  params.addRequiredCoupledVar("p", "pressure");
27 
28  params.addParam<RealVectorValue>(
29  "gravity", RealVectorValue(0, 0, 0), "Direction of the gravity vector");
30 
31  params.addParam<MaterialPropertyName>("mu_name", "mu", "The name of the dynamic viscosity");
32  params.addParam<MaterialPropertyName>("rho_name", "rho", "The name of the density");
33 
34  params.addParam<Real>("alpha", 1., "Multiplicative factor on the stabilization parameter tau.");
35  params.addParam<bool>(
36  "laplace", true, "Whether the viscous term of the momentum equations is in laplace form.");
37  params.addParam<bool>("convective_term", true, "Whether to include the convective term.");
38  params.addParam<bool>("transient_term",
39  false,
40  "Whether there should be a transient term in the momentum residuals.");
41 
42  return params;
43 }
44 
45 INSBase::INSBase(const InputParameters & parameters)
46  : Kernel(parameters),
47  _second_phi(_assembly.secondPhi()),
48 
49  // Coupled variables
50  _u_vel(coupledValue("u")),
51  _v_vel(coupledValue("v")),
52  _w_vel(coupledValue("w")),
53  _p(coupledValue("p")),
54 
55  // Gradients
56  _grad_u_vel(coupledGradient("u")),
57  _grad_v_vel(coupledGradient("v")),
58  _grad_w_vel(coupledGradient("w")),
59  _grad_p(coupledGradient("p")),
60 
61  // second derivative tensors
62  _second_u_vel(coupledSecond("u")),
63  _second_v_vel(coupledSecond("v")),
64  _second_w_vel(coupledSecond("w")),
65 
66  // time derivatives
67  _u_vel_dot(_is_transient ? coupledDot("u") : _zero),
68  _v_vel_dot(_is_transient ? coupledDot("v") : _zero),
69  _w_vel_dot(_is_transient ? coupledDot("w") : _zero),
70 
71  // derivatives of time derivatives
72  _d_u_vel_dot_du(_is_transient ? coupledDotDu("u") : _zero),
73  _d_v_vel_dot_dv(_is_transient ? coupledDotDu("v") : _zero),
74  _d_w_vel_dot_dw(_is_transient ? coupledDotDu("w") : _zero),
75 
76  // Variable numberings
77  _u_vel_var_number(coupled("u")),
78  _v_vel_var_number(coupled("v")),
79  _w_vel_var_number(coupled("w")),
80  _p_var_number(coupled("p")),
81 
82  _gravity(getParam<RealVectorValue>("gravity")),
83 
84  // Material properties
85  _mu(getMaterialProperty<Real>("mu_name")),
86  _rho(getMaterialProperty<Real>("rho_name")),
87 
88  _alpha(getParam<Real>("alpha")),
89  _laplace(getParam<bool>("laplace")),
90  _convective_term(getParam<bool>("convective_term")),
91  _transient_term(getParam<bool>("transient_term"))
92 {
93 }
94 
95 RealVectorValue
97 {
98  RealVectorValue U(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
99  return _rho[_qp] *
100  RealVectorValue(U * _grad_u_vel[_qp], U * _grad_v_vel[_qp], U * _grad_w_vel[_qp]);
101 }
102 
103 RealVectorValue
105 {
106  RealVectorValue U(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
107  RealVectorValue d_U_d_comp(0, 0, 0);
108  d_U_d_comp(comp) = _phi[_j][_qp];
109 
110  RealVectorValue convective_term = _rho[_qp] * RealVectorValue(d_U_d_comp * _grad_u_vel[_qp],
111  d_U_d_comp * _grad_v_vel[_qp],
112  d_U_d_comp * _grad_w_vel[_qp]);
113  convective_term(comp) += _rho[_qp] * U * _grad_phi[_j][_qp];
114 
115  return convective_term;
116 }
117 
118 RealVectorValue
120 {
121  return -_mu[_qp] *
122  RealVectorValue(_second_u_vel[_qp].tr(), _second_v_vel[_qp].tr(), _second_w_vel[_qp].tr());
123 }
124 
125 RealVectorValue
127 {
128  return strongViscousTermLaplace() -
129  _mu[_qp] *
130  (_second_u_vel[_qp].row(0) + _second_v_vel[_qp].row(1) + _second_w_vel[_qp].row(2));
131 }
132 
133 RealVectorValue
135 {
136  RealVectorValue viscous_term(0, 0, 0);
137  viscous_term(comp) = -_mu[_qp] * _second_phi[_j][_qp].tr();
138 
139  return viscous_term;
140 }
141 
142 RealVectorValue
144 {
145  RealVectorValue viscous_term(0, 0, 0);
146  viscous_term(comp) = -_mu[_qp] * (_second_phi[_j][_qp](0, 0) + _second_phi[_j][_qp](1, 1) +
147  _second_phi[_j][_qp](2, 2));
148  for (unsigned i = 0; i < 3; i++)
149  viscous_term(i) += -_mu[_qp] * _second_phi[_j][_qp](i, comp);
150 
151  return viscous_term;
152 }
153 
154 RealVectorValue
156 {
157  switch (comp)
158  {
159  case 0:
160  return _mu[_qp] * _grad_u_vel[_qp];
161 
162  case 1:
163  return _mu[_qp] * _grad_v_vel[_qp];
164 
165  case 2:
166  return _mu[_qp] * _grad_w_vel[_qp];
167 
168  default:
169  return _zero[_qp];
170  }
171 }
172 
173 RealVectorValue
175 {
176  switch (comp)
177  {
178  case 0:
179  {
180  RealVectorValue transpose(_grad_u_vel[_qp](0), _grad_v_vel[_qp](0), _grad_w_vel[_qp](0));
181  return _mu[_qp] * _grad_u_vel[_qp] + _mu[_qp] * transpose;
182  }
183 
184  case 1:
185  {
186  RealVectorValue transpose(_grad_u_vel[_qp](1), _grad_v_vel[_qp](1), _grad_w_vel[_qp](1));
187  return _mu[_qp] * _grad_v_vel[_qp] + _mu[_qp] * transpose;
188  }
189 
190  case 2:
191  {
192  RealVectorValue transpose(_grad_u_vel[_qp](2), _grad_v_vel[_qp](2), _grad_w_vel[_qp](2));
193  return _mu[_qp] * _grad_w_vel[_qp] + _mu[_qp] * transpose;
194  }
195 
196  default:
197  return _zero[_qp];
198  }
199 }
200 
201 RealVectorValue
203 {
204  return _mu[_qp] * _grad_phi[_j][_qp];
205 }
206 
207 RealVectorValue
209 {
210  return _mu[_qp] * _grad_phi[_j][_qp];
211 }
212 
213 RealVectorValue
215 {
216  return _grad_p[_qp];
217 }
218 
219 Real
221 {
222  return -_p[_qp];
223 }
224 
225 RealVectorValue
227 {
228  return _grad_phi[_j][_qp];
229 }
230 
231 Real
233 {
234  return -_phi[_j][_qp];
235 }
236 
237 RealVectorValue
239 {
240  return -_rho[_qp] * _gravity;
241 }
242 
243 RealVectorValue
245 {
246  return _rho[_qp] * RealVectorValue(_u_vel_dot[_qp], _v_vel_dot[_qp], _w_vel_dot[_qp]);
247 }
248 
249 RealVectorValue
251 {
252  Real base = _rho[_qp] * _phi[_j][_qp];
253  switch (comp)
254  {
255  case 0:
256  return RealVectorValue(base * _d_u_vel_dot_du[_qp], 0, 0);
257 
258  case 1:
259  return RealVectorValue(0, base * _d_v_vel_dot_dv[_qp], 0);
260 
261  case 2:
262  return RealVectorValue(0, 0, base * _d_w_vel_dot_dw[_qp]);
263 
264  default:
265  mooseError("comp must be 0, 1, or 2");
266  }
267 }
268 
269 Real
271 {
272  Real nu = _mu[_qp] / _rho[_qp];
273  RealVectorValue U(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
274  Real h = _current_elem->hmax();
275  Real transient_part = _transient_term ? 4. / (_dt * _dt) : 0.;
276  return _alpha / std::sqrt(transient_part + (2. * U.norm() / h) * (2. * U.norm() / h) +
277  9. * (4. * nu / (h * h)) * (4. * nu / (h * h)));
278 }
279 
280 Real
282 {
283  Real nu = _mu[_qp] / _rho[_qp];
284  RealVectorValue U(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
285  Real h = _current_elem->hmax();
286  Real xi;
287  if (nu < std::numeric_limits<Real>::epsilon())
288  xi = 1;
289  else
290  {
291  Real alpha = U.norm() * h / (2 * nu);
292  xi = 1. / std::tanh(alpha) - 1. / alpha;
293  }
294  return h / (2 * U.norm()) * xi;
295 }
296 
297 Real
298 INSBase::dTauDUComp(unsigned comp)
299 {
300  Real nu = _mu[_qp] / _rho[_qp];
301  RealVectorValue U(_u_vel[_qp], _v_vel[_qp], _w_vel[_qp]);
302  Real h = _current_elem->hmax();
303  Real transient_part = _transient_term ? 4. / (_dt * _dt) : 0.;
304  return -_alpha / 2. * std::pow(transient_part + (2. * U.norm() / h) * (2. * U.norm() / h) +
305  9. * (4. * nu / (h * h)) * (4. * nu / (h * h)),
306  -1.5) *
307  2. * (2. * U.norm() / h) * 2. / h * U(comp) * _phi[_j][_qp] /
308  (U.norm() + std::numeric_limits<double>::epsilon());
309 }
INSBase::gravityTerm
virtual RealVectorValue gravityTerm()
Definition: INSBase.C:238
INSBase::_second_u_vel
const VariableSecond & _second_u_vel
Definition: INSBase.h:81
validParams< INSBase >
InputParameters validParams< INSBase >()
Definition: INSBase.C:15
INSBase::strongPressureTerm
virtual RealVectorValue strongPressureTerm()
Definition: INSBase.C:214
INSBase::_d_v_vel_dot_dv
const VariableValue & _d_v_vel_dot_dv
Definition: INSBase.h:92
INSBase::_second_phi
const VariablePhiSecond & _second_phi
second derivatives of the shape function
Definition: INSBase.h:66
INSBase::_v_vel
const VariableValue & _v_vel
Definition: INSBase.h:70
INSBase::dWeakPressureDPressure
virtual Real dWeakPressureDPressure()
Definition: INSBase.C:232
INSBase::_gravity
RealVectorValue _gravity
Definition: INSBase.h:101
pow
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
Definition: ExpressionBuilder.h:673
INSBase::_w_vel_dot
const VariableValue & _w_vel_dot
Definition: INSBase.h:88
INSBase::dStrongPressureDPressure
virtual RealVectorValue dStrongPressureDPressure()
Definition: INSBase.C:226
INSBase::_d_w_vel_dot_dw
const VariableValue & _d_w_vel_dot_dw
Definition: INSBase.h:93
INSBase::dStrongViscDUCompLaplace
virtual RealVectorValue dStrongViscDUCompLaplace(unsigned comp)
Definition: INSBase.C:134
INSBase::dTimeDerivativeDUComp
virtual RealVectorValue dTimeDerivativeDUComp(unsigned comp)
Definition: INSBase.C:250
INSBase::strongViscousTermLaplace
virtual RealVectorValue strongViscousTermLaplace()
Definition: INSBase.C:119
INSBase::_v_vel_dot
const VariableValue & _v_vel_dot
Definition: INSBase.h:87
INSBase.h
INSBase::strongViscousTermTraction
virtual RealVectorValue strongViscousTermTraction()
Definition: INSBase.C:126
INSBase::tauNodal
virtual Real tauNodal()
Provides tau which yields superconvergence for 1D advection-diffusion.
Definition: INSBase.C:281
INSBase::tau
virtual Real tau()
Definition: INSBase.C:270
INSBase::_d_u_vel_dot_du
const VariableValue & _d_u_vel_dot_du
Definition: INSBase.h:91
INSBase::_second_w_vel
const VariableSecond & _second_w_vel
Definition: INSBase.h:83
INSBase::_grad_w_vel
const VariableGradient & _grad_w_vel
Definition: INSBase.h:77
INSBase::_p
const VariableValue & _p
Definition: INSBase.h:72
INSBase::convectiveTerm
virtual RealVectorValue convectiveTerm()
Definition: INSBase.C:96
INSBase::weakViscousTermTraction
virtual RealVectorValue weakViscousTermTraction(unsigned comp)
Definition: INSBase.C:174
INSBase::_rho
const MaterialProperty< Real > & _rho
Definition: INSBase.h:105
INSBase::dConvecDUComp
virtual RealVectorValue dConvecDUComp(unsigned comp)
Definition: INSBase.C:104
INSBase::_grad_p
const VariableGradient & _grad_p
Definition: INSBase.h:78
INSBase::_grad_u_vel
const VariableGradient & _grad_u_vel
Definition: INSBase.h:75
INSBase::_alpha
const Real & _alpha
Definition: INSBase.h:107
INSBase::_u_vel
const VariableValue & _u_vel
Definition: INSBase.h:69
INSBase::weakPressureTerm
virtual Real weakPressureTerm()
Definition: INSBase.C:220
INSBase::dWeakViscDUCompTraction
virtual RealVectorValue dWeakViscDUCompTraction()
Definition: INSBase.C:208
INSBase::dStrongViscDUCompTraction
virtual RealVectorValue dStrongViscDUCompTraction(unsigned comp)
Definition: INSBase.C:143
INSBase::_grad_v_vel
const VariableGradient & _grad_v_vel
Definition: INSBase.h:76
INSBase::weakViscousTermLaplace
virtual RealVectorValue weakViscousTermLaplace(unsigned comp)
Definition: INSBase.C:155
INSBase::_w_vel
const VariableValue & _w_vel
Definition: INSBase.h:71
INSBase::_transient_term
bool _transient_term
Definition: INSBase.h:110
INSBase::_second_v_vel
const VariableSecond & _second_v_vel
Definition: INSBase.h:82
INSBase::_mu
const MaterialProperty< Real > & _mu
Definition: INSBase.h:104
INSBase::_u_vel_dot
const VariableValue & _u_vel_dot
Definition: INSBase.h:86
INSBase::INSBase
INSBase(const InputParameters &parameters)
Definition: INSBase.C:45
INSBase::timeDerivativeTerm
virtual RealVectorValue timeDerivativeTerm()
Definition: INSBase.C:244
INSBase::dWeakViscDUCompLaplace
virtual RealVectorValue dWeakViscDUCompLaplace()
Definition: INSBase.C:202
INSBase::dTauDUComp
virtual Real dTauDUComp(unsigned comp)
Definition: INSBase.C:298