https://mooseframework.inl.gov
Loading...
Searching...
No Matches
WCNSFVFluidHeatTransferPhysicsBase.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
12#include "WCNSFVFlowPhysics.h"
14#include "NSFVBase.h"
15
18{
21 params.addClassDescription("Define the Navier Stokes weakly-compressible energy equation");
22
25 "effective_conductivity");
26 params.addParamNamesToGroup("effective_conductivity", "Material properties");
27
28 // TODO Remove the parameter once NavierStokesFV syntax has been removed
29 params.addParam<bool>("add_energy_equation",
30 "Whether to add the energy equation. This parameter is not necessary if "
31 "using the Physics syntax");
32 params.addParam<bool>("solve_for_enthalpy",
33 false,
34 "Whether to solve for the enthalpy or the temperature of the fluid");
35 params.addParam<NonlinearVariableName>(
36 "fluid_temperature_variable", NS::T_fluid, "Name of the fluid temperature variable");
37
38 params.addParam<UserObjectName>(NS::fluid, "Fluid properties userobject");
39 params.addParamNamesToGroup(NS::fluid, "Material properties");
40
41 // Initial conditions
42 params.addParam<FunctionName>(
43 "initial_enthalpy",
44 "Initial value of the enthalpy variable, only to be used when solving for enthalpy");
45
46 // Spatial finite volume discretization scheme
47 params.transferParam<MooseEnum>(NSFVBase::validParams(), "energy_advection_interpolation");
48 params.transferParam<MooseEnum>(NSFVBase::validParams(), "energy_face_interpolation");
49 params.transferParam<bool>(NSFVBase::validParams(), "energy_two_term_bc_expansion");
50
51 params.addParamNamesToGroup("specific_heat thermal_conductivity thermal_conductivity_blocks "
52 "use_external_enthalpy_material",
53 "Material properties");
54 params.addParamNamesToGroup("energy_advection_interpolation energy_face_interpolation "
55 "energy_two_term_bc_expansion",
56 "Numerical scheme");
57 params.addParamNamesToGroup("energy_inlet_types energy_inlet_functors",
58 "Inlet boundary conditions");
59 params.addParamNamesToGroup("energy_wall_boundaries energy_wall_types energy_wall_functors",
60 "Wall boundary conditions");
61
62 return params;
63}
64
66 const InputParameters & parameters)
67 : NavierStokesPhysicsBase(parameters),
69 _has_energy_equation(
70 isParamValid("add_energy_equation")
71 ? getParam<bool>("add_energy_equation")
72 : (usingNavierStokesFVSyntax() ? isParamSetByUser("energy_inlet_functors") : true)),
73 _solve_for_enthalpy(getParam<bool>("solve_for_enthalpy")),
74 _fluid_enthalpy_name(getSpecificEnthalpyName()),
75 _fluid_temperature_name(getParam<NonlinearVariableName>("fluid_temperature_variable")),
76 _specific_heat_name(getParam<MooseFunctorName>("specific_heat")),
77 _thermal_conductivity_blocks(
78 parameters.isParamValid("thermal_conductivity_blocks")
79 ? getParam<std::vector<std::vector<SubdomainName>>>("thermal_conductivity_blocks")
80 : std::vector<std::vector<SubdomainName>>()),
81 _thermal_conductivity_name(getParam<std::vector<MooseFunctorName>>("thermal_conductivity")),
82 _ambient_convection_blocks(
83 getParam<std::vector<std::vector<SubdomainName>>>("ambient_convection_blocks")),
84 _ambient_convection_alpha(getParam<std::vector<MooseFunctorName>>("ambient_convection_alpha")),
85 _ambient_temperature(getParam<std::vector<MooseFunctorName>>("ambient_temperature")),
86 _energy_inlet_types(getParam<MultiMooseEnum>("energy_inlet_types")),
87 _energy_inlet_functors(getParam<std::vector<MooseFunctorName>>("energy_inlet_functors")),
88 _energy_wall_types(getParam<MultiMooseEnum>("energy_wall_types")),
89 _energy_wall_functors(getParam<std::vector<MooseFunctorName>>("energy_wall_functors"))
90{
91 // For compatibility with Modules/NavierStokesFV syntax
93 return;
94
97 else
99
100 // set block restrictions if not set by user
101 // This should probably be done for all the coupled physics, tbd
102 if (!isParamSetByUser("block"))
104
105 // Parameter checks
106 checkSecondParamSetOnlyIfFirstOneTrue("solve_for_enthalpy", "initial_enthalpy");
107 checkVectorParamsSameLengthIfSet<MooseFunctorName, MooseFunctorName>("ambient_convection_alpha",
108 "ambient_temperature");
109 checkSecondParamSetOnlyIfFirstOneSet("external_heat_source", "external_heat_source_coeff");
110
111 // Check boundary parameters if provided.
112 // The boundaries are checked again when the boundary conditions are added as we want
113 // to be able to more boundary conditions to a Physics dynamically
114 if (isParamValid("energy_inlet_types"))
115 checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_inlet_functors",
116 "energy_inlet_types");
117 if (isParamSetByUser("energy_wall_boundaries"))
118 checkVectorParamsSameLengthIfSet<BoundaryName, MooseFunctorName>(
119 "energy_wall_boundaries", "energy_wall_functors", false);
120 if (isParamValid("energy_wall_types"))
121 checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_wall_functors",
122 "energy_wall_types");
123
124 addRequiredPhysicsTask("get_turbulence_physics");
125 addRequiredPhysicsTask("add_variables_physics");
126 addRequiredPhysicsTask("add_ics_physics");
127 addRequiredPhysicsTask("add_fv_kernel");
128 addRequiredPhysicsTask("add_fv_bc");
129 addRequiredPhysicsTask("add_materials_physics");
130}
131
132void
134{
135 // For compatibility with Modules/NavierStokesFV syntax
137 return;
138
141 _blocks,
142 /*error if already defined*/ false))
144
147 if (getParam<std::vector<MooseFunctorName>>("ambient_temperature").size())
149 if (isParamValid("external_heat_source"))
151}
152
153void
155{
156 // For compatibility with Modules/NavierStokesFV syntax
158 return;
159
164}
165
166void
168{
169 // Turbulence physics would not be initialized before this task
170 if (_current_task == "get_turbulence_physics")
171 {
174 }
175}
176
177bool
179{
180 checkBlockwiseConsistency<MooseFunctorName>("thermal_conductivity_blocks",
181 {"thermal_conductivity"});
182 bool have_scalar = false;
183 bool have_vector = false;
184
185 for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
186 {
187 // First, check if the name is just a number (only in case of isotropic conduction)
189 have_scalar = true;
190 // Now we determine what kind of functor we are dealing with
191 else
192 {
193 if (getProblem().hasFunctorWithType<ADReal>(_thermal_conductivity_name[i],
194 /*thread_id=*/0) ||
195 getProblem().hasFunctorWithType<Real>(_thermal_conductivity_name[i],
196 /*thread_id=*/0))
197 have_scalar = true;
198 else
199 {
200 if (getProblem().hasFunctorWithType<ADRealVectorValue>(_thermal_conductivity_name[i],
201 /*thread_id=*/0))
202 have_vector = true;
203 else if (getProblem().hasFunctor(_thermal_conductivity_name[i],
204 /*thread_id=*/0))
205 paramError("thermal_conductivity",
206 "We only allow functor of type Real/ADReal or ADRealVectorValue for thermal "
207 "conductivity! Functor '" +
208 _thermal_conductivity_name[i] + "' is not of the requested type.");
209 else
210 // If another Physics is creating this functor, we could be running into an order of
211 // creation problem
212 paramWarning("thermal_conductivity",
213 "Functor '" + _thermal_conductivity_name[i] +
214 "' was not found in the Problem. Did you mispell it?");
215 }
216 }
217 }
218
219 if (have_vector && !_porous_medium_treatment)
220 paramError("thermal_conductivity", "Cannot use anisotropic diffusion with non-porous flows!");
221
222 if (have_vector && (have_vector == have_scalar))
223 paramError("thermal_conductivity",
224 "The entries on thermal conductivity shall either be scalars of vectors, mixing "
225 "them is not supported!");
226 return have_vector;
227}
228
229void
231{
232 // For compatibility with Modules/NavierStokesFV syntax
234 return;
235 if (!_define_variables && isParamSetByUser("initial_temperature"))
237 "initial_temperature",
238 "T_fluid is defined externally of WCNSFVFluidHeatTransferPhysicsBase, so should the inital "
239 "condition");
240 // do not set initial conditions if we are not defining variables
242 {
243 reportPotentiallyMissedParameters({"initial_temperature", "initial_enthalpy"}, "FunctionIC");
244 return;
245 }
246
247 InputParameters params = getFactory().getValidParams("FVFunctionIC");
248 assignBlocks(params, _blocks);
249
250 // initial_temperature has a default so we should almost always set it (see shouldCreateIC logic)
251 {
252 bool temperature_ic_used = false;
255 _blocks,
256 /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
257 /*error if already an IC*/ isParamSetByUser("initial_temperature")))
258 {
259 params.set<VariableName>("variable") = _fluid_temperature_name;
260 params.set<FunctionName>("function") = getParam<FunctionName>("initial_temperature");
261
262 getProblem().addFVInitialCondition("FVFunctionIC", _fluid_temperature_name + "_ic", params);
263 temperature_ic_used = true;
264 }
265 // Needed to solve for enthalpy: an initial condition on enthalpy based on the initial
266 // temperature
267 if (isParamValid(NS::fluid) && _solve_for_enthalpy && !isParamValid("initial_enthalpy") &&
269 _blocks,
270 /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
271 /*error if already an IC*/ isParamSetByUser("initial_temperature")))
272 {
273 // from the FluidProperties module
274 InputParameters params =
275 getFactory().getValidParams("SpecificEnthalpyFromPressureTemperatureIC");
276 assignBlocks(params, _blocks);
277 params.set<VariableName>("variable") = _fluid_enthalpy_name;
278 params.set<UserObjectName>(NS::fluid) = getParam<UserObjectName>(NS::fluid);
279 params.set<std::vector<VariableName>>("p") = {_flow_equations_physics->getPressureName()};
280 Real temp;
281 if (MooseUtils::parsesToReal(getParam<FunctionName>("initial_temperature"), &temp))
282 {
283 params.defaultCoupledValue("T", temp, 0);
284 params.set<std::vector<VariableName>>("T") = {};
285 }
286 else
287 paramError("initial_temperature", "Only Real values supported when solving for enthalpy");
289 "SpecificEnthalpyFromPressureTemperatureIC", _fluid_enthalpy_name + "_ic", params);
290 temperature_ic_used = true;
291 }
292
293 if (!temperature_ic_used && isParamSetByUser("initial_temperature"))
294 reportPotentiallyMissedParameters({"initial_temperature"}, "FunctionIC");
295 }
296 if (isParamValid("initial_enthalpy") && _solve_for_enthalpy &&
298 _blocks,
299 /*whether IC is a default*/ false,
300 /*error if already an IC*/ false))
301 {
302 params.set<VariableName>("variable") = _fluid_enthalpy_name;
303 params.set<FunctionName>("function") = getParam<FunctionName>("initial_enthalpy");
304
305 getProblem().addFVInitialCondition("FVFunctionIC", _fluid_enthalpy_name + "_ic", params);
306 }
307 else if (isParamValid("initial_enthalpy"))
308 reportPotentiallyMissedParameters({"initial_enthalpy"}, "FunctionIC");
309}
310
311void
313{
314 // Define alpha, the diffusion coefficient when solving for enthalpy, on each block
315 for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
316 {
317 const auto object_type = use_ad ? "ADParsedFunctorMaterial" : "ParsedFunctorMaterial";
318 InputParameters params = getFactory().getValidParams(object_type);
319 assignBlocks(params, _blocks);
320 std::vector<std::string> f_names;
322 f_names.push_back(_thermal_conductivity_name[i]);
324 f_names.push_back(getSpecificHeatName());
325 const auto th_cond_name =
326 _thermal_conductivity_name[i] + (_has_turbulence_model ? "_plus_kt" : "");
328 params.set<std::string>("expression") =
330 (_solve_for_enthalpy ? ("/" + getSpecificHeatName()) : "");
331 else
332 {
333 f_names.push_back("k_t");
334 params.set<std::string>("expression") =
335 "(" + _thermal_conductivity_name[i] + " + k_t) " +
336 (_solve_for_enthalpy ? ("/" + getSpecificHeatName()) : "");
337 }
338 params.set<std::vector<std::string>>("functor_names") = f_names;
339 params.set<std::string>("property_name") = th_cond_name + (_solve_for_enthalpy ? "_by_cp" : "");
341 object_type, prefix() + "rho_alpha_from_" + _thermal_conductivity_name[i], params);
342 }
343}
344
345unsigned short
347{
348 unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
349 necessary_layers =
351 if (getParam<MooseEnum>("energy_face_interpolation") == "skewness-corrected")
352 necessary_layers = std::max(necessary_layers, (unsigned short)3);
353
354 return necessary_layers;
355}
const std::string & _current_task
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
virtual void addFVInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
InputParameters getValidParams(const std::string &name) const
void checkSecondParamSetOnlyIfFirstOneTrue(const std::string &param1, const std::string &param2) const
void checkSecondParamSetOnlyIfFirstOneSet(const std::string &param1, const std::string &param2) const
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void transferParam(const InputParameters &source_param, const std::string &name, const std::string &new_name="", const std::string &new_description="")
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)
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
void paramWarning(const std::string &param, Args... args) const
void paramError(const std::string &param, Args... args) const
bool isParamSetByUser(const std::string &name) const
const T & getParam(const std::string &name) const
bool isParamValid(const std::string &name) const
static InputParameters commonFluidEnergyEquationParams()
Definition NSFVBase.C:197
static InputParameters validParams()
Definition NSFVBase.C:371
Base class to hold common parameters and utilities between all the weakly compressible Navier Stokes-...
static InputParameters validParams()
bool _define_variables
Whether to define variables if they do not exist.
virtual FEProblemBase & getProblem()
Factory & getFactory()
bool shouldCreateIC(const VariableName &var_name, const std::vector< SubdomainName > &blocks, const bool ic_is_default_ic, const bool error_if_already_defined) const
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
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type, const std::string &object_name="") const
void saveSolverVariableName(const VariableName &var_name)
std::string prefix() const
bool variableExists(const VariableName &var_name, bool error_if_aux) const
std::vector< SubdomainName > _blocks
const std::vector< SubdomainName > & blocks() const
void addRequiredPhysicsTask(const std::string &task)
Helper class to interact with a flow and turbulence physics for a Physics that solves an advection pr...
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
const WCNSFVTurbulencePhysicsBase * _turbulence_physics
Turbulence.
const WCNSFVTurbulencePhysicsBase * getCoupledTurbulencePhysics() const
bool _has_turbulence_model
Because of the Modules/navierStokesFV syntax, a turbulence physics often exists without a model we sa...
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
const NonlinearVariableName & getPressureName() const
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
virtual void addEnergyExternalHeatSource()=0
virtual void addEnergyAmbientConvection()=0
const VariableName _fluid_enthalpy_name
Name of the fluid specific enthalpy.
WCNSFVFluidHeatTransferPhysicsBase(const InputParameters &parameters)
bool processThermalConductivity()
Process thermal conductivity (multiple functor input options are available).
virtual void addEnergyTimeKernels()=0
Functions adding kernels for the incompressible / weakly compressible energy equation.
const MooseFunctorName & getSpecificHeatName() const
Get the name of the specific heat material property.
VariableName _fluid_temperature_name
Fluid temperature name.
void defineEffectiveThermalDiffusionCoeffFunctors(const bool use_ad)
Define the effective diffusion coefficient when:
virtual void addEnergyInletBC()=0
Functions adding boundary conditions for the fluid heat transfer equation.
const bool _has_energy_equation
A boolean to help compatibility with the old Modules/NavierStokesFV syntax.
virtual void addEnergyHeatConductionKernels()=0
virtual void addEnergyAdvectionKernels()=0
const bool _solve_for_enthalpy
User-selected option to solve for enthalpy.
std::vector< MooseFunctorName > _thermal_conductivity_name
Name of the thermal conductivity functor for each block-group.
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
bool hasTurbulenceModel() const
Whether a turbulence model is in use.
bool parsesToReal(const std::string &input, Real *parsed_real)
static const std::string T_fluid
Definition NS.h:110
static const std::string fluid
Definition NS.h:88