https://mooseframework.inl.gov
LinearFVTurbulentViscosityWallFunctionBC.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 "NavierStokesMethods.h"
12 
14 
17 {
19  params.addClassDescription("Adds Dirichlet BC for wall values of the turbulent viscosity.");
20  params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
21  params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
22  params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
23  params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
24  params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
25  params.addParam<MooseFunctorName>("k", "The turbulent kinetic energy.");
26  params.deprecateParam("k", NS::TKE, "01/01/2025");
27  params.addParam<Real>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
28 
29  MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
30  params.addParam<MooseEnum>(
31  "wall_treatment", wall_treatment, "The method used for computing the wall functions");
32  return params;
33 }
34 
36  const InputParameters & params)
38  _dim(_subproblem.mesh().dimension()),
39  _u_var(getFunctor<Real>("u")),
40  _v_var(params.isParamValid("v") ? &(getFunctor<Real>("v")) : nullptr),
41  _w_var(params.isParamValid("w") ? &(getFunctor<Real>("w")) : nullptr),
42  _rho(getFunctor<Real>(NS::density)),
43  _mu(getFunctor<Real>(NS::mu)),
44  _k(getFunctor<Real>(NS::TKE)),
45  _C_mu(getParam<Real>("C_mu")),
46  _wall_treatment(getParam<MooseEnum>("wall_treatment").getEnum<NS::WallTreatmentEnum>())
47 {
48 }
49 
50 Real
52 {
53  // Utility functions
54  const auto wall_dist = computeCellToFaceDistance();
58  const auto re = makeElemArg(elem);
60  const auto mu = _mu(re, old_state);
61  const auto rho = _rho(re, old_state);
62 
63  // Get the velocity vector
64  RealVectorValue velocity(_u_var(re, old_state));
65  if (_v_var)
66  velocity(1) = (*_v_var)(re, old_state);
67  if (_w_var)
68  velocity(2) = (*_w_var)(re, old_state);
69 
70  // Compute the velocity and direction of the velocity component that is parallel to the wall
71  const auto parallel_speed = NS::computeSpeed<Real>(
73 
74  // Switch for determining the near wall quantities
75  // wall_treatment can be: "eq_newton eq_incremental eq_linearized neq"
76  Real y_plus = 0.0;
77  Real mu_wall = 0.0; // total wall viscosity to obtain the shear stress at the wall
78 
80  {
81  // Full Newton-Raphson solve to find the wall quantities from the law of the wall
82  const auto u_tau = NS::findUStar<Real>(mu, rho, parallel_speed, wall_dist);
83  y_plus = wall_dist * u_tau * rho / mu;
84  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
85  }
87  {
88  // Incremental solve on y_plus to get the near-wall quantities
89  y_plus = NS::findyPlus<Real>(mu, rho, std::max(parallel_speed, 1e-10), wall_dist);
90  mu_wall = mu * (NS::von_karman_constant * y_plus /
91  std::log(std::max(NS::E_turb_constant * y_plus, 1 + 1e-4)));
92  }
94  {
95  // Linearized approximation to the wall function to find the near-wall quantities faster
96  const Real a_c = 1 / NS::von_karman_constant;
97  const Real b_c = 1 / NS::von_karman_constant *
98  (std::log(NS::E_turb_constant * std::max(wall_dist, 1.0) / mu) + 1.0);
99  const Real c_c = parallel_speed;
100 
101  const auto u_tau = (-b_c + std::sqrt(std::pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c);
102  y_plus = wall_dist * u_tau * rho / mu;
103  mu_wall = rho * Utility::pow<2>(u_tau) * wall_dist / parallel_speed;
104  }
106  {
107  // Assign non-equilibrium wall function value
108  y_plus = std::pow(_C_mu, 0.25) * wall_dist * std::sqrt(_k(re, old_state)) * rho / mu;
109  mu_wall = mu * (NS::von_karman_constant * y_plus /
110  std::log(std::max(NS::E_turb_constant * y_plus, 1.0 + 1e-4)));
111  }
112  else
113  mooseAssert(false,
114  "For `INSFVTurbulentViscosityWallFunction` , wall treatment should not reach here");
115 
116  const Real mut_log = mu_wall - mu; // turbulent log-layer viscosity
117 
118  Real mu_t = 0;
119 
120  if (y_plus <= 5.0)
121  // sub-laminar layer
122  mu_t += 0.0;
123  else if (y_plus >= 30.0)
124  // log-layer
125  mu_t += std::max(mut_log, NS::mu_t_low_limit);
126  else
127  {
128  // buffer layer
129  const auto blending_function = (y_plus - 5.0) / 25.0;
130  // the blending depends on the mut_log at y+=30
131  const auto mut_log = mu * _mut_30;
132  mu_t += std::max(blending_function * mut_log, NS::mu_t_low_limit);
133  }
134  return mu_t;
135 }
136 
137 Real
139 {
140  return this->computeTurbulentViscosity();
141 }
142 
143 Real
145 {
150  return (this->computeTurbulentViscosity() - raw_value(_var(elem_arg, determineState()))) /
151  distance;
152 }
153 
154 Real
156 {
157  mooseError("We should not solve for the turbulent viscosity directly meaning that this should "
158  "contribute to neither vector nor a right hand side.");
159 }
160 
161 Real
163 {
164  mooseError("We should not solve for the turbulent viscosity directly meaning that this should "
165  "contribute to neither vector nor a right hand side.");
166 }
167 
168 Real
170 {
171  mooseError("We should not solve for the turbulent viscosity directly meaning that this should "
172  "contribute to neither vector nor a right hand side.");
173 }
174 
175 Real
177 {
178  mooseError("We should not solve for the turbulent viscosity directly meaning that this should "
179  "contribute to neither vector nor a right hand side.");
180 }
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)
Real computeCellToFaceDistance() const
Moose::StateArg determineState() const
MeshBase & mesh
static const std::string density
Definition: NS.h:33
auto raw_value(const Eigen::Map< T > &in)
static const std::string TKE
Definition: NS.h:176
WallTreatmentEnum
Wall treatment options.
Definition: NS.h:182
LinearFVTurbulentViscosityWallFunctionBC(const InputParameters &parameters)
Class constructor.
template Real findUStar< Real >(const Real &mu, const Real &rho, const Real &u, const Real dist)
Real distance(const Point &p)
void addRequiredParam(const std::string &name, const std::string &doc_string)
Class implementing a Dirichlet boundary condition for the turbulent viscosity wall function in a RANS...
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
template Real findyPlus< Real >(const Real &mu, const Real &rho, const Real &u, Real dist)
const Elem * neighborPtr() const
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
FaceInfo::VarFaceNeighbors _current_face_type
const Point & normal() const
MooseLinearVariableFV< Real > & _var
const Moose::Functor< Real > & _k
Turbulent kinetic energy.
const Elem * elemPtr() const
const Moose::Functor< Real > & _mu
Dynamic viscosity.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static constexpr Real E_turb_constant
Definition: NS.h:192
const FaceInfo * _current_face_info
const NS::WallTreatmentEnum _wall_treatment
Method used for wall treatment.
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
registerMooseObject("NavierStokesApp", LinearFVTurbulentViscosityWallFunctionBC)
static const std::string velocity
Definition: NS.h:45
template Real computeSpeed< Real >(const libMesh::VectorValue< Real > &velocity)
static constexpr Real mu_t_low_limit
Definition: NS.h:194
static InputParameters validParams()
MooseUnits pow(const MooseUnits &, int)