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
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
90void
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
102void
104{
105 if (_turbulence_model == "k-epsilon")
106 getProblem().needSolutionState(1, Moose::SolutionIterationType::Nonlinear);
107}
108
109void
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
120void
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
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 = "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
204void
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
233void
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
256void
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
299void
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
326void
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
350unsigned 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 addVariable(const std::string &var_type, const std::string &var_name, InputParameters &params)
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
const SolverSystemName & getSolverSystem(unsigned int variable_index) const
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 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:181
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:180