https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
20registerMooseAction("NavierStokesApp",
22 "add_interpolation_method_physics");
23registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_functor_material");
24
27{
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'.");
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
85 "porous_medium_treatment",
86 "The porous medium treatment is not implemented for the linear turbulence physics");
87 if (_turbulence_model != "k-epsilon")
88 errorDependentParameter("turbulence_handling", "k-epsilon", {"use_nonorthogonal_correction"});
89 if (_turbulence_model == "mixing-length")
90 paramError("turbulence_handling",
91 "Mixing length is not implemented for the linear finite volume discretization");
92}
93
94void
96{
97 if (_turbulence_model != "k-epsilon")
98 return;
99
100 if (!isParamValid("tke_advection_interpolation_method_name"))
101 addFVAdvectedInterpolationMethod(getParam<MooseEnum>("tke_advection_interpolation"));
102 if (!isParamValid("tked_advection_interpolation_method_name"))
103 addFVAdvectedInterpolationMethod(getParam<MooseEnum>("tked_advection_interpolation"));
104}
105
106void
108{
109 if (_turbulence_model == "k-epsilon")
110 getProblem().needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
111}
112
113void
115{
117
119 !_flow_equations_physics->getParam<bool>("include_deviatoric_stress"))
121 "include_deviatoric_stress", "This should be set to true when using a turbulence model");
122}
123
124void
126{
127 if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
128 return;
129 else if (_turbulence_model == "k-epsilon")
130 {
131 // Dont add if the user already defined the variable
132 // Add turbulent kinetic energy variable
133 if (!shouldCreateVariable(_tke_name, _blocks, /*error if aux*/ true))
134 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
135 else if (_define_variables)
136 {
137 std::string variable_type = "MooseLinearVariableFVReal";
138
139 auto params = getFactory().getValidParams(variable_type);
140
141 addSharedSolverVariable(variable_type, _tke_name, params);
142 }
143 else
144 paramError("turbulence_kinetic_energy_variable",
145 "Variable (" + _tke_name +
146 ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
147
148 // Add turbulent kinetic energy dissipation variable
149 if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
150 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
151 else if (_define_variables)
152 {
153 std::string variable_type = "MooseLinearVariableFVReal";
154
155 auto params = getFactory().getValidParams(variable_type);
156
157 addSharedSolverVariable(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
166void
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())
185 }
186}
187
188void
190{
191 const std::string kernel_type = "LinearFVTurbulentTimeDerivative";
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 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
201 if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
202 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_time", params);
203}
204
205void
207{
208 const auto tke_method_name =
209 isParamValid("tke_advection_interpolation_method_name")
210 ? getParam<InterpolationMethodName>("tke_advection_interpolation_method_name")
211 : InterpolationMethodName(
212 std::string(getParam<MooseEnum>("tke_advection_interpolation")));
213 const auto tked_method_name =
214 isParamValid("tked_advection_interpolation_method_name")
215 ? getParam<InterpolationMethodName>("tked_advection_interpolation_method_name")
216 : InterpolationMethodName(
217 std::string(getParam<MooseEnum>("tked_advection_interpolation")));
218
219 const std::string kernel_type = "LinearFVTurbulentAdvection";
220 InputParameters params = getFactory().getValidParams(kernel_type);
221
222 assignBlocks(params, _blocks);
223
224 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
225 params.set<InterpolationMethodName>("advected_interp_method_name") = tke_method_name;
226 params.set<LinearVariableName>("variable") = _tke_name;
227 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_advection", params);
228 params.set<LinearVariableName>("variable") = _tked_name;
229 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
230 params.set<InterpolationMethodName>("advected_interp_method_name") = tked_method_name;
231 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_advection", params);
232}
233
234void
236{
237 {
238 const std::string kernel_type = "LinearFVTurbulentDiffusion";
239 InputParameters params = getFactory().getValidParams(kernel_type);
240 assignBlocks(params, _blocks);
241 params.set<bool>("use_nonorthogonal_correction") =
242 getParam<bool>("use_nonorthogonal_correction");
243
244 // Note: we have to use a single diffusion kernel in case we have a flux BC so it is not applied
245 // twice
246 params.set<LinearVariableName>("variable") = _tke_name;
247 params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tke";
248 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
249
250 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
251 params.set<LinearVariableName>("variable") = _tked_name;
252 params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tked";
253 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
254 }
255}
256
257void
259{
260 const std::string u_names[3] = {"u", "v", "w"};
261 {
262 const std::string kernel_type = "LinearFVTKESourceSink";
263 InputParameters params = getFactory().getValidParams(kernel_type);
264 assignBlocks(params, _blocks);
265 params.set<LinearVariableName>("variable") = _tke_name;
266 params.set<MooseFunctorName>(NS::TKED) = _tked_name;
267 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
268 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
269 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
270 params.set<Real>("C_mu") = getParam<Real>("C_mu");
271 params.set<Real>("C_pl") = getParam<Real>("C_pl");
272 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
273 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
274 for (const auto d : make_range(dimension()))
275 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
276 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_source_sink", params);
277 }
278
279 {
280 const std::string kernel_type = "LinearFVTKEDSourceSink";
281 InputParameters params = getFactory().getValidParams(kernel_type);
282 assignBlocks(params, _blocks);
283 params.set<LinearVariableName>("variable") = _tked_name;
284 params.set<MooseFunctorName>(NS::TKE) = _tke_name;
285 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
286 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
287 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
288 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
289 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
290 params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
291 params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
292 params.set<Real>("C_mu") = getParam<Real>("C_mu");
293 params.set<Real>("C_pl") = getParam<Real>("C_pl");
294 for (const auto d : make_range(dimension()))
295 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
296 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_source_sink", params);
297 }
298}
299
300void
302{
303 const std::string u_names[3] = {"u", "v", "w"};
304
305 if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
306 {
307 mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
308 const std::string bc_type = "LinearFVTurbulentViscosityWallFunctionBC";
309 InputParameters params = getFactory().getValidParams(bc_type);
310 params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
311 params.set<LinearVariableName>("variable") = _turbulent_viscosity_name;
312 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
313 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
314 params.set<MooseFunctorName>(NS::TKE) = _tke_name;
315 params.set<Real>("C_mu") = getParam<Real>("C_mu");
316 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
317 for (const auto d : make_range(dimension()))
318 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
319
320 getProblem().addLinearFVBC(bc_type, prefix() + "turbulence_walls", params);
321 // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
322 // because it facilitates counting the number of walls, specifying energy wall functors
323 // the same way as for boundary conditions
324 }
325}
326
327void
329{
330 // Functor materials for the diffusion coefficients
331 if (_turbulence_model == "k-epsilon")
332 {
333 // Since sigma_k = 1 in the standard k-epsilon, this is often unnecessary
334 const std::string mat_type = "FunctorEffectiveDynamicViscosity";
335 InputParameters params = getFactory().getValidParams(mat_type);
336 assignBlocks(params, _blocks);
337 params.set<MooseFunctorName>("property_name") = "mu_eff_tke";
338 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
339 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
340 params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
341 getParam<MooseFunctorName>("sigma_k");
342 getProblem().addMaterial(mat_type, prefix() + "mu_eff_tke", params);
343
344 params.set<MooseFunctorName>("property_name") = "mu_eff_tked";
345 params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
346 getParam<MooseFunctorName>("sigma_eps");
347 getProblem().addMaterial(mat_type, prefix() + "mu_eff_tked", params);
348 }
349}
350
351unsigned short
registerWCNSFVTurbulenceBaseTasks("NavierStokesApp", WCNSLinearFVTurbulencePhysics)
registerMooseAction("NavierStokesApp", WCNSLinearFVTurbulencePhysics, "add_interpolation_method_physics")
void needSolutionState(unsigned int oldest_needed, Moose::SolutionIterationType iteration_type)
virtual void addLinearFVKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual void addLinearFVBC(const std::string &fv_bc_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void errorDependentParameter(const std::string &param1, const std::string &value_not_set, const std::vector< std::string > &dependent_params) const
void suppressParameter(const std::string &name)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
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 paramWarning(const std::string &param, Args... args) const
void paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
bool _define_variables
Whether to define variables if they do not exist.
void addFVAdvectedInterpolationMethod(const MooseEnum &interpolation_method)
Add the FVInterpolationMethod object for an advected interpolation method if absent.
virtual void checkIntegrity() const
virtual FEProblemBase & getProblem()
Factory & getFactory()
bool shouldCreateTimeDerivative(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_already_defined) const
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
unsigned int dimension() const
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
std::string prefix() const
void addSharedSolverVariable(const std::string &var_type, const VariableName &var_name, InputParameters params)
bool shouldCreateVariable(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool error_if_aux)
bool isTransient() const
std::vector< SubdomainName > _blocks
void addRequiredPhysicsTask(const std::string &task)
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
const std::vector< std::string > _velocity_names
Velocity names.
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
const MooseFunctorName & dynamicViscosityName() const
Return the name of the dynamic viscosity functor.
const UserObjectName & rhieChowUOName() const
Return the name of the Rhie Chow user object.
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
const MooseFunctorName & densityName() const
Return the name of the density functor.
Base class for a Physics that creates all the objects needed to add a turbulence model to an incompre...
std::vector< BoundaryName > _turbulence_walls
List of boundaries to act as walls for turbulence models.
const VariableName _tke_name
Name of the turbulent kinetic energy.
MooseEnum _wall_treatment_eps
Turbulence wall treatment for epsilon (same for all walls currently)
const VariableName _tked_name
Name of the turbulent kinetic energy dissipation.
const MooseEnum _turbulence_model
Turbulence model to create the equation(s) for.
const VariableName _turbulent_viscosity_name
Name of the turbulence viscosity auxiliary variable (or property)
Creates all the objects needed to add a turbulence model to an incompressible / weakly-compressible N...
virtual void checkIntegrity() const override
virtual void initializePhysicsAdditional() override
WCNSLinearFVTurbulencePhysics(const InputParameters &parameters)
void addKEpsilonTimeDerivatives()
Functions adding kernels for the k-epsilon to the k-epsilon equations.
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
virtual void addFVInterpolationMethods() override
static const std::string density
Definition NS.h:34
static const std::string TKED
Definition NS.h:182
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