https://mooseframework.inl.gov
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 
27  // TODO Remove the parameter once NavierStokesFV syntax has been removed
28  params.addParam<bool>("add_energy_equation",
29  "Whether to add the energy equation. This parameter is not necessary if "
30  "using the Physics syntax");
31  params.addParam<bool>("solve_for_enthalpy",
32  false,
33  "Whether to solve for the enthalpy or the temperature of the fluid");
34  params.addParam<NonlinearVariableName>(
35  "fluid_temperature_variable", NS::T_fluid, "Name of the fluid temperature variable");
36 
37  // Initial conditions
38  params.addParam<FunctionName>(
39  "initial_enthalpy",
40  "Initial value of the enthalpy variable, only to be used when solving for enthalpy");
41 
42  // New functor boundary conditions
43  params.deprecateParam("energy_inlet_function", "energy_inlet_functors", "01/01/2025");
44  params.deprecateParam("energy_wall_function", "energy_wall_functors", "01/01/2025");
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_types energy_wall_functors", "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_function") : 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 
124 void
126 {
127  // For compatibility with Modules/NavierStokesFV syntax
129  return;
130 
133  _blocks,
134  /*error if already defined*/ false))
136 
139  if (getParam<std::vector<MooseFunctorName>>("ambient_temperature").size())
141  if (isParamValid("external_heat_source"))
143 }
144 
145 void
147 {
148  // For compatibility with Modules/NavierStokesFV syntax
150  return;
151 
153  addEnergyWallBC();
156 }
157 
158 void
160 {
161  // Turbulence physics would not be initialized before this task
162  if (_current_task == "get_turbulence_physics")
164 }
165 
166 bool
168 {
169  checkBlockwiseConsistency<MooseFunctorName>("thermal_conductivity_blocks",
170  {"thermal_conductivity"});
171  bool have_scalar = false;
172  bool have_vector = false;
173 
174  for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
175  {
176  // First, check if the name is just a number (only in case of isotropic conduction)
178  have_scalar = true;
179  // Now we determine what kind of functor we are dealing with
180  else
181  {
183  /*thread_id=*/0) ||
185  /*thread_id=*/0))
186  have_scalar = true;
187  else
188  {
190  /*thread_id=*/0))
191  have_vector = true;
192  else
193  paramError("thermal_conductivity",
194  "We only allow functor of type Real/ADReal or ADRealVectorValue for thermal "
195  "conductivity! Functor '" +
196  _thermal_conductivity_name[i] + "' is not of the requested type.");
197  }
198  }
199  }
200 
201  if (have_vector && !_porous_medium_treatment)
202  paramError("thermal_conductivity", "Cannot use anisotropic diffusion with non-porous flows!");
203 
204  if (have_vector == have_scalar)
205  paramError("thermal_conductivity",
206  "The entries on thermal conductivity shall either be scalars of vectors, mixing "
207  "them is not supported!");
208  return have_vector;
209 }
210 
211 void
213 {
214  // For compatibility with Modules/NavierStokesFV syntax
216  return;
217  if (!_define_variables && parameters().isParamSetByUser("initial_temperature"))
218  paramError(
219  "initial_temperature",
220  "T_fluid is defined externally of WCNSFVFluidHeatTransferPhysicsBase, so should the inital "
221  "condition");
222  // do not set initial conditions if we are not defining variables
223  if (!_define_variables)
224  return;
225 
226  InputParameters params = getFactory().getValidParams("FunctionIC");
227  assignBlocks(params, _blocks);
228 
230  _blocks,
231  /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
232  /*error if already an IC*/ isParamSetByUser("initial_temperature")))
233  {
234  params.set<VariableName>("variable") = _fluid_temperature_name;
235  params.set<FunctionName>("function") = getParam<FunctionName>("initial_temperature");
236 
237  getProblem().addInitialCondition("FunctionIC", _fluid_temperature_name + "_ic", params);
238  }
239  if (parameters().isParamValid("initial_enthalpy") &&
241  _blocks,
242  /*whether IC is a default*/ false,
243  /*error if already an IC*/ true))
244  {
245  params.set<VariableName>("variable") = _fluid_enthalpy_name;
246  params.set<FunctionName>("function") = getParam<FunctionName>("initial_enthalpy");
247 
248  getProblem().addInitialCondition("FunctionIC", _fluid_enthalpy_name + "_ic", params);
249  }
250 }
251 
252 void
254 {
255  // For compatibility with Modules/NavierStokesFV syntax
257  return;
258 
259  // Note that this material choice would not work for Newton-INSFV + solve_for_enthalpy
260  const auto object_type =
261  _solve_for_enthalpy ? "LinearFVEnthalpyFunctorMaterial" : "INSFVEnthalpyFunctorMaterial";
262 
263  InputParameters params = getFactory().getValidParams(object_type);
264  assignBlocks(params, _blocks);
265 
267  {
268  params.set<MooseFunctorName>(NS::pressure) = _flow_equations_physics->getPressureName();
269  params.set<MooseFunctorName>(NS::T_fluid) = _fluid_temperature_name;
270  params.set<MooseFunctorName>(NS::specific_enthalpy) = _fluid_enthalpy_name;
271  if (isParamValid(NS::fluid))
272  params.set<UserObjectName>(NS::fluid) = getParam<UserObjectName>(NS::fluid);
273  else
274  {
275  if (!getProblem().hasFunctor("h_from_p_T_functor", 0) ||
276  !getProblem().hasFunctor("T_from_p_h_functor", 0))
278  "Either 'fp' must be specified or the 'h_from_p_T_functor' and "
279  "'T_from_p_h_functor' must be defined outside the Physics");
280  // Note: we could define those in the Physics if cp is constant
281  params.set<MooseFunctorName>("h_from_p_T_functor") = "h_from_p_T_functor";
282  params.set<MooseFunctorName>("T_from_p_h_functor") = "T_from_p_h_functor";
283  }
284  }
285  else
286  {
287  params.set<MooseFunctorName>(NS::density) = _density_name;
288  params.set<MooseFunctorName>(NS::cp) = _specific_heat_name;
289  params.set<MooseFunctorName>("temperature") = _fluid_temperature_name;
290  }
291 
292  getProblem().addMaterial(object_type, prefix() + "enthalpy_material", params);
293 }
294 
295 unsigned short
297 {
298  unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
299  necessary_layers =
301  if (getParam<MooseEnum>("energy_face_interpolation") == "skewness-corrected")
302  necessary_layers = std::max(necessary_layers, (unsigned short)3);
303 
304  return necessary_layers;
305 }
std::string prefix() const
bool parsesToReal(const std::string &input)
static InputParameters validParams()
Definition: NSFVBase.C:368
MooseFunctorName _specific_heat_name
Name of the specific heat material property.
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
virtual void addEnergyExternalHeatSource()=0
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
const MooseFunctorName _density_name
Name of the density material property.
Factory & getFactory()
virtual void addEnergyTimeKernels()=0
Functions adding kernels for the incompressible / weakly compressible energy equation.
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
virtual void addMaterial(const std::string &material_name, const std::string &name, InputParameters &parameters)
T & set(const std::string &name, bool quiet_mode=false)
static const std::string density
Definition: NS.h:33
InputParameters getValidParams(const std::string &name) const
const std::vector< SubdomainName > & blocks() const
static const std::string fluid
Definition: NS.h:87
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
VariableName _fluid_temperature_name
Fluid temperature name.
std::vector< SubdomainName > _blocks
const WCNSFVTurbulencePhysics * _turbulence_physics
Turbulence.
virtual void addEnergyAmbientConvection()=0
bool isParamValid(const std::string &name) const
virtual void addInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
void checkSecondParamSetOnlyIfFirstOneSet(const std::string &param1, const std::string &param2) const
virtual FEProblemBase & getProblem()
static InputParameters validParams()
static const std::string cp
Definition: NS.h:121
static const std::string T_fluid
Definition: NS.h:106
void deprecateParam(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
bool hasFunctorWithType(const std::string &name, const THREAD_ID tid) const
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
virtual void addEnergyAdvectionKernels()=0
const T & getParam(const std::string &name) const
const std::string & _current_task
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
void paramError(const std::string &param, Args... args) const
Helper class to interact with a flow and turbulence physics for a Physics that solves an advection pr...
void transferParam(const InputParameters &source_param, const std::string &name, const std::string &new_name="", const std::string &new_description="")
const VariableName _fluid_enthalpy_name
Name of the fluid specific enthalpy.
const bool _has_energy_equation
A boolean to help compatibility with the old Modules/NavierStokesFV syntax.
virtual void addEnergyInletBC()=0
Functions adding boundary conditions for the fluid heat transfer equation.
WCNSFVFluidHeatTransferPhysicsBase(const InputParameters &parameters)
bool _define_variables
Whether to define variables if they do not exist.
bool isParamSetByUser(const std::string &nm) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool processThermalConductivity()
Process thermal conductivity (multiple functor input options are available).
static const std::string pressure
Definition: NS.h:56
std::vector< MooseFunctorName > _thermal_conductivity_name
Name of the thermal conductivity functor for each block-group.
const bool _solve_for_enthalpy
User-selected option to solve for enthalpy.
void addClassDescription(const std::string &doc_string)
const InputParameters & parameters() const
Base class to hold common parameters and utilities between all the weakly compressible Navier Stokes-...
const WCNSFVTurbulencePhysics * getCoupledTurbulencePhysics() const
bool hasFunctor(const std::string &name, const THREAD_ID tid) const
void checkSecondParamSetOnlyIfFirstOneTrue(const std::string &param1, const std::string &param2) const
static InputParameters commonFluidEnergyEquationParams()
Definition: NSFVBase.C:191
void saveSolverVariableName(const VariableName &var_name)
const WCNSFVFlowPhysicsBase * _flow_equations_physics
Flow physics.
virtual void addEnergyHeatConductionKernels()=0
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
static const std::string specific_enthalpy
Definition: NS.h:68
const NonlinearVariableName & getPressureName() const