https://mooseframework.inl.gov
WCNSLinearFVTurbulencePhysics.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 "WCNSFVFlowPhysics.h"
16 #include "INSFVTKESourceSink.h"
17 #include "NSFVBase.h"
18 
20 registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_functor_material");
21 
24 {
26  params.addClassDescription(
27  "Define a turbulence model for an incompressible or weakly-compressible Navier Stokes "
28  "flow with a linear finite volume discretization");
29 
30  params.addParam<std::vector<SolverSystemName>>(
31  "system_names",
32  {"TKE_system", "TKED_system"},
33  "Names of the linear solver systems for each equation. Default is set for K-Epsilon and "
34  "should be adapted for other models");
35 
36  // Not an option
37  params.addParam<bool>("mu_t_as_aux_variable",
38  true,
39  "Whether to use an auxiliary variable instead of a functor material "
40  "property for the turbulent viscosity");
41  params.suppressParameter<bool>("mu_t_as_aux_variable");
42  params.suppressParameter<bool>("turbulent_viscosity_two_term_bc_expansion");
43 
44  // Could be implemented when boundary conditions are implemented in turbulence physics
45  params.suppressParameter<bool>("tke_two_term_bc_expansion");
46  params.suppressParameter<bool>("tked_two_term_bc_expansion");
47 
48  // Not implemented
49  params.suppressParameter<MooseEnum>("wall_treatment_T");
50  params.suppressParameter<MooseEnum>("tke_face_interpolation");
51  params.suppressParameter<MooseEnum>("tked_face_interpolation");
52 
53  // LinearFV-specific parameters
54  params.addParam<bool>(
55  "use_nonorthogonal_correction",
56  true,
57  "Whether to use a non-orthogonal correction. This can potentially slow down convergence "
58  ", but reduces numerical dispersion on non-orthogonal meshes. Can be safely turned off on "
59  "orthogonal meshes.");
60  params.addParamNamesToGroup("use_nonorthogonal_correction", "Numerical scheme");
61  return params;
62 }
63 
65  : WCNSFVTurbulencePhysicsBase(parameters)
66 {
67  if (_turbulence_model != "k-epsilon")
68  errorDependentParameter("turbulence_handling", "k-epsilon", {"use_nonorthogonal_correction"});
69  if (_turbulence_model == "mixing-length")
70  paramError("turbulence_handling",
71  "Mixing length is not implemented for the linear finite volume discretization");
72 }
73 
74 void
76 {
77  if (_turbulence_model == "k-epsilon")
79 }
80 
81 void
83 {
85 
87  !_flow_equations_physics->getParam<bool>("include_deviatoric_stress"))
89  "include_deviatoric_stress", "This should be set to true when using a turbulence model");
90 }
91 
92 void
94 {
95  if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
96  return;
97  else if (_turbulence_model == "k-epsilon")
98  {
99  // Dont add if the user already defined the variable
100  // Add turbulent kinetic energy variable
101  if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ true))
102  reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
103  else if (_define_variables)
104  {
105  std::string variable_type = "MooseLinearVariableFVReal";
106 
107  auto params = getFactory().getValidParams(variable_type);
108  assignBlocks(params, _blocks);
109  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tke_name);
110 
111  getProblem().addVariable(variable_type, _tke_name, params);
112  }
113  else
114  paramError("turbulence_kinetic_energy_variable",
115  "Variable (" + _tke_name +
116  ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
117 
118  // Add turbulent kinetic energy dissipation variable
119  if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
120  reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
121  else if (_define_variables)
122  {
123  std::string variable_type = "MooseLinearVariableFVReal";
124 
125  auto params = getFactory().getValidParams(variable_type);
126  assignBlocks(params, _blocks);
127  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tked_name);
128 
129  getProblem().addVariable(variable_type, _tked_name, params);
130  }
131  else
132  paramError("turbulence_kinetic_energy_dissipation_variable",
133  "Variable (" + _tked_name +
134  ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
135  }
136 }
137 
138 void
140 {
141  if (_turbulence_model == "none")
142  return;
143 
144  // For linear FV discretization:
145  // We have to add the kernel in the flow/heat/scalar physics with mu_eff instead of two kernels
146  // one with mu, one with mu_turb, and chose one of the two to NOT have the advective term
147  // Also, flux boundary conditions would be executed twice with two kernels
148 
149  // Turbulence models with their own set of equations
150  if (_turbulence_model == "k-epsilon")
151  {
152  if (isTransient())
156  addKEpsilonSink();
157  }
158 }
159 
160 void
162 {
163  const std::string kernel_type = "LinearFVTimeDerivative";
164  InputParameters params = getFactory().getValidParams(kernel_type);
165  assignBlocks(params, _blocks);
166 
167  params.set<LinearVariableName>("variable") = _tke_name;
168  params.set<MooseFunctorName>("factor") = _flow_equations_physics->densityName();
169  if (shouldCreateTimeDerivative(_tke_name, _blocks, /*error if already defined*/ false))
170  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_time", params);
171  params.set<LinearVariableName>("variable") = _tked_name;
172  if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
173  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_time", params);
174 }
175 
176 void
178 {
179  const std::string kernel_type = "LinearFVTurbulentAdvection";
180  InputParameters params = getFactory().getValidParams(kernel_type);
181 
182  assignBlocks(params, _blocks);
183 
184  params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
185  params.set<MooseEnum>("advected_interp_method") =
186  getParam<MooseEnum>("tke_advection_interpolation");
187  params.set<LinearVariableName>("variable") = _tke_name;
188  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_advection", params);
189  params.set<LinearVariableName>("variable") = _tked_name;
190  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
191  params.set<MooseEnum>("advected_interp_method") =
192  getParam<MooseEnum>("tked_advection_interpolation");
193  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_advection", params);
194 }
195 
196 void
198 {
199  {
200  const std::string kernel_type = "LinearFVTurbulentDiffusion";
201  InputParameters params = getFactory().getValidParams(kernel_type);
202  assignBlocks(params, _blocks);
203  params.set<bool>("use_nonorthogonal_correction") =
204  getParam<bool>("use_nonorthogonal_correction");
205 
206  // Note: we have to use a single diffusion kernel in case we have a flux BC so it is not applied
207  // twice
208  params.set<LinearVariableName>("variable") = _tke_name;
209  params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tke";
210  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
211 
212  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
213  params.set<LinearVariableName>("variable") = _tked_name;
214  params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tked";
215  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
216  }
217 }
218 
219 void
221 {
222  const std::string u_names[3] = {"u", "v", "w"};
223  {
224  const std::string kernel_type = "LinearFVTKESourceSink";
225  InputParameters params = getFactory().getValidParams(kernel_type);
226  assignBlocks(params, _blocks);
227  params.set<LinearVariableName>("variable") = _tke_name;
228  params.set<MooseFunctorName>(NS::TKED) = _tked_name;
229  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
230  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
231  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
232  params.set<Real>("C_mu") = getParam<Real>("C_mu");
233  params.set<Real>("C_pl") = getParam<Real>("C_pl");
234  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
235  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
236  for (const auto d : make_range(dimension()))
237  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
238  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_source_sink", params);
239  }
240 
241  {
242  const std::string kernel_type = "LinearFVTKEDSourceSink";
243  InputParameters params = getFactory().getValidParams(kernel_type);
244  assignBlocks(params, _blocks);
245  params.set<LinearVariableName>("variable") = _tked_name;
246  params.set<MooseFunctorName>(NS::TKE) = _tke_name;
247  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
248  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
249  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
250  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
251  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
252  params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
253  params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
254  params.set<Real>("C_mu") = getParam<Real>("C_mu");
255  params.set<Real>("C_pl") = getParam<Real>("C_pl");
256  for (const auto d : make_range(dimension()))
257  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
258  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_source_sink", params);
259  }
260 }
261 
262 void
264 {
265  const std::string u_names[3] = {"u", "v", "w"};
266 
267  if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
268  {
269  mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
270  const std::string bc_type = "LinearFVTurbulentViscosityWallFunctionBC";
271  InputParameters params = getFactory().getValidParams(bc_type);
272  params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
273  params.set<LinearVariableName>("variable") = _turbulent_viscosity_name;
274  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
275  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
276  params.set<MooseFunctorName>(NS::TKE) = _tke_name;
277  params.set<Real>("C_mu") = getParam<Real>("C_mu");
278  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
279  for (const auto d : make_range(dimension()))
280  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
281 
282  getProblem().addLinearFVBC(bc_type, prefix() + "turbulence_walls", params);
283  // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
284  // because it facilitates counting the number of walls, specifying energy wall functors
285  // the same way as for boundary conditions
286  }
287 }
288 
289 void
291 {
292  // Functor materials for the diffusion coefficients
293  if (_turbulence_model == "k-epsilon")
294  {
295  // Since sigma_k = 1 in the standard k-epsilon, this is often unnecessary
296  const std::string mat_type = "FunctorEffectiveDynamicViscosity";
297  InputParameters params = getFactory().getValidParams(mat_type);
298  assignBlocks(params, _blocks);
299  params.set<MooseFunctorName>("property_name") = "mu_eff_tke";
300  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
301  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
302  params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
303  getParam<MooseFunctorName>("sigma_k");
304  getProblem().addMaterial(mat_type, prefix() + "mu_eff_tke", params);
305 
306  params.set<MooseFunctorName>("property_name") = "mu_eff_tked";
307  params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
308  getParam<MooseFunctorName>("sigma_eps");
309  getProblem().addMaterial(mat_type, prefix() + "mu_eff_tked", params);
310  }
311 }
312 
313 unsigned short
315 {
317 }
std::string prefix() const
const VariableName _turbulent_viscosity_name
Name of the turbulence viscosity auxiliary variable (or property)
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
Base class for a Physics that creates all the objects needed to add a turbulence model to an incompre...
static const std::string mu_t
Definition: NS.h:129
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
const MooseFunctorName & dynamicViscosityName() const
Return the name of the dynamic viscosity functor.
Factory & getFactory()
void paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const VariableName _tked_name
Name of the turbulent kinetic energy dissipation.
virtual void checkIntegrity() const
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
T & set(const std::string &name, bool quiet_mode=false)
static const std::string density
Definition: NS.h:34
InputParameters getValidParams(const std::string &name) const
static const std::string TKE
Definition: NS.h:180
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
void addKEpsilonTimeDerivatives()
Functions adding kernels for the k-epsilon to the k-epsilon equations.
WCNSLinearFVTurbulencePhysics(const InputParameters &parameters)
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_functor_material")
const MooseEnum _turbulence_model
Turbulence model to create the equation(s) for.
virtual void checkIntegrity() const override
std::vector< SubdomainName > _blocks
unsigned int dimension() const
const MooseFunctorName & densityName() const
Return the name of the density functor.
void suppressParameter(const std::string &name)
std::vector< BoundaryName > _turbulence_walls
List of boundaries to act as walls for turbulence models.
void errorDependentParameter(const std::string &param1, const std::string &value_not_set, const std::vector< std::string > &dependent_params) const
registerWCNSFVTurbulenceBaseTasks("NavierStokesApp", WCNSLinearFVTurbulencePhysics)
virtual void initializePhysicsAdditional() override
virtual FEProblemBase & getProblem()
Creates all the objects needed to add a turbulence model to an incompressible / weakly-compressible N...
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
static const std::string mu
Definition: NS.h:127
const VariableName _tke_name
Name of the turbulent kinetic energy.
void needSolutionState(unsigned int oldest_needed, Moose::SolutionIterationType iteration_type)
virtual void addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
bool _define_variables
Whether to define variables if they do not exist.
const std::vector< std::string > _velocity_names
Velocity names.
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
IntRange< T > make_range(T beg, T end)
static const std::string TKED
Definition: NS.h:181
void addClassDescription(const std::string &doc_string)
void paramWarning(const std::string &param, Args... args) const
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
static InputParameters validParams()
MooseEnum _wall_treatment_eps
Turbulence wall treatment for epsilon (same for all walls currently)
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
bool isTransient() const
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)