https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LinearFVTKEDSourceSink.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 "Assembly.h"
12#include "SubProblem.h"
13#include "NavierStokesMethods.h"
14#include "TheWarehouse.h"
18
20
23{
25 params.addClassDescription("Elemental kernel to compute the production and destruction "
26 " terms of turbulent kinetic energy dissipation (TKED).");
27 params.addRequiredParam<MooseFunctorName>("u", "The velocity in the x direction.");
28 params.addParam<MooseFunctorName>("v", "The velocity in the y direction.");
29 params.addParam<MooseFunctorName>("w", "The velocity in the z direction.");
30 params.addRequiredParam<MooseFunctorName>(NS::TKE, "Coupled turbulent kinetic energy.");
31 params.addRequiredParam<MooseFunctorName>(NS::density, "fluid density");
32 params.addRequiredParam<MooseFunctorName>(NS::mu, "Dynamic viscosity.");
33 params.addRequiredParam<MooseFunctorName>(NS::mu_t, "Turbulent viscosity.");
34
35 params.addParam<std::vector<BoundaryName>>(
36 "walls", {}, "Boundaries that correspond to solid walls.");
37 MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
38 params.addParam<MooseEnum>("wall_treatment",
39 wall_treatment,
40 "The method used for computing the wall functions "
41 "'eq_newton', 'eq_incremental', 'eq_linearized', 'neq'");
42
43 params.addParam<MooseFunctorName>("C1_eps", 1.44, "First epsilon coefficient");
44 params.addParam<MooseFunctorName>("C2_eps", 1.92, "Second epsilon coefficient");
45 params.addParam<Real>("C_mu", 0.09, "Coupled turbulent kinetic energy closure.");
46 params.addParam<Real>("C_pl", 10.0, "Production limiter constant multiplier.");
47
48 return params;
49}
50
53 _dim(_subproblem.mesh().dimension()),
54 _u_var(getFunctor<Real>("u")),
55 _v_var(params.isParamValid("v") ? &(getFunctor<Real>("v")) : nullptr),
56 _w_var(params.isParamValid("w") ? &(getFunctor<Real>("w")) : nullptr),
57 _k(getFunctor<Real>(NS::TKE)),
58 _rho(getFunctor<Real>(NS::density)),
59 _mu(getFunctor<Real>(NS::mu)),
60 _mu_t(getFunctor<Real>(NS::mu_t)),
61 _wall_boundary_names(getParam<std::vector<BoundaryName>>("walls")),
62 _wall_treatment(getParam<MooseEnum>("wall_treatment").getEnum<NS::WallTreatmentEnum>()),
63 _C1_eps(getFunctor<Real>("C1_eps")),
64 _C2_eps(getFunctor<Real>("C2_eps")),
65 _C_mu(getParam<Real>("C_mu")),
66 _C_pl(getParam<Real>("C_pl"))
67{
68 // An informational message rather than a warning, because flows without walls are valid and
69 // warnings are treated as errors in the test suite
70 if (_wall_boundary_names.empty())
71 mooseInfo("No 'walls' were specified for the turbulent kinetic energy dissipation rate. "
72 "Wall-bounded flows need 'walls' for the wall treatment of this variable, "
73 "otherwise no wall boundary condition is applied to it.");
74
75 if (_dim >= 2 && !_v_var)
76 paramError("v", "In two or more dimensions, the v velocity must be supplied!");
77
78 if (_dim >= 3 && !_w_var)
79 paramError("w", "In three or more dimensions, the w velocity must be supplied!");
80
81 // Strain tensor term requires velocity gradients;
82 if (dynamic_cast<const MooseLinearVariableFV<Real> *>(&_u_var))
83 requestVariableCellGradient(getParam<MooseFunctorName>("u"));
84 if (dynamic_cast<const MooseLinearVariableFV<Real> *>(_v_var))
85 requestVariableCellGradient(getParam<MooseFunctorName>("v"));
86 if (dynamic_cast<const MooseLinearVariableFV<Real> *>(_w_var))
87 requestVariableCellGradient(getParam<MooseFunctorName>("w"));
88}
89
90void
92{
94
95 // TKED is fixed by the wall function in wall-bounded cells, so the turbulent transport kernels
96 // of TKED must skip those cells, which requires them to know the walls as well.
97 // Kernels are registered in the warehouse under their elemental or flux system name
98 if (!_wall_boundary_names.empty())
99 {
100 std::vector<LinearFVKernel *> kernels;
101 for (const auto & system : {"LinearFVElementalKernel", "LinearFVFluxKernel"})
102 {
103 std::vector<LinearFVKernel *> system_kernels;
105 .query()
106 .condition<AttribSystem>(system)
107 .condition<AttribSysNum>(_var.sys().number())
108 .condition<AttribVar>(_var.number())
109 .condition<AttribThread>(_tid)
110 .queryInto(system_kernels);
111 kernels.insert(kernels.end(), system_kernels.begin(), system_kernels.end());
112 }
113 for (const auto kernel : kernels)
114 if ((dynamic_cast<LinearFVTurbulentAdvection *>(kernel) ||
115 dynamic_cast<LinearFVTurbulentDiffusion *>(kernel) ||
116 dynamic_cast<LinearFVTurbulentTimeDerivative *>(kernel)) &&
117 kernel->getParam<std::vector<BoundaryName>>("walls").empty())
118 kernel->paramError("walls",
119 "Walls must be specified for turbulent kernels acting on the "
120 "turbulent kinetic energy dissipation rate variable '",
121 _var.name(),
122 "' when they are specified in '",
123 name(),
124 "'. Otherwise the wall-bounded cells, whose value is set by the wall "
125 "function, are not skipped by this kernel.");
126 }
127
132}
133
134Real
136{
138 // TKED value for near wall element will be directly assigned for this cell
139 return 1.0;
140 else
141 {
142 // Convenient definitions
143 const auto state = determineState();
144 const auto elem_arg = makeElemArg(_current_elem_info->elem());
145 const Real rho = _rho(elem_arg, state);
146 const Real TKE = _k(elem_arg, state);
147 const auto epsilon = _var.getElemValue(*_current_elem_info, state);
148
149 // Compute destruction
150 const auto destruction = _C2_eps(elem_arg, state) * rho * epsilon / TKE;
151
152 // Assign to matrix (term gets multiplied by TKED)
153 return destruction * _current_elem_volume;
154 }
155}
156
157Real
159{
161 {
162 // Convenient definitions
163 const auto state = determineState();
164 const auto elem_arg = makeElemArg(_current_elem_info->elem());
165 const Real rho = _rho(elem_arg, state);
166 const Real mu = _mu(elem_arg, state);
167 const Real TKE = _k(elem_arg, state);
168
169 // Convenient variables
170 Real destruction = 0.0;
171 std::vector<Real> y_plus_vec, velocity_grad_norm_vec;
172 Real tot_weight = 0.0;
173
174 // Get velocity vector
175 RealVectorValue velocity(_u_var(elem_arg, state));
176 if (_v_var)
177 velocity(1) = (*_v_var)(elem_arg, state);
178 if (_w_var)
179 velocity(2) = (*_w_var)(elem_arg, state);
180
181 // Get near wall faceInfo and distances from cell center to every wall
182 const auto & face_info_vec = libmesh_map_find(_face_infos, _current_elem_info->elem());
183 const auto & distance_vec = libmesh_map_find(_dist, _current_elem_info->elem());
184 mooseAssert(distance_vec.size(), "Should have found a distance vector");
185 mooseAssert(distance_vec.size() == face_info_vec.size(),
186 "Should be as many distance vectors as face info vectors");
187
188 // Update y+ and wall face cell
189 for (unsigned int i = 0; i < distance_vec.size(); i++)
190 {
191 const auto distance = distance_vec[i];
192 mooseAssert(distance > 0, "Should be at a non-zero distance");
193
194 Real y_plus;
195 if (_wall_treatment == NS::WallTreatmentEnum::NEQ) // Non-equilibrium / Non-iterative
196 y_plus = distance * std::sqrt(std::sqrt(_C_mu) * TKE) * rho / mu;
197 else // Equilibrium / Iterative
198 {
199 const auto parallel_speed = NS::computeSpeed<Real>(
200 velocity - velocity * face_info_vec[i]->normal() * face_info_vec[i]->normal());
201 y_plus = NS::findyPlus<Real>(mu, rho, std::max(parallel_speed, 1e-10), distance);
202 }
203
204 y_plus_vec.push_back(y_plus);
205 tot_weight += 1.0;
206 }
207
208 // Compute near wall epsilon value
209 for (const auto i : index_range(y_plus_vec))
210 {
211 const auto y_plus = y_plus_vec[i];
212
213 if (y_plus < 11.25)
214 destruction += 2.0 * TKE * mu / rho / Utility::pow<2>(distance_vec[i]) / tot_weight;
215 else
216 destruction += std::pow(_C_mu, 0.75) * std::pow(TKE, 1.5) /
217 (NS::von_karman_constant * distance_vec[i]) / tot_weight;
218 }
219
220 // Assign the computed value of TKED for element near the wall
221 return destruction;
222 }
223 else
224 {
225 // Convenient definitions
226 const auto state = determineState();
227 const auto elem_arg = makeElemArg(_current_elem_info->elem());
228 const Real rho = _rho(elem_arg, state);
229 const Real TKE = _k(elem_arg, state);
230 const Real TKED = _var.getElemValue(*_current_elem_info, state);
231
232 // Compute production of TKE
233 const auto subdomain_id = _current_elem_info->elem()->subdomain_id();
234 const auto coord_sys = _subproblem.getCoordSystem(subdomain_id);
235 const unsigned int rz_radial_coord =
237 const auto symmetric_strain_tensor_sq_norm = NS::computeShearStrainRateNormSquared<Real>(
238 _u_var, _v_var, _w_var, elem_arg, state, coord_sys, rz_radial_coord);
239 Real production = _mu_t(elem_arg, state) * symmetric_strain_tensor_sq_norm;
240
241 // Limit TKE production (needed for flows with stagnation zones)
242 const Real production_limit = _C_pl * rho * TKED;
243 production = std::min(production, production_limit);
244
245 // Compute production - recasted with mu_t definition to avoid division by epsilon
246 const auto production_epsilon = _C1_eps(elem_arg, state) * production * TKED / TKE;
247
248 // Assign to matrix (term gets multiplied by TKED)
249 return production_epsilon * _current_elem_volume;
250 }
251}
const double mu
const double rho
registerMooseObject("NavierStokesApp", LinearFVTKEDSourceSink)
virtual const std::set< SubdomainID > & blockIDs() const
const Elem * elem() const
TheWarehouse & theWarehouse() const
Moose::ElemArg makeElemArg(const Elem *elem, bool correct_skewnewss=false) const
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)
const ElemInfo * _current_elem_info
static InputParameters validParams()
MooseLinearVariableFV< Real > & _var
void requestVariableCellGradient(const std::string &variable_name)
Kernel that adds contributions to the source and the sink of the turbulent kinetic energy dissipation...
const Moose::Functor< Real > & _u_var
x-velocity
const Moose::Functor< Real > * _w_var
z-velocity
const Moose::Functor< Real > & _C1_eps
Value of the first epsilon closure coefficient.
NS::WallTreatmentEnum _wall_treatment
Method used for wall treatment.
std::map< const Elem *, std::vector< Real > > _dist
static InputParameters validParams()
const unsigned int _dim
The dimension of the simulation.
const Moose::Functor< Real > & _C2_eps
Value of the second epsilon closure coefficient.
std::map< const Elem *, std::vector< const FaceInfo * > > _face_infos
virtual void initialSetup() override
const Moose::Functor< Real > & _mu_t
Turbulent dynamic viscosity.
const Moose::Functor< Real > & _k
Turbulent kinetic energy.
virtual Real computeMatrixContribution() override
const std::vector< BoundaryName > & _wall_boundary_names
Wall boundaries.
const Real _C_pl
Production Limiter Constant.
std::unordered_set< const Elem * > _wall_bounded
Maps for wall treatment.
virtual Real computeRightHandSideContribution() override
const Moose::Functor< Real > * _v_var
y-velocity
const Moose::Functor< Real > & _rho
Density.
LinearFVTKEDSourceSink(const InputParameters &params)
Class constructor.
const Moose::Functor< Real > & _mu
Dynamic viscosity.
const Real _C_mu
C_mu constant.
An advection kernel that implements the advection term for the turbulent variables limited for the fi...
Kernel that adds contributions from a diffusion term of the turbulent variables, limited in the near-...
Kernel that adds contributions from a time derivative term of the turbulent variables,...
const THREAD_ID _tid
FEProblemBase & _fe_problem
const std::string & name() const
void paramError(const std::string &param, Args... args) const
void mooseInfo(Args &&... args) const
Real getElemValue(const ElemInfo &elem_info, const StateArg &state) const
SystemBase & sys()
unsigned int number() const
virtual void initialSetup()
unsigned int getAxisymmetricRadialCoord() const
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
unsigned int number() const
SubProblem & _subproblem
Query query()
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...
static const std::string density
Definition NS.h:34
template Real computeSpeed< Real >(const libMesh::VectorValue< Real > &velocity)
static constexpr Real von_karman_constant
Definition NS.h:206
static const std::string mu_t
Definition NS.h:129
static const std::string mu
Definition NS.h:127
static const std::string TKE
Definition NS.h:181
template Real findyPlus< Real >(const Real &mu, const Real &rho, const Real &u, Real dist)
template Real computeShearStrainRateNormSquared< Real >(const Moose::Functor< Real > &u, const Moose::Functor< Real > *v, const Moose::Functor< Real > *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)