https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFVMixingLengthTurbulentViscosityAux.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
14
17{
19 params.addClassDescription("Computes the turbulent viscosity for the mixing length model.");
20 params.addRequiredCoupledVar("u", "The velocity in the x direction.");
21 params.addCoupledVar("v", "The velocity in the y direction.");
22 params.addCoupledVar("w", "The velocity in the z direction.");
23 params.addRequiredCoupledVar("mixing_length", "Turbulent eddy mixing length.");
24 return params;
25}
26
28 const InputParameters & params)
29 : AuxKernel(params),
30 _dim(_subproblem.mesh().dimension()),
31 _u_var(dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("u", 0))),
32 _v_var(params.isParamValid("v")
33 ? dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("v", 0))
34 : nullptr),
35 _w_var(params.isParamValid("w")
36 ? dynamic_cast<const INSFVVelocityVariable *>(getFieldVar("w", 0))
37 : nullptr),
38 _mixing_len(coupledValue("mixing_length"))
39{
40 if (!_u_var)
41 paramError("u", "the u velocity must be an INSFVVelocityVariable.");
42
43 if (_dim >= 2 && !_v_var)
44 paramError("v",
45 "In two or more dimensions, the v velocity must be supplied and it must be an "
46 "INSFVVelocityVariable.");
47
48 if (_dim >= 3 && !_w_var)
49 paramError("w",
50 "In three-dimensions, the w velocity must be supplied and it must be an "
51 "INSFVVelocityVariable.");
52}
53
54Real
56{
57 constexpr Real offset = 1e-15; // prevents explosion of sqrt(x) derivative to infinity
58 const Elem & elem = *_current_elem;
59 const auto state = determineState();
60
61 const auto grad_u = MetaPhysicL::raw_value(_u_var->adGradSln(&elem, state));
62 Real symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
63 if (_dim >= 2)
64 {
65 const auto grad_v = MetaPhysicL::raw_value(_v_var->adGradSln(&elem, state));
66 symmetric_strain_tensor_norm +=
67 2.0 * Utility::pow<2>(grad_v(1)) + Utility::pow<2>(grad_v(0) + grad_u(1));
68 if (_dim >= 3)
69 {
70 const auto grad_w = MetaPhysicL::raw_value(_w_var->adGradSln(&elem, state));
71 symmetric_strain_tensor_norm += 2.0 * Utility::pow<2>(grad_w(2)) +
72 Utility::pow<2>(grad_u(2) + grad_w(0)) +
73 Utility::pow<2>(grad_v(2) + grad_w(1));
74 }
75 }
76
77 symmetric_strain_tensor_norm = std::sqrt(symmetric_strain_tensor_norm + offset);
78
79 // Compute the eddy diffusivitiy
80 const Real eddy_diff = symmetric_strain_tensor_norm * _mixing_len[_qp] * _mixing_len[_qp];
81
82 // Return the turbulent stress contribution to the momentum equation
83 return eddy_diff;
84}
registerMooseObject("NavierStokesApp", INSFVMixingLengthTurbulentViscosityAux)
const Elem *const & _current_elem
static InputParameters validParams()
const unsigned int _dim
the dimension of the simulation
INSFVMixingLengthTurbulentViscosityAux(const InputParameters &parameters)
const INSFVVelocityVariable *const _v_var
y-velocity
const INSFVVelocityVariable *const _u_var
x-velocity
const VariableValue & _mixing_len
Turbulent eddy mixing length.
const INSFVVelocityVariable *const _w_var
z-velocity
const VectorValue< ADReal > & adGradSln(const Elem *const elem, const StateArg &time, bool correct_skewness=false) const override
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void paramError(const std::string &param, Args... args) const
Moose::StateArg determineState() const
MeshBase & mesh
auto raw_value(const Eigen::Map< T > &in)