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 "Material properties");
53 params.addParamNamesToGroup("energy_advection_interpolation energy_face_interpolation "
54 "energy_two_term_bc_expansion",
55 "Numerical scheme");
56 params.addParamNamesToGroup("energy_inlet_types energy_inlet_functors",
57 "Inlet boundary conditions");
58 params.addParamNamesToGroup("energy_wall_boundaries energy_wall_types energy_wall_functors",
59 "Wall boundary conditions");
60
61 return params;
62}
63
65 const InputParameters & parameters)
66 : NavierStokesPhysicsBase(parameters),
68 _has_energy_equation(
69 isParamValid("add_energy_equation")
70 ? getParam<bool>("add_energy_equation")
71 : (usingNavierStokesFVSyntax() ? isParamSetByUser("energy_inlet_functors") : true)),
72 _solve_for_enthalpy(getParam<bool>("solve_for_enthalpy")),
73 _fluid_enthalpy_name(getSpecificEnthalpyName()),
74 _fluid_temperature_name(getParam<NonlinearVariableName>("fluid_temperature_variable")),
75 _specific_heat_name(getParam<MooseFunctorName>("specific_heat")),
76 _thermal_conductivity_blocks(
77 parameters.isParamValid("thermal_conductivity_blocks")
78 ? getParam<std::vector<std::vector<SubdomainName>>>("thermal_conductivity_blocks")
79 : std::vector<std::vector<SubdomainName>>()),
80 _thermal_conductivity_name(getParam<std::vector<MooseFunctorName>>("thermal_conductivity")),
81 _ambient_convection_blocks(
82 getParam<std::vector<std::vector<SubdomainName>>>("ambient_convection_blocks")),
83 _ambient_convection_alpha(getParam<std::vector<MooseFunctorName>>("ambient_convection_alpha")),
84 _ambient_temperature(getParam<std::vector<MooseFunctorName>>("ambient_temperature")),
85 _energy_inlet_types(getParam<MultiMooseEnum>("energy_inlet_types")),
86 _energy_inlet_functors(getParam<std::vector<MooseFunctorName>>("energy_inlet_functors")),
87 _energy_wall_types(getParam<MultiMooseEnum>("energy_wall_types")),
88 _energy_wall_functors(getParam<std::vector<MooseFunctorName>>("energy_wall_functors"))
89{
90 // For compatibility with Modules/NavierStokesFV syntax
92 return;
93
96 else
98
99 // set block restrictions if not set by user
100 // This should probably be done for all the coupled physics, tbd
101 if (!isParamSetByUser("block"))
103
104 // Parameter checks
105 checkSecondParamSetOnlyIfFirstOneTrue("solve_for_enthalpy", "initial_enthalpy");
106 checkVectorParamsSameLengthIfSet<MooseFunctorName, MooseFunctorName>("ambient_convection_alpha",
107 "ambient_temperature");
108 checkSecondParamSetOnlyIfFirstOneSet("external_heat_source", "external_heat_source_coeff");
109
110 // Check boundary parameters if provided.
111 // The boundaries are checked again when the boundary conditions are added as we want
112 // to be able to more boundary conditions to a Physics dynamically
113 if (isParamValid("energy_inlet_types"))
114 checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_inlet_functors",
115 "energy_inlet_types");
116 if (isParamSetByUser("energy_wall_boundaries"))
117 checkVectorParamsSameLengthIfSet<BoundaryName, MooseFunctorName>(
118 "energy_wall_boundaries", "energy_wall_functors", false);
119 if (isParamValid("energy_wall_types"))
120 checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_wall_functors",
121 "energy_wall_types");
122
123 addRequiredPhysicsTask("get_turbulence_physics");
124 addRequiredPhysicsTask("add_variables_physics");
125 addRequiredPhysicsTask("add_ics_physics");
126 addRequiredPhysicsTask("add_fv_kernel");
127 addRequiredPhysicsTask("add_fv_bc");
128 addRequiredPhysicsTask("add_materials_physics");
129}
130
131void
133{
134 // For compatibility with Modules/NavierStokesFV syntax
136 return;
137
140 _blocks,
141 /*error if already defined*/ false))
143
146 if (getParam<std::vector<MooseFunctorName>>("ambient_temperature").size())
148 if (isParamValid("external_heat_source"))
150}
151
152void
154{
155 // For compatibility with Modules/NavierStokesFV syntax
157 return;
158
163}
164
165void
167{
168 // Turbulence physics would not be initialized before this task
169 if (_current_task == "get_turbulence_physics")
170 {
173 }
174}
175
176bool
178{
179 checkBlockwiseConsistency<MooseFunctorName>("thermal_conductivity_blocks",
180 {"thermal_conductivity"});
181 bool have_scalar = false;
182 bool have_vector = false;
183
184 for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
185 {
186 // First, check if the name is just a number (only in case of isotropic conduction)
188 have_scalar = true;
189 // Now we determine what kind of functor we are dealing with
190 else
191 {
192 if (getProblem().hasFunctorWithType<ADReal>(_thermal_conductivity_name[i],
193 /*thread_id=*/0) ||
194 getProblem().hasFunctorWithType<Real>(_thermal_conductivity_name[i],
195 /*thread_id=*/0))
196 have_scalar = true;
197 else
198 {
199 if (getProblem().hasFunctorWithType<ADRealVectorValue>(_thermal_conductivity_name[i],
200 /*thread_id=*/0))
201 have_vector = true;
202 else if (getProblem().hasFunctor(_thermal_conductivity_name[i],
203 /*thread_id=*/0))
204 paramError("thermal_conductivity",
205 "We only allow functor of type Real/ADReal or ADRealVectorValue for thermal "
206 "conductivity! Functor '" +
207 _thermal_conductivity_name[i] + "' is not of the requested type.");
208 else
209 // If another Physics is creating this functor, we could be running into an order of
210 // creation problem
211 paramWarning("thermal_conductivity",
212 "Functor '" + _thermal_conductivity_name[i] +
213 "' was not found in the Problem. Did you mispell it?");
214 }
215 }
216 }
217
218 if (have_vector && !_porous_medium_treatment)
219 paramError("thermal_conductivity", "Cannot use anisotropic diffusion with non-porous flows!");
220
221 if (have_vector && (have_vector == have_scalar))
222 paramError("thermal_conductivity",
223 "The entries on thermal conductivity shall either be scalars of vectors, mixing "
224 "them is not supported!");
225 return have_vector;
226}
227
228void
230{
231 // For compatibility with Modules/NavierStokesFV syntax
233 return;
234 if (!_define_variables && isParamSetByUser("initial_temperature"))
236 "initial_temperature",
237 "T_fluid is defined externally of WCNSFVFluidHeatTransferPhysicsBase, so should the inital "
238 "condition");
239 // do not set initial conditions if we are not defining variables
241 {
242 reportPotentiallyMissedParameters({"initial_temperature", "initial_enthalpy"}, "FunctionIC");
243 return;
244 }
245
246 InputParameters params = getFactory().getValidParams("FVFunctionIC");
247 assignBlocks(params, _blocks);
248
249 // initial_temperature has a default so we should almost always set it (see shouldCreateIC logic)
250 {
251 bool temperature_ic_used = false;
254 _blocks,
255 /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
256 /*error if already an IC*/ isParamSetByUser("initial_temperature")))
257 {
258 params.set<VariableName>("variable") = _fluid_temperature_name;
259 params.set<FunctionName>("function") = getParam<FunctionName>("initial_temperature");
260
261 getProblem().addFVInitialCondition("FVFunctionIC", _fluid_temperature_name + "_ic", params);
262 temperature_ic_used = true;
263 }
264 // Needed to solve for enthalpy: an initial condition on enthalpy based on the initial
265 // temperature
266 if (isParamValid(NS::fluid) && _solve_for_enthalpy && !isParamValid("initial_enthalpy") &&
268 _blocks,
269 /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
270 /*error if already an IC*/ isParamSetByUser("initial_temperature")))
271 {
272 // from the FluidProperties module
273 InputParameters params =
274 getFactory().getValidParams("SpecificEnthalpyFromPressureTemperatureIC");
275 assignBlocks(params, _blocks);
276 params.set<VariableName>("variable") = _fluid_enthalpy_name;
277 params.set<UserObjectName>(NS::fluid) = getParam<UserObjectName>(NS::fluid);
278 params.set<std::vector<VariableName>>("p") = {_flow_equations_physics->getPressureName()};
279 Real temp;
280 if (MooseUtils::parsesToReal(getParam<FunctionName>("initial_temperature"), &temp))
281 {
282 params.defaultCoupledValue("T", temp, 0);
283 params.set<std::vector<VariableName>>("T") = {};
284 }
285 else
286 paramError("initial_temperature", "Only Real values supported when solving for enthalpy");
288 "SpecificEnthalpyFromPressureTemperatureIC", _fluid_enthalpy_name + "_ic", params);
289 temperature_ic_used = true;
290 }
291
292 if (!temperature_ic_used && isParamSetByUser("initial_temperature"))
293 reportPotentiallyMissedParameters({"initial_temperature"}, "FunctionIC");
294 }
295 if (isParamValid("initial_enthalpy") && _solve_for_enthalpy &&
297 _blocks,
298 /*whether IC is a default*/ false,
299 /*error if already an IC*/ false))
300 {
301 params.set<VariableName>("variable") = _fluid_enthalpy_name;
302 params.set<FunctionName>("function") = getParam<FunctionName>("initial_enthalpy");
303
304 getProblem().addFVInitialCondition("FVFunctionIC", _fluid_enthalpy_name + "_ic", params);
305 }
306 else if (isParamValid("initial_enthalpy"))
307 reportPotentiallyMissedParameters({"initial_enthalpy"}, "FunctionIC");
308}
309
310void
312{
313 // Define alpha, the diffusion coefficient when solving for enthalpy, on each block
314 for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
315 {
316 const auto object_type = use_ad ? "ADParsedFunctorMaterial" : "ParsedFunctorMaterial";
317 InputParameters params = getFactory().getValidParams(object_type);
318 assignBlocks(params, _blocks);
319 std::vector<std::string> f_names;
321 f_names.push_back(_thermal_conductivity_name[i]);
323 f_names.push_back(getSpecificHeatName());
324 const auto th_cond_name =
325 _thermal_conductivity_name[i] + (_has_turbulence_model ? "_plus_kt" : "");
327 params.set<std::string>("expression") =
329 (_solve_for_enthalpy ? ("/" + getSpecificHeatName()) : "");
330 else
331 {
332 f_names.push_back("k_t");
333 params.set<std::string>("expression") =
334 "(" + _thermal_conductivity_name[i] + " + k_t) " +
335 (_solve_for_enthalpy ? ("/" + getSpecificHeatName()) : "");
336 }
337 params.set<std::vector<std::string>>("functor_names") = f_names;
338 params.set<std::string>("property_name") = th_cond_name + (_solve_for_enthalpy ? "_by_cp" : "");
340 object_type, prefix() + "rho_alpha_from_" + _thermal_conductivity_name[i], params);
341 }
342}
343
344unsigned short
346{
347 unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
348 necessary_layers =
350 if (getParam<MooseEnum>("energy_face_interpolation") == "skewness-corrected")
351 necessary_layers = std::max(necessary_layers, (unsigned short)3);
352
353 return necessary_layers;
354}
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:378
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