https://mooseframework.inl.gov
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 
11 #include "INSFVVelocityVariable.h"
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 
54 Real
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 = _u_var->adGradSln(&elem, state);
62  ADReal symmetric_strain_tensor_norm = 2.0 * Utility::pow<2>(grad_u(0));
63  if (_dim >= 2)
64  {
65  const auto & grad_v = _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 = _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  ADReal 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.value();
84 }
const VariableValue & _mixing_len
Turbulent eddy mixing length.
registerMooseObject("NavierStokesApp", INSFVMixingLengthTurbulentViscosityAux)
Moose::StateArg determineState() const
MeshBase & mesh
const INSFVVelocityVariable *const _v_var
y-velocity
DualNumber< Real, DNDerivativeType, true > ADReal
const INSFVVelocityVariable *const _w_var
z-velocity
INSFVMixingLengthTurbulentViscosityAux(const InputParameters &parameters)
void paramError(const std::string &param, Args... args) const
void addCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
const INSFVVelocityVariable *const _u_var
x-velocity
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int _dim
the dimension of the simulation
const Elem *const & _current_elem
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
const VectorValue< ADReal > & adGradSln(const Elem *const elem, const StateArg &time, bool correct_skewness=false) const override