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