https://mooseframework.inl.gov
INSFVEnthalpyFunctorMaterial.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 
11 #include "NS.h"
13 
14 registerMooseObjectRenamed("NavierStokesApp",
15  INSFVEnthalpyMaterial,
16  "02/01/2024 00:00",
19 
22 {
24  params.addClassDescription(
25  "This is the material class used to compute enthalpy for the "
26  "incompressible/weakly-compressible finite-volume implementation of the Navier-Stokes "
27  "equations.");
28  params.addRequiredParam<MooseFunctorName>(NS::density, "The value for the density");
29  params.addRequiredParam<MooseFunctorName>("temperature", "the temperature");
30  params.addParam<MooseFunctorName>(
31  NS::cp, NS::cp, "The constant value for the specific heat capacity");
32  params.addParam<MooseFunctorName>(
33  NS::enthalpy_density, NS::enthalpy_density, "the name of the (extensive) enthalpy");
34  params.addParam<MooseFunctorName>(
35  NS::specific_enthalpy, NS::specific_enthalpy, "the name of the specific enthalpy");
36 
37  // To handle non constant cp
38  params.addParam<bool>("assumed_constant_cp", true, "Whether to assume cp is constant");
39  params.addParam<UserObjectName>(
40  NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
41  params.addParam<MooseFunctorName>(
42  NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");
43  params.addParam<MooseFunctorName>(
44  NS::specific_enthalpy + "_in",
45  "Specific enthalpy functor, to be used when cp is not constant to compute the enthalpy, as "
46  "an alternative to using a 'fp' FluidProperties object");
47 
48  return params;
49 }
50 
52  : FunctorMaterial(parameters),
53  _assumed_constant_cp(getParam<bool>("assumed_constant_cp")),
54  _fp(isParamValid(NS::fluid)
56  : nullptr),
57  _rho(getFunctor<ADReal>(NS::density)),
58  _temperature(getFunctor<ADReal>("temperature")),
59  _pressure(isParamValid("pressure") ? &getFunctor<ADReal>("pressure") : nullptr),
60  _cp(getFunctor<ADReal>(NS::cp)),
61  _h(isParamValid(NS::specific_enthalpy + "_in")
62  ? &getFunctor<ADReal>(NS::specific_enthalpy + "_in")
63  : nullptr)
64 {
65  // We have to use a warning because fp is often in the global parameters
68  "fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
69  if (!_assumed_constant_cp && ((!_fp || !_pressure) && !_h))
70  paramError("fp",
71  "Must specify both fluid properties and pressure or an enthalpy functor if not "
72  "assuming the specific enthalpy is constant");
73 
75  {
76  const auto & rho_h =
77  addFunctorProperty<ADReal>(NS::enthalpy_density,
78  [this](const auto & r, const auto & t)
79  { return _rho(r, t) * _cp(r, t) * _temperature(r, t); });
80 
81  const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
82  [this](const auto & r, const auto & t)
83  { return _cp(r, t) * _temperature(r, t); });
84 
85  addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
86  [this](const auto & r, const auto & t)
87  { return _cp(r, t) * _temperature.dot(r, t); });
88 
89  addFunctorProperty<ADReal>(
90  "rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
91 
92  addFunctorProperty<ADReal>("cp_temp",
93  [&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
94  }
95  else if (_h)
96  {
97  addFunctorProperty<ADReal>(NS::enthalpy_density,
98  [this](const auto & r, const auto & t)
99  { return _rho(r, t) * (*_h)(r, t); });
100 
101  addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
102  [this](const auto & r, const auto & t) { return _h->dot(r, t); });
103  }
104  else
105  {
106  addFunctorProperty<ADReal>(
108  [this](const auto & r, const auto & t)
109  { return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t)); });
110 
111  addFunctorProperty<ADReal>(NS::specific_enthalpy,
112  [this](const auto & r, const auto & t)
113  { return _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t)); });
114 
115  addFunctorProperty<ADReal>(
116  NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
117  [this](const auto & r, const auto & t)
118  {
119  Real h, dh_dp, dh_dT;
120  _fp->h_from_p_T((*_pressure)(r, t).value(), _temperature(r, t).value(), h, dh_dp, dh_dT);
121  return dh_dT * _temperature.dot(r, t) + dh_dp * _pressure->dot(r, t);
122  });
123  }
124 }
registerMooseObjectRenamed("NavierStokesApp", INSFVEnthalpyMaterial, "02/01/2024 00:00", INSFVEnthalpyFunctorMaterial)
const Moose::Functor< ADReal > & _cp
the specific heat capacity
static InputParameters validParams()
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
bool _assumed_constant_cp
whether we can use a constant cp as a shortcut to compute enthalpy
static const std::string density
Definition: NS.h:33
static const std::string fluid
Definition: NS.h:87
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
registerMooseObject("NavierStokesApp", INSFVEnthalpyFunctorMaterial)
static const std::string cp
Definition: NS.h:121
const Moose::Functor< ADReal > & _temperature
the temperature
const Moose::Functor< ADReal > * _h
the specific enthalpy
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
This is the material class used to compute enthalpy for the incompressible/weakly-compressible finite...
static const std::string enthalpy_density
Definition: NS.h:70
Common class for single phase fluid properties.
void paramError(const std::string &param, Args... args) const
const Moose::Functor< ADReal > * _pressure
the pressure
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const SinglePhaseFluidProperties * _fp
A fluid properties user object to compute enthalpy.
static const std::string pressure
Definition: NS.h:56
void addClassDescription(const std::string &doc_string)
INSFVEnthalpyFunctorMaterial(const InputParameters &parameters)
void paramWarning(const std::string &param, Args... args) const
const Moose::Functor< ADReal > & _rho
density
std::string time_deriv(const std::string &var)
Definition: NS.h:97
static const std::string specific_enthalpy
Definition: NS.h:68