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
137 addSharedSolverVariable(variable_type, _tke_name, params);
138 }
139 else
140 paramError("turbulence_kinetic_energy_variable",
141 "Variable (" + _tke_name +
142 ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
143
144 // Add turbulent kinetic energy dissipation variable
145 if (!shouldCreateVariable(_tked_name, _blocks, /*error if aux*/ true))
146 reportPotentiallyMissedParameters({"system_names"}, "MooseLinearVariableFVReal");
147 else if (_define_variables)
148 {
149 std::string variable_type = "MooseLinearVariableFVReal";
150
151 auto params = getFactory().getValidParams(variable_type);
152
153 addSharedSolverVariable(variable_type, _tked_name, params);
154 }
155 else
156 paramError("turbulence_kinetic_energy_dissipation_variable",
157 "Variable (" + _tked_name +
158 ") supplied to the WCNSLinearFVTurbulencePhysics does not exist!");
159 }
160}
161
162void
164{
165 if (_turbulence_model == "none")
166 return;
167
168 // For linear FV discretization:
169 // We have to add the kernel in the flow/heat/scalar physics with mu_eff instead of two kernels
170 // one with mu, one with mu_turb, and chose one of the two to NOT have the advective term
171 // Also, flux boundary conditions would be executed twice with two kernels
172
173 // Turbulence models with their own set of equations
174 if (_turbulence_model == "k-epsilon")
175 {
176 if (isTransient())
181 }
182}
183
184void
186{
187 const std::string kernel_type = "LinearFVTurbulentTimeDerivative";
188 InputParameters params = getFactory().getValidParams(kernel_type);
189 assignBlocks(params, _blocks);
190
191 params.set<LinearVariableName>("variable") = _tke_name;
192 params.set<MooseFunctorName>("factor") = _flow_equations_physics->densityName();
193 if (shouldCreateTimeDerivative(_tke_name, _blocks, /*error if already defined*/ false))
194 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_time", params);
195 params.set<LinearVariableName>("variable") = _tked_name;
196 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
197 if (shouldCreateTimeDerivative(_tked_name, _blocks, /*error if already defined*/ false))
198 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_time", params);
199}
200
201void
203{
204 const auto tke_method_name =
205 isParamValid("tke_advection_interpolation_method_name")
206 ? getParam<InterpolationMethodName>("tke_advection_interpolation_method_name")
207 : InterpolationMethodName(
208 std::string(getParam<MooseEnum>("tke_advection_interpolation")));
209 const auto tked_method_name =
210 isParamValid("tked_advection_interpolation_method_name")
211 ? getParam<InterpolationMethodName>("tked_advection_interpolation_method_name")
212 : InterpolationMethodName(
213 std::string(getParam<MooseEnum>("tked_advection_interpolation")));
214
215 const std::string kernel_type = "LinearFVTurbulentAdvection";
216 InputParameters params = getFactory().getValidParams(kernel_type);
217
218 assignBlocks(params, _blocks);
219
220 params.set<UserObjectName>("rhie_chow_user_object") = _flow_equations_physics->rhieChowUOName();
221 params.set<InterpolationMethodName>("advected_interp_method_name") = tke_method_name;
222 params.set<LinearVariableName>("variable") = _tke_name;
223 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_advection", params);
224 params.set<LinearVariableName>("variable") = _tked_name;
225 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
226 params.set<InterpolationMethodName>("advected_interp_method_name") = tked_method_name;
227 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_advection", params);
228}
229
230void
232{
233 {
234 const std::string kernel_type = "LinearFVTurbulentDiffusion";
235 InputParameters params = getFactory().getValidParams(kernel_type);
236 assignBlocks(params, _blocks);
237 params.set<bool>("use_nonorthogonal_correction") =
238 getParam<bool>("use_nonorthogonal_correction");
239
240 // Note: we have to use a single diffusion kernel in case we have a flux BC so it is not applied
241 // twice
242 params.set<LinearVariableName>("variable") = _tke_name;
243 params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tke";
244 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_diffusion_mu", params);
245
246 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
247 params.set<LinearVariableName>("variable") = _tked_name;
248 params.set<MooseFunctorName>("diffusion_coeff") = "mu_eff_tked";
249 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_diffusion_mu", params);
250 }
251}
252
253void
255{
256 const std::string u_names[3] = {"u", "v", "w"};
257 {
258 const std::string kernel_type = "LinearFVTKESourceSink";
259 InputParameters params = getFactory().getValidParams(kernel_type);
260 assignBlocks(params, _blocks);
261 params.set<LinearVariableName>("variable") = _tke_name;
262 params.set<MooseFunctorName>(NS::TKED) = _tked_name;
263 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
264 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
265 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
266 params.set<Real>("C_mu") = getParam<Real>("C_mu");
267 params.set<Real>("C_pl") = getParam<Real>("C_pl");
268 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
269 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
270 for (const auto d : make_range(dimension()))
271 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
272 getProblem().addLinearFVKernel(kernel_type, prefix() + "tke_source_sink", params);
273 }
274
275 {
276 const std::string kernel_type = "LinearFVTKEDSourceSink";
277 InputParameters params = getFactory().getValidParams(kernel_type);
278 assignBlocks(params, _blocks);
279 params.set<LinearVariableName>("variable") = _tked_name;
280 params.set<MooseFunctorName>(NS::TKE) = _tke_name;
281 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
282 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
283 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
284 params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
285 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
286 params.set<MooseFunctorName>("C1_eps") = getParam<MooseFunctorName>("C1_eps");
287 params.set<MooseFunctorName>("C2_eps") = getParam<MooseFunctorName>("C2_eps");
288 params.set<Real>("C_mu") = getParam<Real>("C_mu");
289 params.set<Real>("C_pl") = getParam<Real>("C_pl");
290 for (const auto d : make_range(dimension()))
291 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
292 getProblem().addLinearFVKernel(kernel_type, prefix() + "tked_source_sink", params);
293 }
294}
295
296void
298{
299 const std::string u_names[3] = {"u", "v", "w"};
300
301 if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
302 {
303 mooseAssert(_flow_equations_physics, "Should have a flow equation physics");
304 const std::string bc_type = "LinearFVTurbulentViscosityWallFunctionBC";
305 InputParameters params = getFactory().getValidParams(bc_type);
306 params.set<std::vector<BoundaryName>>("boundary") = _turbulence_walls;
307 params.set<LinearVariableName>("variable") = _turbulent_viscosity_name;
308 params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
309 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
310 params.set<MooseFunctorName>(NS::TKE) = _tke_name;
311 params.set<Real>("C_mu") = getParam<Real>("C_mu");
312 params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
313 for (const auto d : make_range(dimension()))
314 params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
315
316 getProblem().addLinearFVBC(bc_type, prefix() + "turbulence_walls", params);
317 // Energy wall function boundary conditions are added in the WCNSFVFluidEnergyPhysics
318 // because it facilitates counting the number of walls, specifying energy wall functors
319 // the same way as for boundary conditions
320 }
321}
322
323void
325{
326 // Functor materials for the diffusion coefficients
327 if (_turbulence_model == "k-epsilon")
328 {
329 // Since sigma_k = 1 in the standard k-epsilon, this is often unnecessary
330 const std::string mat_type = "FunctorEffectiveDynamicViscosity";
331 InputParameters params = getFactory().getValidParams(mat_type);
332 assignBlocks(params, _blocks);
333 params.set<MooseFunctorName>("property_name") = "mu_eff_tke";
334 params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
335 params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
336 params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
337 getParam<MooseFunctorName>("sigma_k");
338 getProblem().addMaterial(mat_type, prefix() + "mu_eff_tke", params);
339
340 params.set<MooseFunctorName>("property_name") = "mu_eff_tked";
341 params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") =
342 getParam<MooseFunctorName>("sigma_eps");
343 getProblem().addMaterial(mat_type, prefix() + "mu_eff_tked", params);
344 }
345}
346
347unsigned 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 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