https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
12#include "NS.h"
13#include "SystemBase.h"
14
16
19{
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)
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
62{
63 using std::sqrt;
64
65 constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
66
67 const auto face = makeCDFace(*_face_info);
68 const auto state = determineState();
69
70 const auto grad_u = _u.gradient(face, state);
71 // Compute the dot product of the strain rate tensor and the normal vector
72 // aka (grad_v + grad_v^T) * n_hat
73 ADReal norm_strain_rate = grad_u(_axis_index) * _normal(0);
74 ADRealVectorValue grad_v;
75 ADRealVectorValue grad_w;
76 if (_dim >= 2)
77 {
78 grad_v = _v->gradient(face, state);
79 norm_strain_rate += grad_v(_axis_index) * _normal(1);
80 if (_dim >= 3)
81 {
82 grad_w = _w->gradient(face, state);
83 norm_strain_rate += grad_w(_axis_index) * _normal(2);
84 }
85 }
86 const ADRealVectorValue & var_grad = _index == 0 ? grad_u : (_index == 1 ? grad_v : grad_w);
87 norm_strain_rate += var_grad * _normal;
88
89 ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
90 if (_dim >= 2)
91 {
92 symmetric_strain_tensor_norm +=
93 2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
94 if (_dim >= 3)
95 symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
96 Utility::pow<2>(grad_u(2) + grad_w(0)) +
97 Utility::pow<2>(grad_v(2) + grad_w(1));
98 }
99
100 symmetric_strain_tensor_norm = sqrt(symmetric_strain_tensor_norm + offset);
101
102 // Interpolate the mixing length to the face
103 const ADReal mixing_len = _mixing_len(face, state);
104
105 // Compute the eddy diffusivity
106 ADReal eddy_diff = symmetric_strain_tensor_norm * mixing_len * mixing_len;
107
108 const ADReal rho = _rho(face, state);
109
110 if (populate_a_coeffs)
111 {
112 if (_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
113 _face_type == FaceInfo::VarFaceNeighbors::BOTH)
114 {
115 const auto dof_number = _face_info->elem().dof_number(_sys.number(), _var.number(), 0);
116 // norm_strain_rate is a linear combination of degrees of freedom so it's safe to straight-up
117 // index into the derivatives vector at the dof we care about
118 _ae = norm_strain_rate.derivatives()[dof_number];
119 _ae *= -rho * eddy_diff;
120 }
121 if (_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR ||
122 _face_type == FaceInfo::VarFaceNeighbors::BOTH)
123 {
124 const auto dof_number = _face_info->neighbor().dof_number(_sys.number(), _var.number(), 0);
125 _an = norm_strain_rate.derivatives()[dof_number];
126 _an *= rho * eddy_diff;
127 }
128 }
129
130 // Return the turbulent stress contribution to the momentum equation
131 return -1 * rho * eddy_diff * norm_strain_rate;
132}
133
134ADReal
139
140void
142{
143 if (skipForBoundary(fi))
144 return;
145
146 _face_info = &fi;
147 _normal = fi.normal();
148 _face_type = fi.faceType(std::make_pair(_var.number(), _var.sys().number()));
149
151
152 if (_face_type == FaceInfo::VarFaceNeighbors::ELEM ||
153 _face_type == FaceInfo::VarFaceNeighbors::BOTH)
154 _rc_uo.addToA(&fi.elem(), _index, _ae * (fi.faceArea() * fi.faceCoord()));
155 if (_face_type == FaceInfo::VarFaceNeighbors::NEIGHBOR ||
156 _face_type == FaceInfo::VarFaceNeighbors::BOTH)
157 _rc_uo.addToA(fi.neighborPtr(), _index, _an * (fi.faceArea() * fi.faceCoord()));
158}
DualNumber< Real, DNDerivativeType, true > ADReal
const double rho
registerMooseObject("NavierStokesApp", INSFVMixingLengthReynoldsStress)
RealVectorValue _normal
virtual bool skipForBoundary(const FaceInfo &fi) const
MooseVariableFV< Real > & _var
const FaceInfo * _face_info
FaceInfo::VarFaceNeighbors _face_type
Moose::FaceArg makeCDFace(const FaceInfo &fi, const bool correct_skewness=false) const
const Point & normal() const
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const
const Elem & elem() const
const Elem * neighborPtr() const
Real faceArea() const
Real & faceCoord()
const Elem & neighbor() const
A flux kernel that momentum residual objects that add non-advection flux terms, or more specifically ...
static InputParameters validParams()
void addResidualAndJacobian(const ADReal &residual)
Process into either the system residual or Jacobian.
void gatherRCData(const FaceInfo &) override final
Should be a non-empty implementation if the residual object is a FVFluxKernel and introduces residual...
const Moose::Functor< ADReal > & _u
x-velocity
virtual ADReal computeSegregatedContribution() override
Compute the contribution which goes into the residual of the segregated system.
const unsigned int _dim
The dimension of the simulation.
INSFVMixingLengthReynoldsStress(const InputParameters &params)
const Moose::Functor< ADReal > & _mixing_len
Turbulent eddy mixing length.
ADReal _ae
Rhie-Chow element coefficient.
ADReal computeStrongResidual(const bool populate_a_coeffs)
Routine to compute this object's strong residual (e.g.
const Moose::Functor< ADReal > *const _v
y-velocity
const Moose::Functor< ADReal > & _rho
Density.
ADReal _an
Rhie-Chow neighbor coefficient.
const Moose::Functor< ADReal > *const _w
z-velocity
const unsigned int _index
index x|y|z
RhieChowInterpolatorBase & _rc_uo
The Rhie Chow user object that is responsible for generating face velocities for advection terms.
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void mooseError(Args &&... args) const
SystemBase & sys()
unsigned int number() const
SystemBase & _sys
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.
unsigned int number() const
Moose::StateArg determineState() const
static const std::string density
Definition NS.h:34