Skip to content

Commit

Permalink
Add MeanAtomicProperties for analytic EOS's to use and implement for …
Browse files Browse the repository at this point in the history
…ideal gas
  • Loading branch information
jonahm-LANL committed Dec 2, 2024
1 parent f37996c commit 6b2c05c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
31 changes: 27 additions & 4 deletions singularity-eos/eos/eos_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real MeanAtomicMassFromDensityTemperature(
const Real rho, const Real T,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
CRTP copy = *(static_cast<CRTP const *>(this));
return copy.MeanAtomicMass(rho, T, lambda);
return copy.MeanAtomicMass();
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real MeanAtomicNumberFromDensityTemperature(
const Real rho, const Real T,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
CRTP copy = *(static_cast<CRTP const *>(this));
return copy.MeanAtomicNumber(rho, T, lambda);
return copy.MeanAtomicNumber();
}

// Default entropy behavior is to cause an error
Expand Down
20 changes: 16 additions & 4 deletions singularity-eos/eos/eos_ideal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ using namespace eos_base;
class IdealGas : public EosBase<IdealGas> {
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();
}

Expand Down Expand Up @@ -148,6 +152,12 @@ class IdealGas : public EosBase<IdealGas> {
FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod,
const unsigned long output,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;

PORTABLE_INLINE_FUNCTION
Real MeanAtomicMass() const { return _AZbar.Abar; }
PORTABLE_INLINE_FUNCTION
Real MeanAtomicNumber() const { return _AZbar.Zbar; }

template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void
ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv,
Expand Down Expand Up @@ -198,6 +208,8 @@ class IdealGas : public EosBase<IdealGas> {
thermalqs::density | thermalqs::specific_internal_energy;
// optional entropy reference state variables
Real _EntropyT0, _EntropyRho0;
// optional mean atomic mass and number
MeanAtomicProperties _AZbar;
};

template <typename Indexer_t>
Expand Down

0 comments on commit 6b2c05c

Please sign in to comment.