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  params.addParam<UserObjectName>(NS::fluid, "Fluid properties userobject");
38  params.addParamNamesToGroup(NS::fluid, "Material properties");
39 
40  // Initial conditions
41  params.addParam<FunctionName>(
42  "initial_enthalpy",
43  "Initial value of the enthalpy variable, only to be used when solving for enthalpy");
44 
45  // Spatial finite volume discretization scheme
46  params.transferParam<MooseEnum>(NSFVBase::validParams(), "energy_advection_interpolation");
47  params.transferParam<MooseEnum>(NSFVBase::validParams(), "energy_face_interpolation");
48  params.transferParam<bool>(NSFVBase::validParams(), "energy_two_term_bc_expansion");
49 
50  params.addParamNamesToGroup("specific_heat thermal_conductivity thermal_conductivity_blocks "
51  "use_external_enthalpy_material",
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_types energy_wall_functors", "Wall boundary conditions");
59 
60  return params;
61 }
62 
64  const InputParameters & parameters)
65  : NavierStokesPhysicsBase(parameters),
67  _has_energy_equation(
68  isParamValid("add_energy_equation")
69  ? getParam<bool>("add_energy_equation")
70  : (usingNavierStokesFVSyntax() ? isParamSetByUser("energy_inlet_functors") : true)),
71  _solve_for_enthalpy(getParam<bool>("solve_for_enthalpy")),
72  _fluid_enthalpy_name(getSpecificEnthalpyName()),
73  _fluid_temperature_name(getParam<NonlinearVariableName>("fluid_temperature_variable")),
74  _specific_heat_name(getParam<MooseFunctorName>("specific_heat")),
75  _thermal_conductivity_blocks(
76  parameters.isParamValid("thermal_conductivity_blocks")
77  ? getParam<std::vector<std::vector<SubdomainName>>>("thermal_conductivity_blocks")
78  : std::vector<std::vector<SubdomainName>>()),
79  _thermal_conductivity_name(getParam<std::vector<MooseFunctorName>>("thermal_conductivity")),
80  _ambient_convection_blocks(
81  getParam<std::vector<std::vector<SubdomainName>>>("ambient_convection_blocks")),
82  _ambient_convection_alpha(getParam<std::vector<MooseFunctorName>>("ambient_convection_alpha")),
83  _ambient_temperature(getParam<std::vector<MooseFunctorName>>("ambient_temperature")),
84  _energy_inlet_types(getParam<MultiMooseEnum>("energy_inlet_types")),
85  _energy_inlet_functors(getParam<std::vector<MooseFunctorName>>("energy_inlet_functors")),
86  _energy_wall_types(getParam<MultiMooseEnum>("energy_wall_types")),
87  _energy_wall_functors(getParam<std::vector<MooseFunctorName>>("energy_wall_functors"))
88 {
89  // For compatibility with Modules/NavierStokesFV syntax
91  return;
92 
95  else
97 
98  // set block restrictions if not set by user
99  // This should probably be done for all the coupled physics, tbd
100  if (!isParamSetByUser("block"))
102 
103  // Parameter checks
104  checkSecondParamSetOnlyIfFirstOneTrue("solve_for_enthalpy", "initial_enthalpy");
105  checkVectorParamsSameLengthIfSet<MooseFunctorName, MooseFunctorName>("ambient_convection_alpha",
106  "ambient_temperature");
107  checkSecondParamSetOnlyIfFirstOneSet("external_heat_source", "external_heat_source_coeff");
108 
109  // Check boundary parameters if provided.
110  // The boundaries are checked again when the boundary conditions are added as we want
111  // to be able to more boundary conditions to a Physics dynamically
112  if (isParamValid("energy_inlet_types"))
113  checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_inlet_functors",
114  "energy_inlet_types");
115  if (isParamSetByUser("energy_wall_boundaries"))
116  checkVectorParamsSameLengthIfSet<BoundaryName, MooseFunctorName>(
117  "energy_wall_boundaries", "energy_wall_functors", false);
118  if (isParamValid("energy_wall_types"))
119  checkVectorParamAndMultiMooseEnumLength<MooseFunctorName>("energy_wall_functors",
120  "energy_wall_types");
121 }
122 
123 void
125 {
126  // For compatibility with Modules/NavierStokesFV syntax
128  return;
129 
132  _blocks,
133  /*error if already defined*/ false))
135 
138  if (getParam<std::vector<MooseFunctorName>>("ambient_temperature").size())
140  if (isParamValid("external_heat_source"))
142 }
143 
144 void
146 {
147  // For compatibility with Modules/NavierStokesFV syntax
149  return;
150 
152  addEnergyWallBC();
155 }
156 
157 void
159 {
160  // Turbulence physics would not be initialized before this task
161  if (_current_task == "get_turbulence_physics")
163 }
164 
165 bool
167 {
168  checkBlockwiseConsistency<MooseFunctorName>("thermal_conductivity_blocks",
169  {"thermal_conductivity"});
170  bool have_scalar = false;
171  bool have_vector = false;
172 
173  for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
174  {
175  // First, check if the name is just a number (only in case of isotropic conduction)
177  have_scalar = true;
178  // Now we determine what kind of functor we are dealing with
179  else
180  {
182  /*thread_id=*/0) ||
184  /*thread_id=*/0))
185  have_scalar = true;
186  else
187  {
189  /*thread_id=*/0))
190  have_vector = true;
191  else
192  paramError("thermal_conductivity",
193  "We only allow functor of type Real/ADReal or ADRealVectorValue for thermal "
194  "conductivity! Functor '" +
195  _thermal_conductivity_name[i] + "' is not of the requested type.");
196  }
197  }
198  }
199 
200  if (have_vector && !_porous_medium_treatment)
201  paramError("thermal_conductivity", "Cannot use anisotropic diffusion with non-porous flows!");
202 
203  if (have_vector == have_scalar)
204  paramError("thermal_conductivity",
205  "The entries on thermal conductivity shall either be scalars of vectors, mixing "
206  "them is not supported!");
207  return have_vector;
208 }
209 
210 void
212 {
213  // For compatibility with Modules/NavierStokesFV syntax
215  return;
216  if (!_define_variables && parameters().isParamSetByUser("initial_temperature"))
217  paramError(
218  "initial_temperature",
219  "T_fluid is defined externally of WCNSFVFluidHeatTransferPhysicsBase, so should the inital "
220  "condition");
221  // do not set initial conditions if we are not defining variables
222  if (!_define_variables)
223  {
224  reportPotentiallyMissedParameters({"initial_temperature", "initial_enthalpy"}, "FunctionIC");
225  return;
226  }
227 
228  InputParameters params = getFactory().getValidParams("FVFunctionIC");
229  assignBlocks(params, _blocks);
230 
231  // initial_temperature has a default so we should almost always set it (see shouldCreateIC logic)
232  {
233  bool temperature_ic_used = false;
236  _blocks,
237  /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
238  /*error if already an IC*/ isParamSetByUser("initial_temperature")))
239  {
240  params.set<VariableName>("variable") = _fluid_temperature_name;
241  params.set<FunctionName>("function") = getParam<FunctionName>("initial_temperature");
242 
243  getProblem().addFVInitialCondition("FVFunctionIC", _fluid_temperature_name + "_ic", params);
244  temperature_ic_used = true;
245  }
246  // Needed to solve for enthalpy: an initial condition on enthalpy based on the initial
247  // temperature
248  if (isParamValid(NS::fluid) && _solve_for_enthalpy && !isParamValid("initial_enthalpy") &&
250  _blocks,
251  /*whether IC is a default*/ !isParamSetByUser("initial_temperature"),
252  /*error if already an IC*/ isParamSetByUser("initial_temperature")))
253  {
254  // from the FluidProperties module
255  InputParameters params =
256  getFactory().getValidParams("SpecificEnthalpyFromPressureTemperatureIC");
257  assignBlocks(params, _blocks);
258  params.set<VariableName>("variable") = _fluid_enthalpy_name;
259  params.set<UserObjectName>(NS::fluid) = getParam<UserObjectName>(NS::fluid);
260  params.set<std::vector<VariableName>>("p") = {_flow_equations_physics->getPressureName()};
261  Real temp;
262  if (MooseUtils::parsesToReal(getParam<FunctionName>("initial_temperature"), &temp))
263  {
264  params.defaultCoupledValue("T", temp, 0);
265  params.set<std::vector<VariableName>>("T") = {};
266  }
267  else
268  paramError("initial_temperature", "Only Real values supported when solving for enthalpy");
270  "SpecificEnthalpyFromPressureTemperatureIC", _fluid_enthalpy_name + "_ic", params);
271  temperature_ic_used = true;
272  }
273 
274  if (!temperature_ic_used && isParamSetByUser("initial_temperature"))
275  reportPotentiallyMissedParameters({"initial_temperature"}, "FunctionIC");
276  }
277  if (isParamValid("initial_enthalpy") && _solve_for_enthalpy &&
279  _blocks,
280  /*whether IC is a default*/ false,
281  /*error if already an IC*/ false))
282  {
283  params.set<VariableName>("variable") = _fluid_enthalpy_name;
284  params.set<FunctionName>("function") = getParam<FunctionName>("initial_enthalpy");
285 
286  getProblem().addFVInitialCondition("FVFunctionIC", _fluid_enthalpy_name + "_ic", params);
287  }
288  else if (isParamValid("initial_enthalpy"))
289  reportPotentiallyMissedParameters({"initial_enthalpy"}, "FunctionIC");
290 }
291 
292 void
294 {
295  // Define alpha, the diffusion coefficient when solving for enthalpy, on each block
296  for (unsigned int i = 0; i < _thermal_conductivity_name.size(); ++i)
297  {
298  const auto object_type = use_ad ? "ADParsedFunctorMaterial" : "ParsedFunctorMaterial";
299  InputParameters params = getFactory().getValidParams(object_type);
300  assignBlocks(params, _blocks);
301  std::vector<std::string> f_names;
303  f_names.push_back(_thermal_conductivity_name[i]);
305  f_names.push_back(getSpecificHeatName());
306  params.set<std::vector<std::string>>("functor_names") = f_names;
307  params.set<std::string>("expression") =
309  params.set<std::string>("property_name") = _thermal_conductivity_name[i] + "_by_cp";
311  object_type, prefix() + "rho_alpha_from_" + _thermal_conductivity_name[i], params);
312  }
313 }
314 
315 unsigned short
317 {
318  unsigned short necessary_layers = getParam<unsigned short>("ghost_layers");
319  necessary_layers =
321  if (getParam<MooseEnum>("energy_face_interpolation") == "skewness-corrected")
322  necessary_layers = std::max(necessary_layers, (unsigned short)3);
323 
324  return necessary_layers;
325 }
std::string prefix() const
virtual void addFVInitialCondition(const std::string &ic_name, const std::string &name, InputParameters &parameters)
static InputParameters validParams()
Definition: NSFVBase.C:371
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of algebraic ghosting layers needed.
void defineKOverCpFunctors(const bool use_ad)
Define the k/cp diffusion coefficients when solving for enthalpy.
virtual void addEnergyExternalHeatSource()=0
void assignBlocks(InputParameters &params, const std::vector< SubdomainName > &blocks) const
Factory & getFactory()
virtual void addEnergyTimeKernels()=0
Functions adding kernels for the incompressible / weakly compressible energy equation.
void paramError(const std::string &param, Args... args) const
const T & getParam(const std::string &name) const
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)
const InputParameters & parameters() const
T & set(const std::string &name, bool quiet_mode=false)
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
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()
const MooseFunctorName & getSpecificHeatName() const
Get the name of the specific heat material property.
static const std::string T_fluid
Definition: NS.h:106
bool hasFunctorWithType(const std::string &name, const THREAD_ID tid) const
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
const bool _porous_medium_treatment
Switch to show if porous medium treatment is requested or not.
virtual void addEnergyAdvectionKernels()=0
const std::string & _current_task
unsigned short getNumberAlgebraicGhostingLayersNeeded() const override
Return the number of ghosting layers needed.
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 variableExists(const VariableName &var_name, bool error_if_aux) const
bool _define_variables
Whether to define variables if they do not exist.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool processThermalConductivity()
Process thermal conductivity (multiple functor input options are available).
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)
bool isParamValid(const std::string &name) const
Base class to hold common parameters and utilities between all the weakly compressible Navier Stokes-...
void reportPotentiallyMissedParameters(const std::vector< std::string > &param_names, const std::string &object_type) const
const WCNSFVTurbulencePhysics * getCoupledTurbulencePhysics() const
void checkSecondParamSetOnlyIfFirstOneTrue(const std::string &param1, const std::string &param2) const
bool parsesToReal(const std::string &input, Real *parsed_real)
static InputParameters commonFluidEnergyEquationParams()
Definition: NSFVBase.C:197
bool isParamSetByUser(const std::string &name) const
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)
const NonlinearVariableName & getPressureName() const