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  const Real wall_dist = std::abs((fi.elemCentroid() - fi.faceCentroid()) * fi.normal());
59  const Elem & _current_elem = fi.elem();
60  const auto current_argument = makeElemArg(&_current_elem);
61  // Get the previous non linear iteration values
63  const auto mu = _mu(current_argument, old_state);
64  const auto rho = _rho(current_argument, old_state);
65 
66  // Get the velocity vector
67  ADRealVectorValue velocity(_u_var(current_argument, old_state));
68  if (_v_var)
69  velocity(1) = (*_v_var)(current_argument, old_state);
70  if (_w_var)
71  velocity(2) = (*_w_var)(current_argument, old_state);
72 
73  // Compute the velocity and direction of the velocity component that is parallel to the wall
74  const auto parallel_speed = NS::computeSpeed(velocity - velocity * (fi.normal()) * (fi.normal()));
75 
76  // Switch for determining the near wall quantities
77  // wall_treatment can be: "eq_newton eq_incremental eq_linearized neq"
78  ADReal y_plus;
79  ADReal mut_log; // turbulent log-layer viscosity
80  ADReal mu_wall; // total wall viscosity to obtain the shear stress at the wall
81 
83  {
84  // Full Newton-Raphson solve to find the wall quantities from the law of the wall
85  const auto u_tau = NS::findUStar(mu, rho, parallel_speed, wall_dist);
86  y_plus = wall_dist * u_tau * rho / mu;
87  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
88  mut_log = mu_wall - mu;
89  }
91  {
92  // Incremental solve on y_plus to get the near-wall quantities
93  y_plus = NS::findyPlus(mu, rho, std::max(parallel_speed, 1e-10), wall_dist);
94  mu_wall = mu * (NS::von_karman_constant * y_plus /
95  std::log(std::max(NS::E_turb_constant * y_plus, 1 + 1e-4)));
96  mut_log = mu_wall - mu;
97  }
99  {
100  // Linearized approximation to the wall function to find the near-wall quantities faster
101  const ADReal a_c = 1 / NS::von_karman_constant;
102  const ADReal b_c = 1 / NS::von_karman_constant *
103  (std::log(NS::E_turb_constant * std::max(wall_dist, 1.0) / mu) + 1.0);
104  const ADReal c_c = parallel_speed;
105 
106  const auto u_tau = (-b_c + std::sqrt(std::pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c);
107  y_plus = wall_dist * u_tau * rho / mu;
108  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
109  mut_log = mu_wall - mu;
110  }
112  {
113  // Assign non-equilibrium wall function value
114  y_plus =
115  std::pow(_C_mu, 0.25) * wall_dist * std::sqrt(_k(current_argument, old_state)) * rho / mu;
116  mu_wall = mu * (NS::von_karman_constant * y_plus /
117  std::log(std::max(NS::E_turb_constant * y_plus, 1.0 + 1e-4)));
118  mut_log = mu_wall - mu;
119  }
120  else
121  mooseAssert(false,
122  "For `INSFVTurbulentViscosityWallFunction` , wall treatment should not reach here");
123 
124  ADReal residual = 0;
125  // To keep the same sparsity pattern for all y_plus
127  residual = 0 * mut_log * y_plus;
128 
129  if (y_plus <= 5.0)
130  // sub-laminar layer
131  residual += 0.0;
132  else if (y_plus >= 30.0)
133  // log-layer
134  residual += std::max(mut_log, NS::mu_t_low_limit);
135  else
136  {
137  // buffer layer
138  const auto blending_function = (y_plus - 5.0) / 25.0;
139  // the blending depends on the mut_log at y+=30
140  const auto mut_log = mu * _mut_30;
141  residual += std::max(blending_function * mut_log, NS::mu_t_low_limit);
142  }
143  return residual;
144 }
static constexpr Real von_karman_constant
Definition: NS.h:191
static const std::string mu_t
Definition: NS.h:125
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const Elem & elem() const
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
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 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.
ADReal findyPlus(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
Finds the non-dimensional wall distance normalized with the friction velocity Implements a fixed-poin...
const Moose::Functor< ADReal > & _u_var
x-velocity
const Point & normal() const
const Real _C_mu
C_mu turbulent coefficient.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static constexpr Real E_turb_constant
Definition: NS.h:192
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
ADReal findUStar(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
Finds the friction velocity using standard velocity wall functions formulation.
const Moose::Functor< ADReal > & _rho
Density.
static constexpr Real mu_t_low_limit
Definition: NS.h:194
ADReal computeSpeed(const ADRealVectorValue &velocity)
Compute the speed (velocity norm) given the supplied velocity.
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
MooseUnits pow(const MooseUnits &, int)