https://mooseframework.inl.gov
INSFVTurbulentViscosityWallFunction.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 "Function.h"
12 #include "NavierStokesMethods.h"
13 
15 
18 {
20  params.addClassDescription("Adds Dirichlet BC for wall values of the turbulent viscosity.");
21  params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
22  params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
23  params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
24  params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
25  params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
26  params.addRequiredParam<MooseFunctorName>(NS::mu_t, "The turbulent viscosity.");
27  params.addParam<MooseFunctorName>("k", "The turbulent kinetic energy.");
28  params.deprecateParam("k", NS::TKE, "01/01/2025");
29  params.addParam<Real>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
30 
31  MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
32  params.addParam<MooseEnum>(
33  "wall_treatment", wall_treatment, "The method used for computing the wall functions");
34  return params;
35 }
36 
38  const InputParameters & params)
39  : FVDirichletBCBase(params),
40  _dim(_subproblem.mesh().dimension()),
41  _u_var(getFunctor<ADReal>("u")),
42  _v_var(params.isParamValid("v") ? &(getFunctor<ADReal>("v")) : nullptr),
43  _w_var(params.isParamValid("w") ? &(getFunctor<ADReal>("w")) : nullptr),
44  _rho(getFunctor<ADReal>(NS::density)),
45  _mu(getFunctor<ADReal>(NS::mu)),
46  _mu_t(getFunctor<ADReal>(NS::mu_t)),
47  _k(getFunctor<ADReal>(NS::TKE)),
48  _C_mu(getParam<Real>("C_mu")),
49  _wall_treatment(getParam<MooseEnum>("wall_treatment").getEnum<NS::WallTreatmentEnum>()),
50  _preserve_sparsity_pattern(_fv_problem.preserveMatrixSparsityPattern())
51 {
52 }
53 
54 ADReal
56  const Moose::StateArg & /* state */) const
57 {
58  // if on an internal face (internal to the mesh, but an external boundary of the flow area),
59  // we have to select the element on which the flow variables / viscosity is defined
61  const Real wall_dist = std::abs(
62  ((use_elem ? fi.elemCentroid() : fi.neighborCentroid()) - fi.faceCentroid()) * fi.normal());
63  const Elem * const elem_ptr = use_elem ? fi.elemPtr() : fi.neighborPtr();
64  const auto elem_arg = makeElemArg(elem_ptr);
65 
66  // Get the previous non linear iteration values
68  const auto mu = _mu(elem_arg, old_state);
69  const auto rho = _rho(elem_arg, old_state);
70 
71  // Get the velocity vector
72  ADRealVectorValue velocity(_u_var(elem_arg, old_state));
73  if (_v_var)
74  velocity(1) = (*_v_var)(elem_arg, old_state);
75  if (_w_var)
76  velocity(2) = (*_w_var)(elem_arg, old_state);
77 
78  // Compute the velocity and direction of the velocity component that is parallel to the wall
79  const auto parallel_speed =
81 
82  // Switch for determining the near wall quantities
83  // wall_treatment can be: "eq_newton eq_incremental eq_linearized neq"
84  ADReal y_plus;
85  ADReal mut_log; // turbulent log-layer viscosity
86  ADReal mu_wall; // total wall viscosity to obtain the shear stress at the wall
87 
89  {
90  // Full Newton-Raphson solve to find the wall quantities from the law of the wall
91  const auto u_tau = NS::findUStar<ADReal>(mu, rho, parallel_speed, wall_dist);
92  y_plus = wall_dist * u_tau * rho / mu;
93  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
94  mut_log = mu_wall - mu;
95  }
97  {
98  // Incremental solve on y_plus to get the near-wall quantities
99  y_plus = NS::findyPlus<ADReal>(mu, rho, std::max(parallel_speed, 1e-10), wall_dist);
100  mu_wall = mu * (NS::von_karman_constant * y_plus /
101  std::log(std::max(NS::E_turb_constant * y_plus, 1 + 1e-4)));
102  mut_log = mu_wall - mu;
103  }
105  {
106  // Linearized approximation to the wall function to find the near-wall quantities faster
107  const ADReal a_c = 1 / NS::von_karman_constant;
108  const ADReal b_c = 1 / NS::von_karman_constant *
109  (std::log(NS::E_turb_constant * std::max(wall_dist, 1.0) / mu) + 1.0);
110  const ADReal c_c = parallel_speed;
111 
112  const auto u_tau = (-b_c + std::sqrt(std::pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c);
113  y_plus = wall_dist * u_tau * rho / mu;
114  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
115  mut_log = mu_wall - mu;
116  }
118  {
119  // Assign non-equilibrium wall function value
120  y_plus = std::pow(_C_mu, 0.25) * wall_dist * std::sqrt(_k(elem_arg, old_state)) * rho / mu;
121  mu_wall = mu * (NS::von_karman_constant * y_plus /
122  std::log(std::max(NS::E_turb_constant * y_plus, 1.0 + 1e-4)));
123  mut_log = mu_wall - mu;
124  }
125  else
126  mooseAssert(false,
127  "For `INSFVTurbulentViscosityWallFunction` , wall treatment should not reach here");
128 
129  ADReal residual = 0;
130  // To keep the same sparsity pattern for all y_plus
132  residual = 0 * mut_log * y_plus;
133 
134  if (y_plus <= 5.0)
135  // sub-laminar layer
136  residual += 0.0;
137  else if (y_plus >= 30.0)
138  // log-layer
139  residual += std::max(mut_log, NS::mu_t_low_limit);
140  else
141  {
142  // buffer layer
143  const auto blending_function = (y_plus - 5.0) / 25.0;
144  // the blending depends on the mut_log at y+=30
145  const auto mut_log = mu * _mut_30;
146  residual += std::max(blending_function * mut_log, NS::mu_t_low_limit);
147  }
148  return residual;
149 }
static constexpr Real von_karman_constant
Definition: NS.h:191
static const std::string mu_t
Definition: NS.h:125
const std::pair< unsigned int, unsigned int > _var_sys_numbers_pair
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const Moose::Functor< ADReal > * _v_var
y-velocity
Applies a wall function to the turbulent viscosity field.
const Point & faceCentroid() const
MeshBase & mesh
static const std::string density
Definition: NS.h:33
static const std::string TKE
Definition: NS.h:176
WallTreatmentEnum
Wall treatment options.
Definition: NS.h:182
const Moose::Functor< ADReal > * _w_var
z-velocity
const Point & neighborCentroid() const
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
INSFVTurbulentViscosityWallFunction(const InputParameters &parameters)
ADReal boundaryValue(const FaceInfo &fi, const Moose::StateArg &state) const override
const Elem * neighborPtr() const
const Point & elemCentroid() const
static InputParameters validParams()
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
static const std::string mu
Definition: NS.h:123
const Moose::Functor< ADReal > & _k
Turbulent kinetic energy.
registerMooseObject("NavierStokesApp", INSFVTurbulentViscosityWallFunction)
NS::WallTreatmentEnum _wall_treatment
Method used for wall treatment.
const Moose::Functor< ADReal > & _u_var
x-velocity
template ADReal findUStar< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, const Real dist)
const Point & normal() const
const Elem * elemPtr() const
const Real _C_mu
C_mu turbulent coefficient.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)
static constexpr Real E_turb_constant
Definition: NS.h:192
template ADReal findyPlus< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
void addClassDescription(const std::string &doc_string)
const bool _preserve_sparsity_pattern
For Newton solves we want to add extra zero-valued terms regardless of y-plus to avoid sparsity patte...
static const std::string velocity
Definition: NS.h:45
const Moose::Functor< ADReal > & _rho
Density.
static constexpr Real mu_t_low_limit
Definition: NS.h:194
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
MooseUnits pow(const MooseUnits &, int)
VarFaceNeighbors faceType(const std::pair< unsigned int, unsigned int > &var_sys) const