From c84f6869928c2e9b82886d4439f56afd93375abf Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 11:33:36 -0600 Subject: [PATCH 01/39] template ideal gas on eos lambda --- singularity-eos/eos/eos_ideal.hpp | 64 ++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/singularity-eos/eos/eos_ideal.hpp b/singularity-eos/eos/eos_ideal.hpp index dc52e84fa7..793c9693d3 100644 --- a/singularity-eos/eos/eos_ideal.hpp +++ b/singularity-eos/eos/eos_ideal.hpp @@ -52,8 +52,9 @@ class IdealGas : public EosBase { } IdealGas GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, sie / _Cv); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -66,64 +67,78 @@ class IdealGas : public EosBase { PORTABLE_ALWAYS_REQUIRE(_EntropyRho0 >= 0, "Entropy reference density must be positive"); } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, _Cv * temperature); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, _gm1 * rho * _Cv * temperature); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, _gm1 * rho * sie); } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, LambdaIndexer &&lambda = nullptr) const { return 0.0; }; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return _Cv * log(robust::ratio(temperature, _EntropyT0)) + _gm1 * _Cv * log(robust::ratio(_EntropyRho0, rho)); } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return EntropyFromDensityTemperature(rho, temp, lambda); } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * _Cv * temperature); } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * sie); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { return _gm1; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { return _gm1; } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + LambdaIndexer &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + LambdaIndexer &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; @@ -147,9 +162,11 @@ class IdealGas : public EosBase { PORTABLE_INLINE_FUNCTION void PrintParams() const { printf("Ideal Gas Parameters:\nGamma = %g\nCv = %g\n", _gm1 + 1.0, _Cv); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + LambdaIndexer &&lambda, Real &rho, + Real &sie) const { sie = MYMAX(0.0, _Cv * temp); rho = MYMAX(0.0, press / (_gm1 * sie)); } @@ -170,9 +187,10 @@ class IdealGas : public EosBase { Real _EntropyT0, _EntropyRho0; }; -PORTABLE_INLINE_FUNCTION -void IdealGas::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +IdealGas::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, LambdaIndexer &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From 3946c9b0c54cb8f03285318843cf1f45600b4640 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 16:08:26 -0600 Subject: [PATCH 02/39] Change LambdaIndexer to Indexer_t in eos_ideal --- singularity-eos/eos/eos_ideal.hpp | 69 +++++++++++++++---------------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/singularity-eos/eos/eos_ideal.hpp b/singularity-eos/eos/eos_ideal.hpp index 793c9693d3..6faf03b904 100644 --- a/singularity-eos/eos/eos_ideal.hpp +++ b/singularity-eos/eos/eos_ideal.hpp @@ -52,9 +52,9 @@ class IdealGas : public EosBase { } IdealGas GetOnDevice() { return *this; } - template + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, sie / _Cv); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -67,78 +67,78 @@ class IdealGas : public EosBase { PORTABLE_ALWAYS_REQUIRE(_EntropyRho0 >= 0, "Entropy reference density must be positive"); } - template + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, _Cv * temperature); } - template + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, _gm1 * rho * _Cv * temperature); } - template + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, _gm1 * rho * sie); } - template + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, LambdaIndexer &&lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return 0.0; }; - template + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv * log(robust::ratio(temperature, _EntropyT0)) + _gm1 * _Cv * log(robust::ratio(_EntropyRho0, rho)); } - template + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return EntropyFromDensityTemperature(rho, temp, lambda); } - template + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv; } - template + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } - template + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * _Cv * temperature); } - template + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * sie); } - template + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _gm1; } - template + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, LambdaIndexer &&lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _gm1; } - template + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - LambdaIndexer &&lambda = nullptr) const; - template + Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - LambdaIndexer &&lambda = nullptr) const { + Indexer_t &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; @@ -162,11 +162,10 @@ class IdealGas : public EosBase { PORTABLE_INLINE_FUNCTION void PrintParams() const { printf("Ideal Gas Parameters:\nGamma = %g\nCv = %g\n", _gm1 + 1.0, _Cv); } - template + template PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - LambdaIndexer &&lambda, Real &rho, - Real &sie) const { + Indexer_t &&lambda, Real &rho, Real &sie) const { sie = MYMAX(0.0, _Cv * temp); rho = MYMAX(0.0, press / (_gm1 * sie)); } @@ -187,10 +186,10 @@ class IdealGas : public EosBase { Real _EntropyT0, _EntropyRho0; }; -template +template PORTABLE_INLINE_FUNCTION void IdealGas::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, - const unsigned long output, LambdaIndexer &&lambda) const { + const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From 30534d7a529539b3f1606b2f253a220c57ccd26b Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 16:32:50 -0600 Subject: [PATCH 03/39] davis use indexer_t --- singularity-eos/eos/eos_davis.hpp | 157 +++++++++++++++++++----------- 1 file changed, 99 insertions(+), 58 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index c24b826821..d180a2a57f 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -37,80 +37,96 @@ class DavisReactants : public EosBase { : _rho0(rho0), _e0(e0), _P0(P0), _T0(T0), _A(A), _B(B), _C(C), _G0(G0), _Z(Z), _alpha(alpha), _Cv0(Cv0) {} DavisReactants GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real es = Es(rho); const Real tmp = std::pow((1.0 + _alpha) / (Ts(rho) * _Cv0) * (sie - es) + 1.0, 1.0 / (1.0 + _alpha)); if (tmp > 0) return Ts(rho) * tmp; return Ts(rho) + (sie - es) / _Cv0; // This branch is a negative temperature } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real t_s = Ts(rho); return Es(rho) + _Cv0 * t_s / (1.0 + _alpha) * (std::pow(temp / t_s, 1.0 + _alpha) - 1.0); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Ps(rho) + Gamma(rho) * rho * (sie - Es(rho)); } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("DavisReactants"); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { EntropyIsNotEnabled("DavisReactants"); return 1.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { EntropyIsNotEnabled("DavisReactants"); return 1.0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return SpecificHeatFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv0 / std::pow((1 + _alpha) / (Ts(rho) * _Cv0) * (sie - Es(rho)) + 1, -_alpha / (1 + _alpha)); } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return Gamma(rho); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Gamma(rho); } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(DavisReactants) @@ -151,71 +167,87 @@ class DavisProducts : public EosBase { const Real pc, const Real Cv, const Real E0) : _a(a), _b(b), _k(k), _n(n), _vc(vc), _pc(pc), _Cv(Cv), _E0(E0) {} DavisProducts GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Ts(rho) + (sie - Es(rho)) / _Cv; } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return _Cv * (temp - Ts(rho)) + Es(rho); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Ps(rho) + rho * Gamma(rho) * (sie - Es(rho)); } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("DavisProducts"); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { EntropyIsNotEnabled("DavisProducts"); return 1.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { EntropyIsNotEnabled("DavisProducts"); return 1.0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return Gamma(rho); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Gamma(rho); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(DavisProducts) @@ -315,8 +347,9 @@ PORTABLE_INLINE_FUNCTION Real DavisReactants::Gamma(const Real rho) const { } } +template PORTABLE_INLINE_FUNCTION Real DavisReactants::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace math_utils; const Real y = 1 - _rho0 / rho; const Real phat = 0.25 * _A * _A / _B * _rho0; @@ -334,8 +367,9 @@ PORTABLE_INLINE_FUNCTION Real DavisReactants::BulkModulusFromDensityInternalEner rho; } +template PORTABLE_INLINE_FUNCTION void DavisReactants::DensityEnergyFromPressureTemperature( - const Real press, const Real temp, Real *lambda, Real &rho, Real &sie) const { + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { // First, solve P=P(rho,T) for rho. Note P(rho,e) has an sie-es term, which is only a // function of T auto PofRatT = [&](const Real r) { @@ -353,9 +387,11 @@ PORTABLE_INLINE_FUNCTION void DavisReactants::DensityEnergyFromPressureTemperatu sie = InternalEnergyFromDensityTemperature(rho, temp); } -PORTABLE_INLINE_FUNCTION -void DavisReactants::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void DavisReactants::FillEos(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda) const { if (output & thermalqs::pressure) press = PressureFromDensityInternalEnergy(rho, sie); if (output & thermalqs::temperature) temp = TemperatureFromDensityInternalEnergy(rho, sie); @@ -367,10 +403,11 @@ void DavisReactants::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real // TODO: Chad please decide if this is sane // TODO(JMM): Pre-cache values instead of computing inline -PORTABLE_INLINE_FUNCTION -void DavisReactants::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +DavisReactants::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, + Real &cv, Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { rho = _rho0; temp = _T0; sie = InternalEnergyFromDensityTemperature(_rho0, _T0); @@ -383,8 +420,9 @@ void DavisReactants::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Re dvdt = gm1 * cv / bmod; } +template PORTABLE_INLINE_FUNCTION Real DavisProducts::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace math_utils; const Real vvc = 1 / (rho * _vc); const Real Fx = -4 * _a * std::pow(vvc, 2 * _n - 1) / pow<2>(1 + std::pow(vvc, 2 * _n)); @@ -403,8 +441,9 @@ PORTABLE_INLINE_FUNCTION Real DavisProducts::BulkModulusFromDensityInternalEnerg return -(psv + (sie - Es(rho)) * rho * (gammav - gamma * rho) - gamma * rho * esv) / rho; } +template PORTABLE_INLINE_FUNCTION void DavisProducts::DensityEnergyFromPressureTemperature( - const Real press, const Real temp, Real *lambda, Real &rho, Real &sie) const { + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { auto PofRatT = [&](const Real r) { return (Ps(r) + Gamma(r) * r * _Cv * (temp - Ts(r))); }; @@ -419,9 +458,10 @@ PORTABLE_INLINE_FUNCTION void DavisProducts::DensityEnergyFromPressureTemperatur } sie = InternalEnergyFromDensityTemperature(rho, temp); } -PORTABLE_INLINE_FUNCTION -void DavisProducts::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +DavisProducts::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::pressure) press = PressureFromDensityInternalEnergy(rho, sie); if (output & thermalqs::temperature) temp = TemperatureFromDensityInternalEnergy(rho, sie); @@ -432,10 +472,11 @@ void DavisProducts::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real } // TODO: pre-cache values instead of computing them // TODO: chad please decide if these choices are sane -PORTABLE_INLINE_FUNCTION -void DavisProducts::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +DavisProducts::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, + Real &cv, Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { rho = 1.0 / _vc; sie = 2. * Es(rho); temp = TemperatureFromDensityInternalEnergy(rho, sie); From 3aaa2cda64b7962fad7ef5693512518535cb76a8 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 16:49:55 -0600 Subject: [PATCH 04/39] template gruneisen and eospac --- singularity-eos/eos/eos_eospac.hpp | 163 +++++++++++++++----------- singularity-eos/eos/eos_gruneisen.hpp | 97 +++++++++------ 2 files changed, 158 insertions(+), 102 deletions(-) diff --git a/singularity-eos/eos/eos_eospac.hpp b/singularity-eos/eos/eos_eospac.hpp index c6bd2d1604..dcb1d45653 100644 --- a/singularity-eos/eos/eos_eospac.hpp +++ b/singularity-eos/eos/eos_eospac.hpp @@ -142,57 +142,73 @@ class EOSPAC : public EosBase { bool linear_interp = false); inline EOSPAC GetOnDevice() { return *this; } SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; - SG_PIF_NOWARN + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + SG_PIF_NOWARN + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + template + PORTABLE_INLINE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; SG_PIF_NOWARN - PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic (Scalar) using EosBase::is_raw_pointer; @@ -1180,8 +1196,9 @@ inline EOSPAC::EOSPAC(const int matid, bool invert_at_setup, Real insert_data, } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, E[1] = {sieToSesame(sie)}, T[1], dTdr[1], dTde[1]; EOS_INTEGER nxypairs = 1; @@ -1191,9 +1208,9 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::TemperatureFromDensityInternalEnergy( } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, P[1], T[1] = {temperatureToSesame(temp)}, dPdr[1], dPdT[1]; EOS_INTEGER nxypairs = 1; @@ -1203,17 +1220,18 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityTemperature(const Real } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { EntropyIsNotEnabled("EOSPAC"); return 1.0; } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION void EOSPAC::FillEos(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION void +EOSPAC::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, T[1] = {temperatureToSesame(temp)}; EOS_REAL E[1] = {sieToSesame(sie)}, P[1] = {pressureToSesame(press)}; @@ -1294,8 +1312,9 @@ PORTABLE_INLINE_FUNCTION void EOSPAC::FillEos(Real &rho, Real &temp, Real &sie, } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::InternalEnergyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; const unsigned long output = thermalqs::specific_internal_energy; @@ -1303,8 +1322,9 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::InternalEnergyFromDensityTemperature( return sie; } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; const unsigned long output = thermalqs::bulk_modulus; @@ -1312,8 +1332,9 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityTemperature( return bmod; } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; const unsigned long output = thermalqs::specific_heat; @@ -1321,8 +1342,9 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityTemperature( return cv; } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_INTEGER options[]{EOS_Y_CONVERT, EOS_F_CONVERT}; EOS_REAL values[]{sieFromSesame(1.0), pressureFromSesame(1.0)}; @@ -1336,8 +1358,9 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityInternalEnergy( return Real(P[0]); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real +EOSPAC::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_INTEGER options[]{EOS_F_CONVERT}; EOS_REAL values[]{sieFromSesame(1.0)}; @@ -1351,30 +1374,34 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::MinInternalEnergyFromDensity(const Real rh return Real(S[0]); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return EntropyFromDensityTemperature(rho, temp, lambda); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return SpecificHeatFromDensityTemperature(rho, temp, lambda); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return BulkModulusFromDensityTemperature(rho, temp, lambda); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, T[1] = {temperatureToSesame(temperature)}; EOS_REAL E[1], P[1], dx[1], dy[1]; @@ -1390,16 +1417,18 @@ PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityTemperature( return robust::ratio(pressureFromSesame(sieToSesame(DPDE)), rho); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { +template + PORTABLE_INLINE_FUNCTION Real +EOSPAC::GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, + Indexer_t &&lambda) const { Real temperature = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return GruneisenParamFromDensityTemperature(rho, temperature, lambda); } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION void -EOSPAC::DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { +template + PORTABLE_INLINE_FUNCTION void EOSPAC::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { using namespace EospacWrapper; EOS_REAL P[1] = {pressureToSesame(press)}; EOS_REAL T[1] = {temperatureToSesame(temp)}; @@ -1417,9 +1446,11 @@ EOSPAC::DensityEnergyFromPressureTemperature(const Real press, const Real temp, } SG_PIF_NOWARN -PORTABLE_INLINE_FUNCTION void +template + PORTABLE_INLINE_FUNCTION void EOSPAC::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, Real *lambda) const { + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { using namespace EospacWrapper; rho = rho_ref_; temp = temp_ref_; diff --git a/singularity-eos/eos/eos_gruneisen.hpp b/singularity-eos/eos/eos_gruneisen.hpp index 1cbdc90061..27f75bf71f 100644 --- a/singularity-eos/eos/eos_gruneisen.hpp +++ b/singularity-eos/eos/eos_gruneisen.hpp @@ -64,51 +64,66 @@ class Gruneisen : public EosBase { static PORTABLE_INLINE_FUNCTION Real ComputeRhoMax(const Real s1, const Real s2, const Real s3, const Real rho0); Gruneisen GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _T0 + sie / _Cv; } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return _Cv * (temp - _T0); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperatummmmmmre, Real *lambda = nullptr) const { + const Real rho, const Real temperatummmmmmre, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return Gamma(std::min(rho, _rho_max)); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return Gamma(std::min(rho, _rho_max)); } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(Gruneisen) @@ -125,9 +140,10 @@ class Gruneisen : public EosBase { "rho_max:%e\n", s1, _C0, _s1, _s2, _s3, _G0, _b, _rho0, _T0, _P0, _Cv, _rho_max); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; inline void Finalize() {} static std::string EosType() { return std::string("Gruneisen"); } static std::string EosPyType() { return EosType(); } @@ -297,8 +313,9 @@ PORTABLE_INLINE_FUNCTION Real Gruneisen::dPres_drho_e(const Real rho_in, } } +template PORTABLE_INLINE_FUNCTION Real Gruneisen::PressureFromDensityInternalEnergy( - const Real rho_in, const Real sie, Real *lambda) const { + const Real rho_in, const Real sie, Indexer_t &&lambda) const { using namespace math_utils; const Real rho = std::min(rho_in, _rho_max); Real P_H; @@ -315,20 +332,23 @@ PORTABLE_INLINE_FUNCTION Real Gruneisen::PressureFromDensityInternalEnergy( } return P_H + Gamma(rho) * rho * (sie - E_H); } +template PORTABLE_INLINE_FUNCTION Real -Gruneisen::MinInternalEnergyFromDensity(const Real rho_in, Real *lambda) const { +Gruneisen::MinInternalEnergyFromDensity(const Real rho_in, Indexer_t &&lambda) const { const Real rho = std::min(rho_in, _rho_max); MinInternalEnergyIsNotEnabled("Gruneisen"); return 0.0; } +template PORTABLE_INLINE_FUNCTION Real Gruneisen::EntropyFromDensityInternalEnergy( - const Real rho_in, const Real sie, Real *lambda) const { + const Real rho_in, const Real sie, Indexer_t &&lambda) const { const Real rho = std::min(rho_in, _rho_max); EntropyIsNotEnabled("Gruneisen"); return 1.0; } +template PORTABLE_INLINE_FUNCTION Real Gruneisen::BulkModulusFromDensityInternalEnergy( - const Real rho_in, const Real sie, Real *lambda) const { + const Real rho_in, const Real sie, Indexer_t &&lambda) const { using namespace gruneisen_utils; const Real rho = std::min(rho_in, _rho_max); // The if statement exists here to avoid the divide by zero @@ -343,26 +363,30 @@ PORTABLE_INLINE_FUNCTION Real Gruneisen::BulkModulusFromDensityInternalEnergy( } } // Below are "unimplemented" routines +template PORTABLE_INLINE_FUNCTION Real Gruneisen::PressureFromDensityTemperature( - const Real rho_in, const Real temp, Real *lambda) const { + const Real rho_in, const Real temp, Indexer_t &&lambda) const { const Real rho = std::min(rho_in, _rho_max); return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } +template PORTABLE_INLINE_FUNCTION Real Gruneisen::EntropyFromDensityTemperature( - const Real rho_in, const Real temp, Real *lambda) const { + const Real rho_in, const Real temp, Indexer_t &&lambda) const { const Real rho = std::min(rho_in, _rho_max); const Real sie = InternalEnergyFromDensityTemperature(rho, temp); return EntropyFromDensityInternalEnergy(rho, sie); } +template PORTABLE_INLINE_FUNCTION Real Gruneisen::BulkModulusFromDensityTemperature( - const Real rho_in, const Real temp, Real *lambda) const { + const Real rho_in, const Real temp, Indexer_t &&lambda) const { const Real rho = std::min(rho_in, _rho_max); return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } +template PORTABLE_INLINE_FUNCTION void Gruneisen::DensityEnergyFromPressureTemperature( - const Real press, const Real temp, Real *lambda, Real &rho, Real &sie) const { + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { sie = _Cv * (temp - _T0); // We have a branch at rho0, so we need to decide, based on our pressure, whether we // should be above or below rho0 @@ -383,10 +407,10 @@ PORTABLE_INLINE_FUNCTION void Gruneisen::DensityEnergyFromPressureTemperature( } } } -PORTABLE_INLINE_FUNCTION void Gruneisen::FillEos(Real &rho_in, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +Gruneisen::FillEos(Real &rho_in, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { // The following could be sped up with work! const unsigned long input = ~output; if (thermalqs::temperature & input && thermalqs::pressure & input) { @@ -408,10 +432,11 @@ PORTABLE_INLINE_FUNCTION void Gruneisen::FillEos(Real &rho_in, Real &temp, Real } // TODO(JMM): pre-cache these rather than recomputing them each time -PORTABLE_INLINE_FUNCTION -void Gruneisen::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +Gruneisen::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { rho = _rho0; temp = _T0; sie = 0; From 9159b456d4f9f2111aebb405b2b8f7dafb963452 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:01:54 -0600 Subject: [PATCH 05/39] template-ify helm and jwl --- singularity-eos/eos/eos_helmholtz.hpp | 107 ++++++++++++-------- singularity-eos/eos/eos_jwl.hpp | 140 +++++++++++++++----------- 2 files changed, 147 insertions(+), 100 deletions(-) diff --git a/singularity-eos/eos/eos_helmholtz.hpp b/singularity-eos/eos/eos_helmholtz.hpp index 957cdc2854..b6af4b51f0 100644 --- a/singularity-eos/eos/eos_helmholtz.hpp +++ b/singularity-eos/eos/eos_helmholtz.hpp @@ -460,32 +460,36 @@ class Helmholtz : public EosBase { dxnida = -xni * ytot; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; FillEos(rl, temperature, el, p, cv, bmod, thermalqs::temperature, lambda); return temperature; } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; FillEos(rl, tl, sie, p, cv, bmod, thermalqs::specific_internal_energy, lambda); return sie; } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; FillEos(rl, tl, sie, p, cv, bmod, thermalqs::pressure, lambda); return p; } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -493,35 +497,40 @@ class Helmholtz : public EosBase { thermalqs::pressure | thermalqs::temperature, lambda); return p; } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("Helmholtz"); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityTemperature_(rho, temperature, lambda, p, e, s, etaele, nep); return s[HelmUtils::VAL]; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityInternalEnergy_(rho, sie, lambda, p, e, s, etaele, nep); return s[HelmUtils::VAL]; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; FillEos(rl, tl, sie, p, cv, bmod, thermalqs::specific_heat, lambda); return cv; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -529,16 +538,18 @@ class Helmholtz : public EosBase { thermalqs::specific_heat | thermalqs::temperature, lambda); return cv; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; FillEos(rl, tl, sie, p, cv, bmod, thermalqs::bulk_modulus, lambda); return bmod; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -547,16 +558,18 @@ class Helmholtz : public EosBase { return bmod; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { using namespace HelmUtils; Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityTemperature_(rho, temperature, lambda, p, e, s, etaele, nep); Real gamma3 = ComputeGamma3_(rho, temperature, p, e); return gamma3 - 1.0; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { using namespace HelmUtils; Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; Real abar = lambda[Lambda::Abar]; @@ -571,21 +584,24 @@ class Helmholtz : public EosBase { return gamma3 - 1.0; } - PORTABLE_INLINE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { // JMM: I'm not sure what to put here or if it matters. Some // reference state, maybe stellar denity, would be appropriate. PORTABLE_ALWAYS_ABORT("Stub"); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { // This is only used for mixed cell closures. Stubbing it out for now. PORTABLE_ALWAYS_ABORT("Stub"); } @@ -631,10 +647,11 @@ class Helmholtz : public EosBase { return std::log10((2.0 / 3.0) * robust::ratio(e * rho, ni + ne) * ions_.KBi); } - PORTABLE_INLINE_FUNCTION - void GetFromDensityTemperature_(const Real rho, const Real temperature, Real *lambda, - Real p[NDERIV], Real e[NDERIV], Real s[NDERIV], - Real etaele[NDERIV], Real nep[NDERIV]) const { + template + PORTABLE_INLINE_FUNCTION void + GetFromDensityTemperature_(const Real rho, const Real temperature, Indexer_t &&lambda, + Real p[NDERIV], Real e[NDERIV], Real s[NDERIV], + Real etaele[NDERIV], Real nep[NDERIV]) const { Real abar = lambda[Lambda::Abar]; Real zbar = lambda[Lambda::Zbar]; Real lT = std::log10(temperature); @@ -645,10 +662,11 @@ class Helmholtz : public EosBase { p, e, s, etaele, nep); } - PORTABLE_INLINE_FUNCTION - void GetFromDensityInternalEnergy_(const Real rho, const Real sie, Real *lambda, - Real p[NDERIV], Real e[NDERIV], Real s[NDERIV], - Real etaele[NDERIV], Real nep[NDERIV]) const { + template + PORTABLE_INLINE_FUNCTION void + GetFromDensityInternalEnergy_(const Real rho, const Real sie, Indexer_t &&lambda, + Real p[NDERIV], Real e[NDERIV], Real s[NDERIV], + Real etaele[NDERIV], Real nep[NDERIV]) const { Real abar = lambda[Lambda::Abar]; Real zbar = lambda[Lambda::Zbar]; Real ytot, ye, ywot, De, lDe; @@ -667,10 +685,12 @@ class Helmholtz : public EosBase { // TODO(JMM): Decide which of the quantities below to keep const bool only_e = false) const; - PORTABLE_INLINE_FUNCTION - Real lTFromRhoSie_(const Real rho, const Real e, const Real abar, const Real zbar, - const Real ye, const Real ytot, const Real ywot, const Real De, - const Real lDe, Real *lambda) const; + template + PORTABLE_INLINE_FUNCTION Real lTFromRhoSie_(const Real rho, const Real e, + const Real abar, const Real zbar, + const Real ye, const Real ytot, + const Real ywot, const Real De, + const Real lDe, Indexer_t &&lambda) const; static constexpr Real ROOT_THRESH = 1e-14; static constexpr Real HELM_EOS_EPS = 1e-10; @@ -681,9 +701,10 @@ class Helmholtz : public EosBase { HelmElectrons electrons_; }; -PORTABLE_INLINE_FUNCTION -void Helmholtz::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +Helmholtz::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { using namespace HelmUtils; bool need_temp = (output & thermalqs::temperature); bool need_sie = (output & thermalqs::specific_internal_energy); @@ -727,11 +748,13 @@ void Helmholtz::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real & } } -PORTABLE_INLINE_FUNCTION -Real Helmholtz::lTFromRhoSie_(const Real rho, const Real e, const Real abar, - const Real zbar, const Real ye, const Real ytot, - const Real ywot, const Real De, const Real lDe, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real Helmholtz::lTFromRhoSie_(const Real rho, const Real e, + const Real abar, const Real zbar, + const Real ye, const Real ytot, + const Real ywot, const Real De, + const Real lDe, + Indexer_t &&lambda) const { using namespace HelmUtils; const Real abari = robust::ratio(1.0, abar); const Real ni = abari * rho * ions_.NA; diff --git a/singularity-eos/eos/eos_jwl.hpp b/singularity-eos/eos/eos_jwl.hpp index d670a4e279..d20ecfd32d 100644 --- a/singularity-eos/eos/eos_jwl.hpp +++ b/singularity-eos/eos/eos_jwl.hpp @@ -50,44 +50,59 @@ class JWL : public EosBase { assert(Cv > 0.0); } JWL GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const; + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(JWL) PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return 0; } - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; static constexpr unsigned long PreferredInput() { return _preferred_input; } static inline unsigned long scratch_size(std::string method, unsigned int nelements) { return 0; @@ -98,9 +113,10 @@ class JWL : public EosBase { printf("%sA:%e B:%e R1: %e\nR2:%e w:%e rho0:%e\nCv:%e\n", s1, _A, _B, _R1, _R2, _w, _rho0, _Cv); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; inline void Finalize() {} static std::string EosType() { return std::string("JWL"); } static std::string EosPyType() { return EosType(); } @@ -122,36 +138,41 @@ PORTABLE_FORCEINLINE_FUNCTION Real JWL::ReferenceEnergy(const Real rho) const { const Real x = robust::ratio(_rho0, rho); return _c1 * robust::safe_arg_exp(-_R1 * x) + _c2 * robust::safe_arg_exp(-_R2 * x); } +template PORTABLE_INLINE_FUNCTION Real JWL::InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { return ReferenceEnergy(rho) + _Cv * temp; } -PORTABLE_INLINE_FUNCTION Real JWL::PressureFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { return ReferencePressure(rho) + _w * rho * (sie - ReferenceEnergy(rho)); } -PORTABLE_INLINE_FUNCTION Real JWL::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +JWL::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("JWL"); return 0.0; } -PORTABLE_INLINE_FUNCTION Real JWL::EntropyFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { EntropyIsNotEnabled("JWL"); return 1.0; } +template PORTABLE_INLINE_FUNCTION Real JWL::TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { return robust::ratio((sie - ReferenceEnergy(rho)), _Cv); } +template PORTABLE_INLINE_FUNCTION Real JWL::SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { return _Cv; } +template PORTABLE_INLINE_FUNCTION Real JWL::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { const Real x = robust::ratio(_rho0, rho); // return // (_w+1)*(PressureFromDensityInternalEnergy(rho,sie)-ReferencePressure(rho))+x*(_A*_R1*std::exp(-_R1*x)+_B*_R2*std::exp(-_R2*x)); @@ -159,43 +180,44 @@ PORTABLE_INLINE_FUNCTION Real JWL::BulkModulusFromDensityInternalEnergy( x * (_A * _R1 * robust::safe_arg_exp(-_R1 * x) + _B * _R2 * robust::safe_arg_exp(-_R2 * x)); } -PORTABLE_INLINE_FUNCTION -Real JWL::GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { return _w; } // Below are "unimplemented" routines -PORTABLE_INLINE_FUNCTION Real JWL::PressureFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::PressureFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } -PORTABLE_INLINE_FUNCTION Real JWL::EntropyFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::EntropyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { EntropyIsNotEnabled("JWL"); return 1.0; } +template PORTABLE_INLINE_FUNCTION Real JWL::SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { return SpecificHeatFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } -PORTABLE_INLINE_FUNCTION Real JWL::BulkModulusFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::BulkModulusFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } -PORTABLE_INLINE_FUNCTION -Real JWL::GruneisenParamFromDensityTemperature(const Real rho, const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real JWL::GruneisenParamFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { return _w; } -PORTABLE_INLINE_FUNCTION void -JWL::DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void JWL::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { // sie = sie_r + cv*T; Thus sie-sie_r = cv*T // Thus P = P_r +_w*rho*cv*T ==> Invertable? // Turns out not to be exactly invertible @@ -212,10 +234,10 @@ JWL::DensityEnergyFromPressureTemperature(const Real press, const Real temp, Rea } sie = InternalEnergyFromDensityTemperature(rho, temp); } -PORTABLE_INLINE_FUNCTION void JWL::FillEos(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +JWL::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::pressure) press = PressureFromDensityInternalEnergy(rho, sie); if (output & thermalqs::temperature) temp = TemperatureFromDensityInternalEnergy(rho, sie); @@ -228,9 +250,11 @@ PORTABLE_INLINE_FUNCTION void JWL::FillEos(Real &rho, Real &temp, Real &sie, Rea // TODO(JMM): pre-cache these rather than recomputing them each time // TODO: Chad, please decide if STP is actually right here. Should it be // based on the reference energy and pressure instead? -PORTABLE_INLINE_FUNCTION -void JWL::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +JWL::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { rho = _rho0; temp = ROOM_TEMPERATURE; sie = InternalEnergyFromDensityTemperature(rho, temp, lambda); From 8a7fe022d0b25e7ed934dcd15d5b3fd6b3e3e355 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:09:01 -0600 Subject: [PATCH 06/39] templateify eos_mgusup --- singularity-eos/eos/eos_mgusup.hpp | 126 ++++++++++++++++++----------- 1 file changed, 77 insertions(+), 49 deletions(-) diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index 58b560268f..54d4a5d47d 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -44,26 +44,35 @@ class MGUsup : public EosBase { } MGUsup GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return _Cv0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv0; } // added for testing AEM Dec 2023 @@ -71,30 +80,38 @@ class MGUsup : public EosBase { PORTABLE_INLINE_FUNCTION Real HugInternalEnergyFromDensity(const Real rho) const; PORTABLE_INLINE_FUNCTION Real HugTemperatureFromDensity(const Real rho) const; // Thermal Bulk Modulus added AEM Dec 2022 + template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; // Thermal expansion coefficient added AEM 2022 + template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return robust::ratio(_G0 * _rho0, rho); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return robust::ratio(_G0 * _rho0, rho); } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(MGUsup) @@ -112,9 +129,10 @@ class MGUsup : public EosBase { printf("\n\n"); } // Density/Energy from P/T not unique, if used will give error + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; inline void Finalize() {} static std::string EosType() { return std::string("MGUsup"); } static std::string EosPyType() { return EosType(); } @@ -201,34 +219,37 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::HugTemperatureFromDensity(Real rho) const return temp; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = HugInternalEnergyFromDensity(rho) + _Cv0 * (temp - HugTemperatureFromDensity(rho)); return value; } -PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = HugPressureFromDensity(rho) + _G0 * _rho0 * _Cv0 * (temp - HugTemperatureFromDensity(rho)); return value; } -PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = _S0 - _G0 * _Cv0 * eta + _Cv0 * std::log(temp / _T0); return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = robust::ratio(_Cv0 * _rho0 * _G0, TBulkModulusFromDensityTemperature(rho, temp)); return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = robust::ratio((1.0 + _s * eta - _G0 * _s * eta * eta), (1.0 - _s * eta)); if (eta == 0.0) { @@ -240,8 +261,9 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::TBulkModulusFromDensityTemperature( value = robust::ratio(_rho0, rho) * value; return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = robust::ratio((1.0 + _s * eta - _G0 * _s * eta * eta), eta * (1.0 - _s * eta)); @@ -254,8 +276,9 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::BulkModulusFromDensityTemperature( value = robust::ratio(_rho0, rho) * value; return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real value = (sie - HugInternalEnergyFromDensity(rho)) / _Cv0 + HugTemperatureFromDensity(rho); if (value < 0.0) { @@ -266,19 +289,22 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::TemperatureFromDensityInternalEnergy( } return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real value = HugPressureFromDensity(rho) + _rho0 * _G0 * (sie - HugInternalEnergyFromDensity(rho)); return value; } -PORTABLE_INLINE_FUNCTION Real MGUsup::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +MGUsup::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("MGUsup"); return 0.0; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = std::log(TemperatureFromDensityInternalEnergy(rho, sie) / _T0); value = _S0 - _G0 * _Cv0 * eta + _Cv0 * value; @@ -290,8 +316,9 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy( } return value; } +template PORTABLE_INLINE_FUNCTION Real MGUsup::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = robust::ratio((1.0 + _s * eta - _G0 * _s * eta * eta), (1.0 - _s * eta)); if (eta == 0.0) { @@ -304,18 +331,18 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::BulkModulusFromDensityInternalEnergy( return value; } // AEM: Give error since function is not well defined -PORTABLE_INLINE_FUNCTION void -MGUsup::DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void MGUsup::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { EOS_ERROR("MGUsup::DensityEnergyFromPressureTemperature: " "Not implemented.\n"); } // AEM: We should add entropy and Gruneissen parameters here so that it is complete // If we add also alpha and BT, those should also be in here. -PORTABLE_INLINE_FUNCTION void MGUsup::FillEos(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +MGUsup::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { const unsigned long input = ~output; // everything that is not output is input if (thermalqs::density & output) { EOS_ERROR("MGUsup FillEos: Density is required input.\n"); @@ -338,10 +365,11 @@ PORTABLE_INLINE_FUNCTION void MGUsup::FillEos(Real &rho, Real &temp, Real &sie, } // TODO(JMM): pre-cache these rather than recomputing them each time -PORTABLE_INLINE_FUNCTION -void MGUsup::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +MGUsup::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { // AEM: Added all variables I think should be output eventually Real tbmod; // Real entropy, alpha, Gamma; From 92eb4dd50cd76a52de600dd460be839f89c4acae Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:10:20 -0600 Subject: [PATCH 07/39] CC --- singularity-eos/eos/eos_davis.hpp | 2 +- singularity-eos/eos/eos_eospac.hpp | 2 +- singularity-eos/eos/eos_gruneisen.hpp | 2 +- singularity-eos/eos/eos_helmholtz.hpp | 2 +- singularity-eos/eos/eos_ideal.hpp | 2 +- singularity-eos/eos/eos_jwl.hpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index d180a2a57f..7534e88104 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/singularity-eos/eos/eos_eospac.hpp b/singularity-eos/eos/eos_eospac.hpp index dcb1d45653..85a584a8a9 100644 --- a/singularity-eos/eos/eos_eospac.hpp +++ b/singularity-eos/eos/eos_eospac.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/singularity-eos/eos/eos_gruneisen.hpp b/singularity-eos/eos/eos_gruneisen.hpp index 27f75bf71f..ff9e8c883b 100644 --- a/singularity-eos/eos/eos_gruneisen.hpp +++ b/singularity-eos/eos/eos_gruneisen.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/singularity-eos/eos/eos_helmholtz.hpp b/singularity-eos/eos/eos_helmholtz.hpp index b6af4b51f0..276c094fb4 100644 --- a/singularity-eos/eos/eos_helmholtz.hpp +++ b/singularity-eos/eos/eos_helmholtz.hpp @@ -6,7 +6,7 @@ // Original work is open-sourced under the CC-By license // https://creativecommons.org/licenses/by/4.0/ //------------------------------------------------------------------------------ -// © 2023. Triad National Security, LLC. All rights reserved. This +// © 2023-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/singularity-eos/eos/eos_ideal.hpp b/singularity-eos/eos/eos_ideal.hpp index 6faf03b904..ab1617e276 100644 --- a/singularity-eos/eos/eos_ideal.hpp +++ b/singularity-eos/eos/eos_ideal.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/singularity-eos/eos/eos_jwl.hpp b/singularity-eos/eos/eos_jwl.hpp index d20ecfd32d..e1a671122f 100644 --- a/singularity-eos/eos/eos_jwl.hpp +++ b/singularity-eos/eos/eos_jwl.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National From 96d98ae49c4a8447de64c2fe954aec17a1b264f2 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:13:25 -0600 Subject: [PATCH 08/39] templateify noble_abel --- singularity-eos/eos/eos_noble_abel.hpp | 85 +++++++++++++++----------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/singularity-eos/eos/eos_noble_abel.hpp b/singularity-eos/eos/eos_noble_abel.hpp index fc2edd49c4..e080246ba8 100644 --- a/singularity-eos/eos/eos_noble_abel.hpp +++ b/singularity-eos/eos/eos_noble_abel.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -57,8 +57,9 @@ class NobleAbel : public EosBase { checkParams(); } NobleAbel GetOnDevice() { return *this; } - PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), (sie - _qq) / _Cv); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -66,77 +67,91 @@ class NobleAbel : public EosBase { PORTABLE_ALWAYS_REQUIRE(_gm1 >= 0, "Gruneisen parameter must be positive"); PORTABLE_ALWAYS_REQUIRE(_bb >= 0, "Covolume must be positive"); } - PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(_qq, _Cv * temperature + _qq); } - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * _Cv * temperature, 1.0 - _bb * rho)); } - PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * (sie - _qq), 1.0 - _bb * rho)); } - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("Noble Abel"); return 0.0; } - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(temperature, _T0) + robust::SMALL()) + _gm1 * _Cv * std::log(robust::ratio(vol - _bb, _vol0 - _bb) + robust::SMALL()) + _qp; } - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(sie - _qq, _sie0 - _qq) + robust::SMALL()) + _gm1 * _Cv * std::log(robust::ratio(vol - _bb, _vol0 - _bb) + robust::SMALL()) + _qp; } - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv; } - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * _Cv * temperature, (1.0 - _bb * rho) * (1.0 - _bb * rho))); } - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * (sie - _qq), (1.0 - _bb * rho) * (1.0 - _bb * rho))); } - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + template +PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + template +PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION + Indexer_t &&lambda = nullptr) const; + template +PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + Indexer_t &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; @@ -161,9 +176,10 @@ class NobleAbel : public EosBase { "%g\n", _gm1 + 1.0, _Cv, _bb, _qq); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { sie = std::max(_qq, _Cv * temp + _qq); rho = std::max(robust::SMALL(), robust::ratio(press, _gm1 * _Cv * temp + _bb * press)); @@ -184,9 +200,10 @@ class NobleAbel : public EosBase { thermalqs::density | thermalqs::specific_internal_energy; }; + template PORTABLE_INLINE_FUNCTION void NobleAbel::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { + Real &bmod, const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From d36e7b4dab5969a589fee06aa98b1e77d4cd904d Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:16:18 -0600 Subject: [PATCH 09/39] templateify eos_powermg --- singularity-eos/eos/eos_powermg.hpp | 123 +++++++++++++++++----------- 1 file changed, 76 insertions(+), 47 deletions(-) diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index ad76320964..b9c0666caf 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -45,26 +45,35 @@ class PowerMG : public EosBase { } PowerMG GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return _Cv0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv0; } // added for testing AEM Dec 2023 @@ -72,30 +81,38 @@ class PowerMG : public EosBase { PORTABLE_INLINE_FUNCTION Real AllHugInternalEnergyFromDensity(const Real rho) const; PORTABLE_INLINE_FUNCTION Real AllHugTemperatureFromDensity(const Real rho) const; // Thermal Bulk Modulus added AEM Dec 2022 + template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; // Thermal expansion coefficient added AEM 2022 + template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return robust::ratio(_G0 * _rho0, rho); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return robust::ratio(_G0 * _rho0, rho); } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(PowerMG) @@ -117,9 +134,10 @@ class PowerMG : public EosBase { printf("\n\n"); } // Density/Energy from P/T not unique, if used will give error + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; inline void Finalize() {} static std::string EosType() { return std::string("PowerMG"); } static std::string EosPyType() { return EosType(); } @@ -256,33 +274,37 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::AllHugTemperatureFromDensity(Real rho) co return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = AllHugInternalEnergyFromDensity(rho) + _Cv0 * (temp - AllHugTemperatureFromDensity(rho)); return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = AllHugPressureFromDensity(rho) + _G0 * _rho0 * _Cv0 * (temp - AllHugTemperatureFromDensity(rho)); return value; } -PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { const Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = _S0 - _G0 * _Cv0 * eta + _Cv0 * std::log(temp / _T0); return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real value = robust::ratio(_Cv0 * _rho0 * _G0, TBulkModulusFromDensityTemperature(rho, temp)); return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { return BulkModulusFromDensityTemperature(rho, temp) - _G0 * _G0 * _Cv0 * _rho0 * robust::ratio(_rho0, rho) * temp; } @@ -300,8 +322,9 @@ PowerMG::_compBulkModulusFromDensityTemperature(const Real rho, const Real temp) value = robust::ratio(_rho0, rho) * value; return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { const Real eta = 1.0 - robust::ratio(_rho0, rho); Real value; if (eta <= 0.0) { @@ -330,8 +353,9 @@ PowerMG::_compBulkModulusFromDensityInternalEnergy(const Real rho, const Real si value = robust::ratio(_rho0, rho) * value; return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { const Real eta = 1.0 - robust::ratio(_rho0, rho); Real value; if (eta <= 0.0) { @@ -349,8 +373,9 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::BulkModulusFromDensityInternalEnergy( return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real value = (sie - AllHugInternalEnergyFromDensity(rho)) / _Cv0 + AllHugTemperatureFromDensity(rho); if (value < 0.0) { @@ -361,19 +386,22 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::TemperatureFromDensityInternalEnergy( } return value; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real value = AllHugPressureFromDensity(rho) + _rho0 * _G0 * (sie - AllHugInternalEnergyFromDensity(rho)); return value; } -PORTABLE_INLINE_FUNCTION Real PowerMG::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +PowerMG::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("PowerMG"); return 0.0; } +template PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { const Real eta = 1.0 - robust::ratio(_rho0, rho); Real value = std::log(TemperatureFromDensityInternalEnergy(rho, sie) / _T0); value = _S0 - _G0 * _Cv0 * eta + _Cv0 * value; @@ -386,18 +414,18 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityInternalEnergy( return value; } // AEM: Give error since function is not well defined -PORTABLE_INLINE_FUNCTION void -PowerMG::DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void PowerMG::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { EOS_ERROR("PowerMG::DensityEnergyFromPressureTemperature: " "Not implemented.\n"); } // AEM: We should add entropy and Gruneissen parameters here so that it is complete // If we add also alpha and BT, those should also be in here. -PORTABLE_INLINE_FUNCTION void PowerMG::FillEos(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +PowerMG::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { const unsigned long input = ~output; // everything that is not output is input if (thermalqs::density & output) { EOS_ERROR("PowerMG FillEos: Density is required input.\n"); @@ -420,10 +448,11 @@ PORTABLE_INLINE_FUNCTION void PowerMG::FillEos(Real &rho, Real &temp, Real &sie, } // TODO(JMM): pre-cache these rather than recomputing them each time -PORTABLE_INLINE_FUNCTION -void PowerMG::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +PowerMG::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { // AEM: Added all variables I think should be output eventually Real tbmod; // Real entropy, alpha, Gamma; From 35fc794944ec0f78a2acdfba5750ddcf4beadbd7 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:17:32 -0600 Subject: [PATCH 10/39] templateify sap polynomial --- singularity-eos/eos/eos_sap_polynomial.hpp | 69 ++++++++++++++-------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/singularity-eos/eos/eos_sap_polynomial.hpp b/singularity-eos/eos/eos_sap_polynomial.hpp index c5d0369c7c..bd2d812675 100644 --- a/singularity-eos/eos/eos_sap_polynomial.hpp +++ b/singularity-eos/eos/eos_sap_polynomial.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -49,23 +49,27 @@ class SAP_Polynomial : public EosBase { PORTABLE_INLINE_FUNCTION void checkParams() const { PORTABLE_ALWAYS_REQUIRE(_rho0 >= 0, "Reference density must be non-negative"); } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return _a0 + _a1 * mu + _a2c * mu * mu + _a3 * mu * mu * mu + @@ -75,52 +79,61 @@ class SAP_Polynomial : public EosBase { sie * (_b0 + _b1 * mu + _b2e * mu * mu + _b3 * mu * mu * mu); } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("SAP Polynomial"); return 0.0; }; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return _b0 + _b1 * mu + _b2c * mu * mu + _b3 * mu * mu * mu; else return _b0 + _b1 * mu + _b2e * mu * mu + _b3 * mu * mu * mu; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return (1 + mu) * (_a1 + 2 * _a2c * mu + 3 * _a3 * mu * mu + @@ -129,19 +142,22 @@ class SAP_Polynomial : public EosBase { return (1 + mu) * (_a1 + 2 * _a2e * mu + 3 * _a3 * mu * mu + sie * (_b1 + 2 * _b2e * mu + 3 * _b3 * mu * mu)); } + template PORTABLE_INLINE_FUNCTION Real MuFromDensity(const Real rho, - Real *lambda = nullptr) const { + Indexer_t &&lambda = nullptr) const { return rho / _rho0 - 1; } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = 0.0; @@ -176,9 +192,10 @@ class SAP_Polynomial : public EosBase { printf(" b2e = %g\n", _b2e); printf(" b3 = %g\n", _b3); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); sie = 0.0; rho = 0.0; @@ -196,9 +213,11 @@ class SAP_Polynomial : public EosBase { thermalqs::density | thermalqs::specific_internal_energy; }; -PORTABLE_INLINE_FUNCTION -void SAP_Polynomial::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void SAP_Polynomial::FillEos(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From 14fec2a1d1aaf6bf12065799b4c9bf640e04b0a4 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:22:37 -0600 Subject: [PATCH 11/39] tempalteify eos_spiner --- singularity-eos/eos/eos_spiner.hpp | 543 +++++++++++++++-------------- 1 file changed, 273 insertions(+), 270 deletions(-) diff --git a/singularity-eos/eos/eos_spiner.hpp b/singularity-eos/eos/eos_spiner.hpp index 45938111cf..4e03d131c3 100644 --- a/singularity-eos/eos/eos_spiner.hpp +++ b/singularity-eos/eos/eos_spiner.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -102,56 +102,60 @@ class SpinerEOSDependsRhoT : public EosBase { inline SpinerEOSDependsRhoT GetOnDevice(); - PORTABLE_INLINE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const; - PORTABLE_INLINE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; PORTABLE_INLINE_FUNCTION Real RhoPmin(const Real temp) const; @@ -220,18 +224,22 @@ class SpinerEOSDependsRhoT : public EosBase { PORTABLE_FORCEINLINE_FUNCTION Real T_(const Real lT) const noexcept { return fromLog_(lT, lTOffset_); } - PORTABLE_INLINE_FUNCTION - Real lTFromlRhoSie_(const Real lRho, const Real sie, TableStatus &whereAmI, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real lTFromlRhoP_(const Real lRho, const Real press, TableStatus &whereAmI, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real lRhoFromPlT_(const Real P, const Real lT, TableStatus &whereAmI, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void getLogsRhoT_(const Real rho, const Real temperature, Real &lRho, Real &lT, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real lTFromlRhoSie_(const Real lRho, const Real sie, + TableStatus &whereAmI, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real lTFromlRhoP_(const Real lRho, const Real press, + TableStatus &whereAmI, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real lRhoFromPlT_(const Real P, const Real lT, + TableStatus &whereAmI, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void getLogsRhoT_(const Real rho, const Real temperature, + Real &lRho, Real &lT, + Indexer_t &&lambda = nullptr) const; PORTABLE_INLINE_FUNCTION Real sieFromlRhoTlT_(const Real lRho, const Real T, const Real lT, const TableStatus &whereAmI) const; @@ -334,57 +342,61 @@ class SpinerEOSDependsRhoSie : public EosBase { bool reproducibility_mode = false); inline SpinerEOSDependsRhoSie GetOnDevice(); - PORTABLE_INLINE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real T, - Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real T, - Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real T, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real T, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real T, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const; - PORTABLE_INLINE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; static constexpr unsigned long PreferredInput() { return _preferred_input; } static inline unsigned long scratch_size(std::string method, unsigned int nelements) { @@ -443,14 +455,17 @@ class SpinerEOSDependsRhoSie : public EosBase { static PORTABLE_FORCEINLINE_FUNCTION Real fromLog_(const Real lx, const Real offset) { return FastMath::pow10(lx) - offset; } - PORTABLE_INLINE_FUNCTION - Real interpRhoT_(const Real rho, const Real T, const DataBox &db, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real interpRhoSie_(const Real rho, const Real sie, const DataBox &db, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real lRhoFromPlT_(const Real P, const Real lT, Real *lambda) const; + template + PORTABLE_INLINE_FUNCTION Real interpRhoT_(const Real rho, const Real T, + const DataBox &db, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real interpRhoSie_(const Real rho, const Real sie, + const DataBox &db, + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real lRhoFromPlT_(const Real P, const Real lT, + Indexer_t &&lambda) const; DataBox sie_; // depends on (rho,T) DataBox T_; // depends on (rho, sie) @@ -906,40 +921,36 @@ inline void SpinerEOSDependsRhoT::setlTColdCrit_() { } } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::TemperatureFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { TableStatus whereAmI; const Real lRho = lRho_(rho); const Real lT = lTFromlRhoSie_(lRho, sie, whereAmI, lambda); return T_(lT); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::InternalEnergyFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT; getLogsRhoT_(rho, temperature, lRho, lT, lambda); TableStatus whereAmI = getLocDependsRhoT_(lRho, lT); return sieFromlRhoTlT_(lRho, temperature, lT, whereAmI); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::PressureFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT; getLogsRhoT_(rho, temperature, lRho, lT, lambda); TableStatus whereAmI = getLocDependsRhoT_(lRho, lT); return PFromRholRhoTlT_(rho, lRho, temperature, lT, whereAmI); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::PressureFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { TableStatus whereAmI; Real lRho = lRho_(rho); Real lT = lTFromlRhoSie_(lRho, sie, whereAmI, lambda); @@ -955,41 +966,37 @@ Real SpinerEOSDependsRhoT::PressureFromDensityInternalEnergy(const Real rho, return P; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("SpinerEOSDependsRhoT"); return 0.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::EntropyFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { EntropyIsNotEnabled("SpinerEOSDependsRhoT"); return 1.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::EntropyFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { EntropyIsNotEnabled("SpinerEOSDependsRhoT"); return 1.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::SpecificHeatFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT; getLogsRhoT_(rho, temperature, lRho, lT, lambda); TableStatus whereAmI = getLocDependsRhoT_(lRho, lT); return CvFromlRholT_(lRho, lT, whereAmI); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::SpecificHeatFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { TableStatus whereAmI; Real Cv; const Real lRho = lRho_(rho); @@ -1006,20 +1013,18 @@ Real SpinerEOSDependsRhoT::SpecificHeatFromDensityInternalEnergy(const Real rho, return Cv > robust::EPS() ? Cv : robust::EPS(); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::BulkModulusFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT; getLogsRhoT_(rho, temperature, lRho, lT, lambda); TableStatus whereAmI = getLocDependsRhoT_(lRho, lT); return bModFromRholRhoTlT_(rho, lRho, temperature, lT, whereAmI); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::GruneisenParamFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::GruneisenParamFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real lRho, lT, gm1; getLogsRhoT_(rho, temp, lRho, lT, lambda); @@ -1037,10 +1042,9 @@ Real SpinerEOSDependsRhoT::GruneisenParamFromDensityTemperature(const Real rho, return gm1; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::BulkModulusFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { TableStatus whereAmI; Real bMod; const Real lRho = lRho_(rho); @@ -1056,10 +1060,11 @@ Real SpinerEOSDependsRhoT::BulkModulusFromDensityInternalEnergy(const Real rho, return bMod; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::GruneisenParamFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoT::GruneisenParamFromDensityInternalEnergy(const Real rho, + const Real sie, + Indexer_t &&lambda) const { TableStatus whereAmI; Real gm1; const Real lRho = lRho_(rho); @@ -1077,11 +1082,9 @@ Real SpinerEOSDependsRhoT::GruneisenParamFromDensityInternalEnergy(const Real rh } // TODO(JMM): This would be faster with hand-tuned code -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoT::DensityEnergyFromPressureTemperature(const Real press, - const Real temp, - Real *lambda, Real &rho, - Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void SpinerEOSDependsRhoT::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { TableStatus whereAmI; Real lT = lT_(temp); Real lRho = lRhoFromPlT_(press, lT, whereAmI, lambda); @@ -1089,10 +1092,11 @@ void SpinerEOSDependsRhoT::DensityEnergyFromPressureTemperature(const Real press sie = InternalEnergyFromDensityTemperature(rho, temp, lambda); } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoT::FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +SpinerEOSDependsRhoT::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, + Real &bmod, const unsigned long output, + Indexer_t &&lambda) const { Real lRho, lT; TableStatus whereAmI; const unsigned long input = ~output; @@ -1141,11 +1145,10 @@ void SpinerEOSDependsRhoT::FillEos(Real &rho, Real &temp, Real &energy, Real &pr } } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoT::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void SpinerEOSDependsRhoT::ValuesAtReferenceState( + Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, + Real &dvdt, Indexer_t &&lambda) const { rho = rhoNormal_; temp = TNormal_; sie = sieNormal_; @@ -1164,9 +1167,10 @@ Real SpinerEOSDependsRhoT::RhoPmin(const Real temp) const { return rho_at_pmin_.interpToReal(lT); } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoT::getLogsRhoT_(const Real rho, const Real temperature, - Real &lRho, Real &lT, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +SpinerEOSDependsRhoT::getLogsRhoT_(const Real rho, const Real temperature, Real &lRho, + Real &lT, Indexer_t &&lambda) const { lRho = lRho_(rho); lT = lT_(temperature); if (lambda != nullptr) { @@ -1175,9 +1179,9 @@ void SpinerEOSDependsRhoT::getLogsRhoT_(const Real rho, const Real temperature, } } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::lRhoFromPlT_(const Real P, const Real lT, - TableStatus &whereAmI, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lRhoFromPlT_( + const Real P, const Real lT, TableStatus &whereAmI, Indexer_t &&lambda) const { RootFinding1D::Status status = RootFinding1D::Status::SUCCESS; Real lRho; @@ -1234,9 +1238,9 @@ Real SpinerEOSDependsRhoT::lRhoFromPlT_(const Real P, const Real lT, return lRho; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::lTFromlRhoSie_(const Real lRho, const Real sie, - TableStatus &whereAmI, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoSie_( + const Real lRho, const Real sie, TableStatus &whereAmI, Indexer_t &&lambda) const { const RootFinding1D::RootCounts *pcounts = (memoryStatus_ == DataStatus::OnDevice) ? nullptr : &counts; @@ -1296,9 +1300,9 @@ Real SpinerEOSDependsRhoT::lTFromlRhoSie_(const Real lRho, const Real sie, return lT; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoT::lTFromlRhoP_(const Real lRho, const Real press, - TableStatus &whereAmI, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoP_( + const Real lRho, const Real press, TableStatus &whereAmI, Indexer_t &&lambda) const { const RootFinding1D::RootCounts *pcounts = (memoryStatus_ == DataStatus::OnDevice) ? nullptr : &counts; RootFinding1D::Status status = RootFinding1D::Status::SUCCESS; @@ -1690,115 +1694,115 @@ void SpinerEOSDependsRhoSie::Finalize() { memoryStatus_ = DataStatus::Deallocated; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::TemperatureFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::TemperatureFromDensityInternalEnergy(const Real rho, + const Real sie, + Indexer_t &&lambda) const { return interpRhoSie_(rho, sie, T_, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::InternalEnergyFromDensityTemperature(const Real rho, - const Real T, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::InternalEnergyFromDensityTemperature(const Real rho, const Real T, + Indexer_t &&lambda) const { return interpRhoT_(rho, T, sie_, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::PressureFromDensityTemperature(const Real rho, const Real T, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::PressureFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda) const { return interpRhoT_(rho, T, dependsRhoT_.P, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::PressureFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { return interpRhoSie_(rho, sie, dependsRhoSie_.P, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("SpinerEOSDependsRhoSie"); return 0.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::EntropyFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { EntropyIsNotEnabled("SpinerEOSDependsRhoSie"); return 1.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::EntropyFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { EntropyIsNotEnabled("SpinerEOSDependsRhoSie"); return 1.0; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::SpecificHeatFromDensityTemperature(const Real rho, - const Real T, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::SpecificHeatFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda) const { return 1. / interpRhoT_(rho, T, dependsRhoT_.dTdE, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::SpecificHeatFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::SpecificHeatFromDensityInternalEnergy(const Real rho, + const Real sie, + Indexer_t &&lambda) const { return 1. / interpRhoSie_(rho, sie, dependsRhoSie_.dTdE, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::BulkModulusFromDensityTemperature(const Real rho, - const Real T, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::BulkModulusFromDensityTemperature( + const Real rho, const Real T, Indexer_t &&lambda) const { return interpRhoT_(rho, T, dependsRhoT_.bMod, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::BulkModulusFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::BulkModulusFromDensityInternalEnergy(const Real rho, + const Real sie, + Indexer_t &&lambda) const { return interpRhoSie_(rho, sie, dependsRhoSie_.bMod, lambda); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::GruneisenParamFromDensityTemperature(const Real rho, - const Real T, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::GruneisenParamFromDensityTemperature(const Real rho, const Real T, + Indexer_t &&lambda) const { const Real dpde = interpRhoT_(rho, T, dependsRhoT_.dPdE, lambda); return dpde / rho; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::GruneisenParamFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +SpinerEOSDependsRhoSie::GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { const Real lRho = toLog_(rho, lRhoOffset_); const Real lE = toLog_(sie, lEOffset_); const Real dpde = dependsRhoSie_.dPdE.interpToReal(lRho, lE); return dpde / rho; } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoSie::DensityEnergyFromPressureTemperature(const Real press, - const Real temp, - Real *lambda, Real &rho, - Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void +SpinerEOSDependsRhoSie::DensityEnergyFromPressureTemperature(const Real press, + const Real temp, + Indexer_t &&lambda, + Real &rho, Real &sie) const { Real lT = toLog_(temp, lTOffset_); Real lRho = lRhoFromPlT_(press, lT, lambda); rho = fromLog_(lRho, lRhoOffset_); sie = sie_.interpToReal(lRho, lT); } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoSie::FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +SpinerEOSDependsRhoSie::FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda) const { Real lRho, lT, lE; if (output == thermalqs::none) { UNDEFINED_ERROR; @@ -1846,11 +1850,10 @@ void SpinerEOSDependsRhoSie::FillEos(Real &rho, Real &temp, Real &energy, Real & } } -PORTABLE_INLINE_FUNCTION -void SpinerEOSDependsRhoSie::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void SpinerEOSDependsRhoSie::ValuesAtReferenceState( + Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, + Real &dvdt, Indexer_t &&lambda) const { rho = rhoNormal_; temp = TNormal_; sie = sieNormal_; @@ -1861,9 +1864,9 @@ void SpinerEOSDependsRhoSie::ValuesAtReferenceState(Real &rho, Real &temp, Real dvdt = dVdTNormal_; } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::interpRhoT_(const Real rho, const Real T, const DataBox &db, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoT_( + const Real rho, const Real T, const DataBox &db, Indexer_t &&lambda) const { const Real lRho = toLog_(rho, lRhoOffset_); const Real lT = toLog_(T, lTOffset_); if (lambda != nullptr) { @@ -1872,9 +1875,9 @@ Real SpinerEOSDependsRhoSie::interpRhoT_(const Real rho, const Real T, const Dat return db.interpToReal(lRho, lT); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::interpRhoSie_(const Real rho, const Real sie, - const DataBox &db, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoSie_( + const Real rho, const Real sie, const DataBox &db, Indexer_t &&lambda) const { const Real lRho = toLog_(rho, lRhoOffset_); const Real lE = toLog_(sie, lEOffset_); if (lambda != nullptr) { @@ -1883,9 +1886,9 @@ Real SpinerEOSDependsRhoSie::interpRhoSie_(const Real rho, const Real sie, return db.interpToReal(lRho, lE); } -PORTABLE_INLINE_FUNCTION -Real SpinerEOSDependsRhoSie::lRhoFromPlT_(const Real P, const Real lT, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::lRhoFromPlT_( + const Real P, const Real lT, Indexer_t &&lambda) const { const RootFinding1D::RootCounts *pcounts = (memoryStatus_ == DataStatus::OnDevice) ? nullptr : &counts; Real lRho; From e4e39e642fc8335756c1790a31a3c4c90b424fc6 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:26:50 -0600 Subject: [PATCH 12/39] templateify stellar collapse --- singularity-eos/eos/eos_stellar_collapse.hpp | 269 ++++++++++--------- 1 file changed, 135 insertions(+), 134 deletions(-) diff --git a/singularity-eos/eos/eos_stellar_collapse.hpp b/singularity-eos/eos/eos_stellar_collapse.hpp index 59b93447b6..b028872390 100644 --- a/singularity-eos/eos/eos_stellar_collapse.hpp +++ b/singularity-eos/eos/eos_stellar_collapse.hpp @@ -97,69 +97,72 @@ class StellarCollapse : public EosBase { inline StellarCollapse GetOnDevice(); - PORTABLE_INLINE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const; + template + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; // Properties of an NSE EOS - PORTABLE_INLINE_FUNCTION - void MassFractionsFromDensityTemperature(const Real rho, const Real temperature, - Real &Xa, Real &Xh, Real &Xn, Real &Xp, - Real &Abar, Real &Zbar, - Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - void ChemicalPotentialsFromDensityTemperature(const Real rho, const Real temperature, - Real &mu_e, Real &mu_n, Real &mu_p, - Real &muhat, Real &munu, - Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const; - - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + MassFractionsFromDensityTemperature(const Real rho, const Real temperature, Real &Xa, + Real &Xh, Real &Xn, Real &Xp, Real &Abar, + Real &Zbar, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION void ChemicalPotentialsFromDensityTemperature( + const Real rho, const Real temperature, Real &mu_e, Real &mu_n, Real &mu_p, + Real &muhat, Real &munu, Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const; + + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here static constexpr unsigned long PreferredInput() { return _preferred_input; } @@ -222,7 +225,8 @@ class StellarCollapse : public EosBase { inline void computeColdAndHotCurves_(); inline void setNormalValues_(); - PORTABLE_FORCEINLINE_FUNCTION void checkLambda_(Real *lambda) const noexcept { + template + PORTABLE_FORCEINLINE_FUNCTION void checkLambda_(Indexer_t &&lambda) const noexcept { if (lambda == nullptr) { EOS_ERROR("StellarCollapse: lambda must contain Ye and 1 space for caching.\n"); } @@ -275,20 +279,23 @@ class StellarCollapse : public EosBase { return toLog_(B, lBOffset_); } + template PORTABLE_INLINE_FUNCTION Real lTFromlRhoSie_(const Real lRho, const Real sie, - Real *lambda) const noexcept; + Indexer_t &&lambda) const noexcept; + template PORTABLE_INLINE_FUNCTION __attribute__((always_inline)) void - getLogsFromRhoT_(const Real rho, const Real temp, Real *lambda, Real &lRho, Real &lT, - Real &Ye) const noexcept { + getLogsFromRhoT_(const Real rho, const Real temp, Indexer_t &&lambda, Real &lRho, + Real &lT, Real &Ye) const noexcept { checkLambda_(lambda); lRho = lRho_(rho); lT = lT_(temp); Ye = lambda[Lambda::Ye]; lambda[Lambda::lT] = lT; } + template PORTABLE_INLINE_FUNCTION __attribute__((always_inline)) void - getLogsFromRhoSie_(const Real rho, const Real sie, Real *lambda, Real &lRho, Real &lT, - Real &Ye) const noexcept { + getLogsFromRhoSie_(const Real rho, const Real sie, Indexer_t &&lambda, Real &lRho, + Real &lT, Real &Ye) const noexcept { lRho = lRho_(rho); lT = lTFromlRhoSie_(lRho, sie, lambda); Ye = lambda[Lambda::Ye]; @@ -501,91 +508,86 @@ inline void StellarCollapse::Finalize() { memoryStatus_ = DataStatus::Deallocated; } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { const Real lRho = lRho_(rho); const Real lT = lTFromlRhoSie_(lRho, sie, lambda); return T_(lT); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::InternalEnergyFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::InternalEnergyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temp, lambda, lRho, lT, Ye); const Real lE = lE_.interpToReal(Ye, lT, lRho); return le2e_(lE); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::PressureFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); const Real lP = lP_.interpToReal(Ye, lT, lRho); return lP2P_(lP); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoSie_(rho, sie, lambda, lRho, lT, Ye); const Real lP = lP_.interpToReal(Ye, lT, lRho); return lP2P_(lP); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::MinInternalEnergyFromDensity(const Real rho, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +StellarCollapse::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("Stellar Collapse"); return 0.0; } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::EntropyFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); const Real entropy = entropy_.interpToReal(Ye, lT, lRho); return (entropy > robust::EPS() ? entropy : robust::EPS()); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoSie_(rho, sie, lambda, lRho, lT, Ye); const Real entropy = entropy_.interpToReal(Ye, lT, lRho); return (entropy > robust::EPS() ? entropy : robust::EPS()); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::SpecificHeatFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); const Real Cv = dEdT_.interpToReal(Ye, lT, lRho); return (Cv > robust::EPS() ? Cv : robust::EPS()); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::SpecificHeatFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoSie_(rho, sie, lambda, lRho, lT, Ye); const Real Cv = dEdT_.interpToReal(Ye, lT, lRho); return (Cv > robust::EPS() ? Cv : robust::EPS()); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::BulkModulusFromDensityTemperature(const Real rho, - const Real temperature, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); const Real lbmod = lBMod_.interpToReal(Ye, lT, lRho); @@ -593,10 +595,9 @@ Real StellarCollapse::BulkModulusFromDensityTemperature(const Real rho, return bMod > robust::EPS() ? bMod : robust::EPS(); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::GruneisenParamFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::GruneisenParamFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temp, lambda, lRho, lT, Ye); const Real dpde = dPdE_.interpToReal(Ye, lT, lRho); @@ -604,9 +605,9 @@ Real StellarCollapse::GruneisenParamFromDensityTemperature(const Real rho, return gm1; } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoSie_(rho, sie, lambda, lRho, lT, Ye); const Real lbmod = lBMod_.interpToReal(Ye, lT, lRho); @@ -614,10 +615,9 @@ Real StellarCollapse::BulkModulusFromDensityInternalEnergy(const Real rho, const return bMod; } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::GruneisenParamFromDensityInternalEnergy(const Real rho, - const Real sie, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoSie_(rho, sie, lambda, lRho, lT, Ye); const Real dpde = dPdE_.interpToReal(Ye, lT, lRho); @@ -626,17 +626,16 @@ Real StellarCollapse::GruneisenParamFromDensityInternalEnergy(const Real rho, } // TODO(JMM): Fill in this stub if we ever use this EOS in a PTE code. -PORTABLE_INLINE_FUNCTION -void StellarCollapse::DensityEnergyFromPressureTemperature(const Real press, - const Real temp, Real *lambda, - Real &rho, Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void StellarCollapse::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { EOS_ERROR("StellarCollapse::DensityEnergyFromPRessureTemperature is a stub"); } -PORTABLE_INLINE_FUNCTION -void StellarCollapse::MassFractionsFromDensityTemperature( +template +PORTABLE_INLINE_FUNCTION void StellarCollapse::MassFractionsFromDensityTemperature( const Real rho, const Real temperature, Real &Xa, Real &Xh, Real &Xn, Real &Xp, - Real &Abar, Real &Zbar, Real *lambda) const { + Real &Abar, Real &Zbar, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); Xa = Xa_.interpToReal(Ye, lT, lRho); @@ -647,10 +646,10 @@ void StellarCollapse::MassFractionsFromDensityTemperature( Zbar = Zbar_.interpToReal(Ye, lT, lRho); } -PORTABLE_INLINE_FUNCTION -void StellarCollapse::ChemicalPotentialsFromDensityTemperature( +template +PORTABLE_INLINE_FUNCTION void StellarCollapse::ChemicalPotentialsFromDensityTemperature( const Real rho, const Real temperature, Real &mu_e, Real &mu_n, Real &mu_p, - Real &muhat, Real &munu, Real *lambda) const { + Real &muhat, Real &munu, Indexer_t &&lambda) const { Real lRho, lT, Ye; getLogsFromRhoT_(rho, temperature, lambda, lRho, lT, Ye); mu_e = mu_e_.interpToReal(Ye, lT, lRho); @@ -660,10 +659,11 @@ void StellarCollapse::ChemicalPotentialsFromDensityTemperature( munu = munu_.interpToReal(Ye, lT, lRho); } -PORTABLE_INLINE_FUNCTION -void StellarCollapse::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, - Real &bmod, const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +StellarCollapse::FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, + Real &bmod, const unsigned long output, + Indexer_t &&lambda) const { Real lRho, lT, Ye; const unsigned long input = ~output; if (output == thermalqs::none) { @@ -697,10 +697,11 @@ void StellarCollapse::FillEos(Real &rho, Real &temp, Real &energy, Real &press, } } -PORTABLE_INLINE_FUNCTION -void StellarCollapse::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - Real &dpde, Real &dvdt, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +StellarCollapse::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, + Real &cv, Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { rho = rhoNormal_; temp = TNormal_; sie = sieNormal_; @@ -1118,9 +1119,9 @@ inline void StellarCollapse::setNormalValues_() { dVdTNormal_ = dPdENormal_ * CvNormal_ / (rhoNormal_ * rhoNormal_ * dPdR); } -PORTABLE_INLINE_FUNCTION -Real StellarCollapse::lTFromlRhoSie_(const Real lRho, const Real sie, - Real *lambda) const noexcept { +template +PORTABLE_INLINE_FUNCTION Real StellarCollapse::lTFromlRhoSie_( + const Real lRho, const Real sie, Indexer_t &&lambda) const noexcept { checkLambda_(lambda); RootFinding1D::Status status = RootFinding1D::Status::SUCCESS; using RootFinding1D::regula_falsi; From 286fefea553a4e4128ceb07426136769068fe334 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:28:04 -0600 Subject: [PATCH 13/39] templateify stiff gas --- singularity-eos/eos/eos_stiff.hpp | 65 +++++++++++++++++++------------ 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/singularity-eos/eos/eos_stiff.hpp b/singularity-eos/eos/eos_stiff.hpp index c60f2f60a4..4810858873 100644 --- a/singularity-eos/eos/eos_stiff.hpp +++ b/singularity-eos/eos/eos_stiff.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -57,77 +57,92 @@ class StiffGas : public EosBase { checkParams(); } StiffGas GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(rho * (sie - _qq) - _Pinf, rho * _Cv)); } PORTABLE_INLINE_FUNCTION void checkParams() const { PORTABLE_ALWAYS_REQUIRE(_Cv >= 0, "Heat capacity must be positive"); PORTABLE_ALWAYS_REQUIRE(_gm1 >= 0, "Gruneisen parameter must be positive"); } + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(_qq, robust::ratio(rho * _Cv * temperature + _Pinf, rho) + _qq); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(-_Pinf, _gm1 * rho * _Cv * temperature - _Pinf); } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(-_Pinf, _gm1 * rho * (sie - _qq) - (_gm1 + 1.0) * _Pinf); } + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("StiffGas"); return 0.0; }; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv * std::log(robust::ratio(temperature, _T0) + robust::SMALL()) + _gm1 * _Cv * std::log(robust::ratio(_rho0, rho) + robust::SMALL()) + _qp; } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio((sie - _qq - _Pinf * vol), (_sie0 - _qq - _Pinf * _vol0)) + robust::SMALL()) + _Cv * _gm1 * std::log(robust::ratio(vol, _vol0) + robust::SMALL()) + _qp; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), _gm1 * (_gm1 + 1.0) * rho * _Cv * temperature); } + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), _gm1 * (_gm1 + 1.0) * (rho * (sie - _qq) - _Pinf)); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Real *lambda = nullptr) const { + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _gm1; } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _gm1; } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; @@ -152,9 +167,10 @@ class StiffGas : public EosBase { "%g\n", _gm1 + 1.0, _Cv, _Pinf, _qq); } + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const { + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { sie = std::max( _qq, robust::ratio(press + (_gm1 + 1.0) * _Pinf, press + _Pinf) * _Cv * temp + _qq); @@ -176,9 +192,10 @@ class StiffGas : public EosBase { thermalqs::density | thermalqs::specific_internal_energy; }; -PORTABLE_INLINE_FUNCTION -void StiffGas::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +StiffGas::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From f71358dbaa2a4b544f87e1944b0c2aa51222def2 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:30:44 -0600 Subject: [PATCH 14/39] templateify vinet --- singularity-eos/eos/eos_vinet.hpp | 128 ++++++++++++++++++------------ 1 file changed, 78 insertions(+), 50 deletions(-) diff --git a/singularity-eos/eos/eos_vinet.hpp b/singularity-eos/eos/eos_vinet.hpp index 50a18e8686..0ec7b87627 100644 --- a/singularity-eos/eos/eos_vinet.hpp +++ b/singularity-eos/eos/eos_vinet.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -47,54 +47,71 @@ class Vinet : public EosBase { } Vinet GetOnDevice() { return *this; } + template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const; + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; // Entropy added AEM Dec. 2022 + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return _Cv0; } + template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv0; } // Thermal Bulk Modulus added AEM Dec 2022 + template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const; + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; // Thermal expansion coefficient added AEM 2022 + template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const; + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Real *lambda = nullptr) const { + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { return robust::ratio(_A0 * _B0, _Cv0 * rho); } + template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda = nullptr) const { + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return robust::ratio(_A0 * _B0, _Cv0 * rho); } + template PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, - Real *lambda = nullptr) const; - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const; + Indexer_t &&lambda = nullptr) const; + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(Vinet) @@ -116,9 +133,10 @@ class Vinet : public EosBase { printf("\n\n"); } // Density/Energy from P/T not unique, if used will give error + template PORTABLE_INLINE_FUNCTION void - DensityEnergyFromPressureTemperature(const Real press, const Real temp, Real *lambda, - Real &rho, Real &sie) const; + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const; inline void Finalize() {} static std::string EosType() { return std::string("Vinet"); } static std::string EosPyType() { return EosType(); } @@ -252,75 +270,84 @@ PORTABLE_INLINE_FUNCTION void Vinet::Vinet_F_DT_func(const Real rho, const Real return; } +template PORTABLE_INLINE_FUNCTION Real Vinet::InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return output[0]; } -PORTABLE_INLINE_FUNCTION Real Vinet::PressureFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real Vinet::PressureFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return output[1]; } -PORTABLE_INLINE_FUNCTION Real Vinet::EntropyFromDensityTemperature(const Real rho, - const Real temp, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real Vinet::EntropyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return output[6]; } +template PORTABLE_INLINE_FUNCTION Real Vinet::TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return robust::ratio(output[3], output[2] * rho); } +template PORTABLE_INLINE_FUNCTION Real Vinet::TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return output[2] * rho; } +template PORTABLE_INLINE_FUNCTION Real Vinet::BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Real *lambda) const { + const Real rho, const Real temp, Indexer_t &&lambda) const { Real output[8]; Vinet_F_DT_func(rho, temp, output); return output[7] * output[7] * rho; } +template PORTABLE_INLINE_FUNCTION Real Vinet::TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real Tref; Real output[8]; Tref = _T0; Vinet_F_DT_func(rho, Tref, output); return robust::ratio(sie - output[0], _Cv0) + Tref; } +template PORTABLE_INLINE_FUNCTION Real Vinet::PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real temp; Real output[8]; temp = TemperatureFromDensityInternalEnergy(rho, sie); Vinet_F_DT_func(rho, temp, output); return output[1]; } -PORTABLE_INLINE_FUNCTION Real Vinet::MinInternalEnergyFromDensity(const Real rho, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION Real +Vinet::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { MinInternalEnergyIsNotEnabled("Vinet"); return 0.0; } +template PORTABLE_INLINE_FUNCTION Real Vinet::EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real temp; Real output[8]; temp = TemperatureFromDensityInternalEnergy(rho, sie); Vinet_F_DT_func(rho, temp, output); return output[6]; } +template PORTABLE_INLINE_FUNCTION Real Vinet::BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Real *lambda) const { + const Real rho, const Real sie, Indexer_t &&lambda) const { Real temp; Real output[8]; temp = TemperatureFromDensityInternalEnergy(rho, sie); @@ -328,18 +355,18 @@ PORTABLE_INLINE_FUNCTION Real Vinet::BulkModulusFromDensityInternalEnergy( return output[7] * output[7] * rho; } // AEM: Give error since function is not well defined -PORTABLE_INLINE_FUNCTION void -Vinet::DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { +template +PORTABLE_INLINE_FUNCTION void Vinet::DensityEnergyFromPressureTemperature( + const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { EOS_ERROR("Vinet::DensityEnergyFromPressureTemperature: " "Not implemented.\n"); } // AEM: We should add entropy and Gruneissen parameters here so that it is complete // If we add also alpha and BT, those should also be in here. -PORTABLE_INLINE_FUNCTION void Vinet::FillEos(Real &rho, Real &temp, Real &sie, - Real &press, Real &cv, Real &bmod, - const unsigned long output, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +Vinet::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { const unsigned long input = ~output; // everything that is not output is input if (thermalqs::density & output) { EOS_ERROR("Vinet FillEos: Density is required input.\n"); @@ -361,10 +388,11 @@ PORTABLE_INLINE_FUNCTION void Vinet::FillEos(Real &rho, Real &temp, Real &sie, } // TODO(JMM): pre-cache these rather than recomputing them each time -PORTABLE_INLINE_FUNCTION -void Vinet::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, - Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Real *lambda) const { +template +PORTABLE_INLINE_FUNCTION void +Vinet::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda) const { // AEM: Added all variables I think should be output eventually Real tbmod; // Real entropy, alpha, Gamma; From c47bc567a493c7e02205283f793a7a03e3dc0eef Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:33:18 -0600 Subject: [PATCH 15/39] templateify unitsystem --- .../eos/modifiers/eos_unitsystem.hpp | 102 +++++++++--------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/singularity-eos/eos/modifiers/eos_unitsystem.hpp b/singularity-eos/eos/modifiers/eos_unitsystem.hpp index bdf6bf97a6..5d513fd543 100644 --- a/singularity-eos/eos/modifiers/eos_unitsystem.hpp +++ b/singularity-eos/eos/modifiers/eos_unitsystem.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -110,108 +110,111 @@ class UnitSystem : public EosBase> { } inline void Finalize() { t_.Finalize(); } - PORTABLE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real temp = t_.TemperatureFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return inv_temp_unit_ * temp; } - PORTABLE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { const Real sie = t_.InternalEnergyFromDensityTemperature( rho * rho_unit_, temperature * temp_unit_, lambda); return inv_sie_unit_ * sie; } - PORTABLE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real P = t_.PressureFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return inv_press_unit_ * P; } - PORTABLE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { const Real S = t_.MinInternalEnergyFromDensity(rho * rho_unit_, lambda); return inv_sie_unit_ * S; } - PORTABLE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real S = t_.EntropyFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return inv_entropy_unit_ * S; } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real cv = t_.SpecificHeatFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return inv_cv_unit_ * cv; } - PORTABLE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real bmod = t_.BulkModulusFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return inv_bmod_unit_ * bmod; } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real gm1 = t_.GruneisenParamFromDensityInternalEnergy(rho * rho_unit_, sie * sie_unit_, lambda); return gm1; } - PORTABLE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temp, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real P = t_.PressureFromDensityTemperature(rho * rho_unit_, temp * temp_unit_, lambda); return inv_press_unit_ * P; } - PORTABLE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temp, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real S = t_.EntropyFromDensityTemperature(rho * rho_unit_, temp * temp_unit_, lambda); return inv_entropy_unit_ * S; } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temp, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real cv = t_.SpecificHeatFromDensityTemperature(rho * rho_unit_, temp * temp_unit_, lambda); return inv_cv_unit_ * cv; } - PORTABLE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temp, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real bmod = t_.BulkModulusFromDensityTemperature(rho * rho_unit_, temp * temp_unit_, lambda); return inv_bmod_unit_ * bmod; } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temp, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { const Real gm1 = t_.GruneisenParamFromDensityTemperature(rho * rho_unit_, temp * temp_unit_, lambda); return gm1; } - PORTABLE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { + template + PORTABLE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { t_.DensityEnergyFromPressureTemperature(press * press_unit_, temp * temp_unit_, lambda, rho, sie); rho *= inv_rho_unit_; sie *= inv_sie_unit_; } - PORTABLE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { // TODO(JMM): Is this general enough? Do I need more switches/scales? Real srho = rho_unit_ * rho; switch (t_.PreferredInput()) { @@ -235,10 +238,11 @@ class UnitSystem : public EosBase> { bmod *= inv_bmod_unit_; } - PORTABLE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda); rho *= inv_rho_unit_; temp *= inv_temp_unit_; From 8bf8debe9048ea95e2f60d6ce534ea4b5ab130cb Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:34:30 -0600 Subject: [PATCH 16/39] templateify ramp --- singularity-eos/eos/modifiers/ramps_eos.hpp | 95 +++++++++++---------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/singularity-eos/eos/modifiers/ramps_eos.hpp b/singularity-eos/eos/modifiers/ramps_eos.hpp index 38d72f804a..d9c46048c8 100644 --- a/singularity-eos/eos/modifiers/ramps_eos.hpp +++ b/singularity-eos/eos/modifiers/ramps_eos.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -124,19 +124,19 @@ class BilinearRampEOS : public EosBase> { return dpdr; } - PORTABLE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.TemperatureFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.InternalEnergyFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { // ramp pressure const Real p_ramp{get_ramp_pressure(rho)}; // pressure from eos @@ -144,68 +144,70 @@ class BilinearRampEOS : public EosBase> { // return max(p_ramp, p_eos) return p_eos < p_ramp ? p_ramp : p_eos; } - PORTABLE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return t_.MinInternalEnergyFromDensity(rho, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real p_ramp{get_ramp_pressure(rho)}; const Real p_eos{t_.PressureFromDensityInternalEnergy(rho, sie, lambda)}; return p_eos < p_ramp ? rho * get_ramp_dpdrho(rho) : t_.BulkModulusFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { const Real p_ramp{get_ramp_pressure(rho)}; const Real p_eos{t_.PressureFromDensityTemperature(rho, temperature, lambda)}; return p_eos < p_ramp ? p_ramp : p_eos; } - PORTABLE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { const Real p_ramp{get_ramp_pressure(rho)}; const Real p_eos{t_.PressureFromDensityTemperature(rho, temperature, lambda)}; return p_eos < p_ramp ? rho * get_ramp_dpdrho(rho) : t_.BulkModulusFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { // output passed into internal filleos can't include pressure const unsigned long ramp_out = output & ~thermalqs::pressure; // if pressure is output, calculate it first @@ -434,10 +436,11 @@ class BilinearRampEOS : public EosBase> { t_.DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie); } - PORTABLE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda); } From 510392106d19a41cc94fb0defde67931744b3877 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Wed, 17 Apr 2024 17:36:35 -0600 Subject: [PATCH 17/39] templateify relativistic eos --- .../eos/modifiers/relativistic_eos.hpp | 102 +++++++++--------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/singularity-eos/eos/modifiers/relativistic_eos.hpp b/singularity-eos/eos/modifiers/relativistic_eos.hpp index 39a1f4e599..47726b8c6e 100644 --- a/singularity-eos/eos/modifiers/relativistic_eos.hpp +++ b/singularity-eos/eos/modifiers/relativistic_eos.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National @@ -78,80 +78,82 @@ class RelativisticEOS : public EosBase> { auto GetOnDevice() { return RelativisticEOS(t_.GetOnDevice(), cl_); } inline void Finalize() { t_.Finalize(); } - PORTABLE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.TemperatureFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.InternalEnergyFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return t_.MinInternalEnergyFromDensity(rho, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { Real P = PressureFromDensityInternalEnergy(rho, sie, lambda); Real h = cl2_ + sie + robust::ratio(P, rho); Real bmod = t_.BulkModulusFromDensityInternalEnergy(rho, sie, lambda); return std::max(0.0, robust::ratio(bmod, std::abs(h))); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityInternalEnergy(rho, sie, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real P = PressureFromDensityTemperature(rho, temperature, lambda); Real sie = InternalEnergyFromDensityTemperature(rho, temperature, lambda); Real h = cl2_ + sie + robust::ratio(P, rho); Real bmod = t_.BulkModulusFromDensityTemperature(rho, temperature, lambda); return std::max(0.0, robust::ratio(bmod, std::abs(h))); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { t_.FillEos(rho, temp, energy, press, cv, bmod, output, lambda); } @@ -176,16 +178,18 @@ class RelativisticEOS : public EosBase> { } PORTABLE_FUNCTION void PrintParams() const { t_.PrintParams(); } - PORTABLE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { + template + PORTABLE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { t_.DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie); } - PORTABLE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda); } From a69ab025ebcd5fead4f5d4481e10b0b53065676e Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 09:40:17 -0600 Subject: [PATCH 18/39] templateify shift and scale --- singularity-eos/eos/modifiers/scaled_eos.hpp | 100 +++++++++--------- singularity-eos/eos/modifiers/shifted_eos.hpp | 100 +++++++++--------- 2 files changed, 104 insertions(+), 96 deletions(-) diff --git a/singularity-eos/eos/modifiers/scaled_eos.hpp b/singularity-eos/eos/modifiers/scaled_eos.hpp index e991cc1c37..930e5baa83 100644 --- a/singularity-eos/eos/modifiers/scaled_eos.hpp +++ b/singularity-eos/eos/modifiers/scaled_eos.hpp @@ -75,79 +75,81 @@ class ScaledEOS : public EosBase> { auto GetOnDevice() { return ScaledEOS(t_.GetOnDevice(), scale_); } inline void Finalize() { t_.Finalize(); } - PORTABLE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.TemperatureFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real energy = t_.InternalEnergyFromDensityTemperature(rho, temperature, lambda); return scale_ * energy; } - PORTABLE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return t_.MinInternalEnergyFromDensity(scale_ * rho, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return scale_ * t_.EntropyFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.BulkModulusFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityInternalEnergy(scale_ * rho, inv_scale_ * sie, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityTemperature(scale_ * rho, temperature, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return scale_ * t_.EntropyFromDensityTemperature(scale_ * rho, temperature, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityTemperature(scale_ * rho, temperature, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.BulkModulusFromDensityTemperature(scale_ * rho, temperature, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityTemperature(scale_ * rho, temperature, lambda); } - PORTABLE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { Real srho, senergy; switch (t_.PreferredInput()) { case thermalqs::density | thermalqs::temperature: @@ -165,10 +167,11 @@ class ScaledEOS : public EosBase> { } } - PORTABLE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda); rho *= inv_scale_; sie *= scale_; @@ -334,9 +337,10 @@ class ScaledEOS : public EosBase> { t_.PrintParams(); printf("scaling_ratio = %f\n", scale_); } - PORTABLE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { + template + PORTABLE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { t_.DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie); rho = rho * inv_scale_; sie = sie * scale_; diff --git a/singularity-eos/eos/modifiers/shifted_eos.hpp b/singularity-eos/eos/modifiers/shifted_eos.hpp index fa10c1c445..d36a243135 100644 --- a/singularity-eos/eos/modifiers/shifted_eos.hpp +++ b/singularity-eos/eos/modifiers/shifted_eos.hpp @@ -74,74 +74,76 @@ class ShiftedEOS : public EosBase> { auto GetOnDevice() { return ShiftedEOS(t_.GetOnDevice(), shift_); } inline void Finalize() { t_.Finalize(); } - PORTABLE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.TemperatureFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { Real energy = t_.InternalEnergyFromDensityTemperature(rho, temperature, lambda); return energy + shift_; } - PORTABLE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return t_.MinInternalEnergyFromDensity(rho, lambda) + shift_; } - PORTABLE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.BulkModulusFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityInternalEnergy(rho, sie - shift_, lambda); } - PORTABLE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.PressureFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.EntropyFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.SpecificHeatFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.BulkModulusFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return t_.GruneisenParamFromDensityTemperature(rho, temperature, lambda); } - PORTABLE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { Real senergy; switch (t_.PreferredInput()) { case thermalqs::density | thermalqs::temperature: @@ -340,17 +342,19 @@ class ShiftedEOS : public EosBase> { t_.PrintParams(); printf("shift_value = %f\n", shift_); } - PORTABLE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { + template + PORTABLE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { t_.DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie); sie = sie + shift_; } - PORTABLE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, + Real &press, Real &cv, Real &bmod, + Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { t_.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, lambda); sie += shift_; } From cf4adca8c90da5c9a500aba90ebeff0c20c13050 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 09:43:14 -0600 Subject: [PATCH 19/39] make lambda an indexer --- singularity-eos/eos/eos_variant.hpp | 105 +++++++++++++++------------- 1 file changed, 55 insertions(+), 50 deletions(-) diff --git a/singularity-eos/eos/eos_variant.hpp b/singularity-eos/eos/eos_variant.hpp index 7836364633..08e88622d9 100644 --- a/singularity-eos/eos/eos_variant.hpp +++ b/singularity-eos/eos/eos_variant.hpp @@ -98,9 +98,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.TemperatureFromDensityInternalEnergy(rho, sie, lambda); @@ -108,9 +108,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.InternalEnergyFromDensityTemperature(rho, temperature, lambda); @@ -118,9 +118,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.PressureFromDensityTemperature(rho, temperature, lambda); @@ -128,26 +128,27 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real PressureFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.PressureFromDensityInternalEnergy(rho, sie, lambda); }, eos_); } - PORTABLE_INLINE_FUNCTION - Real MinInternalEnergyFromDensity(const Real rho, Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real + MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &lambda](const auto &eos) { return eos.MinInternalEnergyFromDensity(rho, lambda); }, eos_); } - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.EntropyFromDensityTemperature(rho, temperature, lambda); @@ -155,9 +156,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real EntropyFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.EntropyFromDensityInternalEnergy(rho, sie, lambda); @@ -165,9 +166,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.SpecificHeatFromDensityTemperature(rho, temperature, lambda); @@ -175,9 +176,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.SpecificHeatFromDensityInternalEnergy(rho, sie, lambda); @@ -185,9 +186,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.BulkModulusFromDensityTemperature(rho, temperature, lambda); @@ -195,9 +196,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.BulkModulusFromDensityInternalEnergy(rho, sie, lambda); @@ -205,9 +206,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.GruneisenParamFromDensityTemperature(rho, temperature, lambda); @@ -215,9 +216,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.GruneisenParamFromDensityInternalEnergy(rho, sie, lambda); @@ -225,9 +226,10 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temp, &energy, &press, &cv, &bmod, &output, &lambda](const auto &eos) { return eos.FillEos(rho, temp, energy, press, cv, bmod, output, lambda); @@ -235,8 +237,9 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - void ReferenceDensityTemperature(Real &rho, Real &T, Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void + ReferenceDensityTemperature(Real &rho, Real &T, Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &T, &lambda](const auto &eos) { return eos.ReferenceDensityTemperature(rho, T, lambda); @@ -244,10 +247,11 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Real *lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { return mpark::visit( [&rho, &temp, &sie, &press, &cv, &bmod, &dpde, &dvdt, &lambda](const auto &eos) { return eos.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, @@ -256,9 +260,10 @@ class Variant { eos_); } - PORTABLE_INLINE_FUNCTION - void DensityEnergyFromPressureTemperature(const Real press, const Real temp, - Real *lambda, Real &rho, Real &sie) const { + template + PORTABLE_INLINE_FUNCTION void + DensityEnergyFromPressureTemperature(const Real press, const Real temp, + Indexer_t &&lambda, Real &rho, Real &sie) const { return mpark::visit( [&press, &temp, &lambda, &rho, &sie](const auto &eos) { return eos.DensityEnergyFromPressureTemperature(press, temp, lambda, rho, sie); From 941da07677f4e6e03288f88d62fb540c58088d16 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:27:44 -0600 Subject: [PATCH 20/39] sfinae check for nullptr --- singularity-eos/base/variadic_utils.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 50e9b14269..0d033c53dc 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -23,6 +23,16 @@ namespace variadic_utils { // Some generic variatic utilities // ====================================================================== +// SFINAE to check if a value is a null ptr +template ::value, int>::type = 0> +inline bool is_nullptr(T &&t) { + return t == nullptr; +} +template ::value, int>::type = 0> +inline bool is_nullptr(T &&t) { + return false; +} + // Backport of C++17 bool_constant. // With C++17, can be replaced with // using std::bool_constant From 49e38ef299d237eebc53027c2adb82ad172171a1 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:28:15 -0600 Subject: [PATCH 21/39] apply sfinae check for null pointer --- singularity-eos/closure/mixed_cell_models.hpp | 8 +++--- singularity-eos/eos/eos_spiner.hpp | 28 ++++++++++--------- singularity-eos/eos/eos_stellar_collapse.hpp | 3 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/singularity-eos/closure/mixed_cell_models.hpp b/singularity-eos/closure/mixed_cell_models.hpp index 365e1dd4a6..bc5504d505 100644 --- a/singularity-eos/closure/mixed_cell_models.hpp +++ b/singularity-eos/closure/mixed_cell_models.hpp @@ -551,7 +551,7 @@ class PTESolverRhoT : public mix_impl::PTESolverBase { vtemp = AssignIncrement(scratch, nmat); // TODO(JCD): use whatever lambdas are passed in /*for (int m = 0; m < nmat; m++) { - if (lambda[m] != nullptr) Cache[m] = lambda[m]; + if (variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; }*/ } @@ -766,7 +766,7 @@ class PTESolverFixedT : public mix_impl::PTESolverBase Tnorm = 1.0; // TODO(JCD): use whatever lambdas are passed in /*for (int m = 0; m < nmat; m++) { - if (lambda[m] != nullptr) Cache[m] = lambda[m]; + if (variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; }*/ } @@ -963,7 +963,7 @@ class PTESolverFixedP : public mix_impl::PTESolverBase Pequil = P; // TODO(JCD): use whatever lambdas are passed in /*for (int m = 0; m < nmat; m++) { - if (lambda[m] != nullptr) Cache[m] = lambda[m]; + if (variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; }*/ } @@ -1184,7 +1184,7 @@ class PTESolverRhoU : public mix_impl::PTESolverBase { utemp = AssignIncrement(scratch, nmat); // TODO(JCD): use whatever lambdas are passed in /*for (int m = 0; m < nmat; m++) { - if (lambda[m] != nullptr) Cache[m] = lambda[m]; + if (variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; }*/ } diff --git a/singularity-eos/eos/eos_spiner.hpp b/singularity-eos/eos/eos_spiner.hpp index 4e03d131c3..a84b134cd7 100644 --- a/singularity-eos/eos/eos_spiner.hpp +++ b/singularity-eos/eos/eos_spiner.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include // spiner @@ -1139,7 +1140,7 @@ SpinerEOSDependsRhoT::FillEos(Real &rho, Real &temp, Real &energy, Real &press, if (output & thermalqs::bulk_modulus) { bmod = bModFromRholRhoTlT_(rho, lRho, temp, lT, whereAmI); } - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { lambda[Lambda::lRho] = lRho; lambda[Lambda::lT] = lT; } @@ -1173,7 +1174,7 @@ SpinerEOSDependsRhoT::getLogsRhoT_(const Real rho, const Real temperature, Real Real &lT, Indexer_t &&lambda) const { lRho = lRho_(rho); lT = lT_(temperature); - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { lambda[Lambda::lRho] = lRho; lambda[Lambda::lT] = lT; } @@ -1189,7 +1190,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lRhoFromPlT_( // Real lRhoGuess = lRhoMin_ + 0.9*(lRhoMax_ - lRhoMin_); const RootFinding1D::RootCounts *pcounts = (memoryStatus_ == DataStatus::OnDevice) ? nullptr : &counts; - if (lambda != nullptr && lRhoMin_ <= lambda[Lambda::lRho] && + if (!variadic_utils::is_nullptr(lambda) && lRhoMin_ <= lambda[Lambda::lRho] && lambda[Lambda::lRho] <= lRhoMax_) { lRhoGuess = lambda[Lambda::lRho]; } @@ -1227,7 +1228,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lRhoFromPlT_( #endif // SPINER_EOS_VERBOSE lRho = reproducible_ ? lRhoMax_ : lRhoGuess; } - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { lambda[Lambda::lRho] = lRho; lambda[Lambda::lT] = lT; } @@ -1265,7 +1266,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoSie_( } } else { Real lTGuess = reproducible_ ? lTMin_ : 0.5 * (lTMin_ + lTMax_); - if (lambda != nullptr && lTMin_ <= lambda[Lambda::lT] && + if (!variadic_utils::is_nullptr(lambda) && lTMin_ <= lambda[Lambda::lT] && lambda[Lambda::lT] <= lTMax_) { lTGuess = lambda[Lambda::lT]; } @@ -1289,7 +1290,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoSie_( lT = reproducible_ ? lTMin_ : lTGuess; } } - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { lambda[Lambda::lRho] = lRho; lambda[Lambda::lT] = lT; } @@ -1325,7 +1326,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoP_( } } else { whereAmI = TableStatus::OnTable; - if (lambda != nullptr && lTMin_ <= lambda[Lambda::lT] && + if (!variadic_utils::is_nullptr(lambda) && lTMin_ <= lambda[Lambda::lT] && lambda[Lambda::lT] <= lTMax_) { lTGuess = lambda[Lambda::lT]; } else { @@ -1347,7 +1348,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoT::lTFromlRhoP_( lT = reproducible_ ? lTMin_ : lTGuess; } } - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { lambda[Lambda::lRho] = lRho; lambda[Lambda::lT] = lT; } @@ -1820,7 +1821,7 @@ SpinerEOSDependsRhoSie::FillEos(Real &rho, Real &temp, Real &energy, Real &press } } else { lRho = toLog_(rho, lRhoOffset_); - if (lambda != nullptr) *lambda = lRho; + if (!variadic_utils::is_nullptr(lambda)) *lambda = lRho; } if (output & thermalqs::temperature) { lE = toLog_(energy, lEOffset_); @@ -1869,7 +1870,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoT_( const Real rho, const Real T, const DataBox &db, Indexer_t &&lambda) const { const Real lRho = toLog_(rho, lRhoOffset_); const Real lT = toLog_(T, lTOffset_); - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { *lambda = lRho; } return db.interpToReal(lRho, lT); @@ -1880,7 +1881,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoSie_( const Real rho, const Real sie, const DataBox &db, Indexer_t &&lambda) const { const Real lRho = toLog_(rho, lRhoOffset_); const Real lE = toLog_(sie, lEOffset_); - if (lambda != nullptr) { + if (!variadic_utils::is_nullptr(lambda)) { *lambda = lRho; } return db.interpToReal(lRho, lE); @@ -1902,7 +1903,8 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::lRhoFromPlT_( } } else { Real lRhoGuess = reproducible_ ? lRhoMin_ : 0.5 * (lRhoMin_ + lRhoMax_); - if (lambda != nullptr && lRhoMin_ <= *lambda && *lambda <= lRhoMax_) { + if (!variadic_utils::is_nullptr(lambda) && lRhoMin_ <= *lambda && + *lambda <= lRhoMax_) { lRhoGuess = *lambda; } const callable_interp::l_interp PFunc(dependsRhoT_.P, lT); @@ -1924,7 +1926,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::lRhoFromPlT_( lRho = reproducible_ ? lRhoMin_ : lRhoGuess; } } - if (lambda != nullptr) *lambda = lRho; + if (!variadic_utils::is_nullptr(lambda)) *lambda = lRho; return lRho; } diff --git a/singularity-eos/eos/eos_stellar_collapse.hpp b/singularity-eos/eos/eos_stellar_collapse.hpp index b028872390..062d9fe93b 100644 --- a/singularity-eos/eos/eos_stellar_collapse.hpp +++ b/singularity-eos/eos/eos_stellar_collapse.hpp @@ -37,6 +37,7 @@ #include #include #include +#include #include // spiner @@ -227,7 +228,7 @@ class StellarCollapse : public EosBase { template PORTABLE_FORCEINLINE_FUNCTION void checkLambda_(Indexer_t &&lambda) const noexcept { - if (lambda == nullptr) { + if (variadic_utils::is_nullptr(lambda)) { EOS_ERROR("StellarCollapse: lambda must contain Ye and 1 space for caching.\n"); } } From c840b905e2d9e3aa0061d9feafb0e2c95ef10e69 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:28:56 -0600 Subject: [PATCH 22/39] add a check that indexers work --- test/test_eos_stellar_collapse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_eos_stellar_collapse.cpp b/test/test_eos_stellar_collapse.cpp index 79fd922a5a..76fb5f5dd0 100644 --- a/test/test_eos_stellar_collapse.cpp +++ b/test/test_eos_stellar_collapse.cpp @@ -121,7 +121,7 @@ SCENARIO("Stellar Collapse EOS", "[StellarCollapse]") { THEN("We can load the file") { // don't bother filtering bmod here. StellarCollapse sc(filename, false, false); AND_THEN("Some properties we expect for ideal gas hold") { - Real lambda[2]; + std::vector lambda(2); Real rho, t, sie, p, cv, b, dpde, dvdt; sc.ValuesAtReferenceState(rho, t, sie, p, cv, b, dpde, dvdt, lambda); Real yemin = sc.YeMin(); From d04298f9c42b1addb965920de88f407946a8d674 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:29:25 -0600 Subject: [PATCH 23/39] formatting --- singularity-eos/eos/eos_eospac.hpp | 59 ++++++++++---------- singularity-eos/eos/eos_noble_abel.hpp | 74 +++++++++++++------------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/singularity-eos/eos/eos_eospac.hpp b/singularity-eos/eos/eos_eospac.hpp index 85a584a8a9..fd981b2aee 100644 --- a/singularity-eos/eos/eos_eospac.hpp +++ b/singularity-eos/eos/eos_eospac.hpp @@ -165,47 +165,47 @@ class EOSPAC : public EosBase { template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; - SG_PIF_NOWARN + SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void - FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, - const unsigned long output, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + Real &cv, Real &bmod, const unsigned long output, + Indexer_t &&lambda = nullptr) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void + PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void + PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, Indexer_t &&lambda = nullptr) const; @@ -1197,7 +1197,7 @@ inline EOSPAC::EOSPAC(const int matid, bool invert_at_setup, Real insert_data, SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::TemperatureFromDensityInternalEnergy( +PORTABLE_INLINE_FUNCTION Real EOSPAC::TemperatureFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, E[1] = {sieToSesame(sie)}, T[1], dTdr[1], dTde[1]; @@ -1209,7 +1209,7 @@ template SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityTemperature( const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, P[1], T[1] = {temperatureToSesame(temp)}, dPdr[1], dPdT[1]; @@ -1221,7 +1221,7 @@ template SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda) const { EntropyIsNotEnabled("EOSPAC"); return 1.0; @@ -1229,7 +1229,7 @@ template SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void +PORTABLE_INLINE_FUNCTION void EOSPAC::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, const unsigned long output, Indexer_t &&lambda) const { using namespace EospacWrapper; @@ -1313,7 +1313,7 @@ EOSPAC::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &b SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::InternalEnergyFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::InternalEnergyFromDensityTemperature( const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; @@ -1323,7 +1323,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityTemperature( const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; @@ -1333,7 +1333,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityTemperature( const Real rho, const Real temp, Indexer_t &&lambda) const { using namespace EospacWrapper; Real RHO = rho, TEMP = temp, sie, press, cv, bmod; @@ -1343,7 +1343,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityInternalEnergy( +PORTABLE_INLINE_FUNCTION Real EOSPAC::PressureFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_INTEGER options[]{EOS_Y_CONVERT, EOS_F_CONVERT}; @@ -1359,7 +1359,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real +PORTABLE_INLINE_FUNCTION Real EOSPAC::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_INTEGER options[]{EOS_F_CONVERT}; @@ -1375,7 +1375,7 @@ EOSPAC::MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda) const { } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityInternalEnergy( +PORTABLE_INLINE_FUNCTION Real EOSPAC::EntropyFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); @@ -1383,7 +1383,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityInternalEnergy( +PORTABLE_INLINE_FUNCTION Real EOSPAC::SpecificHeatFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); @@ -1391,7 +1391,7 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityInternalEnergy( +PORTABLE_INLINE_FUNCTION Real EOSPAC::BulkModulusFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { using namespace EospacWrapper; Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); @@ -1400,7 +1400,7 @@ template SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityTemperature( +PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda) const { using namespace EospacWrapper; EOS_REAL R[1] = {rho}, T[1] = {temperatureToSesame(temperature)}; @@ -1418,16 +1418,15 @@ template } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real -EOSPAC::GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, - Indexer_t &&lambda) const { +PORTABLE_INLINE_FUNCTION Real EOSPAC::GruneisenParamFromDensityInternalEnergy( + const Real rho, const Real sie, Indexer_t &&lambda) const { Real temperature = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return GruneisenParamFromDensityTemperature(rho, temperature, lambda); } SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void EOSPAC::DensityEnergyFromPressureTemperature( +PORTABLE_INLINE_FUNCTION void EOSPAC::DensityEnergyFromPressureTemperature( const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const { using namespace EospacWrapper; EOS_REAL P[1] = {pressureToSesame(press)}; @@ -1447,7 +1446,7 @@ template SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void +PORTABLE_INLINE_FUNCTION void EOSPAC::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, Indexer_t &&lambda) const { diff --git a/singularity-eos/eos/eos_noble_abel.hpp b/singularity-eos/eos/eos_noble_abel.hpp index e080246ba8..ffad7b0546 100644 --- a/singularity-eos/eos/eos_noble_abel.hpp +++ b/singularity-eos/eos/eos_noble_abel.hpp @@ -57,8 +57,8 @@ class NobleAbel : public EosBase { checkParams(); } NobleAbel GetOnDevice() { return *this; } - template -PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), (sie - _qq) / _Cv); } @@ -67,32 +67,32 @@ PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( PORTABLE_ALWAYS_REQUIRE(_gm1 >= 0, "Gruneisen parameter must be positive"); PORTABLE_ALWAYS_REQUIRE(_bb >= 0, "Covolume must be positive"); } - template -PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(_qq, _Cv * temperature + _qq); } - template -PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * _Cv * temperature, 1.0 - _bb * rho)); } - template -PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * (sie - _qq), 1.0 - _bb * rho)); } - template -PORTABLE_INLINE_FUNCTION Real + template + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { MinInternalEnergyIsNotEnabled("Noble Abel"); return 0.0; } - template -PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(temperature, _T0) + robust::SMALL()) + @@ -100,8 +100,8 @@ PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( std::log(robust::ratio(vol - _bb, _vol0 - _bb) + robust::SMALL()) + _qp; } - template -PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(sie - _qq, _sie0 - _qq) + robust::SMALL()) + @@ -109,49 +109,49 @@ PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( std::log(robust::ratio(vol - _bb, _vol0 - _bb) + robust::SMALL()) + _qp; } - template -PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return _Cv; } - template -PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return _Cv; } - template -PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * _Cv * temperature, (1.0 - _bb * rho) * (1.0 - _bb * rho))); } - template -PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * (sie - _qq), (1.0 - _bb * rho) * (1.0 - _bb * rho))); } - template -PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } - template -PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( + template + PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } - template -PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, + template + PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, Indexer_t &&lambda = nullptr) const; - template -PORTABLE_INLINE_FUNCTION - void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + template + PORTABLE_INLINE_FUNCTION void + ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, + Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; @@ -200,10 +200,10 @@ PORTABLE_INLINE_FUNCTION thermalqs::density | thermalqs::specific_internal_energy; }; - template -PORTABLE_INLINE_FUNCTION -void NobleAbel::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, - Real &bmod, const unsigned long output, Indexer_t &&lambda) const { +template +PORTABLE_INLINE_FUNCTION void +NobleAbel::FillEos(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, + const unsigned long output, Indexer_t &&lambda) const { if (output & thermalqs::density && output & thermalqs::specific_internal_energy) { if (output & thermalqs::pressure || output & thermalqs::temperature) { UNDEFINED_ERROR; From d6fd1889de807e4554463a5fc18fce41e3a99b62 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:29:34 -0600 Subject: [PATCH 24/39] CC --- singularity-eos/base/variadic_utils.hpp | 2 +- test/test_eos_stellar_collapse.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 0d033c53dc..7656bf750f 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National diff --git a/test/test_eos_stellar_collapse.cpp b/test/test_eos_stellar_collapse.cpp index 76fb5f5dd0..cc547879da 100644 --- a/test/test_eos_stellar_collapse.cpp +++ b/test/test_eos_stellar_collapse.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2023. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. Triad National Security, LLC. All rights reserved. This // program was produced under U.S. Government contract 89233218CNA000001 // for Los Alamos National Laboratory (LANL), which is operated by Triad // National Security, LLC for the U.S. Department of Energy/National From d272d7cb3339eb926f44c81ee4fd1da6fc51b134 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:55:43 -0600 Subject: [PATCH 25/39] update docs and use more robust sfinae --- doc/sphinx/src/using-closures.rst | 10 +- doc/sphinx/src/using-eos.rst | 141 +++++++++++++++++------- singularity-eos/base/variadic_utils.hpp | 12 +- 3 files changed, 115 insertions(+), 48 deletions(-) diff --git a/doc/sphinx/src/using-closures.rst b/doc/sphinx/src/using-closures.rst index d4d50cae6a..351303cb6b 100644 --- a/doc/sphinx/src/using-closures.rst +++ b/doc/sphinx/src/using-closures.rst @@ -460,11 +460,11 @@ total specific internal energy in the problem, ``rho`` is an indexer over densities, one per material. ``vfract`` is an indexer over volume fractions, one per material. ``sie`` is an indexer over temperatures, one per material. ``press`` is an indexer over pressures, one per -material. ``lambda`` is an indexer over lambda arrays, one ``Real *`` -object per material. ``scratch`` is a pointer to pre-allocated scratch -memory, as described above. It is assumed enough scratch has been -allocated. Finally, the optional argument ``Tguess`` allows for host -codes to pass in an initial temperature guess for the solver. For more +material. ``lambda`` is an indexer over lambda arrays, one per +material. ``scratch`` is a pointer to pre-allocated scratch memory, as +described above. It is assumed enough scratch has been allocated. +Finally, the optional argument ``Tguess`` allows for host codes to +pass in an initial temperature guess for the solver. For more information on initial guesses, see the section below. The constructor for the ``PTESolverRhoU`` has the same structure: diff --git a/doc/sphinx/src/using-eos.rst b/doc/sphinx/src/using-eos.rst index 7f1d975863..38e24d7150 100644 --- a/doc/sphinx/src/using-eos.rst +++ b/doc/sphinx/src/using-eos.rst @@ -77,7 +77,7 @@ method. ``get`` is templated and type deduction is not possible. You must specify the type of the class you're pulling out of the variant. For example: -.. code-block:: +.. code-block:: cpp auto my_ideal_gas = my_eos.get(); @@ -91,7 +91,7 @@ The EOS model also allows some host-side introspection. The method returns a string representing the equation of state an ``EOS`` object currently is. For example: -.. code-block:: +.. code-block:: cpp auto tpe_str = my_ideal_gas.EosType(); // prints "IdealGas" @@ -158,20 +158,16 @@ method, which can be called as, e.g., eos.Finalize(); -Vector and Scalar API, Accessors ---------------------------------- +Accessors and Indexers +----------------------- -Most ``EOS`` methods have both scalar and vector overloads, where the -scalar version returns a value, and the vector version modifies an -array. By default the vector version is called from host on device (if -``singularity-eos`` was compiled for device). - -The vector API is templated to accept *accessors*. An accessor is any -object with a square bracket operator. One-dimensional arrays, -pointers, and ``std::vector`` are all examples of what we call -an accessor. However, the value of an accessor is it doesn't have to -be an array. You can create an accessor class that wraps your -preferred memory layout, and ``singularity-eos`` will handle it +Many functions in ``singularity-eos`` accept **accessors**, also +called **indexers**. An accessor is any object with a square bracket +operator. One-dimensional arrays, pointers, and +``std::vector`` are all examples of what we call an +accessor. However, the value of an accessor is it doesn't have to be +an array. You can create an accessor class that wraps your preferred +memory layout, and ``singularity-eos`` will handle it appropriately. An accessor that indexes into an array with some stride might look like this: @@ -186,8 +182,20 @@ might look like this: int stride_; }; -We do note, however, that vectorization may suffer if your underlying -data structure is not contiguous in memory. +The Vector API and the ``lambda`` optional arguments all use +accessors, as discussed below. + +Vector and Scalar API +---------------------- + +Most ``EOS`` methods have both scalar and vector overloads, where the +scalar version returns a value, and the vector version modifies an +array. By default the vector version is called from host on device (if +``singularity-eos`` was compiled for device). + +The vector API is templated to accept accessors. We do note, however, +that vectorization may suffer if your underlying data structure is not +contiguous in memory. .. _eospac_vector: @@ -246,7 +254,7 @@ decorated so that it may be evaluated on either host or device, depending on desired use-case. Alternatively, you may use an anonymous function with an `auto` argument as the input, e.g., -.. code-block:: +.. code-block:: cpp // equivalent to [=], but with device markings eos.Evaluate(PORTABLE_LAMBDA(auto eos) { /* my code snippet */ }); @@ -339,12 +347,16 @@ Lambdas and Optional Parameters -------------------------------- Most methods for ``EOS`` objects accept an optional ``lambda`` -parameter, which is a ``Real *``. Unless specified in :ref:`the -models section `, this parameter does nothing. However, some -models require or benefit from additional information. For example -models with internal root finds can leverage initial guesses and -models with composition mixing parameters may need additional input to -return a meaningful state. +parameter, which is an accessor as discussed above. ``lambda[i]`` +should return a real number unless ``lambda==nullptr``. Unless +specified in :ref:`the models section `, this parameter does +nothing, and the default type is ``Real*`` with a default value of +``nullptr`` + +However, some models require or benefit from additional +information. For example models with internal root finds can leverage +initial guesses and models with composition mixing parameters may need +additional input to return a meaningful state. ``EOS`` models are introspective and can provide the desired/required size of the lambda array with: @@ -352,8 +364,8 @@ size of the lambda array with: .. cpp:function:: int EOS::nlambda() which is the desired size of the ``lambda`` array per scalar call. For -vector calls, there should be one such array per grid point. An -accessor for ``lambda`` should return a ``Real *`` pointer at each +vector calls, there should be one such accessor per grid point. A +vector accessor for ``lambda`` should return an accessor at each index. A trivial example of such an indexer for ``lambda`` might be the null indexer: @@ -544,13 +556,17 @@ cgs. Unless specified, all functions work on device, if the code is compiled appropriately. The exceptions are constructors, ``GetOnDevice``, and ``Finalize``, all of which are host-only. -.. cpp:function:: Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, Rela &lambda = nullptr) const; +.. code-block:: cpp + + template + Real TemperatureFromDensityInternalEnergy(const Real rho, const Real sie, + Indexer_t &&lambda = nullptr) const; Returns temperature in Kelvin. Inputs are density in :math:`g/cm^3` and specific internal energy in :math:`erg/g`. The vector equivalent of this function is -.. code-block:: +.. code-block:: cpp template inline void @@ -567,33 +583,57 @@ parameter is always last in the function signature. As they are all almost exactly analogous to their scalar counterparts, we will mostly not list the vector functions here. -.. cpp:function:: Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, Real *lambda=nullptr) const; +.. code-block:: cpp + + template + Real InternalEnergyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns specific internal energy in :math:`erg/g` given a density in :math:`g/cm^3` and a temperature in Kelvin. -.. cpp:function:: Real PressureFromDensityTemperature(const Real rho, const Real temperature, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns pressure in Barye given density in :math:`g/cm^3` and temperature in Kelvin. -.. cpp:function:: Real PressureFromDensityInternalEnergy(const Real rho, const Real temperature, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real PressureFromDensityInternalEnergy(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns pressure in Barye given density in :math:`g/cm^3` and specific internal energy in :math:`erg/g`. -.. cpp:function:: Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real SpecificHeatFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns specific heat capacity at constant volume, in units of :math:`erg/(g K)` in terms of density in :math:`g/cm^3` and temperature in Kelvin. -.. cpp:function:: Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real SpecificHeatFromDensityInternalEnergy(const Real rho, const Real sie, + Indexer_t &&lambda = nullptr) const; returns specific heat capacity at constant volume, in units of :math:`erg/(g K)` in terms of density in :math:`g/cm^3` and specific internal energy in :math:`erg/g`. -.. cpp:function:: Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real BulkModulusFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns the the bulk modulus @@ -620,12 +660,20 @@ enthalpy by volume. The sound speed may also differ for, e.g., porous models, where the pressure is less directly correlated with the density. -.. cpp:function:: Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real BulkModulusFromDensityInternalEnergy(const Real rho, const Real sie, + Indexer_t &&lambda = nullptr) const; returns the bulk modulus in units of :math:`g cm^2/s^2` given density in :math:`g/cm^3` and specific internal energy in :math:`erg/g`. -.. cpp:function:: Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real GruneisenParamFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = nullptr) const; returns the unitless Gruneisen parameter @@ -635,14 +683,23 @@ returns the unitless Gruneisen parameter given density in :math:`g/cm^3` and temperature in Kelvin. -.. cpp:function:: Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + Real GruneisenParamFromDensityInternalEnergy(const Real rho, const Real sie, + Indexer_t &&lambda = nullptr) const; returns the unitless Gruneisen parameter given density in :math:`g/cm^3` and specific internal energy in :math:`erg/g`. The function -.. cpp:function:: void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, + Real &cv, Real &bmod, Real &dpde, Real &dvdt, + Indexer_t &&lambda = nullptr) const; fills the density, temperature, specific internal energy, pressure, and thermodynamic derivatives a specifically chosen characteristic @@ -653,7 +710,13 @@ representative energy and density scale. The function -.. cpp:function:: void FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, const unsigned long output, Real *lambda = nullptr) const; +.. code-block:: cpp + + template + void FillEos(Real &rho, Real &temp, Real &energy, + Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = nullptr) const; is a a bit of a special case. ``output`` is a bitfield represented as an unsigned 64 bit number. Quantities such ``pressure`` and diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 7656bf750f..883e1b593e 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -24,12 +24,16 @@ namespace variadic_utils { // ====================================================================== // SFINAE to check if a value is a null ptr -template ::value, int>::type = 0> +template ::type>::type>::value>::type> inline bool is_nullptr(T &&t) { - return t == nullptr; + return std::forward(t) == nullptr; } -template ::value, int>::type = 0> -inline bool is_nullptr(T &&t) { +template ::type>::type>::value>::type * = nullptr> +inline bool is_nullptr(T &&) { return false; } From 5ea11113228718912ff1ecee1cff040ef1274fe6 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 10:57:53 -0600 Subject: [PATCH 26/39] constexpr and include utility --- singularity-eos/base/variadic_utils.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 883e1b593e..89b195017e 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -16,6 +16,7 @@ #define SINGULARITY_EOS_BASE_VARIADIC_UTILS_HPP_ #include +#include namespace singularity { namespace variadic_utils { @@ -27,13 +28,13 @@ namespace variadic_utils { template ::type>::type>::value>::type> -inline bool is_nullptr(T &&t) { +constexpr inline bool is_nullptr(T &&t) { return std::forward(t) == nullptr; } template ::type>::type>::value>::type * = nullptr> -inline bool is_nullptr(T &&) { +constexpr inline bool is_nullptr(T &&) { return false; } From 1254adf170da98eba9533532cc55baca119c9664 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Thu, 18 Apr 2024 11:02:07 -0600 Subject: [PATCH 27/39] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbc326098b..3ebdf8f869 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - [[PR326]](https://github.com/lanl/singularity-eos/pull/326) Document how to do a release ### Changed (changing behavior/API/variables/...) +- [[PR363]](https://github.com/lanl/singularity-eos/pull/363) Template lambda values for scalar calls ### Infrastructure (changes irrelevant to downstream codes) - [[PR329]](https://github.com/lanl/singularity-eos/pull/329) Move vinet tests into analytic test suite From df116899a5b1146f91ee291ab2b47d300596b767 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Fri, 19 Apr 2024 15:20:01 -0600 Subject: [PATCH 28/39] python: update method signature --- python/module.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/module.hpp b/python/module.hpp index a4a3788a8f..d2feb36ec8 100644 --- a/python/module.hpp +++ b/python/module.hpp @@ -27,12 +27,12 @@ using namespace singularity; // Helper function to convert lambda numpy array to double* buffer // With std::optional we would add support for a default value of lambda=None -template +template Real two_params(const T& self, const Real a, const Real b, py::array_t lambda) { return (self.*Func)(a, b, lambda.mutable_data()); } -template +template Real two_params_no_lambda(const T& self, const Real a, const Real b) { return (self.*Func)(a, b, nullptr); } From 4ea36aa30895341823c7e738e2ef9683fcfc2ac1 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Fri, 19 Apr 2024 16:04:54 -0600 Subject: [PATCH 29/39] no dereferencing indexers. they're not pointers necessarily. --- singularity-eos/eos/eos_spiner.hpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/singularity-eos/eos/eos_spiner.hpp b/singularity-eos/eos/eos_spiner.hpp index a84b134cd7..1dfb874b8c 100644 --- a/singularity-eos/eos/eos_spiner.hpp +++ b/singularity-eos/eos/eos_spiner.hpp @@ -1821,7 +1821,7 @@ SpinerEOSDependsRhoSie::FillEos(Real &rho, Real &temp, Real &energy, Real &press } } else { lRho = toLog_(rho, lRhoOffset_); - if (!variadic_utils::is_nullptr(lambda)) *lambda = lRho; + if (!variadic_utils::is_nullptr(lambda)) lambda[0] = lRho; } if (output & thermalqs::temperature) { lE = toLog_(energy, lEOffset_); @@ -1871,7 +1871,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoT_( const Real lRho = toLog_(rho, lRhoOffset_); const Real lT = toLog_(T, lTOffset_); if (!variadic_utils::is_nullptr(lambda)) { - *lambda = lRho; + lambda[0] = lRho; } return db.interpToReal(lRho, lT); } @@ -1882,7 +1882,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::interpRhoSie_( const Real lRho = toLog_(rho, lRhoOffset_); const Real lE = toLog_(sie, lEOffset_); if (!variadic_utils::is_nullptr(lambda)) { - *lambda = lRho; + lambda[0] = lRho; } return db.interpToReal(lRho, lE); } @@ -1903,9 +1903,9 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::lRhoFromPlT_( } } else { Real lRhoGuess = reproducible_ ? lRhoMin_ : 0.5 * (lRhoMin_ + lRhoMax_); - if (!variadic_utils::is_nullptr(lambda) && lRhoMin_ <= *lambda && - *lambda <= lRhoMax_) { - lRhoGuess = *lambda; + if (!variadic_utils::is_nullptr(lambda) && lRhoMin_ <= lambda[0] && + lambda[0] <= lRhoMax_) { + lRhoGuess = lambda[0]; } const callable_interp::l_interp PFunc(dependsRhoT_.P, lT); auto status = ROOT_FINDER(PFunc, P, lRhoGuess, lRhoMin_, lRhoMax_, robust::EPS(), @@ -1926,7 +1926,7 @@ PORTABLE_INLINE_FUNCTION Real SpinerEOSDependsRhoSie::lRhoFromPlT_( lRho = reproducible_ ? lRhoMin_ : lRhoGuess; } } - if (!variadic_utils::is_nullptr(lambda)) *lambda = lRho; + if (!variadic_utils::is_nullptr(lambda)) lambda[0] = lRho; return lRho; } From b2ae8aa7ef10291b968df3305e0c69250813a6c5 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Fri, 19 Apr 2024 16:06:05 -0600 Subject: [PATCH 30/39] potentially real dumb fix --- python/module.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/module.hpp b/python/module.hpp index d2feb36ec8..603d70a68b 100644 --- a/python/module.hpp +++ b/python/module.hpp @@ -34,7 +34,7 @@ Real two_params(const T& self, const Real a, const Real b, py::array_t lam template Real two_params_no_lambda(const T& self, const Real a, const Real b) { - return (self.*Func)(a, b, nullptr); + return (self.*Func)(a, b, static_cast(nullptr)); } class LambdaHelper { From 35535a3815bb46d6c1b6adc7436e19e1b8d33c1d Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Fri, 19 Apr 2024 16:14:25 -0600 Subject: [PATCH 31/39] static casts. Static casts for everybody. --- python/module.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/module.hpp b/python/module.hpp index 603d70a68b..23f50b958b 100644 --- a/python/module.hpp +++ b/python/module.hpp @@ -326,7 +326,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { auto lambda = kwargs["lmbda"].cast>(); self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, lambda.mutable_data()); } else { - self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, nullptr); + self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, static_cast(nullptr)); } return s; }) @@ -337,7 +337,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { }) .def("ValuesAtReferenceState", [](const T & self){ EOSState s; - self.ValuesAtReferenceState(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, s.dpde, s.dvdt, nullptr); + self.ValuesAtReferenceState(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, s.dpde, s.dvdt, static_cast(nullptr)); return s; }) @@ -354,7 +354,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { }, py::arg("press"), py::arg("temp"), py::arg("lmbda")) .def("DensityEnergyFromPressureTemperature", [](const T & self, const Real press, const Real temp) { Real rho, sie; - self.DensityEnergyFromPressureTemperature(press, temp, nullptr, rho, sie); + self.DensityEnergyFromPressureTemperature(press, temp, static_cast(nullptr), rho, sie); return std::pair(rho, sie); }, py::arg("press"), py::arg("temp")) .def("Finalize", &T::Finalize) From f519eb045865eb4ed6ffa130793de0ec07bd7231 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Fri, 19 Apr 2024 16:25:03 -0600 Subject: [PATCH 32/39] be REALLY explicit about wanting (Real*)(NULL) --- singularity-eos/eos/eos_spiner.hpp | 142 +++++++++++-------- singularity-eos/eos/eos_stellar_collapse.hpp | 62 ++++---- 2 files changed, 121 insertions(+), 83 deletions(-) diff --git a/singularity-eos/eos/eos_spiner.hpp b/singularity-eos/eos/eos_spiner.hpp index 1dfb874b8c..5578d96716 100644 --- a/singularity-eos/eos/eos_spiner.hpp +++ b/singularity-eos/eos/eos_spiner.hpp @@ -105,58 +105,71 @@ class SpinerEOSDependsRhoT : public EosBase { template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const; template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; PORTABLE_INLINE_FUNCTION Real RhoPmin(const Real temp) const; @@ -226,21 +239,21 @@ class SpinerEOSDependsRhoT : public EosBase { Real T_(const Real lT) const noexcept { return fromLog_(lT, lTOffset_); } template - PORTABLE_INLINE_FUNCTION Real lTFromlRhoSie_(const Real lRho, const Real sie, - TableStatus &whereAmI, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + lTFromlRhoSie_(const Real lRho, const Real sie, TableStatus &whereAmI, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real lTFromlRhoP_(const Real lRho, const Real press, - TableStatus &whereAmI, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + lTFromlRhoP_(const Real lRho, const Real press, TableStatus &whereAmI, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real lRhoFromPlT_(const Real P, const Real lT, - TableStatus &whereAmI, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + lRhoFromPlT_(const Real P, const Real lT, TableStatus &whereAmI, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION void getLogsRhoT_(const Real rho, const Real temperature, - Real &lRho, Real &lT, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + getLogsRhoT_(const Real rho, const Real temperature, Real &lRho, Real &lT, + Indexer_t &&lambda = static_cast(nullptr)) const; PORTABLE_INLINE_FUNCTION Real sieFromlRhoTlT_(const Real lRho, const Real T, const Real lT, const TableStatus &whereAmI) const; @@ -345,59 +358,72 @@ class SpinerEOSDependsRhoSie : public EosBase { template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real T, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real T, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real T, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real T, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real T, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real T, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const; template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; static constexpr unsigned long PreferredInput() { return _preferred_input; } static inline unsigned long scratch_size(std::string method, unsigned int nelements) { @@ -457,13 +483,13 @@ class SpinerEOSDependsRhoSie : public EosBase { return FastMath::pow10(lx) - offset; } template - PORTABLE_INLINE_FUNCTION Real interpRhoT_(const Real rho, const Real T, - const DataBox &db, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + interpRhoT_(const Real rho, const Real T, const DataBox &db, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real interpRhoSie_(const Real rho, const Real sie, - const DataBox &db, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + interpRhoSie_(const Real rho, const Real sie, const DataBox &db, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real lRhoFromPlT_(const Real P, const Real lT, Indexer_t &&lambda) const; diff --git a/singularity-eos/eos/eos_stellar_collapse.hpp b/singularity-eos/eos/eos_stellar_collapse.hpp index 062d9fe93b..e3d42f6363 100644 --- a/singularity-eos/eos/eos_stellar_collapse.hpp +++ b/singularity-eos/eos/eos_stellar_collapse.hpp @@ -100,43 +100,55 @@ class StellarCollapse : public EosBase { template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, @@ -144,26 +156,26 @@ class StellarCollapse : public EosBase { // Properties of an NSE EOS template - PORTABLE_INLINE_FUNCTION void - MassFractionsFromDensityTemperature(const Real rho, const Real temperature, Real &Xa, - Real &Xh, Real &Xn, Real &Xp, Real &Abar, - Real &Zbar, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void MassFractionsFromDensityTemperature( + const Real rho, const Real temperature, Real &Xa, Real &Xh, Real &Xn, Real &Xp, + Real &Abar, Real &Zbar, Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ChemicalPotentialsFromDensityTemperature( const Real rho, const Real temperature, Real &mu_e, Real &mu_n, Real &mu_p, - Real &muhat, Real &munu, Indexer_t &&lambda = nullptr) const; + Real &muhat, Real &munu, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here static constexpr unsigned long PreferredInput() { return _preferred_input; } From d7f913eec2112d8f51c1763633bc8ef2c7f5cad1 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Mon, 22 Apr 2024 15:07:45 -0600 Subject: [PATCH 33/39] add remove_cvref --- singularity-eos/base/variadic_utils.hpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 89b195017e..f5d9372f1b 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -24,17 +24,26 @@ namespace variadic_utils { // Some generic variatic utilities // ====================================================================== +// C++14 implementation of std::remove_cvref (available since C++20) +// credit to CJ + Diego +template +struct remove_cvref { + typedef std::remove_cv_t> type; +}; + +// Helper types +template +using remove_cvref_t = typename remove_cvref::type; + // SFINAE to check if a value is a null ptr template ::type>::type>::value>::type> -constexpr inline bool is_nullptr(T &&t) { + std::is_pointer>::value>::type> +inline bool is_nullptr(T &&t) { return std::forward(t) == nullptr; } -template ::type>::type>::value>::type * = nullptr> -constexpr inline bool is_nullptr(T &&) { +template >::value>::type * = nullptr> +inline bool is_nullptr(T &&) { return false; } From e822af29415af1250d300917ceb194465f472766 Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Tue, 23 Apr 2024 11:45:40 -0600 Subject: [PATCH 34/39] typo in commented out code --- singularity-eos/closure/mixed_cell_models.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/singularity-eos/closure/mixed_cell_models.hpp b/singularity-eos/closure/mixed_cell_models.hpp index ad0018b131..cd3c094f8a 100644 --- a/singularity-eos/closure/mixed_cell_models.hpp +++ b/singularity-eos/closure/mixed_cell_models.hpp @@ -566,7 +566,7 @@ class PTESolverRhoT : public mix_impl::PTESolverBase { vtemp = AssignIncrement(scratch, nmat); // TODO(JCD): use whatever lambdas are passed in /*for (int m = 0; m < nmat; m++) { - if (variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; + if (!variadic_utils::is_nullptr(lambda[m])) Cache[m] = lambda[m]; }*/ } From 88f616be9aea675d03d76bd7685912851dea6a0d Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Tue, 23 Apr 2024 11:45:59 -0600 Subject: [PATCH 35/39] static casts for everybody --- singularity-eos/eos/eos_davis.hpp | 102 +++++++++++++-------- singularity-eos/eos/eos_eospac.hpp | 53 +++++++---- singularity-eos/eos/eos_gruneisen.hpp | 53 +++++++---- singularity-eos/eos/eos_helmholtz.hpp | 51 +++++++---- singularity-eos/eos/eos_ideal.hpp | 51 +++++++---- singularity-eos/eos/eos_jwl.hpp | 53 +++++++---- singularity-eos/eos/eos_mgusup.hpp | 59 +++++++----- singularity-eos/eos/eos_noble_abel.hpp | 51 +++++++---- singularity-eos/eos/eos_powermg.hpp | 59 +++++++----- singularity-eos/eos/eos_sap_polynomial.hpp | 55 ++++++----- singularity-eos/eos/eos_stiff.hpp | 51 +++++++---- singularity-eos/eos/eos_variant.hpp | 54 +++++++---- singularity-eos/eos/eos_vinet.hpp | 59 +++++++----- 13 files changed, 470 insertions(+), 281 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index 7534e88104..87e2ef06f6 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -39,7 +39,8 @@ class DavisReactants : public EosBase { DavisReactants GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real es = Es(rho); const Real tmp = std::pow((1.0 + _alpha) / (Ts(rho) * _Cv0) * (sie - es) + 1.0, 1.0 / (1.0 + _alpha)); @@ -48,81 +49,93 @@ class DavisReactants : public EosBase { } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real t_s = Ts(rho); return Es(rho) + _Cv0 * t_s / (1.0 + _alpha) * (std::pow(temp / t_s, 1.0 + _alpha) - 1.0); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Ps(rho) + Gamma(rho) * rho * (sie - Es(rho)); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("DavisReactants"); return 0.0; } template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { EntropyIsNotEnabled("DavisReactants"); return 1.0; } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { EntropyIsNotEnabled("DavisReactants"); return 1.0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return SpecificHeatFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0 / std::pow((1 + _alpha) / (Ts(rho) * _Cv0) * (sie - Es(rho)) + 1, -_alpha / (1 + _alpha)); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(rho); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(rho); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, const Real temp, @@ -169,70 +182,82 @@ class DavisProducts : public EosBase { DavisProducts GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Ts(rho) + (sie - Es(rho)) / _Cv; } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv * (temp - Ts(rho)) + Es(rho); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return PressureFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Ps(rho) + rho * Gamma(rho) * (sie - Es(rho)); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("DavisProducts"); return 0.0; } template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { EntropyIsNotEnabled("DavisProducts"); return 1.0; } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { EntropyIsNotEnabled("DavisProducts"); return 1.0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return BulkModulusFromDensityInternalEnergy( rho, InternalEnergyFromDensityTemperature(rho, temp)); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(rho); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(rho); } template @@ -240,14 +265,15 @@ class DavisProducts : public EosBase { DensityEnergyFromPressureTemperature(const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const; template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(DavisProducts) diff --git a/singularity-eos/eos/eos_eospac.hpp b/singularity-eos/eos/eos_eospac.hpp index fd981b2aee..343d72690b 100644 --- a/singularity-eos/eos/eos_eospac.hpp +++ b/singularity-eos/eos/eos_eospac.hpp @@ -144,60 +144,73 @@ class EOSPAC : public EosBase { SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; SG_PIF_NOWARN template PORTABLE_INLINE_FUNCTION void @@ -208,7 +221,7 @@ class EOSPAC : public EosBase { PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic (Scalar) using EosBase::is_raw_pointer; diff --git a/singularity-eos/eos/eos_gruneisen.hpp b/singularity-eos/eos/eos_gruneisen.hpp index ff9e8c883b..1e8254614a 100644 --- a/singularity-eos/eos/eos_gruneisen.hpp +++ b/singularity-eos/eos/eos_gruneisen.hpp @@ -66,64 +66,77 @@ class Gruneisen : public EosBase { Gruneisen GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _T0 + sie / _Cv; } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv * (temp - _T0); } template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperatummmmmmre, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperatummmmmmre, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(std::min(rho, _rho_max)); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return Gamma(std::min(rho, _rho_max)); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(Gruneisen) diff --git a/singularity-eos/eos/eos_helmholtz.hpp b/singularity-eos/eos/eos_helmholtz.hpp index 276c094fb4..3dc5b07d41 100644 --- a/singularity-eos/eos/eos_helmholtz.hpp +++ b/singularity-eos/eos/eos_helmholtz.hpp @@ -462,7 +462,8 @@ class Helmholtz : public EosBase { template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -471,7 +472,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; @@ -480,7 +482,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; @@ -489,7 +492,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -498,22 +502,24 @@ class Helmholtz : public EosBase { return p; } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("Helmholtz"); return 0.0; } template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityTemperature_(rho, temperature, lambda, p, e, s, etaele, nep); return s[HelmUtils::VAL]; } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityInternalEnergy_(rho, sie, lambda, p, e, s, etaele, nep); return s[HelmUtils::VAL]; @@ -521,7 +527,8 @@ class Helmholtz : public EosBase { template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; @@ -530,7 +537,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -540,7 +548,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real tl = temperature; Real sie, p, cv, bmod; @@ -549,7 +558,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { Real rl = rho; Real el = sie; Real temperature, p, cv, bmod; @@ -560,7 +570,8 @@ class Helmholtz : public EosBase { template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { using namespace HelmUtils; Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; GetFromDensityTemperature_(rho, temperature, lambda, p, e, s, etaele, nep); @@ -569,7 +580,8 @@ class Helmholtz : public EosBase { } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { using namespace HelmUtils; Real p[NDERIV], e[NDERIV], s[NDERIV], etaele[NDERIV], nep[NDERIV]; Real abar = lambda[Lambda::Abar]; @@ -585,15 +597,16 @@ class Helmholtz : public EosBase { } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { // JMM: I'm not sure what to put here or if it matters. Some // reference state, maybe stellar denity, would be appropriate. PORTABLE_ALWAYS_ABORT("Stub"); diff --git a/singularity-eos/eos/eos_ideal.hpp b/singularity-eos/eos/eos_ideal.hpp index ab1617e276..489c3a6553 100644 --- a/singularity-eos/eos/eos_ideal.hpp +++ b/singularity-eos/eos/eos_ideal.hpp @@ -54,7 +54,8 @@ class IdealGas : public EosBase { IdealGas GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, sie / _Cv); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -69,76 +70,88 @@ class IdealGas : public EosBase { } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, _Cv * temperature); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, _gm1 * rho * _Cv * temperature); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, _gm1 * rho * sie); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { return 0.0; }; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv * log(robust::ratio(temperature, _EntropyT0)) + _gm1 * _Cv * log(robust::ratio(_EntropyRho0, rho)); } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real temp = TemperatureFromDensityInternalEnergy(rho, sie, lambda); return EntropyFromDensityTemperature(rho, temp, lambda); } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * _Cv * temperature); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return MYMAX(0.0, (_gm1 + 1) * _gm1 * rho * sie); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _gm1; } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _gm1; } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; diff --git a/singularity-eos/eos/eos_jwl.hpp b/singularity-eos/eos/eos_jwl.hpp index e1a671122f..6cf06ad947 100644 --- a/singularity-eos/eos/eos_jwl.hpp +++ b/singularity-eos/eos/eos_jwl.hpp @@ -52,47 +52,60 @@ class JWL : public EosBase { JWL GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(JWL) @@ -102,7 +115,7 @@ class JWL : public EosBase { PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; static constexpr unsigned long PreferredInput() { return _preferred_input; } static inline unsigned long scratch_size(std::string method, unsigned int nelements) { return 0; diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index 54d4a5d47d..84b999ea1c 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -46,33 +46,41 @@ class MGUsup : public EosBase { MGUsup GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } // added for testing AEM Dec 2023 @@ -82,36 +90,43 @@ class MGUsup : public EosBase { // Thermal Bulk Modulus added AEM Dec 2022 template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; // Thermal expansion coefficient added AEM 2022 template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_G0 * _rho0, rho); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_G0 * _rho0, rho); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(MGUsup) diff --git a/singularity-eos/eos/eos_noble_abel.hpp b/singularity-eos/eos/eos_noble_abel.hpp index ffad7b0546..4a1fdae28f 100644 --- a/singularity-eos/eos/eos_noble_abel.hpp +++ b/singularity-eos/eos/eos_noble_abel.hpp @@ -59,7 +59,8 @@ class NobleAbel : public EosBase { NobleAbel GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), (sie - _qq) / _Cv); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -69,31 +70,35 @@ class NobleAbel : public EosBase { } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(_qq, _Cv * temperature + _qq); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * _Cv * temperature, 1.0 - _bb * rho)); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * rho * (sie - _qq), 1.0 - _bb * rho)); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("Noble Abel"); return 0.0; } template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(temperature, _T0) + robust::SMALL()) + _gm1 * _Cv * @@ -102,7 +107,8 @@ class NobleAbel : public EosBase { } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio(sie - _qq, _sie0 - _qq) + robust::SMALL()) + _gm1 * _Cv * @@ -111,47 +117,54 @@ class NobleAbel : public EosBase { } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * _Cv * temperature, (1.0 - _bb * rho) * (1.0 - _bb * rho))); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), robust::ratio(_gm1 * (_gm1 + 1.0) * rho * (sie - _qq), (1.0 - _bb * rho) * (1.0 - _bb * rho))); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_gm1, (1.0 - _bb * rho)); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index b9c0666caf..b30516a4f0 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -47,33 +47,41 @@ class PowerMG : public EosBase { PowerMG GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } // added for testing AEM Dec 2023 @@ -83,36 +91,43 @@ class PowerMG : public EosBase { // Thermal Bulk Modulus added AEM Dec 2022 template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; // Thermal expansion coefficient added AEM 2022 template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_G0 * _rho0, rho); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_G0 * _rho0, rho); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(PowerMG) diff --git a/singularity-eos/eos/eos_sap_polynomial.hpp b/singularity-eos/eos/eos_sap_polynomial.hpp index bd2d812675..8499de7c59 100644 --- a/singularity-eos/eos/eos_sap_polynomial.hpp +++ b/singularity-eos/eos/eos_sap_polynomial.hpp @@ -51,25 +51,29 @@ class SAP_Polynomial : public EosBase { } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return _a0 + _a1 * mu + _a2c * mu * mu + _a3 * mu * mu * mu + @@ -80,51 +84,58 @@ class SAP_Polynomial : public EosBase { } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("SAP Polynomial"); return 0.0; }; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { PORTABLE_WARN("This function is a stub for an incomplete EoS."); return 0.0; } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return _b0 + _b1 * mu + _b2c * mu * mu + _b3 * mu * mu * mu; @@ -133,7 +144,8 @@ class SAP_Polynomial : public EosBase { } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real mu = MuFromDensity(rho); if (mu >= 0) // Compression return (1 + mu) * (_a1 + 2 * _a2c * mu + 3 * _a3 * mu * mu + @@ -143,21 +155,22 @@ class SAP_Polynomial : public EosBase { sie * (_b1 + 2 * _b2e * mu + 3 * _b3 * mu * mu)); } template - PORTABLE_INLINE_FUNCTION Real MuFromDensity(const Real rho, - Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + MuFromDensity(const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { return rho / _rho0 - 1; } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = 0.0; diff --git a/singularity-eos/eos/eos_stiff.hpp b/singularity-eos/eos/eos_stiff.hpp index 4810858873..d0ca49e096 100644 --- a/singularity-eos/eos/eos_stiff.hpp +++ b/singularity-eos/eos/eos_stiff.hpp @@ -59,7 +59,8 @@ class StiffGas : public EosBase { StiffGas GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), robust::ratio(rho * (sie - _qq) - _Pinf, rho * _Cv)); } PORTABLE_INLINE_FUNCTION void checkParams() const { @@ -68,36 +69,41 @@ class StiffGas : public EosBase { } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(_qq, robust::ratio(rho * _Cv * temperature + _Pinf, rho) + _qq); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(-_Pinf, _gm1 * rho * _Cv * temperature - _Pinf); } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(-_Pinf, _gm1 * rho * (sie - _qq) - (_gm1 + 1.0) * _Pinf); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { MinInternalEnergyIsNotEnabled("StiffGas"); return 0.0; }; template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv * std::log(robust::ratio(temperature, _T0) + robust::SMALL()) + _gm1 * _Cv * std::log(robust::ratio(_rho0, rho) + robust::SMALL()) + _qp; } template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { const Real vol = robust::ratio(1.0, rho); return _Cv * std::log(robust::ratio((sie - _qq - _Pinf * vol), (_sie0 - _qq - _Pinf * _vol0)) + @@ -106,43 +112,50 @@ class StiffGas : public EosBase { } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv; } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), _gm1 * (_gm1 + 1.0) * rho * _Cv * temperature); } template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return std::max(robust::SMALL(), _gm1 * (_gm1 + 1.0) * (rho * (sie - _qq) - _Pinf)); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return _gm1; } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _gm1; } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { // use STP: 1 atmosphere, room temperature rho = _rho0; temp = _T0; diff --git a/singularity-eos/eos/eos_variant.hpp b/singularity-eos/eos/eos_variant.hpp index 08e88622d9..1a98dfdcc8 100644 --- a/singularity-eos/eos/eos_variant.hpp +++ b/singularity-eos/eos/eos_variant.hpp @@ -100,7 +100,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.TemperatureFromDensityInternalEnergy(rho, sie, lambda); @@ -110,7 +111,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.InternalEnergyFromDensityTemperature(rho, temperature, lambda); @@ -120,7 +122,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.PressureFromDensityTemperature(rho, temperature, lambda); @@ -130,7 +133,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.PressureFromDensityInternalEnergy(rho, sie, lambda); @@ -138,8 +142,8 @@ class Variant { eos_); } template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &lambda](const auto &eos) { return eos.MinInternalEnergyFromDensity(rho, lambda); @@ -147,8 +151,9 @@ class Variant { eos_); } template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.EntropyFromDensityTemperature(rho, temperature, lambda); @@ -158,7 +163,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.EntropyFromDensityInternalEnergy(rho, sie, lambda); @@ -168,7 +174,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.SpecificHeatFromDensityTemperature(rho, temperature, lambda); @@ -178,7 +185,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.SpecificHeatFromDensityInternalEnergy(rho, sie, lambda); @@ -188,7 +196,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.BulkModulusFromDensityTemperature(rho, temperature, lambda); @@ -198,7 +207,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.BulkModulusFromDensityInternalEnergy(rho, sie, lambda); @@ -208,7 +218,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temperature, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temperature, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temperature, &lambda](const auto &eos) { return eos.GruneisenParamFromDensityTemperature(rho, temperature, lambda); @@ -218,7 +229,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &sie, &lambda](const auto &eos) { return eos.GruneisenParamFromDensityInternalEnergy(rho, sie, lambda); @@ -227,9 +239,10 @@ class Variant { } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temp, &energy, &press, &cv, &bmod, &output, &lambda](const auto &eos) { return eos.FillEos(rho, temp, energy, press, cv, bmod, output, lambda); @@ -239,7 +252,8 @@ class Variant { template PORTABLE_INLINE_FUNCTION void - ReferenceDensityTemperature(Real &rho, Real &T, Indexer_t &&lambda = nullptr) const { + ReferenceDensityTemperature(Real &rho, Real &T, + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &T, &lambda](const auto &eos) { return eos.ReferenceDensityTemperature(rho, T, lambda); @@ -251,7 +265,7 @@ class Variant { PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const { + Indexer_t &&lambda = static_cast(nullptr)) const { return mpark::visit( [&rho, &temp, &sie, &press, &cv, &bmod, &dpde, &dvdt, &lambda](const auto &eos) { return eos.ValuesAtReferenceState(rho, temp, sie, press, cv, bmod, dpde, dvdt, diff --git a/singularity-eos/eos/eos_vinet.hpp b/singularity-eos/eos/eos_vinet.hpp index 0ec7b87627..e7bbf8e809 100644 --- a/singularity-eos/eos/eos_vinet.hpp +++ b/singularity-eos/eos/eos_vinet.hpp @@ -49,69 +49,84 @@ class Vinet : public EosBase { Vinet GetOnDevice() { return *this; } template PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + PressureFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real PressureFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template - PORTABLE_INLINE_FUNCTION Real - MinInternalEnergyFromDensity(const Real rho, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real MinInternalEnergyFromDensity( + const Real rho, Indexer_t &&lambda = static_cast(nullptr)) const; // Entropy added AEM Dec. 2022 template - PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION Real + EntropyFromDensityTemperature(const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } template PORTABLE_INLINE_FUNCTION Real SpecificHeatFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return _Cv0; } // Thermal Bulk Modulus added AEM Dec 2022 template PORTABLE_INLINE_FUNCTION Real TBulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real BulkModulusFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const; // Thermal expansion coefficient added AEM 2022 template PORTABLE_INLINE_FUNCTION Real TExpansionCoeffFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const; + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityTemperature( - const Real rho, const Real temp, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real temp, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_A0 * _B0, _Cv0 * rho); } template PORTABLE_INLINE_FUNCTION Real GruneisenParamFromDensityInternalEnergy( - const Real rho, const Real sie, Indexer_t &&lambda = nullptr) const { + const Real rho, const Real sie, + Indexer_t &&lambda = static_cast(nullptr)) const { return robust::ratio(_A0 * _B0, _Cv0 * rho); } template - PORTABLE_INLINE_FUNCTION void FillEos(Real &rho, Real &temp, Real &energy, Real &press, - Real &cv, Real &bmod, const unsigned long output, - Indexer_t &&lambda = nullptr) const; + PORTABLE_INLINE_FUNCTION void + FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod, + const unsigned long output, + Indexer_t &&lambda = static_cast(nullptr)) const; template PORTABLE_INLINE_FUNCTION void ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, Real &bmod, Real &dpde, Real &dvdt, - Indexer_t &&lambda = nullptr) const; + Indexer_t &&lambda = static_cast(nullptr)) const; // Generic functions provided by the base class. These contain e.g. the vector // overloads that use the scalar versions declared here SG_ADD_BASE_CLASS_USINGS(Vinet) From 921d1c0fb8d7e22a1176767988f762c27282be1f Mon Sep 17 00:00:00 2001 From: Jonah Maxwell Miller Date: Tue, 23 Apr 2024 17:20:33 -0600 Subject: [PATCH 36/39] one more static cast for those at home --- test/test_eos_tabulated.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_eos_tabulated.cpp b/test/test_eos_tabulated.cpp index 9844677d87..59e9b1b844 100644 --- a/test/test_eos_tabulated.cpp +++ b/test/test_eos_tabulated.cpp @@ -113,7 +113,8 @@ SCENARIO("SpinerEOS depends on Rho and T", "[SpinerEOS],[DependsRhoT][EOSPAC]") std::vector lambda(steelEOS_host_polymorphic.nlambda()); steelEOS_host_polymorphic.DensityEnergyFromPressureTemperature( P, T, lambda.data(), rho, sie); - eospac.DensityEnergyFromPressureTemperature(P, T, nullptr, rho_pac, sie_pac); + eospac.DensityEnergyFromPressureTemperature(P, T, static_cast(nullptr), + rho_pac, sie_pac); REQUIRE(isClose(rho, rho_pac)); } } From 1eeed8a0fd002c43909a57ea444e4cdab20fc3f7 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Wed, 24 Apr 2024 15:31:11 -0600 Subject: [PATCH 37/39] add constexpr --- singularity-eos/base/variadic_utils.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index f5d9372f1b..7db0b0e6b3 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -38,12 +38,12 @@ using remove_cvref_t = typename remove_cvref::type; // SFINAE to check if a value is a null ptr template >::value>::type> -inline bool is_nullptr(T &&t) { +constexpr inline bool is_nullptr(T &&t) { return std::forward(t) == nullptr; } template >::value>::type * = nullptr> -inline bool is_nullptr(T &&) { +constexpr inline bool is_nullptr(T &&) { return false; } From 32bcf9ca46bf2dcb7c29006c49ab7852bf49c00b Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Thu, 25 Apr 2024 09:27:16 -0600 Subject: [PATCH 38/39] use array for host test of lambda, just to make the compiler stop complaining --- test/test_eos_stellar_collapse.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_eos_stellar_collapse.cpp b/test/test_eos_stellar_collapse.cpp index cc547879da..e496900128 100644 --- a/test/test_eos_stellar_collapse.cpp +++ b/test/test_eos_stellar_collapse.cpp @@ -121,7 +121,7 @@ SCENARIO("Stellar Collapse EOS", "[StellarCollapse]") { THEN("We can load the file") { // don't bother filtering bmod here. StellarCollapse sc(filename, false, false); AND_THEN("Some properties we expect for ideal gas hold") { - std::vector lambda(2); + std::array lambda; Real rho, t, sie, p, cv, b, dpde, dvdt; sc.ValuesAtReferenceState(rho, t, sie, p, cv, b, dpde, dvdt, lambda); Real yemin = sc.YeMin(); From f594ee1ccf9bf2a1672680e4bcb3323781000560 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Thu, 25 Apr 2024 09:35:11 -0600 Subject: [PATCH 39/39] add constexpr function for generating nullptr of specific pointer type --- python/module.hpp | 10 ++++++---- singularity-eos/base/variadic_utils.hpp | 6 ++++++ test/test_eos_tabulated.cpp | 5 +++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/python/module.hpp b/python/module.hpp index 23f50b958b..dd22dc6cb2 100644 --- a/python/module.hpp +++ b/python/module.hpp @@ -14,6 +14,7 @@ // clang-format off #include #include +#include #include #include #include @@ -24,6 +25,7 @@ namespace py = pybind11; using namespace singularity; +using singularity::variadic_utils::np; // Helper function to convert lambda numpy array to double* buffer // With std::optional we would add support for a default value of lambda=None @@ -34,7 +36,7 @@ Real two_params(const T& self, const Real a, const Real b, py::array_t lam template Real two_params_no_lambda(const T& self, const Real a, const Real b) { - return (self.*Func)(a, b, static_cast(nullptr)); + return (self.*Func)(a, b, np()); } class LambdaHelper { @@ -326,7 +328,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { auto lambda = kwargs["lmbda"].cast>(); self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, lambda.mutable_data()); } else { - self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, static_cast(nullptr)); + self.FillEos(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, output, np()); } return s; }) @@ -337,7 +339,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { }) .def("ValuesAtReferenceState", [](const T & self){ EOSState s; - self.ValuesAtReferenceState(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, s.dpde, s.dvdt, static_cast(nullptr)); + self.ValuesAtReferenceState(s.density, s.temperature, s.specific_internal_energy, s.pressure, s.specific_heat, s.bulk_modulus, s.dpde, s.dvdt, np()); return s; }) @@ -354,7 +356,7 @@ py::class_ eos_class(py::module_ & m, std::string name) { }, py::arg("press"), py::arg("temp"), py::arg("lmbda")) .def("DensityEnergyFromPressureTemperature", [](const T & self, const Real press, const Real temp) { Real rho, sie; - self.DensityEnergyFromPressureTemperature(press, temp, static_cast(nullptr), rho, sie); + self.DensityEnergyFromPressureTemperature(press, temp, np(), rho, sie); return std::pair(rho, sie); }, py::arg("press"), py::arg("temp")) .def("Finalize", &T::Finalize) diff --git a/singularity-eos/base/variadic_utils.hpp b/singularity-eos/base/variadic_utils.hpp index 7db0b0e6b3..e0ef3d95dc 100644 --- a/singularity-eos/base/variadic_utils.hpp +++ b/singularity-eos/base/variadic_utils.hpp @@ -24,6 +24,12 @@ namespace variadic_utils { // Some generic variatic utilities // ====================================================================== +// Useful for generating nullptr of a specific pointer type +template +inline constexpr T *np() { + return nullptr; +} + // C++14 implementation of std::remove_cvref (available since C++20) // credit to CJ + Diego template diff --git a/test/test_eos_tabulated.cpp b/test/test_eos_tabulated.cpp index 59e9b1b844..f80d373d0a 100644 --- a/test/test_eos_tabulated.cpp +++ b/test/test_eos_tabulated.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #ifndef CATCH_CONFIG_FAST_COMPILE @@ -40,6 +41,7 @@ using singularity::EOSPAC; #endif namespace thermalqs = singularity::thermalqs; +using singularity::variadic_utils::np; const std::string eosName = "../materials.sp5"; const std::string airName = "air"; @@ -113,8 +115,7 @@ SCENARIO("SpinerEOS depends on Rho and T", "[SpinerEOS],[DependsRhoT][EOSPAC]") std::vector lambda(steelEOS_host_polymorphic.nlambda()); steelEOS_host_polymorphic.DensityEnergyFromPressureTemperature( P, T, lambda.data(), rho, sie); - eospac.DensityEnergyFromPressureTemperature(P, T, static_cast(nullptr), - rho_pac, sie_pac); + eospac.DensityEnergyFromPressureTemperature(P, T, np(), rho_pac, sie_pac); REQUIRE(isClose(rho, rho_pac)); } }