diff --git a/singularity-eos/eos/eos_base.hpp b/singularity-eos/eos/eos_base.hpp index e107f2ee82..3f97babe09 100644 --- a/singularity-eos/eos/eos_base.hpp +++ b/singularity-eos/eos/eos_base.hpp @@ -134,6 +134,23 @@ struct Transform { Factor x, y, f; }; +/* + This is a utility struct used for analytic equations of state, + allowing them to store/report mean atomic mass/number easily. + */ +struct MeanAtomicProperties { + Real Abar, Zbar; + + // default is hydrogen + static constexpr Real DEFAULT_ABAR = 1.0; + static constexpr Real DEFAULT_ZBAR = 1.0; + + PORTABLE_INLINE_FUNCTION + MeanAtomicProperties(Real Abar_, Real Zbar_) : Abar(Abar_), Zbar(Zbar_) {} + PORTABLE_INLINE_FUNCTION + MeanAtomicProperties() : Abar(DEFAULT_ABAR), Zbar(DEFAULT_ZBAR) {} +}; + /* This is a CRTP that allows for static inheritance so that default behavior for various member functions can be defined. @@ -751,23 +768,29 @@ class EosBase { // developer is in charge of either throwing an error or choosing // reasonable defaults. PORTABLE_INLINE_FUNCTION - Real MeanAtomicMass() const { return 1.0; } + Real MeanAtomicMass() const { + PORTABLE_THROW_OR_ABORT("Mean atomic mass not implemented!"); + return 1.0; + } PORTABLE_INLINE_FUNCTION - Real MeanAtomicNumber() const { return 1.0; } + Real MeanAtomicNumber() const { + PORTABLE_THROW_OR_ABORT("Mean atomic number not implemented!"); + return 1.0; + } // TODO(JMM): Should we provide vector implementations if we depend on rho, T, etc? template PORTABLE_INLINE_FUNCTION Real MeanAtomicMassFromDensityTemperature( const Real rho, const Real T, Indexer_t &&lambda = static_cast(nullptr)) const { CRTP copy = *(static_cast(this)); - return copy.MeanAtomicMass(rho, T, lambda); + return copy.MeanAtomicMass(); } template PORTABLE_INLINE_FUNCTION Real MeanAtomicNumberFromDensityTemperature( const Real rho, const Real T, Indexer_t &&lambda = static_cast(nullptr)) const { CRTP copy = *(static_cast(this)); - return copy.MeanAtomicNumber(rho, T, lambda); + return copy.MeanAtomicNumber(); } // Default entropy behavior is to cause an error diff --git a/singularity-eos/eos/eos_ideal.hpp b/singularity-eos/eos/eos_ideal.hpp index d395928404..ddb17c243f 100644 --- a/singularity-eos/eos/eos_ideal.hpp +++ b/singularity-eos/eos/eos_ideal.hpp @@ -38,16 +38,20 @@ using namespace eos_base; class IdealGas : public EosBase { public: IdealGas() = default; - PORTABLE_INLINE_FUNCTION IdealGas(Real gm1, Real Cv) + PORTABLE_INLINE_FUNCTION + IdealGas(Real gm1, Real Cv, const MeanAtomicProperties &AZbar = MeanAtomicProperties()) : _Cv(Cv), _gm1(gm1), _rho0(_P0 / (_gm1 * _Cv * _T0)), _sie0(_Cv * _T0), _bmod0((_gm1 + 1) * _gm1 * _rho0 * _Cv * _T0), _dpde0(_gm1 * _rho0), - _dvdt0(1. / (_rho0 * _T0)), _EntropyT0(_T0), _EntropyRho0(_rho0) { + _dvdt0(1. / (_rho0 * _T0)), _EntropyT0(_T0), _EntropyRho0(_rho0), _AZbar(AZbar) { CheckParams(); } - PORTABLE_INLINE_FUNCTION IdealGas(Real gm1, Real Cv, Real EntropyT0, Real EntropyRho0) + PORTABLE_INLINE_FUNCTION + IdealGas(Real gm1, Real Cv, Real EntropyT0, Real EntropyRho0, + const MeanAtomicProperties &AZbar = MeanAtomicProperties()) : _Cv(Cv), _gm1(gm1), _rho0(_P0 / (_gm1 * _Cv * _T0)), _sie0(_Cv * _T0), _bmod0((_gm1 + 1) * _gm1 * _rho0 * _Cv * _T0), _dpde0(_gm1 * _rho0), - _dvdt0(1. / (_rho0 * _T0)), _EntropyT0(EntropyT0), _EntropyRho0(EntropyRho0) { + _dvdt0(1. / (_rho0 * _T0)), _EntropyT0(EntropyT0), _EntropyRho0(EntropyRho0), + _AZbar(AZbar) { CheckParams(); } @@ -148,6 +152,12 @@ class IdealGas : public EosBase { FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, Indexer_t &&lambda = static_cast(nullptr)) const; + + PORTABLE_INLINE_FUNCTION + Real MeanAtomicMass() const { return _AZbar.Abar; } + PORTABLE_INLINE_FUNCTION + Real MeanAtomicNumber() const { return _AZbar.Zbar; } + template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, @@ -198,6 +208,8 @@ class IdealGas : public EosBase { thermalqs::density | thermalqs::specific_internal_energy; // optional entropy reference state variables Real _EntropyT0, _EntropyRho0; + // optional mean atomic mass and number + MeanAtomicProperties _AZbar; }; template