Line data Source code
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 :
10 : #include "WCNSFVTurbulencePhysicsBase.h"
11 : #include "WCNSFVFlowPhysicsBase.h"
12 : #include "WCNSFVFluidHeatTransferPhysicsBase.h"
13 : #include "WCNSFVScalarTransportPhysicsBase.h"
14 : #include "WCNSFVCoupledAdvectionPhysicsHelper.h"
15 : #include "WCNSLinearFVTurbulencePhysics.h"
16 : #include "kEpsilonViscosityAux.h"
17 : #include "INSFVTKESourceSink.h"
18 : #include "INSFVTurbulentViscosityWallFunction.h"
19 : #include "NSFVBase.h"
20 :
21 : InputParameters
22 622 : WCNSFVTurbulencePhysicsBase::validParams()
23 : {
24 622 : InputParameters params = NavierStokesPhysicsBase::validParams();
25 622 : params += WCNSFVCoupledAdvectionPhysicsHelper::validParams();
26 622 : params.addClassDescription(
27 : "Define a turbulence model for a incompressible or weakly-compressible Navier Stokes "
28 : "flow with a finite volume discretization");
29 :
30 1244 : MooseEnum turbulence_type("mixing-length k-epsilon none", "none");
31 1244 : params.addParam<MooseEnum>(
32 : "turbulence_handling",
33 : turbulence_type,
34 : "The way turbulent diffusivities are determined in the turbulent regime.");
35 622 : params += NSFVBase::commonTurbulenceParams();
36 :
37 1244 : params.deprecateParam("mixing_length_walls", "turbulence_walls", "");
38 :
39 : // Not implemented, re-enable with k-epsilon
40 622 : params.suppressParameter<MooseEnum>("preconditioning");
41 :
42 : // K-Epsilon parameters
43 1244 : params.addParam<MooseFunctorName>(
44 : "tke_name", NS::TKE, "Name of the turbulent kinetic energy variable");
45 1244 : params.addParam<MooseFunctorName>(
46 : "tked_name", NS::TKED, "Name of the turbulent kinetic energy dissipation variable");
47 1244 : params.addParam<FunctionName>(
48 : "initial_tke", "0", "Initial value for the turbulence kinetic energy");
49 1244 : params.addParam<FunctionName>(
50 : "initial_tked", "0", "Initial value for the turbulence kinetic energy dissipation");
51 1244 : params.addParam<FunctionName>("initial_mu_t", "Initial value for the turbulence viscosity");
52 :
53 1244 : params.addParam<MooseFunctorName>(
54 : "C1_eps", "C1 coefficient for the turbulent kinetic energy dissipation equation");
55 1244 : params.addParam<MooseFunctorName>(
56 : "C2_eps", "C2 coefficient for the turbulent kinetic energy dissipation equation");
57 1244 : params.addParam<MooseFunctorName>(
58 : "sigma_k", "Scaling coefficient for the turbulent kinetic energy diffusion term");
59 1244 : params.addParam<MooseFunctorName>(
60 : "sigma_eps",
61 : "Scaling coefficient for the turbulent kinetic energy dissipation diffusion term");
62 622 : params.addParam<MooseFunctorName>(
63 : NS::turbulent_Prandtl, NS::turbulent_Prandtl, "Turbulent Prandtl number");
64 622 : params.transferParam<Real>(INSFVTKESourceSink::validParams(), "C_pl");
65 622 : params.transferParam<Real>(kEpsilonViscosityAux::validParams(), "mu_t_ratio_max");
66 :
67 : // Boundary parameters
68 1244 : params.addParam<bool>("bulk_wall_treatment", true, "Whether to treat the wall cell as bulk");
69 1244 : MooseEnum wall_treatment("eq_newton eq_incremental eq_linearized neq", "neq");
70 1244 : params.addParam<MooseEnum>("wall_treatment_eps",
71 : wall_treatment,
72 : "The method used for computing the epsilon wall functions and the "
73 : "turbulence viscosity wall functions");
74 1244 : params.addParam<MooseEnum>("wall_treatment_T",
75 : wall_treatment,
76 : "The method used for computing the temperature wall functions");
77 622 : params.transferParam<Real>(INSFVTurbulentViscosityWallFunction::validParams(), "C_mu");
78 :
79 : // K-Epsilon numerical scheme parameters
80 1244 : MooseEnum face_interpol_types("average skewness-corrected", "average");
81 1244 : MooseEnum adv_interpol_types("average upwind", "upwind");
82 1244 : params.addParam<MooseEnum>("tke_face_interpolation",
83 : face_interpol_types,
84 : "The numerical scheme to interpolate the TKE to the "
85 : "face (separate from the advected quantity interpolation).");
86 1244 : params.addParam<MooseEnum>("tke_advection_interpolation",
87 : adv_interpol_types,
88 : "The numerical scheme to interpolate the TKE to the "
89 : "face when in the advection kernel.");
90 1244 : params.addParam<bool>(
91 : "tke_two_term_bc_expansion",
92 1244 : false,
93 : "If a two-term Taylor expansion is needed for the determination of the boundary values"
94 : "of the turbulent kinetic energy.");
95 :
96 1244 : params.addParam<MooseEnum>("tked_face_interpolation",
97 : face_interpol_types,
98 : "The numerical scheme to interpolate the TKED to the "
99 : "face (separate from the advected quantity interpolation).");
100 1244 : params.addParam<MooseEnum>("tked_advection_interpolation",
101 : adv_interpol_types,
102 : "The numerical scheme to interpolate the TKED to the "
103 : "face when in the advection kernel.");
104 1244 : params.addParam<bool>(
105 : "tked_two_term_bc_expansion",
106 1244 : false,
107 : "If a two-term Taylor expansion is needed for the determination of the boundary values"
108 : "of the turbulent kinetic energy dissipation.");
109 1244 : params.addParam<bool>(
110 : "turbulent_viscosity_two_term_bc_expansion",
111 1244 : true,
112 : "If a two-term Taylor expansion is needed for the determination of the boundary values"
113 : "of the turbulent viscosity.");
114 1244 : params.addParam<bool>("mu_t_as_aux_variable",
115 1244 : false,
116 : "Whether to use an auxiliary variable instead of a functor material "
117 : "property for the turbulent viscosity");
118 1244 : params.addParam<bool>("output_mu_t", true, "Whether to add mu_t to the field outputs");
119 1244 : params.addParam<bool>("k_t_as_aux_variable",
120 1244 : false,
121 : "Whether to use an auxiliary variable for the turbulent conductivity");
122 :
123 : // Add the coupled physics
124 : // TODO Remove the defaults once NavierStokesFV action is removed
125 : // It is a little risky right now because the user could forget to pass the parameter and
126 : // be missing the influence of turbulence on either of these physics. There is a check in the
127 : // constructor to present this from happening
128 1244 : params.addParam<PhysicsName>(
129 : "fluid_heat_transfer_physics",
130 : "NavierStokesFV",
131 : "WCNS(Linear)FVFluidHeatTransferPhysics generating the heat advection equations");
132 1244 : params.addParam<PhysicsName>(
133 : "scalar_transport_physics",
134 : "NavierStokesFV",
135 : "WCNS(Linear)FVScalarTransportPhysics generating the scalar advection equations");
136 :
137 : // Parameter groups
138 1244 : params.addParamNamesToGroup("fluid_heat_transfer_physics turbulent_prandtl "
139 : "scalar_transport_physics Sc_t",
140 : "Coupled Physics");
141 1244 : params.addParamNamesToGroup("initial_tke initial_tked C1_eps C2_eps sigma_k sigma_eps",
142 : "K-Epsilon model");
143 1244 : params.addParamNamesToGroup("C_mu bulk_wall_treatment wall_treatment_eps wall_treatment_T",
144 : "K-Epsilon wall function");
145 1244 : params.addParamNamesToGroup("tke_face_interpolation tke_two_term_bc_expansion "
146 : "tked_face_interpolation tked_two_term_bc_expansion "
147 : "turbulent_viscosity_two_term_bc_expansion "
148 : "mu_t_as_aux_variable k_t_as_aux_variable",
149 : "K-Epsilon model numerical");
150 :
151 622 : return params;
152 622 : }
153 :
154 622 : WCNSFVTurbulencePhysicsBase::WCNSFVTurbulencePhysicsBase(const InputParameters & parameters)
155 : : NavierStokesPhysicsBase(parameters),
156 : WCNSFVCoupledAdvectionPhysicsHelper(this),
157 622 : _turbulence_model(getParam<MooseEnum>("turbulence_handling")),
158 1244 : _turbulence_walls(getParam<std::vector<BoundaryName>>("turbulence_walls")),
159 1244 : _wall_treatment_eps(getParam<MooseEnum>("wall_treatment_eps")),
160 1244 : _wall_treatment_temp(getParam<MooseEnum>("wall_treatment_T")),
161 1244 : _tke_name(getParam<MooseFunctorName>("tke_name")),
162 2488 : _tked_name(getParam<MooseFunctorName>("tked_name"))
163 : {
164 622 : if (_verbose && _turbulence_model != "none")
165 6 : _console << "Creating a " << std::string(_turbulence_model) << " turbulence model."
166 2 : << std::endl;
167 :
168 : // Keep track of the variable names, for loading variables from files notably
169 622 : if (_turbulence_model == "k-epsilon")
170 : {
171 84 : saveSolverVariableName(_tke_name);
172 84 : saveSolverVariableName(_tked_name);
173 168 : if (getParam<bool>("mu_t_as_aux_variable"))
174 66 : saveAuxVariableName(_turbulent_viscosity_name);
175 168 : if (getParam<bool>("k_t_as_aux_variable"))
176 21 : saveAuxVariableName(NS::k_t);
177 : }
178 :
179 : // Parameter checks
180 622 : if (_turbulence_model == "none")
181 1002 : errorInconsistentDependentParameter("turbulence_handling", "none", {"turbulence_walls"});
182 622 : if (_turbulence_model != "k-epsilon")
183 : {
184 1076 : errorDependentParameter("turbulence_handling",
185 : "k-epsilon",
186 : {"C_mu",
187 : "C1_eps",
188 : "C2_eps",
189 : "bulk_wall_treatment",
190 : "tke_scaling",
191 : "tke_face_interpolation",
192 : "tke_two_term_bc_expansion",
193 : "tked_scaling",
194 : "tked_face_interpolation",
195 : "tked_two_term_bc_expansion",
196 : "turbulent_viscosity_two_term_bc_expansion"});
197 1076 : checkSecondParamSetOnlyIfFirstOneTrue("mu_t_as_aux_variable", "initial_mu_t");
198 : }
199 622 : }
200 :
201 : void
202 7312 : WCNSFVTurbulencePhysicsBase::actOnAdditionalTasks()
203 : {
204 : // Other Physics may not exist or be initialized at construction time, so
205 : // we retrieve them now, on this task which occurs after 'init_physics'
206 7312 : if (_current_task == "get_turbulence_physics")
207 614 : retrieveCoupledPhysics();
208 7312 : }
209 :
210 : void
211 614 : WCNSFVTurbulencePhysicsBase::retrieveCoupledPhysics()
212 : {
213 : // _flow_equations_physics is initialized by 'WCNSFVCoupledAdvectionPhysicsHelper'
214 614 : if (_flow_equations_physics && _flow_equations_physics->hasFlowEquations())
215 601 : _has_flow_equations = true;
216 : else
217 13 : _has_flow_equations = false;
218 :
219 : // Sanity check for interaction for fluid heat transfer physics
220 1842 : if (isParamValid("fluid_heat_transfer_physics") && _turbulence_model != "none")
221 : {
222 242 : _fluid_energy_physics = getCoupledPhysics<WCNSFVFluidHeatTransferPhysicsBase>(
223 : getParam<PhysicsName>("fluid_heat_transfer_physics"), true);
224 : // Check for a missing parameter / do not support isolated physics for now
225 155 : if (!_fluid_energy_physics &&
226 155 : !getCoupledPhysics<const WCNSFVFluidHeatTransferPhysicsBase>(true).empty())
227 0 : paramError("fluid_heat_transfer_physics",
228 : "We currently do not support creating both turbulence physics and fluid heat "
229 : "transfer physics that are not coupled together. Use "
230 : "'fluid_heat_transfer_physics' to explicitly specify the coupling");
231 121 : if (_fluid_energy_physics && _fluid_energy_physics->hasEnergyEquation())
232 70 : _has_energy_equation = true;
233 : else
234 51 : _has_energy_equation = false;
235 : }
236 : else
237 : {
238 493 : _has_energy_equation = false;
239 493 : _fluid_energy_physics = nullptr;
240 : }
241 :
242 : // Sanity check for interaction with scalar transport physics
243 1842 : if (isParamValid("scalar_transport_physics") && _turbulence_model != "none")
244 : {
245 242 : _scalar_transport_physics = getCoupledPhysics<WCNSFVScalarTransportPhysicsBase>(
246 : getParam<PhysicsName>("scalar_transport_physics"), true);
247 169 : if (!_scalar_transport_physics &&
248 169 : !getCoupledPhysics<const WCNSFVScalarTransportPhysicsBase>(true).empty())
249 0 : paramError(
250 : "scalar_transport_physics",
251 : "We currently do not support creating both turbulence physics and scalar transport "
252 : "physics that are not coupled together");
253 121 : if (_scalar_transport_physics && _scalar_transport_physics->hasScalarEquations())
254 58 : _has_scalar_equations = true;
255 : else
256 63 : _has_scalar_equations = false;
257 : }
258 : else
259 : {
260 493 : _has_scalar_equations = false;
261 493 : _scalar_transport_physics = nullptr;
262 : }
263 :
264 : // To help remediate the danger of the parameter setup
265 614 : if (_verbose)
266 : {
267 2 : if (_has_energy_equation)
268 4 : mooseInfoRepeated("Coupling turbulence physics with fluid heat transfer physics " +
269 2 : _fluid_energy_physics->name());
270 : else
271 : mooseInfoRepeated("No fluid heat transfer equation considered by this turbulence "
272 : "physics.");
273 2 : if (_has_scalar_equations)
274 4 : mooseInfoRepeated("Coupling turbulence physics with scalar transport physics " +
275 2 : _scalar_transport_physics->name());
276 : else
277 : mooseInfoRepeated("No scalar transport equations considered by this turbulence physics.");
278 : }
279 614 : }
280 :
281 : void
282 600 : WCNSFVTurbulencePhysicsBase::addInitialConditions()
283 : {
284 600 : if (_turbulence_model == "mixing-length" || _turbulence_model == "none")
285 516 : return;
286 84 : const std::string ic_type = "FVFunctionIC";
287 84 : InputParameters params = getFactory().getValidParams(ic_type);
288 :
289 : // Parameter checking: error if initial conditions are provided but not going to be used
290 252 : if ((getParam<bool>("initialize_variables_from_mesh_file") || !_define_variables) &&
291 120 : ((getParam<bool>("mu_t_as_aux_variable") && isParamValid("initial_mu_t")) ||
292 120 : isParamSetByUser("initial_tke") || isParamSetByUser("initial_tked")))
293 0 : mooseError("inital_mu_t/tke/tked should not be provided if we are restarting from a mesh file "
294 : "or not defining variables in the Physics");
295 :
296 : // do not set initial conditions if we are not defining variables
297 84 : if (!_define_variables)
298 : return;
299 : // on regular restarts (from checkpoint), we obey the user specification of initial conditions
300 :
301 168 : if (getParam<bool>("mu_t_as_aux_variable"))
302 : {
303 66 : const auto rho_name = _flow_equations_physics->densityName();
304 : // If the user provided an initial value, we use that
305 132 : if (isParamValid("initial_mu_t"))
306 126 : params.set<FunctionName>("function") = getParam<FunctionName>("initial_mu_t");
307 : // If we can compute the initialization value from the user parameters, we do that
308 48 : else if (MooseUtils::isFloat(rho_name) &&
309 72 : MooseUtils::isFloat(getParam<FunctionName>("initial_tke")) &&
310 72 : MooseUtils::isFloat(getParam<FunctionName>("initial_tked")))
311 48 : params.set<FunctionName>("function") =
312 48 : std::to_string(std::atof(rho_name.c_str()) * getParam<Real>("C_mu") *
313 48 : std::pow(std::atof(getParam<FunctionName>("initial_tke").c_str()), 2) /
314 72 : std::atof(getParam<FunctionName>("initial_tked").c_str()));
315 : else
316 0 : paramError("initial_mu_t",
317 : "Initial turbulent viscosity should be provided. A sensible value is "
318 : "rho * C_mu TKE_initial^2 / TKED_initial");
319 :
320 66 : params.set<VariableName>("variable") = _turbulent_viscosity_name;
321 : // Always obey the user specification of an initial condition
322 264 : if (shouldCreateIC(_turbulent_viscosity_name,
323 66 : _blocks,
324 198 : /*whether IC is a default*/ !isParamSetByUser("initial_mu_t"),
325 132 : /*error if already an IC*/ isParamSetByUser("initial_mu_t")))
326 198 : getProblem().addFVInitialCondition(ic_type, prefix() + "initial_mu_turb", params);
327 : }
328 36 : else if (isParamSetByUser("initial_mu_t"))
329 0 : paramError("initial_mu_t",
330 : "This parameter can only be specified if 'mu_t_as_aux_variable=true'");
331 :
332 84 : params.set<VariableName>("variable") = _tke_name;
333 252 : params.set<FunctionName>("function") = getParam<FunctionName>("initial_tke");
334 336 : if (shouldCreateIC(_tke_name,
335 84 : _blocks,
336 252 : /*whether IC is a default*/ !isParamSetByUser("initial_tke"),
337 168 : /*error if already an IC*/ isParamSetByUser("initial_tke")))
338 222 : getProblem().addFVInitialCondition(ic_type, prefix() + "initial_tke", params);
339 84 : params.set<VariableName>("variable") = _tked_name;
340 252 : params.set<FunctionName>("function") = getParam<FunctionName>("initial_tked");
341 252 : if (shouldCreateIC(_tked_name,
342 : _blocks,
343 252 : /*whether IC is a default*/ !isParamSetByUser("initial_tked"),
344 168 : /*error if already an IC*/ isParamSetByUser("initial_tked")))
345 222 : getProblem().addFVInitialCondition(ic_type, prefix() + "initial_tked", params);
346 84 : }
347 :
348 : void
349 622 : WCNSFVTurbulencePhysicsBase::addAuxiliaryVariables()
350 : {
351 : // Not future-proof
352 622 : const bool is_linear = dynamic_cast<WCNSLinearFVTurbulencePhysics *>(this);
353 622 : const auto var_type = is_linear ? "MooseLinearVariableFVReal" : "MooseVariableFVReal";
354 :
355 790 : if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
356 : {
357 66 : auto params = getFactory().getValidParams(var_type);
358 66 : assignBlocks(params, _blocks);
359 150 : if (!is_linear && isParamValid("turbulent_viscosity_two_term_bc_expansion"))
360 42 : params.set<bool>("two_term_boundary_expansion") =
361 126 : getParam<bool>("turbulent_viscosity_two_term_bc_expansion");
362 66 : if (!shouldCreateVariable(_turbulent_viscosity_name, _blocks, /*error if aux*/ false))
363 0 : reportPotentiallyMissedParameters({"turbulent_viscosity_two_term_bc_expansion"}, var_type);
364 : else
365 132 : getProblem().addAuxVariable(var_type, _turbulent_viscosity_name, params);
366 66 : }
367 790 : if (_turbulence_model == "k-epsilon" && getParam<bool>("k_t_as_aux_variable"))
368 : {
369 21 : auto params = getFactory().getValidParams(var_type);
370 21 : assignBlocks(params, _blocks);
371 42 : if (shouldCreateVariable(NS::k_t, _blocks, /*error if aux*/ false))
372 42 : getProblem().addAuxVariable(var_type, NS::k_t, params);
373 21 : }
374 622 : }
375 :
376 : void
377 600 : WCNSFVTurbulencePhysicsBase::addAuxiliaryKernels()
378 : {
379 2400 : const std::string u_names[3] = {"u", "v", "w"};
380 : // Not future-proof
381 600 : const bool is_linear = dynamic_cast<WCNSLinearFVTurbulencePhysics *>(this);
382 :
383 768 : if (_turbulence_model == "k-epsilon" && getParam<bool>("mu_t_as_aux_variable"))
384 : {
385 66 : auto params = getFactory().getValidParams("kEpsilonViscosityAux");
386 66 : assignBlocks(params, _blocks);
387 :
388 132 : params.set<AuxVariableName>("variable") = _turbulent_viscosity_name;
389 66 : params.set<MooseFunctorName>(NS::density) = _flow_equations_physics->densityName();
390 66 : params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
391 66 : params.set<MooseFunctorName>(NS::TKE) = _tke_name;
392 66 : params.set<MooseFunctorName>(NS::TKED) = _tked_name;
393 66 : params.set<std::vector<BoundaryName>>("walls") = _turbulence_walls;
394 66 : params.set<MooseEnum>("wall_treatment") = _wall_treatment_eps;
395 198 : for (const auto d : make_range(dimension()))
396 264 : params.set<MooseFunctorName>(u_names[d]) = _velocity_names[d];
397 :
398 66 : params.set<bool>("newton_solve") = !is_linear;
399 66 : params.applySpecificParameters(parameters(), {"C_mu", "bulk_wall_treatment", "mu_t_ratio_max"});
400 198 : params.set<ExecFlagEnum>("execute_on") = {EXEC_NONLINEAR};
401 :
402 132 : getProblem().addAuxKernel("kEpsilonViscosityAux", name() + "_viscosity_aux", params);
403 66 : }
404 600 : if (_turbulence_model == "k-epsilon" && _has_energy_equation &&
405 726 : getParam<bool>("k_t_as_aux_variable"))
406 : {
407 21 : auto params = getFactory().getValidParams("TurbulentConductivityAux");
408 21 : assignBlocks(params, _blocks);
409 42 : params.set<AuxVariableName>("variable") = NS::k_t;
410 21 : params.set<MooseFunctorName>(NS::cp) = _fluid_energy_physics->getSpecificHeatName();
411 21 : params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
412 21 : params.applySpecificParameters(parameters(), {"Pr_t"});
413 42 : getProblem().addAuxKernel(
414 21 : "TurbulentConductivityAux", name() + "_thermal_conductivity_aux", params);
415 21 : }
416 3066 : }
417 :
418 : void
419 600 : WCNSFVTurbulencePhysicsBase::addMaterials()
420 : {
421 : // Not future-proof
422 600 : const bool is_linear = dynamic_cast<WCNSLinearFVTurbulencePhysics *>(this);
423 600 : if (_turbulence_model == "k-epsilon")
424 : {
425 84 : if (!getProblem().hasFunctor(NS::mu_eff, /*thread_id=*/0))
426 : {
427 : const auto mat_type =
428 84 : is_linear ? "FunctorEffectiveDynamicViscosity" : "ADFunctorEffectiveDynamicViscosity";
429 84 : InputParameters params = getFactory().getValidParams(mat_type);
430 84 : assignBlocks(params, _blocks);
431 168 : params.set<MooseFunctorName>("property_name") = NS::mu_eff;
432 84 : params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
433 168 : params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
434 168 : params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") = "1";
435 252 : getProblem().addMaterial(mat_type, prefix() + "effective_viscosity", params);
436 84 : }
437 168 : if (!getParam<bool>("mu_t_as_aux_variable"))
438 : {
439 18 : InputParameters params = getFactory().getValidParams("INSFVkEpsilonViscosityFunctorMaterial");
440 18 : params.set<MooseFunctorName>(NS::TKE) = _tke_name;
441 18 : params.set<MooseFunctorName>(NS::TKED) = _tked_name;
442 18 : params.set<MooseFunctorName>(NS::density) = _density_name;
443 54 : params.set<ExecFlagEnum>("execute_on") = {EXEC_NONLINEAR};
444 36 : if (getParam<bool>("output_mu_t"))
445 54 : params.set<std::vector<OutputName>>("outputs") = {"all"};
446 54 : getProblem().addMaterial(
447 18 : "INSFVkEpsilonViscosityFunctorMaterial", prefix() + "compute_mu_t", params);
448 18 : }
449 :
450 84 : if (_has_energy_equation && !getProblem().hasFunctor(NS::k_t, /*thread_id=*/0))
451 : {
452 : mooseAssert(!getParam<bool>("k_t_as_aux_variable"), "k_t should not exist");
453 42 : const auto object_type = is_linear ? "ParsedFunctorMaterial" : "ADParsedFunctorMaterial";
454 42 : InputParameters params = getFactory().getValidParams(object_type);
455 42 : assignBlocks(params, _blocks);
456 42 : const auto mu_t_name = NS::mu_t;
457 42 : const auto cp_name = _fluid_energy_physics->getSpecificHeatName();
458 42 : const auto Pr_t_name = getParam<MooseFunctorName>("Pr_t");
459 :
460 : // Avoid defining floats as functors in the parsed expression
461 42 : if (!MooseUtils::isFloat(cp_name) && !MooseUtils::isFloat(Pr_t_name))
462 0 : params.set<std::vector<std::string>>("functor_names") = {cp_name, Pr_t_name, mu_t_name};
463 42 : else if (MooseUtils::isFloat(cp_name) && !MooseUtils::isFloat(Pr_t_name))
464 0 : params.set<std::vector<std::string>>("functor_names") = {Pr_t_name, mu_t_name};
465 42 : else if (!MooseUtils::isFloat(cp_name) && MooseUtils::isFloat(Pr_t_name))
466 0 : params.set<std::vector<std::string>>("functor_names") = {cp_name, mu_t_name};
467 : else
468 126 : params.set<std::vector<std::string>>("functor_names") = {mu_t_name};
469 :
470 126 : params.set<std::string>("expression") = mu_t_name + "*" + cp_name + "/" + Pr_t_name;
471 42 : params.set<std::string>("property_name") = NS::k_t;
472 126 : params.set<ExecFlagEnum>("execute_on") = {EXEC_NONLINEAR};
473 126 : params.set<std::vector<OutputName>>("outputs") = {"all"};
474 168 : getProblem().addMaterial(object_type, prefix() + "turbulent_heat_eff_conductivity", params);
475 42 : }
476 :
477 84 : if (_has_scalar_equations)
478 : {
479 42 : const auto scalar_diffs = _scalar_transport_physics->getParam<std::vector<MooseFunctorName>>(
480 84 : "passive_scalar_diffusivity");
481 : const auto mat_type =
482 42 : is_linear ? "FunctorEffectiveDynamicViscosity" : "ADFunctorEffectiveDynamicViscosity";
483 42 : InputParameters params = getFactory().getValidParams(mat_type);
484 42 : params.set<MooseFunctorName>(NS::mu) = _flow_equations_physics->dynamicViscosityName();
485 42 : params.set<MooseFunctorName>(NS::mu_t) = _turbulent_viscosity_name;
486 42 : const auto & rho_name = _flow_equations_physics->densityName();
487 42 : params.set<MooseFunctorName>(NS::mu_t + "_inverse_factor") = rho_name;
488 84 : const auto turbulent_schmidt_number = getParam<std::vector<Real>>("Sc_t");
489 42 : assignBlocks(params, _blocks);
490 : // LinearFV can only use 1 diffusion kernel per equation, so we create N_scalars mu_effs
491 42 : if (is_linear)
492 6 : for (const auto i : index_range(scalar_diffs))
493 : {
494 0 : if (!getProblem().hasFunctor(scalar_diffs[i] + "_eff", /*thread_id=*/0))
495 : {
496 0 : params.set<MooseFunctorName>("property_name") = scalar_diffs[i] + "_plus_mut/Sc_t";
497 0 : params.set<bool>("add_dynamic_viscosity") = true;
498 0 : params.set<Real>(NS::mu_t + "_extra_inverse_factor") =
499 0 : (turbulent_schmidt_number.size() == 1 ? turbulent_schmidt_number[0]
500 : : turbulent_schmidt_number[i]);
501 0 : getProblem().addMaterial(
502 0 : mat_type, prefix() + "mu_eff_passive_scalar_" + std::to_string(i), params);
503 : }
504 : }
505 : // WCNSFV can add multiple diffusion kernels
506 : else
507 : {
508 72 : params.set<MooseFunctorName>("property_name") = "mu_t_passive_scalar";
509 36 : params.set<bool>("add_dynamic_viscosity") = false;
510 36 : if (turbulent_schmidt_number.size() != 1)
511 0 : paramError("passive_scalar_schmidt_number",
512 : "A single passive scalar turbulent Schmidt number can and must be specified "
513 : "with k-epsilon and the WCNSFV discretization.");
514 36 : params.set<Real>(NS::mu_t + "_extra_inverse_factor") = turbulent_schmidt_number[0];
515 144 : getProblem().addMaterial(mat_type, prefix() + "mu_t_passive_scalars", params);
516 : }
517 42 : }
518 : }
519 702 : }
|