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",
22  "add_interpolation_method_physics");
23 registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_functor_material");
24 
27 {
29  params.addClassDescription(
30  "Define a turbulence model for an incompressible or weakly-compressible Navier Stokes "
31  "flow with a linear finite volume discretization");
32 
33  params.addParam<std::vector<SolverSystemName>>(
34  "system_names",
35  {"TKE_system", "TKED_system"},
36  "Names of the linear solver systems for each equation. Default is set for K-Epsilon and "
37  "should be adapted for other models");
38 
39  // Not an option
40  params.addParam<bool>("mu_t_as_aux_variable",
41  true,
42  "Whether to use an auxiliary variable instead of a functor material "
43  "property for the turbulent viscosity");
44  params.suppressParameter<bool>("mu_t_as_aux_variable");
45  params.suppressParameter<bool>("turbulent_viscosity_two_term_bc_expansion");
46 
47  // Could be implemented when boundary conditions are implemented in turbulence physics
48  params.suppressParameter<bool>("tke_two_term_bc_expansion");
49  params.suppressParameter<bool>("tked_two_term_bc_expansion");
50 
51  // Not implemented
52  params.suppressParameter<MooseEnum>("wall_treatment_T");
53  params.suppressParameter<MooseEnum>("tke_face_interpolation");
54  params.suppressParameter<MooseEnum>("tked_face_interpolation");
55 
56  // LinearFV-specific parameters
57  params.addParam<bool>(
58  "use_nonorthogonal_correction",
59  true,
60  "Whether to use a non-orthogonal correction. This can potentially slow down convergence "
61  ", but reduces numerical dispersion on non-orthogonal meshes. Can be safely turned off on "
62  "orthogonal meshes.");
63  params.addParamNamesToGroup("use_nonorthogonal_correction", "Numerical scheme");
64  params.addParam<InterpolationMethodName>(
65  "tke_advection_interpolation_method_name",
66  "Name of an externally defined FVInterpolationMethod to use for turbulent kinetic energy "
67  "advection. When provided, this overrides 'tke_advection_interpolation'.");
68  params.addParam<InterpolationMethodName>(
69  "tked_advection_interpolation_method_name",
70  "Name of an externally defined FVInterpolationMethod to use for turbulent kinetic energy "
71  "dissipation advection. When provided, this overrides 'tked_advection_interpolation'.");
72  params.addParamNamesToGroup(
73  "tke_advection_interpolation_method_name tked_advection_interpolation_method_name",
74  "K-Epsilon model numerical");
75  return params;
76 }
77 
79  : WCNSFVTurbulencePhysicsBase(parameters)
80 {
81  addRequiredPhysicsTask("add_interpolation_method_physics");
82 
83  if (_turbulence_model != "k-epsilon")
84  errorDependentParameter("turbulence_handling", "k-epsilon", {"use_nonorthogonal_correction"});
85  if (_turbulence_model == "mixing-length")
86  paramError("turbulence_handling",
87  "Mixing length is not implemented for the linear finite volume discretization");
88 }
89 
90 void
92 {
93  if (_turbulence_model != "k-epsilon")
94  return;
95 
96  if (!isParamValid("tke_advection_interpolation_method_name"))
97  addFVAdvectedInterpolationMethod(getParam<MooseEnum>("tke_advection_interpolation"));
98  if (!isParamValid("tked_advection_interpolation_method_name"))
99  addFVAdvectedInterpolationMethod(getParam<MooseEnum>("tked_advection_interpolation"));
100 }
101 
102 void
104 {
105  if (_turbulence_model == "k-epsilon")
107 }
108 
109 void
111 {
113 
115  !_flow_equations_physics->getParam<bool>("include_deviatoric_stress"))
117  "include_deviatoric_stress", "This should be set to true when using a turbulence model");
118 }
119 
120 void
122 {
123  if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
124  return;
125  else if (_turbulence_model == "k-epsilon")
126  {
127  // Dont add if the user already defined the variable
128  // Add turbulent kinetic energy variable
129  if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ true))
130  reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
131  else if (_define_variables)
132  {
133  std::string variable_type = "MooseLinearVariableFVReal";
134 
135  auto params = getFactory().getValidParams(variable_type);
136  assignBlocks(params, _blocks);
137  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tke_name);
138 
139  getProblem().addVariable(variable_type, _tke_name, params);
140  }
141  else
142  paramError("turbulence_kinetic_energy_variable",
143  "Variable (" + _tke_name +
144  ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
145 
146  // Add turbulent kinetic energy dissipation variable
147  if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
148  reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
149  else if (_define_variables)
150  {
151  std::string variable_type = "MooseLinearVariableFVReal";
152 
153  auto params = getFactory().getValidParams(variable_type);
154  assignBlocks(params, _blocks);
155  params.set<SolverSystemName>("solver_sys") = getSolverSystem(_tked_name);
156 
157  getProblem().addVariable(variable_type, _tked_name, params);
158  }
159  else
160  paramError("turbulence_kinetic_energy_dissipation_variable",
161  "Variable (" + _tked_name +
162  ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
163  }
164 }
165 
166 void
168 {
169  if (_turbulence_model == "none")
170  return;
171 
172  // For linear FV discretization:
173  // We have to add the kernel in the flow/heat/scalar physics with mu_eff instead of two kernels
174  // one with mu, one with mu_turb, and chose one of the two to NOT have the advective term
175  // Also, flux boundary conditions would be executed twice with two kernels
176 
177  // Turbulence models with their own set of equations
178  if (_turbulence_model == "k-epsilon")
179  {
180  if (isTransient())
184  addKEpsilonSink();
185  }
186 }
187 
188 void
190 {
191  const std::string kernel_type = "LinearFVTimeDerivative";
192  InputParameters params = getFactory().getValidParams(kernel_type);
193  assignBlocks(params, _blocks);
194 
195  params.set<LinearVariableName>("variable") = _tke_name;
196  params.set<MooseFunctorName>("factor") = _flow_equations_physics->densityName();
197  if (shouldCreateTimeDerivative(_tke_name, _blocks, /*error if already defined*/ false))
198  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_time", params);
199  params.set<LinearVariableName>("variable") = _tked_name;
200  if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
201  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_time", params);
202 }
203 
204 void
206 {
207  const auto tke_method_name =
208  isParamValid("tke_advection_interpolation_method_name")
209  ? getParam<InterpolationMethodName>("tke_advection_interpolation_method_name")
210  : InterpolationMethodName(
211  std::string(getParam<MooseEnum>("tke_advection_interpolation")));
212  const auto tked_method_name =
213  isParamValid("tked_advection_interpolation_method_name")
214  ? getParam<InterpolationMethodName>("tked_advection_interpolation_method_name")
215  : InterpolationMethodName(
216  std::string(getParam<MooseEnum>("tked_advection_interpolation")));
217 
218  const std::string kernel_type = "LinearFVTurbulentAdvection";
219  InputParameters params = getFactory().getValidParams(kernel_type);
220 
221  assignBlocks(params, _blocks);
222 
223  params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
224  params.set<InterpolationMethodName>("advected_interp_method_name") = tke_method_name;
225  params.set<LinearVariableName>("variable") = _tke_name;
226  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_advection", params);
227  params.set<LinearVariableName>("variable") = _tked_name;
228  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
229  params.set<InterpolationMethodName>("advected_interp_method_name") = tked_method_name;
230  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_advection", params);
231 }
232 
233 void
235 {
236  {
237  const std::string kernel_type = "LinearFVTurbulentDiffusion";
238  InputParameters params = getFactory().getValidParams(kernel_type);
239  assignBlocks(params, _blocks);
240  params.set<bool>("use_nonorthogonal_correction") =
241  getParam<bool>("use_nonorthogonal_correction");
242 
243  // Note: we have to use a single diffusion kernel in case we have a flux BC so it is not applied
244  // twice
245  params.set<LinearVariableName>("variable") = _tke_name;
246  params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tke";
247  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
248 
249  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
250  params.set<LinearVariableName>("variable") = _tked_name;
251  params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tked";
252  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
253  }
254 }
255 
256 void
258 {
259  const std::string u_names[3] = {"u", "v", "w"};
260  {
261  const std::string kernel_type = "LinearFVTKESourceSink";
262  InputParameters params = getFactory().getValidParams(kernel_type);
263  assignBlocks(params, _blocks);
264  params.set<LinearVariableName>("variable") = _tke_name;
265  params.set<MooseFunctorName>(NS::TKED) = _tked_name;
266  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
267  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
268  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
269  params.set<Real>("C_mu") = getParam<Real>("C_mu");
270  params.set<Real>("C_pl") = getParam<Real>("C_pl");
271  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
272  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
273  for (const auto d : make_range(dimension()))
274  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
275  getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_source_sink", params);
276  }
277 
278  {
279  const std::string kernel_type = "LinearFVTKEDSourceSink";
280  InputParameters params = getFactory().getValidParams(kernel_type);
281  assignBlocks(params, _blocks);
282  params.set<LinearVariableName>("variable") = _tked_name;
283  params.set<MooseFunctorName>(NS::TKE) = _tke_name;
284  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
285  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
286  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
287  params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
288  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
289  params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
290  params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
291  params.set<Real>("C_mu") = getParam<Real>("C_mu");
292  params.set<Real>("C_pl") = getParam<Real>("C_pl");
293  for (const auto d : make_range(dimension()))
294  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
295  getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_source_sink", params);
296  }
297 }
298 
299 void
301 {
302  const std::string u_names[3] = {"u", "v", "w"};
303 
304  if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
305  {
306  mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
307  const std::string bc_type = "LinearFVTurbulentViscosityWallFunctionBC";
308  InputParameters params = getFactory().getValidParams(bc_type);
309  params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
310  params.set<LinearVariableName>("variable") = _turbulent_viscosity_name;
311  params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
312  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
313  params.set<MooseFunctorName>(NS::TKE) = _tke_name;
314  params.set<Real>("C_mu") = getParam<Real>("C_mu");
315  params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
316  for (const auto d : make_range(dimension()))
317  params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
318 
319  getProblem().addLinearFVBC(bc_type, prefix() + "turbulence_walls", params);
320  // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
321  // because it facilitates counting the number of walls, specifying energy wall functors
322  // the same way as for boundary conditions
323  }
324 }
325 
326 void
328 {
329  // Functor materials for the diffusion coefficients
330  if (_turbulence_model == "k-epsilon")
331  {
332  // Since sigma_k = 1 in the standard k-epsilon, this is often unnecessary
333  const std::string mat_type = "FunctorEffectiveDynamicViscosity";
334  InputParameters params = getFactory().getValidParams(mat_type);
335  assignBlocks(params, _blocks);
336  params.set<MooseFunctorName>("property_name") = "mu_eff_tke";
337  params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
338  params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
339  params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
340  getParam<MooseFunctorName>("sigma_k");
341  getProblem().addMaterial(mat_type, prefix() + "mu_eff_tke", params);
342 
343  params.set<MooseFunctorName>("property_name") = "mu_eff_tked";
344  params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
345  getParam<MooseFunctorName>("sigma_eps");
346  getProblem().addMaterial(mat_type, prefix() + "mu_eff_tked", params);
347  }
348 }
349 
350 unsigned short
352 {
354 }
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.
registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_interpolation_method_physics")
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 addRequiredPhysicsTask(const std::string &task)
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
void addFVAdvectedInterpolationMethod(const MooseEnum &interpolation_method)
Add the FVInterpolationMethod object for an advected interpolation method if absent.
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
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)
virtual void addFVInterpolationMethods() override
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)
bool isParamValid(const std::string &name) const
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)