Skip to content

Commit

Permalink
Add an option to use a FP UO to compute the enthalpy
Browse files Browse the repository at this point in the history
refs #12174
  • Loading branch information
GiudGiud committed Dec 18, 2024
1 parent 4e4e5dc commit 554a9d9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "FunctorMaterial.h"

class SinglePhaseFluidProperties;

/**
* This is the material class used to compute enthalpy for the incompressible/weakly-compressible
* finite-volume implementation of the Navier-Stokes equations
Expand All @@ -23,12 +25,21 @@ class INSFVEnthalpyFunctorMaterial : public FunctorMaterial
INSFVEnthalpyFunctorMaterial(const InputParameters & parameters);

protected:
/// whether we can use a constant cp as a shortcut to compute enthalpy
bool _assume_constant_cp;

/// A fluid properties user object to compute enthalpy
const SinglePhaseFluidProperties * _fp;

/// density
const Moose::Functor<ADReal> & _rho;

/// the temperature
const Moose::Functor<ADReal> & _temperature;

/// the pressure
const Moose::Functor<ADReal> * _pressure;

/// the specific heat capacity
const Moose::Functor<ADReal> & _cp;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ INSFVEnthalpyFunctorMaterial::validParams()
params.addClassDescription(
"This is the material class used to compute enthalpy for the "
"incompressible/weakly-compressible finite-volume implementation of the Navier-Stokes "
"equations. Note that this class assumes that cp is a constant");
"equations.");
params.addRequiredParam<MooseFunctorName>(NS::density, "The value for the density");
params.addRequiredParam<MooseFunctorName>("temperature", "the temperature");
params.addParam<MooseFunctorName>(
Expand All @@ -32,31 +32,83 @@ INSFVEnthalpyFunctorMaterial::validParams()
NS::enthalpy_density, NS::enthalpy_density, "the name of the (extensive) enthalpy");
params.addParam<MooseFunctorName>(
NS::specific_enthalpy, NS::specific_enthalpy, "the name of the specific enthalpy");

// To handle non constant cp
params.addParam<bool>("assume_constant_cp", true, "Whether to assume cp is constant");
params.addParam<UserObjectName>(
NS::fluid, "Fluid properties, to be used when cp is not constant to compute enthalpy");
params.addParam<MooseFunctorName>(
NS::pressure, "Pressure functor, to be used when cp is not constant to compute enthalpy");

return params;
}

INSFVEnthalpyFunctorMaterial::INSFVEnthalpyFunctorMaterial(const InputParameters & parameters)
: FunctorMaterial(parameters),
_assume_constant_cp(getParam<bool>("assume_constant_cp")),
_fp(isParamValid(NS::fluid)
? &UserObjectInterface::getUserObject<SinglePhaseFluidProperties>(NS::fluid)
: nullptr),
_rho(getFunctor<ADReal>(NS::density)),
_temperature(getFunctor<ADReal>("temperature")),
_pressure(isParamValid("pressure") ? &getFunctor<ADReal>("pressure") : nullptr),
_cp(getFunctor<ADReal>(NS::cp))
{
const auto & rho_h =
addFunctorProperty<ADReal>(NS::enthalpy_density,
[this](const auto & r, const auto & t)
{ return _rho(r, t) * _cp(r, t) * _temperature(r, t); });
// We have to use a warning because fp is often in the global parameters
if (_assume_constant_cp && _fp)
paramWarning(
"fp", "No need to specify fluid properties if assuming the specific enthalpy is constant");
if (!_assume_constant_cp && (!_fp || !_pressure))
paramError("fp",
"Must specify fluid properties if not assuming the specific enthalpy is constant");

if (_assume_constant_cp)
{
const auto & rho_h =
addFunctorProperty<ADReal>(NS::enthalpy_density,
[this](const auto & r, const auto & t)
{ return _rho(r, t) * _cp(r, t) * _temperature(r, t); });

const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
[this](const auto & r, const auto & t)
{ return _cp(r, t) * _temperature(r, t); });

addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
[this](const auto & r, const auto & t)
{ return _cp(r, t) * _temperature.dot(r, t); });

addFunctorProperty<ADReal>(
"rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });

addFunctorProperty<ADReal>("cp_temp",
[&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
}
else
{
const auto & rho_h = addFunctorProperty<ADReal>(
NS::enthalpy_density,
[this](const auto & r, const auto & t)
{ return _rho(r, t) * _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t)); });

const auto & h = addFunctorProperty<ADReal>(NS::specific_enthalpy,
[this](const auto & r, const auto & t)
{ return _cp(r, t) * _temperature(r, t); });
const auto & h =
addFunctorProperty<ADReal>(NS::specific_enthalpy,
[this](const auto & r, const auto & t) {
return _fp->h_from_p_T((*_pressure)(r, t), _temperature(r, t));
});

addFunctorProperty<ADReal>(NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
[this](const auto & r, const auto & t)
{ return _cp(r, t) * _temperature.dot(r, t); });
addFunctorProperty<ADReal>(
NS::time_deriv(getParam<MooseFunctorName>(NS::specific_enthalpy)),
[this](const auto & r, const auto & t)
{
Real h, dh_dp, dh_dT;
_fp->h_from_p_T((*_pressure)(r, t).value(), _temperature(r, t).value(), h, dh_dp, dh_dT);
return dh_dT * _temperature.dot(r, t) + dh_dp * _pressure->dot(r, t);
});

addFunctorProperty<ADReal>(
"rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });
addFunctorProperty<ADReal>(
"rho_cp_temp", [&rho_h](const auto & r, const auto & t) -> ADReal { return rho_h(r, t); });

addFunctorProperty<ADReal>("cp_temp",
[&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
addFunctorProperty<ADReal>("cp_temp",
[&h](const auto & r, const auto & t) -> ADReal { return h(r, t); });
}
}

0 comments on commit 554a9d9

Please sign in to comment.