https://mooseframework.inl.gov
Loading...
Searching...
No Matches
INSFVTKEDSourceSink.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
10#include "INSFVTKEDSourceSink.h"
11#include "NonlinearSystemBase.h"
12#include "NavierStokesMethods.h"
13#include "libmesh/nonlinear_solver.h"
14
16
19{
21 params.addClassDescription("Elemental kernel to compute the production and destruction "
22 " terms of turbulent kinetic energy dissipation (TKED).");
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::TKE, "Coupled turbulent kinetic energy.");
27 params.addRequiredParam<MooseFunctorName>(NS::density, "fluid density");
28 params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
29 params.addRequiredParam<MooseFunctorName>(NS::mu_t, "Turbulent viscosity.");
30 params.addParam<std::vector<BoundaryName>>(
31 "walls", {}, "Boundaries that correspond to solid walls.");
32 params.addParam<bool>(
33 "linearized_model",
34 true,
35 "Boolean to determine if the problem should be used in a linear or nonlinear solve");
36 MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
37 params.addParam<MooseEnum>("wall_treatment",
38 wall_treatment,
39 "The method used for computing the wall functions "
40 "'eq_newton', 'eq_incremental', 'eq_linearized', 'neq'");
41 params.addParam<MooseFunctorName>("C1_eps", 1.44, "First epsilon coefficient");
42 params.addParam<MooseFunctorName>("C2_eps", 1.92, "Second epsilon coefficient");
43 params.addParam<Real>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
44 params.addParam<Real>("C_pl", 10.0, "Production limiter constant multiplier.");
45 params.set<unsigned short>("ghost_layers") = 2;
46 params.addParam<bool>("newton_solve", false, "Whether a Newton nonlinear solve is being used");
47 params.addParamNamesToGroup("newton_solve", "Advanced");
48 return params;
49}
50
52 : FVElementalKernel(params),
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 _k(getFunctor<ADReal>(NS::TKE)),
58 _rho(getFunctor<ADReal>(NS::density)),
59 _mu(getFunctor<ADReal>(NS::mu)),
60 _mu_t(getFunctor<ADReal>(NS::mu_t)),
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 _C1_eps(getFunctor<ADReal>("C1_eps")),
65 _C2_eps(getFunctor<ADReal>("C2_eps")),
66 _C_mu(getParam<Real>("C_mu")),
67 _C_pl(getParam<Real>("C_pl")),
68 _newton_solve(getParam<bool>("newton_solve"))
69{
70 if (_dim >= 2 && !_v_var)
71 paramError("v", "In two or more dimensions, the v velocity must be supplied!");
72
73 if (_dim >= 3 && !_w_var)
74 paramError("w", "In three or more dimensions, the w velocity must be supplied!");
75}
76
77void
85
88{
89 using std::max, std::sqrt, std::pow, std::min;
90
91 ADReal residual = 0.0;
92 ADReal production = 0.0;
93 ADReal destruction = 0.0;
94 const auto elem_arg = makeElemArg(_current_elem);
95 const auto state = determineState();
96 const auto old_state =
97 _linearized_model ? Moose::StateArg(1, Moose::SolutionIterationType::Nonlinear) : state;
98 const auto mu = _mu(elem_arg, state);
99 const auto rho = _rho(elem_arg, state);
100 const auto TKE_old =
101 _newton_solve ? max(_k(elem_arg, old_state), 1e-10) : _k(elem_arg, old_state);
102 ADReal y_plus;
103
104 if (_wall_bounded.find(_current_elem) != _wall_bounded.end())
105 {
106 std::vector<ADReal> y_plus_vec;
107
108 Real tot_weight = 0.0;
109
110 ADRealVectorValue velocity(_u_var(elem_arg, state));
111 if (_v_var)
112 velocity(1) = (*_v_var)(elem_arg, state);
113 if (_w_var)
114 velocity(2) = (*_w_var)(elem_arg, state);
115
116 const auto & face_info_vec = libmesh_map_find(_face_infos, _current_elem);
117 const auto & distance_vec = libmesh_map_find(_dist, _current_elem);
118 mooseAssert(distance_vec.size(), "Should have found a distance vector");
119 mooseAssert(distance_vec.size() == face_info_vec.size(),
120 "Should be as many distance vectors as face info vectors");
121
122 for (unsigned int i = 0; i < distance_vec.size(); i++)
123 {
124 const auto distance = distance_vec[i];
125 mooseAssert(distance > 0, "Should be at a non-zero distance");
126
127 if (_wall_treatment == NS::WallTreatmentEnum::NEQ) // Non-equilibrium / Non-iterative
128 y_plus = distance * sqrt(sqrt(_C_mu) * TKE_old) * rho / mu;
129 else
130 {
131 // Equilibrium / Iterative
132 const auto parallel_speed = NS::computeSpeed<ADReal>(
133 velocity - velocity * face_info_vec[i]->normal() * face_info_vec[i]->normal());
134
135 y_plus = NS::findyPlus<ADReal>(mu, rho, max(parallel_speed, 1e-10), distance);
136 }
137
138 y_plus_vec.push_back(y_plus);
139
140 tot_weight += 1.0;
141 }
142
143 for (const auto i : index_range(y_plus_vec))
144 {
145 const auto y_plus = y_plus_vec[i];
146
147 if (y_plus < 11.25)
148 {
149 const auto fi = face_info_vec[i];
150 const bool defined_on_elem_side = _var.hasFaceSide(*fi, true);
151 const Elem * const loc_elem = defined_on_elem_side ? &fi->elem() : fi->neighborPtr();
152 const Moose::FaceArg facearg = {
153 fi, Moose::FV::LimiterType::CentralDifference, false, false, loc_elem, nullptr};
154 destruction += 2.0 * TKE_old * _mu(facearg, state) / rho /
155 Utility::pow<2>(distance_vec[i]) / tot_weight;
156 }
157 else
158 destruction += pow(_C_mu, 0.75) * pow(TKE_old, 1.5) /
159 (NS::von_karman_constant * distance_vec[i]) / tot_weight;
160 }
161
162 residual = _var(makeElemArg(_current_elem), state) - destruction;
163 }
164 else
165 {
166 const auto subdomain_id = _current_elem->subdomain_id();
167 const auto coord_sys = _subproblem.getCoordSystem(subdomain_id);
168 const auto rz_radial_coord =
170 const auto symmetric_strain_tensor_sq_norm = NS::computeShearStrainRateNormSquared<ADReal>(
171 _u_var, _v_var, _w_var, elem_arg, state, coord_sys, rz_radial_coord);
172
173 ADReal production_k = _mu_t(elem_arg, state) * symmetric_strain_tensor_sq_norm;
174 // Compute production limiter (needed for flows with stagnation zones)
175 const auto eps_old =
176 _newton_solve ? max(_var(elem_arg, old_state), 1e-10) : _var(elem_arg, old_state);
177 const ADReal production_limit = _C_pl * rho * eps_old;
178 // Apply production limiter
179 production_k = min(production_k, production_limit);
180
181 const auto time_scale = raw_value(TKE_old) / raw_value(eps_old);
182 production = _C1_eps(elem_arg, state) * production_k / time_scale;
183 destruction = _C2_eps(elem_arg, state) * rho * _var(elem_arg, state) / time_scale;
184
185 residual = destruction - production;
186 }
187
188 return residual;
189}
DualNumber< Real, DNDerivativeType, true > ADReal
ExpressionBuilder::EBTerm pow(const ExpressionBuilder::EBTerm &left, T exponent)
const double mu
const double rho
registerMooseObject("NavierStokesApp", INSFVTKEDSourceSink)
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 the source and sink terms for the turbulent kinetic energy dissipation rate.
std::map< const Elem *, std::vector< const FaceInfo * > > _face_infos
INSFVTKEDSourceSink(const InputParameters &parameters)
virtual void initialSetup() override
const Moose::Functor< ADReal > & _C2_eps
Value of the second epsilon closure coefficient.
const Moose::Functor< ADReal > & _C1_eps
Value of the first epsilon closure coefficient.
const Moose::Functor< ADReal > & _mu
Dynamic viscosity.
std::unordered_set< const Elem * > _wall_bounded
Maps for wall treatment.
const Moose::Functor< ADReal > * _v_var
y-velocity
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
static InputParameters validParams()
const Moose::Functor< ADReal > & _u_var
x-velocity
const bool _linearized_model
If the user wants to use the linearized model.
const Moose::Functor< ADReal > & _k
Turbulent kinetic energy.
const bool _newton_solve
Whether a nonlinear Newton-like solver is being used (as opposed to a linearized solver)
const Moose::Functor< ADReal > * _w_var
z-velocity
std::map< const Elem *, std::vector< Real > > _dist
NS::WallTreatmentEnum _wall_treatment
Method used for wall treatment.
ADReal computeQpResidual() override
const Real _C_mu
C_mu constant.
const Moose::Functor< ADReal > & _mu_t
Turbulent dynamic viscosity.
const Moose::Functor< ADReal > & _rho
Density.
const unsigned int _dim
The dimension of the simulation.
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)
T & set(const std::string &name, bool quiet_mode=false)
void paramError(const std::string &param, Args... args) const
virtual bool hasFaceSide(const FaceInfo &fi, const bool fi_elem_side) const override
SubProblem & _subproblem
FEProblemBase & _fe_problem
unsigned int getAxisymmetricRadialCoord() const
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
Moose::StateArg determineState() const
MeshBase & mesh
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
Definition NS.h:34
static constexpr Real von_karman_constant
Definition NS.h:205
static const std::string mu_t
Definition NS.h:129
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
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)