https://mooseframework.inl.gov
INSBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "NS.h"
13 
16 {
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(NS::pressure, "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  params.addCoupledVar("disp_x", "The x displacement");
42  params.addCoupledVar("disp_y", "The y displacement");
43  params.addCoupledVar("disp_z", "The z displacement");
44  params.addParam<bool>("picard",
45  false,
46  "Whether we are applying a Picard strategy in which case we will linearize "
47  "the nonlinear convective term.");
48 
49  return params;
50 }
51 
52 INSBase::INSBase(const InputParameters & parameters)
53  : Kernel(parameters),
54  _second_phi(_assembly.secondPhi()),
55 
56  // Coupled variables
57  _u_vel(coupledValue("u")),
58  _v_vel(coupledValue("v")),
59  _w_vel(coupledValue("w")),
60  _p(coupledValue(NS::pressure)),
61 
62  _picard(getParam<bool>("picard")),
63  _u_vel_previous_nl(_picard ? &coupledValuePreviousNL("u") : nullptr),
64  _v_vel_previous_nl(_picard ? &coupledValuePreviousNL("v") : nullptr),
65  _w_vel_previous_nl(_picard ? &coupledValuePreviousNL("w") : nullptr),
66 
67  // Gradients
68  _grad_u_vel(coupledGradient("u")),
69  _grad_v_vel(coupledGradient("v")),
70  _grad_w_vel(coupledGradient("w")),
71  _grad_p(coupledGradient(NS::pressure)),
72 
73  // second derivative tensors
74  _second_u_vel(coupledSecond("u")),
75  _second_v_vel(coupledSecond("v")),
76  _second_w_vel(coupledSecond("w")),
77 
78  // time derivatives
79  _u_vel_dot(_is_transient ? coupledDot("u") : _zero),
80  _v_vel_dot(_is_transient ? coupledDot("v") : _zero),
81  _w_vel_dot(_is_transient ? coupledDot("w") : _zero),
82 
83  // derivatives of time derivatives
84  _d_u_vel_dot_du(_is_transient ? coupledDotDu("u") : _zero),
85  _d_v_vel_dot_dv(_is_transient ? coupledDotDu("v") : _zero),
86  _d_w_vel_dot_dw(_is_transient ? coupledDotDu("w") : _zero),
87 
88  // Variable numberings
89  _u_vel_var_number(coupled("u")),
90  _v_vel_var_number(coupled("v")),
91  _w_vel_var_number(coupled("w")),
92  _p_var_number(coupled(NS::pressure)),
93 
94  _gravity(getParam<RealVectorValue>("gravity")),
95 
96  // Material properties
97  _mu(getMaterialProperty<Real>("mu_name")),
98  _rho(getMaterialProperty<Real>("rho_name")),
99 
100  _alpha(getParam<Real>("alpha")),
101  _laplace(getParam<bool>("laplace")),
102  _convective_term(getParam<bool>("convective_term")),
103  _transient_term(getParam<bool>("transient_term")),
104 
105  // Displacements for mesh velocity for ALE simulations
106  _disps_provided(isParamValid("disp_x")),
107  _disp_x_dot(isParamValid("disp_x") ? coupledDot("disp_x") : _zero),
108  _disp_y_dot(isParamValid("disp_y") ? coupledDot("disp_y") : _zero),
109  _disp_z_dot(isParamValid("disp_z") ? coupledDot("disp_z") : _zero),
110 
111  _rz_radial_coord(_mesh.getAxisymmetricRadialCoord())
112 {
113  if (_picard && _disps_provided)
114  paramError("picard",
115  "Picard is not currently supported for ALE-type simulations in which we subtract "
116  "the mesh velocity from the velocity variables");
117 }
118 
121 {
126  if (_disps_provided)
128  return U;
129 }
130 
133 {
134  const auto U = _picard ? RealVectorValue((*_u_vel_previous_nl)[_qp],
138  return _rho[_qp] *
140 }
141 
144 {
145  if (_picard)
146  {
147  RealVectorValue U(
149  RealVectorValue convective_term;
150  convective_term(comp) = _rho[_qp] * U * _grad_phi[_j][_qp];
151 
152  return convective_term;
153  }
154  else
155  {
157  RealVectorValue d_U_d_comp(0, 0, 0);
158  d_U_d_comp(comp) = _phi[_j][_qp];
159 
160  RealVectorValue convective_term = _rho[_qp] * RealVectorValue(d_U_d_comp * _grad_u_vel[_qp],
161  d_U_d_comp * _grad_v_vel[_qp],
162  d_U_d_comp * _grad_w_vel[_qp]);
163  convective_term(comp) += _rho[_qp] * U * _grad_phi[_j][_qp];
164 
165  return convective_term;
166  }
167 }
168 
171 {
172  return -_mu[_qp] *
174 }
175 
178 {
180  _mu[_qp] *
181  (_second_u_vel[_qp].row(0) + _second_v_vel[_qp].row(1) + _second_w_vel[_qp].row(2));
182 }
183 
186 {
187  RealVectorValue viscous_term(0, 0, 0);
188  viscous_term(comp) = -_mu[_qp] * _second_phi[_j][_qp].tr();
189 
190  return viscous_term;
191 }
192 
195 {
196  RealVectorValue viscous_term(0, 0, 0);
197  viscous_term(comp) = -_mu[_qp] * (_second_phi[_j][_qp](0, 0) + _second_phi[_j][_qp](1, 1) +
198  _second_phi[_j][_qp](2, 2));
199  for (unsigned i = 0; i < 3; i++)
200  viscous_term(i) += -_mu[_qp] * _second_phi[_j][_qp](i, comp);
201 
202  return viscous_term;
203 }
204 
207 {
208  switch (comp)
209  {
210  case 0:
211  return _mu[_qp] * _grad_u_vel[_qp];
212 
213  case 1:
214  return _mu[_qp] * _grad_v_vel[_qp];
215 
216  case 2:
217  return _mu[_qp] * _grad_w_vel[_qp];
218 
219  default:
220  return _zero[_qp];
221  }
222 }
223 
226 {
227  switch (comp)
228  {
229  case 0:
230  {
231  RealVectorValue transpose(_grad_u_vel[_qp](0), _grad_v_vel[_qp](0), _grad_w_vel[_qp](0));
232  return _mu[_qp] * _grad_u_vel[_qp] + _mu[_qp] * transpose;
233  }
234 
235  case 1:
236  {
237  RealVectorValue transpose(_grad_u_vel[_qp](1), _grad_v_vel[_qp](1), _grad_w_vel[_qp](1));
238  return _mu[_qp] * _grad_v_vel[_qp] + _mu[_qp] * transpose;
239  }
240 
241  case 2:
242  {
243  RealVectorValue transpose(_grad_u_vel[_qp](2), _grad_v_vel[_qp](2), _grad_w_vel[_qp](2));
244  return _mu[_qp] * _grad_w_vel[_qp] + _mu[_qp] * transpose;
245  }
246 
247  default:
248  return _zero[_qp];
249  }
250 }
251 
254 {
255  return _mu[_qp] * _grad_phi[_j][_qp];
256 }
257 
260 {
261  return _mu[_qp] * _grad_phi[_j][_qp];
262 }
263 
266 {
267  return _grad_p[_qp];
268 }
269 
270 Real
272 {
273  return -_p[_qp];
274 }
275 
278 {
279  return _grad_phi[_j][_qp];
280 }
281 
282 Real
284 {
285  return -_phi[_j][_qp];
286 }
287 
290 {
291  return -_rho[_qp] * _gravity;
292 }
293 
296 {
298 }
299 
302 {
303  Real base = _rho[_qp] * _phi[_j][_qp];
304  switch (comp)
305  {
306  case 0:
307  return RealVectorValue(base * _d_u_vel_dot_du[_qp], 0, 0);
308 
309  case 1:
310  return RealVectorValue(0, base * _d_v_vel_dot_dv[_qp], 0);
311 
312  case 2:
313  return RealVectorValue(0, 0, base * _d_w_vel_dot_dw[_qp]);
314 
315  default:
316  mooseError("comp must be 0, 1, or 2");
317  }
318 }
319 
320 Real
322 {
323  Real nu = _mu[_qp] / _rho[_qp];
324  const auto U = relativeVelocity();
325  Real h = _current_elem->hmax();
326  Real transient_part = _transient_term ? 4. / (_dt * _dt) : 0.;
327  return _alpha / std::sqrt(transient_part + (2. * U.norm() / h) * (2. * U.norm() / h) +
328  9. * (4. * nu / (h * h)) * (4. * nu / (h * h)));
329 }
330 
331 Real
333 {
334  Real nu = _mu[_qp] / _rho[_qp];
335  const auto U = relativeVelocity();
336  Real h = _current_elem->hmax();
337  Real xi;
338  if (nu < std::numeric_limits<Real>::epsilon())
339  xi = 1;
340  else
341  {
342  Real alpha = U.norm() * h / (2 * nu);
343  xi = 1. / std::tanh(alpha) - 1. / alpha;
344  }
345  return h / (2 * U.norm()) * xi;
346 }
347 
348 Real
349 INSBase::dTauDUComp(const unsigned int comp)
350 {
351  Real nu = _mu[_qp] / _rho[_qp];
352  const auto U = relativeVelocity();
353  Real h = _current_elem->hmax();
354  Real transient_part = _transient_term ? 4. / (_dt * _dt) : 0.;
355  return -_alpha / 2. *
356  std::pow(transient_part + (2. * U.norm() / h) * (2. * U.norm() / h) +
357  9. * (4. * nu / (h * h)) * (4. * nu / (h * h)),
358  -1.5) *
359  2. * (2. * U.norm() / h) * 2. / h * U(comp) * _phi[_j][_qp] /
360  (U.norm() + std::numeric_limits<double>::epsilon());
361 }
362 
365 {
366  // To understand the code below, visit
367  // https://en.wikipedia.org/wiki/Del_in_cylindrical_and_spherical_coordinates.
368  // The u_r / r^2 term comes from the vector Laplacian. The -du_r/dr * 1/r term comes from
369  // the scalar Laplacian. The scalar Laplacian in axisymmetric cylindrical coordinates is
370  // equivalent to the Cartesian Laplacian plus a 1/r * df/dr term. And of course we are
371  // applying a minus sign here because the strong form is -\nabala^2 * \vec{u}
372 
373  const auto r = _q_point[_qp](_rz_radial_coord);
374  RealVectorValue rz_term;
375  rz_term(0) = -_mu[_qp] * _grad_u_vel[_qp](_rz_radial_coord) / r;
376  rz_term(1) = -_mu[_qp] * _grad_v_vel[_qp](_rz_radial_coord) / r;
377  mooseAssert((_rz_radial_coord == 0) || (_rz_radial_coord == 1),
378  "We expect X or Y as the possible radial coordinate");
379  if (_rz_radial_coord == 0)
380  rz_term(0) += _mu[_qp] * _u_vel[_qp] / (r * r);
381  else
382  rz_term(1) += _mu[_qp] * _v_vel[_qp] / (r * r);
383 
384  return rz_term;
385 }
386 
388 INSBase::dStrongViscDUCompLaplaceRZ(const unsigned int comp) const
389 {
390  const auto r = _q_point[_qp](_rz_radial_coord);
391  RealVectorValue add_jac;
392  add_jac(comp) = -_mu[_qp] * _grad_phi[_j][_qp](_rz_radial_coord) / r;
393  if (comp == _rz_radial_coord)
394  add_jac(comp) += _mu[_qp] * _phi[_j][_qp] / (r * r);
395 
396  return add_jac;
397 }
398 
401 {
402  auto ret = strongViscousTermLaplaceRZ();
403 
404  const auto r = _q_point[_qp](_rz_radial_coord);
405 
406  const auto & grad_r_vel = (_rz_radial_coord == 0) ? _grad_u_vel[_qp] : _grad_v_vel[_qp];
407  const auto & r_vel = (_rz_radial_coord == 0) ? _u_vel[_qp] : _v_vel[_qp];
408  ret += -_mu[_qp] * grad_r_vel / r;
409  ret(_rz_radial_coord) += _mu[_qp] * r_vel / (r * r);
410 
411  return ret;
412 }
413 
415 INSBase::dStrongViscDUCompTractionRZ(const unsigned int comp) const
416 {
417  auto ret = dStrongViscDUCompLaplaceRZ(comp);
418  if (comp != _rz_radial_coord)
419  return ret;
420 
421  const auto r = _q_point[_qp](_rz_radial_coord);
422 
423  ret += -_mu[_qp] * _grad_phi[_j][_qp] / r;
424  ret(_rz_radial_coord) += _mu[_qp] * _phi[_j][_qp] / (r * r);
425 
426  return ret;
427 }
virtual RealVectorValue strongViscousTermLaplace()
Definition: INSBase.C:170
const VariableValue & _p
Definition: INSBase.h:96
RealVectorValue dStrongViscDUCompTractionRZ(const unsigned int comp) const
Computes the Jacobian for the additional RZ terms for the Traction form of the strong viscous term fo...
Definition: INSBase.C:415
const VariableValue *const _u_vel_previous_nl
Definition: INSBase.h:99
const VariablePhiSecond & _second_phi
second derivatives of the shape function
Definition: INSBase.h:90
const VariableValue & _zero
virtual RealVectorValue dStrongViscDUCompTraction(unsigned comp)
Definition: INSBase.C:194
static InputParameters validParams()
virtual Real tau()
Definition: INSBase.C:321
RealVectorValue dStrongViscDUCompLaplaceRZ(const unsigned int comp) const
Computes the Jacobian for the additional RZ terms for the Laplace form of the strong viscous term for...
Definition: INSBase.C:388
const MaterialProperty< Real > & _rho
Definition: INSBase.h:134
virtual Real tauNodal()
Provides tau which yields superconvergence for 1D advection-diffusion.
Definition: INSBase.C:332
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const VariableValue & _u_vel
Definition: INSBase.h:93
static InputParameters validParams()
Definition: INSBase.C:15
const VariablePhiGradient & _grad_phi
const VariableValue *const _w_vel_previous_nl
Definition: INSBase.h:101
RealVectorValue relativeVelocity() const
Compute the velocity.
Definition: INSBase.C:120
const MaterialProperty< Real > & _mu
Definition: INSBase.h:133
virtual RealVectorValue dWeakViscDUCompTraction()
Definition: INSBase.C:259
virtual Real dTauDUComp(unsigned comp)
Definition: INSBase.C:349
const VariableValue *const _v_vel_previous_nl
Definition: INSBase.h:100
const VariableGradient & _grad_v_vel
Definition: INSBase.h:105
Real & _dt
const unsigned int _rz_radial_coord
The radial coordinate index for RZ coordinate systems.
Definition: INSBase.h:151
const VariableSecond & _second_u_vel
Definition: INSBase.h:110
const VariableValue & _w_vel_dot
Definition: INSBase.h:117
const VariableValue & _w_vel
Definition: INSBase.h:95
const VariableValue & _disp_x_dot
Time derivative of the x-displacement, mesh velocity in the x-direction.
Definition: INSBase.h:144
RealVectorValue strongViscousTermTractionRZ() const
Computes the additional RZ terms for the Traction form of the strong viscous term.
Definition: INSBase.C:400
const bool _picard
Definition: INSBase.h:98
virtual RealVectorValue dStrongPressureDPressure()
Definition: INSBase.C:277
const bool _disps_provided
Whether displacements are provided.
Definition: INSBase.h:142
virtual RealVectorValue timeDerivativeTerm()
Definition: INSBase.C:295
virtual RealVectorValue convectiveTerm()
Definition: INSBase.C:132
const VariableValue & _d_v_vel_dot_dv
Definition: INSBase.h:121
virtual RealVectorValue weakViscousTermTraction(unsigned comp)
Definition: INSBase.C:225
const VariableGradient & _grad_u_vel
Definition: INSBase.h:104
const VariableSecond & _second_v_vel
Definition: INSBase.h:111
virtual RealVectorValue strongPressureTerm()
Definition: INSBase.C:265
void paramError(const std::string &param, Args... args) const
virtual Real dWeakPressureDPressure()
Definition: INSBase.C:283
bool _transient_term
Definition: INSBase.h:139
const VariableValue & _disp_y_dot
Time derivative of the y-displacement, mesh velocity in the y-direction.
Definition: INSBase.h:146
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const VariableValue & _u_vel_dot
Definition: INSBase.h:115
virtual RealVectorValue dConvecDUComp(unsigned comp)
Definition: INSBase.C:143
unsigned int _j
virtual RealVectorValue dStrongViscDUCompLaplace(unsigned comp)
Definition: INSBase.C:185
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const VariableValue & _d_w_vel_dot_dw
Definition: INSBase.h:122
const VariableGradient & _grad_w_vel
Definition: INSBase.h:106
const VariableSecond & _second_w_vel
Definition: INSBase.h:112
static const std::string alpha
Definition: NS.h:134
RealVectorValue strongViscousTermLaplaceRZ() const
Computes the additional RZ terms for the Laplace form of the strong viscous term. ...
Definition: INSBase.C:364
static const std::string pressure
Definition: NS.h:56
virtual RealVectorValue gravityTerm()
Definition: INSBase.C:289
INSBase(const InputParameters &parameters)
Definition: INSBase.C:52
virtual RealVectorValue strongViscousTermTraction()
Definition: INSBase.C:177
const VariableGradient & _grad_p
Definition: INSBase.h:107
void mooseError(Args &&... args) const
virtual RealVectorValue dWeakViscDUCompLaplace()
Definition: INSBase.C:253
void addClassDescription(const std::string &doc_string)
const Elem *const & _current_elem
const VariableValue & _v_vel
Definition: INSBase.h:94
virtual RealVectorValue weakViscousTermLaplace(unsigned comp)
Definition: INSBase.C:206
RealVectorValue _gravity
Definition: INSBase.h:130
const VariablePhiValue & _phi
const VariableValue & _disp_z_dot
Time derivative of the z-displacement, mesh velocity in the z-direction.
Definition: INSBase.h:148
MooseUnits pow(const MooseUnits &, int)
virtual Real weakPressureTerm()
Definition: INSBase.C:271
const MooseArray< Point > & _q_point
unsigned int _qp
virtual RealVectorValue dTimeDerivativeDUComp(unsigned comp)
Definition: INSBase.C:301
const VariableValue & _d_u_vel_dot_du
Definition: INSBase.h:120
const VariableValue & _v_vel_dot
Definition: INSBase.h:116
const Real & _alpha
Definition: INSBase.h:136