https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFVTurbulentTemperatureWallFunction.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#include "NS.h"
13
15
18{
20
21 params.addClassDescription("Adds turbulent temperature wall function.");
22 params.addRequiredParam<MooseFunctorName>("T_w", "The wall temperature.");
23 params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
24 params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
25 params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
26 params.addRequiredParam<MooseFunctorName>(NS::density, "Density");
27 params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
28 params.addRequiredParam<MooseFunctorName>(NS::cp, "The specific heat at constant pressure.");
29 params.addParam<MooseFunctorName>(NS::kappa, "The thermal conductivity.");
30 params.addParam<MooseFunctorName>("Pr_t", 0.58, "The turbulent Prandtl number.");
31 params.addParam<MooseFunctorName>(NS::TKE, "Turbulent kinetic energy functor.");
32 params.addParam<Real>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
33 MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
34 params.addParam<MooseEnum>(
35 "wall_treatment", wall_treatment, "The method used for computing the wall functions");
36
37 params.addParam<bool>("newton_solve", false, "Whether a Newton nonlinear solve is being used");
38 params.addParamNamesToGroup("newton_solve", "Advanced");
39 return params;
40}
41
43 const InputParameters & parameters)
44 : FVFluxBC(parameters),
45 _dim(_subproblem.mesh().dimension()),
46 _T_w(getFunctor<ADReal>("T_w")),
47 _u_var(getFunctor<ADReal>("u")),
48 _v_var(parameters.isParamValid("v") ? &(getFunctor<ADReal>("v")) : nullptr),
49 _w_var(parameters.isParamValid("w") ? &(getFunctor<ADReal>("w")) : nullptr),
50 _rho(getFunctor<ADReal>(NS::density)),
51 _mu(getFunctor<ADReal>(NS::mu)),
52 _cp(getFunctor<ADReal>(NS::cp)),
53 _kappa(getFunctor<ADReal>(NS::kappa)),
54 _Pr_t(getFunctor<ADReal>("Pr_t")),
55 _k(getFunctor<ADReal>(NS::TKE)),
56 _C_mu(getParam<Real>("C_mu")),
57 _wall_treatment(getParam<MooseEnum>("wall_treatment")),
58 _newton_solve(getParam<bool>("newton_solve"))
59{
60}
61
64{
65 using std::abs, std::log, std::max, std::sqrt, std::pow, std::exp;
66
67 // Useful parameters
68 const FaceInfo & fi = *_face_info;
69 // if on an internal face (internal to the mesh, but an external boundary of the flow area),
70 // we have to select the element on which the flow variables / temperature are defined
71 const bool use_elem = (_face_type == FaceInfo::VarFaceNeighbors::ELEM);
72 const Real wall_dist = abs(
73 ((use_elem ? fi.elemCentroid() : fi.neighborCentroid()) - fi.faceCentroid()) * fi.normal());
74 const Elem * const elem_ptr = use_elem ? fi.elemPtr() : fi.neighborPtr();
75 const auto elem_arg = makeElemArg(elem_ptr);
76 const auto state = determineState();
77 const auto old_state = Moose::StateArg(1, Moose::SolutionIterationType::Nonlinear);
78 const auto mu = _mu(elem_arg, state);
79 const auto rho = _rho(elem_arg, state);
80 const auto cp = _cp(elem_arg, state);
81 const auto kappa = _kappa(elem_arg, state);
82
83 // Get the velocity vector
84 ADRealVectorValue velocity(_u_var(elem_arg, state));
85 if (_v_var)
86 velocity(1) = (*_v_var)(elem_arg, state);
87 if (_w_var)
88 velocity(2) = (*_w_var)(elem_arg, state);
89
90 // Compute the velocity and direction of the velocity component that is parallel to the wall
91 const ADReal parallel_speed =
92 NS::computeSpeed<ADReal>(velocity - velocity * (fi.normal()) * (fi.normal()));
93
94 // Computing friction velocity and y+
95 ADReal u_tau = 0, y_plus = 0;
96
97 if (_wall_treatment == "eq_newton")
98 {
99 // Full Newton-Raphson solve to find the wall quantities from the law of the wall
100 u_tau = NS::findUStar<ADReal>(mu, rho, parallel_speed, wall_dist);
101 y_plus = wall_dist * u_tau * rho / mu;
102 }
103 else if (_wall_treatment == "eq_incremental")
104 {
105 // Incremental solve on y_plus to get the near-wall quantities
106 y_plus = NS::findyPlus<ADReal>(mu, rho, max(parallel_speed, 1e-10), wall_dist);
107 u_tau = parallel_speed /
108 (log(max(NS::E_turb_constant * y_plus, 1.0 + 1e-4)) / NS::von_karman_constant);
109 }
110 else if (_wall_treatment == "eq_linearized")
111 {
112 // Linearized approximation to the wall function to find the near-wall quantities faster
113 const ADReal a_c = 1 / NS::von_karman_constant;
114 const ADReal b_c =
115 1.0 / NS::von_karman_constant * (log(NS::E_turb_constant * max(wall_dist, 1.0) / mu) + 1.0);
116 const ADReal c_c = parallel_speed;
117
118 u_tau = (-b_c + sqrt(pow(b_c, 2) + 4.0 * a_c * c_c)) / (2.0 * a_c);
119 y_plus = wall_dist * u_tau * rho / mu;
120 }
121 else if (_wall_treatment == "neq")
122 {
123 // Assign non-equilibrium wall function value
124 y_plus = wall_dist * sqrt(sqrt(_C_mu) * _k(elem_arg, old_state)) * rho / mu;
125 u_tau = parallel_speed /
126 (log(max(NS::E_turb_constant * y_plus, 1.0 + 1e-4)) / NS::von_karman_constant);
127 }
128
129 ADReal alpha;
130 if (y_plus <= 5.0) // sub-laminar layer
131 {
132 alpha = kappa / (rho * cp);
133 }
134 else if (y_plus >= 30.0) // log-layer
135 {
136 const auto Pr = cp * mu / kappa;
137 const auto Pr_ratio = Pr / _Pr_t(elem_arg, state);
138 const auto jayatilleke_P =
139 9.24 * (pow(Pr_ratio, 0.75) - 1.0) * (1.0 + 0.28 * exp(-0.007 * Pr_ratio));
140 const auto wall_scaling =
141 1.0 / NS::von_karman_constant * log(NS::E_turb_constant * y_plus) + jayatilleke_P;
142 alpha = u_tau * wall_dist / (_Pr_t(elem_arg, state) * wall_scaling);
143 }
144 else // buffer layer
145 {
146 const auto alpha_lam = kappa / (rho * cp);
147 const auto Pr = cp * mu / kappa;
148 const auto Pr_t = _Pr_t(elem_arg, state);
149 const auto Pr_ratio = Pr / Pr_t;
150 const auto jayatilleke_P =
151 9.24 * (pow(Pr_ratio, 0.75) - 1.0) * (1.0 + 0.28 * exp(-0.007 * Pr_ratio));
152 const auto wall_scaling =
153 1.0 / NS::von_karman_constant * log(NS::E_turb_constant * y_plus) + jayatilleke_P;
154 const auto alpha_turb = u_tau * wall_dist / (Pr_t * wall_scaling);
155 const auto blending_function = (y_plus - 5.0) / 25.0;
156 alpha = blending_function * alpha_turb + (1.0 - blending_function) * alpha_lam;
157 }
158
159 // To make sure new derivatives are not introduced as the solve progresses
160 if (_newton_solve)
161 alpha += 0 * kappa * (rho * cp) + 0 * u_tau * _Pr_t(elem_arg, state) * y_plus;
162
163 const auto face_arg = singleSidedFaceArg();
164 return -rho * cp * alpha * (_T_w(face_arg, state) - _var(elem_arg, state)) / wall_dist;
165}
DualNumber< Real, DNDerivativeType, true > ADReal
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const double mu
const double rho
registerADMooseObject("NavierStokesApp", INSFVTurbulentTemperatureWallFunction)
MooseVariableFV< Real > & _var
const FaceInfo * _face_info
Moose::FaceArg singleSidedFaceArg(const FaceInfo *fi=nullptr, Moose::FV::LimiterType limiter_type=Moose::FV::LimiterType::CentralDifference, bool correct_skewness=false, const Moose::StateArg *state_limiter=nullptr) const
FaceInfo::VarFaceNeighbors _face_type
static InputParameters validParams()
const Point & normal() const
const Elem * neighborPtr() const
const Elem * elemPtr() const
const Point & neighborCentroid() const
const Point & elemCentroid() const
const Point & faceCentroid() const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
This boundary condition applies a wall function for the energy equation for turbulent flows.
const Moose::Functor< ADReal > & _u_var
x-velocity
const Moose::Functor< ADReal > * _w_var
z-velocity
const bool _newton_solve
For Newton solves we want to add extra zero-valued terms regardless of y-plus to avoid sparsity patte...
const Moose::Functor< ADReal > * _v_var
y-velocity
const Moose::Functor< ADReal > & _k
Turbulent kinetic energy.
INSFVTurbulentTemperatureWallFunction(const InputParameters &parameters)
const MooseEnum _wall_treatment
Method used for wall treatment.
const Moose::Functor< ADReal > & _Pr_t
Turbulent Prandtl number near the wall.
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
const Moose::Functor< ADReal > & _kappa
Thermal conductivity.
const Moose::Functor< ADReal > & _T_w
Wall Temperature.
const Moose::Functor< ADReal > & _cp
The specific heat at constant pressure.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
Moose::StateArg determineState() const
MeshBase & mesh
template ADReal findyPlus< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
static const std::string density
Definition NS.h:34
static constexpr Real von_karman_constant
Definition NS.h:205
static const std::string cp
Definition NS.h:125
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)
static const std::string mu
Definition NS.h:127
static const std::string TKE
Definition NS.h:180
static constexpr Real E_turb_constant
Definition NS.h:206
static const std::string kappa
Definition NS.h:120
template ADReal findUStar< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, const Real dist)