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.addParam<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>(NS::specific_enthalpy,
36  "the name of the specific enthalpy, for defining it.");
37 
38  // To handle non constant cp
39  params.addParam<bool>("assumed_constant_cp", true, "Whether to assume cp is constant");
40  params.addParam<UserObjectName>(
41  NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
42  params.addParam<MooseFunctorName>(
43  NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");
44  params.addParam<MooseFunctorName>(
45  NS::specific_enthalpy + "_in",
46  "Specific enthalpy functor, to be used when cp is not constant to compute the enthalpy, as "
47  "an alternative to using a 'fp' FluidProperties object");
48 
49  return params;
50 }
51 
53  : FunctorMaterial(parameters),
54  _assumed_constant_cp(getParam<bool>("assumed_constant_cp")),
55  _fp(isParamValid(NS::fluid)
57  : nullptr),
58  _rho(getFunctor<ADReal>(NS::density)),
59  _temperature(isParamValid("temperature") ? &getFunctor<ADReal>("temperature") : nullptr),
60  _pressure(isParamValid(NS::pressure) ? &getFunctor<ADReal>(NS::pressure) : nullptr),
61  _cp(getFunctor<ADReal>(NS::cp)),
62  _h(isParamValid(NS::specific_enthalpy + "_in")
63  ? &getFunctor<ADReal>(NS::specific_enthalpy + "_in")
64  : nullptr)
65 {
66  // We have to use a warning because fp is often in the global parameters
69  "fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
70  if (!_assumed_constant_cp && ((!_fp || !_pressure) && !_h))
71  paramError("fp",
72  "Must specify both fluid properties and pressure or an enthalpy functor if not "
73  "assuming the specific enthalpy is constant");
74  if (!_temperature && (_assumed_constant_cp || !_h))
75  paramError("temperature",
76  "Temperature must be specified if assuming constant specific heat or if not "
77  "specifying the enthalpy functor");
78 
80  {
81  const auto & rho_h =
82  addFunctorProperty<ADReal>(NS::enthalpy_density,
83  [this](const auto & r, const auto & t)
84  { return _rho(r, t) * _cp(r, t) * (*_temperature)(r, t); });
85 
86  const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
87  [this](const auto & r, const auto & t)
88  { return _cp(r, t) * (*_temperature)(r, t); });
89 
90  addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
91  [this](const auto & r, const auto & t)
92  { return _cp(r, t) * (*_temperature).dot(r, t); });
93 
94  addFunctorProperty<ADReal>(
95  "rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
96 
97  addFunctorProperty<ADReal>("cp_temp",
98  [&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
99  }
100  // We did specify h_in, likely because solving for specific enthalpy
101  else if (_h)
102  {
103  addFunctorProperty<ADReal>(NS::enthalpy_density,
104  [this](const auto & r, const auto & t)
105  { return _rho(r, t) * (*_h)(r, t); });
106 
107  addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
108  [this](const auto & r, const auto & t) { return _h->dot(r, t); });
109 
110  // Note that we don't pick the fluid temperature name
111  addFunctorProperty<ADReal>(NS::T_fluid,
112  [this](const auto & r, const auto & t) -> ADReal
113  { return _fp->T_from_p_h((*_pressure)(r, t), (*_h)(r, t)); });
114  }
115  // We did not specify h, or assume a constant cp, we are solving for temperature but using h(p,T)
116  else
117  {
118  addFunctorProperty<ADReal>(
120  [this](const auto & r, const auto & t)
121  { return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t)); });
122 
123  addFunctorProperty<ADReal>(NS::specific_enthalpy,
124  [this](const auto & r, const auto & t) {
125  return _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t));
126  });
127 
128  addFunctorProperty<ADReal>(
129  NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
130  [this](const auto & r, const auto & t)
131  {
132  ADReal h, dh_dp, dh_dT;
133  _fp->h_from_p_T((*_pressure)(r, t), (*_temperature)(r, t), h, dh_dp, dh_dT);
134  return dh_dT * (*_temperature).dot(r, t) + dh_dp * _pressure->dot(r, t);
135  });
136  }
137 }
registerMooseObjectRenamed("NavierStokesApp", INSFVEnthalpyMaterial, "02/01/2024 00:00", INSFVEnthalpyFunctorMaterial)
const Moose::Functor< ADReal > & _cp
the specific heat capacity
void paramError(const std::string &param, Args... args) const
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 > * _h
the specific enthalpy
static const std::string T_fluid
Definition: NS.h:106
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.
const Moose::Functor< ADReal > * _pressure
the pressure
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
const Moose::Functor< ADReal > * _temperature
the temperature
std::string time_deriv(const std::string &var)
Definition: NS.h:97
static const std::string specific_enthalpy
Definition: NS.h:68