https://mooseframework.inl.gov
INSFVMixingLengthReynoldsStress.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 
11 #include "INSFVVelocityVariable.h"
12 #include "NS.h"
13 #include "SystemBase.h"
14 
16 
19 {
21  params.addClassDescription(
22  "Computes the force due to the Reynolds stress term in the incompressible"
23  " Reynolds-averaged Navier-Stokes equations.");
24  params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
25  params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
26  params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
27  params.addRequiredParam<MooseFunctorName>(NS::density, "fluid density");
28  params.addRequiredParam<MooseFunctorName>("mixing_length", "Turbulent eddy mixing length.");
29  MooseEnum momentum_component("x=0 y=1 z=2");
31  "momentum_component",
32  momentum_component,
33  "The component of the momentum equation that this kernel applies to.");
34  // We assume the worst, e.g. we are doing Rhie-Chow. In that case we need three layers. An 'a'
35  // coefficient evaluation at a face will necessitate evaluation of *this* object at every face of
36  // the adjoining element, necessitating a face gradient evaluation at those faces, necessitating a
37  // cell gradient evaluation in neighboring elements, necessitating cell value evaluations in
38  // neighbors of those neighbor elements
39  params.set<unsigned short>("ghost_layers") = 3;
40  return params;
41 }
42 
44  : INSFVFluxKernel(params),
45  _dim(blocksMaxDimension()),
46  _axis_index(getParam<MooseEnum>("momentum_component")),
47  _u(getFunctor<ADReal>("u")),
48  _v(params.isParamValid("v") ? &getFunctor<ADReal>("v") : nullptr),
49  _w(params.isParamValid("w") ? &getFunctor<ADReal>("w") : nullptr),
50  _rho(getFunctor<ADReal>(NS::density)),
51  _mixing_len(getFunctor<ADReal>("mixing_length"))
52 {
53  if (_dim >= 2 && !_v)
54  mooseError(
55  "In two or more dimensions, the v velocity must be supplied using the 'v' parameter");
56  if (_dim >= 3 && !_w)
57  mooseError("In three dimensions, the w velocity must be supplied using the 'w' parameter");
58 }
59 
60 ADReal
62 {
63  constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
64 
65  const auto face = makeCDFace(*_face_info);
66  const auto state = determineState();
67 
68  const auto grad_u = _u.gradient(face, state);
69  // Compute the dot product of the strain rate tensor and the normal vector
70  // aka (grad_v + grad_v^T) * n_hat
71  ADReal norm_strain_rate = grad_u(_axis_index) * _normal(0);
72  ADRealVectorValue grad_v;
73  ADRealVectorValue grad_w;
74  if (_dim >= 2)
75  {
76  grad_v = _v->gradient(face, state);
77  norm_strain_rate += grad_v(_axis_index) * _normal(1);
78  if (_dim >= 3)
79  {
80  grad_w = _w->gradient(face, state);
81  norm_strain_rate += grad_w(_axis_index) * _normal(2);
82  }
83  }
84  const ADRealVectorValue & var_grad = _index == 0 ? grad_u : (_index == 1 ? grad_v : grad_w);
85  norm_strain_rate += var_grad * _normal;
86 
87  ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
88  if (_dim >= 2)
89  {
90  symmetric_strain_tensor_norm +=
91  2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
92  if (_dim >= 3)
93  symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
94  Utility::pow<2>(grad_u(2) + grad_w(0)) +
95  Utility::pow<2>(grad_v(2) + grad_w(1));
96  }
97 
98  symmetric_strain_tensor_norm = std::sqrt(symmetric_strain_tensor_norm + offset);
99 
100  // Interpolate the mixing length to the face
101  const ADReal mixing_len = _mixing_len(face, state);
102 
103  // Compute the eddy diffusivity
104  ADReal eddy_diff = symmetric_strain_tensor_norm * mixing_len * mixing_len;
105 
106  const ADReal rho = _rho(face, state);
107 
108  if (populate_a_coeffs)
109  {
112  {
113  const auto dof_number = _face_info->elem().dof_number(_sys.number(), _var.number(), 0);
114  // norm_strain_rate is a linear combination of degrees of freedom so it's safe to straight-up
115  // index into the derivatives vector at the dof we care about
116  _ae = norm_strain_rate.derivatives()[dof_number];
117  _ae *= -rho * eddy_diff;
118  }
121  {
122  const auto dof_number = _face_info->neighbor().dof_number(_sys.number(), _var.number(), 0);
123  _an = norm_strain_rate.derivatives()[dof_number];
124  _an *= rho * eddy_diff;
125  }
126  }
127 
128  // Return the turbulent stress contribution to the momentum equation
129  return -1 * rho * eddy_diff * norm_strain_rate;
130 }
131 
132 ADReal
134 {
135  return computeStrongResidual(false);
136 }
137 
138 void
140 {
141  if (skipForBoundary(fi))
142  return;
143 
144  _face_info = &fi;
145  _normal = fi.normal();
146  _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
147 
149 
152  _rc_uo.addToA(&fi.elem(), _index, _ae * (fi.faceArea() * fi.faceCoord()));
155  _rc_uo.addToA(fi.neighborPtr(), _index, _an * (fi.faceArea() * fi.faceCoord()));
156 }
A flux kernel that momentum residual objects that add non-advection flux terms, or more specifically ...
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const unsigned int _dim
The dimension of the simulation.
const Moose::Functor< ADReal > & _u
x-velocity
INSFVMixingLengthReynoldsStress(const InputParameters &params)
unsigned int number() const
const Elem & elem() const
const FaceInfo * _face_info
Moose::StateArg determineState() const
T & set(const std::string &name, bool quiet_mode=false)
ADReal _ae
Rhie-Chow element coefficient.
const unsigned int _index
index x|y|z
static const std::string density
Definition: NS.h:33
const Moose::Functor< ADReal > *const _v
y-velocity
Real & faceCoord()
RealVectorValue _normal
DualNumber< Real, DNDerivativeType, true > ADReal
Real faceArea() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObject("NavierStokesApp", INSFVMixingLengthReynoldsStress)
RhieChowInterpolatorBase & _rc_uo
The Rhie Chow user object that is responsible for generating face velocities for advection terms...
SystemBase & _sys
virtual bool skipForBoundary(const FaceInfo &fi) const
const Elem * neighborPtr() const
virtual ADReal computeSegregatedContribution() override
Compute the contribution which goes into the residual of the segregated system.
const Elem & neighbor() const
const Moose::Functor< ADReal > & _mixing_len
Turbulent eddy mixing length.
const Point & normal() const
unsigned int number() const
const unsigned int _axis_index
index x|y|z
FaceInfo::VarFaceNeighbors _face_type
ADReal _an
Rhie-Chow neighbor coefficient.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addResidualAndJacobian(const ADReal &residual)
Process into either the system residual or Jacobian.
virtual void addToA(const libMesh::Elem *elem, unsigned int component, const ADReal &value)=0
API for momentum residual objects that have on-diagonals for velocity call.
void gatherRCData(const FaceInfo &) override final
Should be a non-empty implementation if the residual object is a FVFluxKernel and introduces residual...
ADReal computeStrongResidual(const bool populate_a_coeffs)
Routine to compute this object&#39;s strong residual (e.g.
static InputParameters validParams()
void mooseError(Args &&... args) const
const Moose::Functor< ADReal > & _rho
Density.
void addClassDescription(const std::string &doc_string)
MooseVariableFV< Real > & _var
Moose::FaceArg makeCDFace(const FaceInfo &fi, const bool correct_skewness=false) const
const Moose::Functor< ADReal > *const _w
z-velocity
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const