13#include "libmesh/nonlinear_solver.h"
22 " terms of turbulent kinetic energy (TKE).");
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.");
27 "Coupled turbulent kinetic energy dissipation rate.");
31 params.
addParam<std::vector<BoundaryName>>(
32 "walls", {},
"Boundaries that correspond to solid walls.");
36 "Boolean to determine if the problem should be use in a linear or nonlinear solve.");
37 MooseEnum wall_treatment(
"eq_newton eq_incremental eq_linearized neq",
"neq");
40 "The method used for computing the wall functions "
41 "'eq_newton', 'eq_incremental', 'eq_linearized', 'neq'");
42 params.
addParam<Real>(
"C_mu", 0.09,
"Coupled turbulent kinetic energy closure.");
43 params.
addParam<Real>(
"C_pl", 10.0,
"Production Limiter Constant Multiplier.");
44 params.
set<
unsigned short>(
"ghost_layers") = 2;
45 params.
addParam<
bool>(
"newton_solve",
false,
"Whether a Newton nonlinear solve is being used");
53 _dim(_subproblem.
mesh().dimension()),
54 _u_var(getFunctor<
ADReal>(
"u")),
55 _v_var(params.isParamValid(
"v") ? &(getFunctor<
ADReal>(
"v")) : nullptr),
56 _w_var(params.isParamValid(
"w") ? &(getFunctor<
ADReal>(
"w")) : nullptr),
57 _epsilon(getFunctor<
ADReal>(
NS::TKED)),
58 _rho(getFunctor<
ADReal>(
NS::density)),
61 _wall_boundary_names(getParam<
std::vector<BoundaryName>>(
"walls")),
62 _linearized_model(getParam<bool>(
"linearized_model")),
63 _wall_treatment(getParam<
MooseEnum>(
"wall_treatment").getEnum<
NS::WallTreatmentEnum>()),
64 _C_mu(getParam<Real>(
"C_mu")),
65 _C_pl(getParam<Real>(
"C_pl")),
66 _newton_solve(getParam<bool>(
"newton_solve"))
69 paramError(
"v",
"In two or more dimensions, the v velocity must be supplied!");
72 paramError(
"w",
"In three or more dimensions, the w velocity must be supplied!");
87 using std::max, std::sqrt, std::pow, std::min;
95 const auto old_state =
97 const auto rho =
_rho(elem_arg, state);
98 const auto mu =
_mu(elem_arg, state);
101 :
_var(elem_arg, old_state);
105 TKE = max(TKE, 1e-10);
109 std::vector<ADReal> y_plus_vec, velocity_grad_norm_vec;
111 Real tot_weight = 0.0;
115 velocity(1) = (*_v_var)(elem_arg, state);
117 velocity(2) = (*_w_var)(elem_arg, state);
122 for (
unsigned int i = 0; i < distance_vec.size(); i++)
125 velocity - velocity * face_info_vec[i]->normal() * face_info_vec[i]->normal());
126 const auto distance = distance_vec[i];
134 y_plus_vec.push_back(y_plus);
154 velocity_grad_norm_vec.push_back(velocity_grad_norm);
159 for (
unsigned int i = 0; i < y_plus_vec.size(); i++)
161 const auto y_plus = y_plus_vec[i];
163 const auto fi = face_info_vec[i];
165 const Elem *
const loc_elem = defined_on_elem_side ? &fi->elem() : fi->neighborPtr();
167 fi, Moose::FV::LimiterType::CentralDifference,
false,
false, loc_elem,
nullptr};
169 const ADReal wall_mu =
_mu(facearg, state);
171 const auto destruction_visc = 2.0 * wall_mu / Utility::pow<2>(distance_vec[i]) / tot_weight;
172 const auto destruction_log =
pow(
_C_mu, 0.75) *
rho *
pow(TKE, 0.5) /
174 const auto tau_w = (wall_mut + wall_mu) * velocity_grad_norm_vec[i];
179 destruction += destruction_visc;
181 destruction += 0 * destruction_log + 0 * tau_w;
185 destruction += destruction_log;
187 destruction += 0 * destruction_visc;
188 production += tau_w *
pow(
_C_mu, 0.25) / sqrt(TKE) /
193 residual = (destruction - production) *
_var(elem_arg, state);
196 residual += 0 *
_epsilon(elem_arg, old_state);
202 const auto rz_radial_coord =
207 production =
_mu_t(elem_arg, state) * symmetric_strain_tensor_sq_norm;
209 const auto tke_old_raw = raw_value(TKE);
210 const auto epsilon_old =
_epsilon(elem_arg, old_state);
212 if (MooseUtils::absoluteFuzzyEqual(tke_old_raw, 0))
213 destruction =
rho * epsilon_old;
215 destruction =
rho *
_var(elem_arg, state) / tke_old_raw * raw_value(epsilon_old);
218 const ADReal production_limit =
222 production = min(production, production_limit);
224 residual = destruction - production;
228 residual += 0 *
_epsilon(elem_arg, state);
DualNumber< Real, DNDerivativeType, true > ADReal
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
registerMooseObject("NavierStokesApp", INSFVTKESourceSink)
virtual const std::set< SubdomainID > & blockIDs() const
static InputParameters validParams()
MooseVariableFV< Real > & _var
const Elem *const & _current_elem
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
Computes source the sink terms for the turbulent kinetic energy.
const Real _C_mu
C_mu constant.
std::map< const Elem *, std::vector< Real > > _dist
const bool _newton_solve
For Newton solves we want to add extra zero-valued terms regardless of y-plus to avoid sparsity patte...
virtual void initialSetup() override
INSFVTKESourceSink(const InputParameters ¶meters)
const bool _linearized_model
Linearized model?
static InputParameters validParams()
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
std::unordered_set< const Elem * > _wall_bounded
const unsigned int _dim
The dimension of the domain.
const Moose::Functor< ADReal > & _u_var
x-velocity
const Moose::Functor< ADReal > * _w_var
z-velocity
const Moose::Functor< ADReal > & _rho
Density.
std::map< const Elem *, std::vector< const FaceInfo * > > _face_infos
const Moose::Functor< ADReal > & _mu_t
Turbulent dynamic viscosity.
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
ADReal computeQpResidual() override
NS::WallTreatmentEnum _wall_treatment
Method used for wall treatment.
const Moose::Functor< ADReal > & _epsilon
epsilon - dissipation rate of TKE
const Moose::Functor< ADReal > * _v_var
y-velocity
void paramError(const std::string ¶m, Args... args) const
virtual bool hasFaceSide(const FaceInfo &fi, const bool fi_elem_side) const override
FEProblemBase & _fe_problem
unsigned int getAxisymmetricRadialCoord() const
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
Moose::StateArg determineState() const
void getWallBoundedElements(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::unordered_set< const Elem * > &wall_bounded)
Map marking wall bounded elements The map passed in wall_bounded_map gets cleared and re-populated.
void getWallDistance(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::map< const Elem *, std::vector< Real > > &dist_map)
Map storing wall ditance for near-wall marked elements The map passed in dist_map gets cleared and re...
template ADReal findyPlus< ADReal >(const ADReal &mu, const ADReal &rho, const ADReal &u, Real dist)
static const std::string density
static constexpr Real von_karman_constant
static const std::string TKED
static const std::string mu_t
template ADReal computeSpeed< ADReal >(const libMesh::VectorValue< ADReal > &velocity)
static const std::string mu
template ADReal computeShearStrainRateNormSquared< ADReal >(const Moose::Functor< ADReal > &u, const Moose::Functor< ADReal > *v, const Moose::Functor< ADReal > *w, const Moose::ElemArg &elem_arg, const Moose::StateArg &state, const Moose::CoordinateSystemType coord_sys, const unsigned int rz_radial_coord)
void getElementFaceArgs(const std::vector< BoundaryName > &wall_boundary_name, const FEProblemBase &fe_problem, const SubProblem &subproblem, const std::set< SubdomainID > &block_ids, std::map< const Elem *, std::vector< const FaceInfo * > > &face_info_map)
Map storing face arguments to wall bounded faces The map passed in face_info_map gets cleared and re-...
Real distance(const Point &p)