From 397971f074080c2845d9bb6f6790d68321ca02e1 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sat, 14 Nov 2026 06:39:18 -0700 Subject: [PATCH 01/16] Add analytic InternalEnergyFromDensityPressure to davis --- singularity-eos/eos/eos_davis.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index 34a23fb35cf..3257247b39a 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -82,6 +82,22 @@ class DavisReactants : public EosBase { return Es(rho) + _Cv0 * t_s * _i1pa * (std::pow(robust::ratio(temp, t_s), 1.0 + _alpha) - 1.0); } + // Analytic inverse of PressureFromDensityInternalEnergy, so no root find + // is needed. Overrides the iterative version in EosBase. + template + PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, + Indexer_t &&lambda = static_cast(nullptr)) const { + sie = Es(rho) + robust::ratio(P - Ps(rho), Gamma(rho) * rho); + } + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( + const Real rho, const Real P, + Indexer_t &&lambda = static_cast(nullptr)) const { + Real sie; + InternalEnergyFromDensityPressure(rho, P, sie, lambda); + return sie; + } template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( const Real rho, const Real temp, @@ -239,6 +255,20 @@ class DavisProducts : public EosBase { return _Cv * (temp - Ts(rho)) + Es(rho); } template + PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, + Indexer_t &&lambda = static_cast(nullptr)) const { + sie = Es(rho) + robust::ratio(P - Ps(rho), rho * Gamma(rho)); + } + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( + const Real rho, const Real P, + Indexer_t &&lambda = static_cast(nullptr)) const { + Real sie; + InternalEnergyFromDensityPressure(rho, P, sie, lambda); + return sie; + } + template PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature( const Real rho, const Real temp, Indexer_t &&lambda = static_cast(nullptr)) const { From b8c377e0eb739e137b08804b94baddc3487c1c3e Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sat, 14 Nov 2026 06:41:55 -0700 Subject: [PATCH 02/16] Add change log entries Still needs the actual MR number/URL --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d98fecd3d5d..3e1c07ce1a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [[PR658]](https://github.com/lanl/singularity-eos/pull/658) Add `MinimumInternalEnergy`/`MaximumInternalEnergy` to the EOS introspection API, so energy bounds are reachable through modifiers and the `singularity::EOS` variant - [[PR659]](https://github.com/lanl/singularity-eos/pull/659) Add `sesame2spiner::saveAllMaterials` overloads taking a list of matids instead of a list of input files, with optional per-material `Params` overrides, so host codes can generate an sp5 file without writing input decks to disk. Also added an overload taking an already-open `hid_t`, plus `writeSP5RootAttributes`, so a single sp5 file can be built up one material at a time. - [[PR659]](https://github.com/lanl/singularity-eos/pull/659) Added `sesame2spiner::saveAllMaterials` overloads taking a list of matids instead of a list of input files, with optional per-material `Params` overrides, so host codes can generate an sp5 file without writing input decks to disk. Also added an overload taking an already-open `hid_t`, plus `writeSP5RootAttributes`, so a single sp5 file can be built up one material at a time. +- [[PRXXX]]() Added analytic `InternalEnergyFromDensityPressure` methods to Davis Reactants and Products, overriding the iterative solve previously used. ### Fixed (Repair bugs, etc) - [[PR667]](https://github.com/lanl/singularity-eos/pull/667) Various fixes to shift/unit/scale EOS modifiers. From ba0df48f748642a20b7c220818095d8bf0f55ec5 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sat, 14 Nov 2026 07:06:02 -0700 Subject: [PATCH 03/16] Remove a comment --- singularity-eos/eos/eos_davis.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index 3257247b39a..697a8485b39 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -82,8 +82,6 @@ class DavisReactants : public EosBase { return Es(rho) + _Cv0 * t_s * _i1pa * (std::pow(robust::ratio(temp, t_s), 1.0 + _alpha) - 1.0); } - // Analytic inverse of PressureFromDensityInternalEnergy, so no root find - // is needed. Overrides the iterative version in EosBase. template PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( const Real rho, const Real P, Real &sie, From 17b78fb7e8f0e1b229d61d8e672dd31a493ed337 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sat, 14 Nov 2026 07:42:24 -0700 Subject: [PATCH 04/16] Add testing of InternalEnergyFromDensityPressure in Davis --- test/test_eos_davis.cpp | 98 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/test/test_eos_davis.cpp b/test/test_eos_davis.cpp index 275e951ae87..eae1fd88197 100644 --- a/test/test_eos_davis.cpp +++ b/test/test_eos_davis.cpp @@ -130,6 +130,55 @@ SCENARIO("Davis reactants EOS basic calls", "[DavisReactants]") { } } + WHEN("Internal energy is computed from density and pressure") { + THEN("It inverts the pressure lookup over a range of states") { + int nwrong = 0; + portableReduce( + "Round trip sie -> P -> sie for DavisReactants", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + // sweep both density and energy across the grid + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + + // the out-param signature, which also accepts an initial guess + Real sie_out = 0.0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_out); + nw += !isClose(sie_out, sie, 1e-12); + + // the guess-free signature must agree + const Real sie_ret = eos.InternalEnergyFromDensityPressure(rho, P); + nw += !isClose(sie_ret, sie, 1e-12); + + // and the recovered energy must reproduce the pressure + nw += !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, + 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + + THEN("A supplied initial guess does not change the answer") { + int nwrong = 0; + portableReduce( + "Initial guess independence for DavisReactants", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + // the analytic inverse should ignore the guess entirely + Real sie_lo = 0.1 * e0; + Real sie_hi = 10.0 * e0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_lo); + eos.InternalEnergyFromDensityPressure(rho, P, sie_hi); + nw += !isClose(sie_lo, sie_hi, 1e-12); + nw += !isClose(sie_lo, sie, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + } + eos_host.Finalize(); eos.Finalize(); } @@ -194,6 +243,55 @@ SCENARIO("Davis products EOS basic calls", "[DavisProducts]") { } } + WHEN("Internal energy is computed from density and pressure") { + THEN("It inverts the pressure lookup over a range of states") { + int nwrong = 0; + portableReduce( + "Round trip sie -> P -> sie for DavisProducts", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + // sweep both density and energy across the grid + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + + // the out-param signature, which also accepts an initial guess + Real sie_out = 0.0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_out); + nw += !isClose(sie_out, sie, 1e-12); + + // the guess-free signature must agree + const Real sie_ret = eos.InternalEnergyFromDensityPressure(rho, P); + nw += !isClose(sie_ret, sie, 1e-12); + + // and the recovered energy must reproduce the pressure + nw += !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, + 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + + THEN("A supplied initial guess does not change the answer") { + int nwrong = 0; + portableReduce( + "Initial guess independence for DavisProducts", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + // the analytic inverse should ignore the guess entirely + Real sie_lo = 0.1 * e0; + Real sie_hi = 10.0 * e0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_lo); + eos.InternalEnergyFromDensityPressure(rho, P, sie_hi); + nw += !isClose(sie_lo, sie_hi, 1e-12); + nw += !isClose(sie_lo, sie, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + } + eos_host.Finalize(); eos.Finalize(); } From 67b7348ee5197420e1d1437f1be160982c1e07cc Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sat, 14 Nov 2026 10:06:28 -0700 Subject: [PATCH 05/16] Fix test --- test/test_eos_davis.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/test/test_eos_davis.cpp b/test/test_eos_davis.cpp index eae1fd88197..ec9676d056a 100644 --- a/test/test_eos_davis.cpp +++ b/test/test_eos_davis.cpp @@ -141,18 +141,13 @@ SCENARIO("Davis reactants EOS basic calls", "[DavisReactants]") { const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); - // the out-param signature, which also accepts an initial guess Real sie_out = 0.0; eos.InternalEnergyFromDensityPressure(rho, P, sie_out); nw += !isClose(sie_out, sie, 1e-12); - // the guess-free signature must agree - const Real sie_ret = eos.InternalEnergyFromDensityPressure(rho, P); - nw += !isClose(sie_ret, sie, 1e-12); - // and the recovered energy must reproduce the pressure - nw += !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, - 1e-12); + nw += + !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, 1e-12); }, nwrong); REQUIRE(nwrong == 0); @@ -254,18 +249,13 @@ SCENARIO("Davis products EOS basic calls", "[DavisProducts]") { const Real sie = e0 * (0.25 + 1.75 * i / (N - 1.0)); const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); - // the out-param signature, which also accepts an initial guess Real sie_out = 0.0; eos.InternalEnergyFromDensityPressure(rho, P, sie_out); nw += !isClose(sie_out, sie, 1e-12); - // the guess-free signature must agree - const Real sie_ret = eos.InternalEnergyFromDensityPressure(rho, P); - nw += !isClose(sie_ret, sie, 1e-12); - // and the recovered energy must reproduce the pressure - nw += !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, - 1e-12); + nw += + !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, 1e-12); }, nwrong); REQUIRE(nwrong == 0); From e389780e5935975bb8e882b12465de0efb3ab439 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 16:09:37 -0700 Subject: [PATCH 06/16] Add analytic InternalEnergyFromDensityPressure for mgusup --- singularity-eos/eos/eos_mgusup.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index 0d653be7422..e0a89c2492c 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -64,6 +64,18 @@ class MGUsup : public EosBase { const Real rho, const Real sie, Indexer_t &&lambda = static_cast(nullptr)) const; template + PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, + Indexer_t &&lambda = static_cast(nullptr)) const; + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( + const Real rho, const Real P, + Indexer_t &&lambda = static_cast(nullptr)) const { + Real sie; + InternalEnergyFromDensityPressure(rho, P, sie, lambda); + return sie; + } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature(const Real rho, const Real temp, Indexer_t &&lambda = static_cast(nullptr)) const; @@ -330,6 +342,12 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityInternalEnergy( return value; } template +PORTABLE_INLINE_FUNCTION void MGUsup::InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { + sie = HugInternalEnergyFromDensity(rho) + + robust::ratio(P - HugPressureFromDensity(rho), _rho0 * _G0); +} +template PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { Real eta = 1.0 - robust::ratio(_rho0, rho); From 01fb26c5e3711a67c8ea919e49018e9caf91bc0a Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 16:09:59 -0700 Subject: [PATCH 07/16] Add a test for mgusup --- test/test_eos_mgusup.cpp | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/test_eos_mgusup.cpp b/test/test_eos_mgusup.cpp index 162709cc0cb..bdf347384ee 100644 --- a/test/test_eos_mgusup.cpp +++ b/test/test_eos_mgusup.cpp @@ -536,3 +536,68 @@ SCENARIO("MGUsup EOS SetUp", "[VectorEOS][MGUsupEOS]") { } } } + +SCENARIO("MGUsup EOS SetUp", "PofRE EofRP are inverse operations") { + GIVEN("Parameters for a MGUsup EOS") { + + constexpr int N = 100; + // Unit conversions + constexpr Real Mbcc_per_g = 1e12; + // MGUsup parameters for copper + Real rho0 = 7.285; + Real T0 = 298.0; + Real Cs = 2766.0e2; + Real s = 1.5344; + Real G0 = 2.4659; + Real Cv0 = 0.2149e-05 * Mbcc_per_g; + constexpr Real E0 = 0.658e-03 * Mbcc_per_g; + constexpr Real S0 = 0.4419e-05 * Mbcc_per_g; + // Create the EOS + EOS eos = MGUsup(rho0, T0, Cs, s, G0, Cv0, E0, S0); + + WHEN("Internal energy is computed from density and pressure") { + THEN("It inverts the pressure lookup over a range of states") { + int nwrong = 0; + portableReduce( + "Round trip sie -> P -> sie for DavisProducts", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + // sweep both density and energy across the grid + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = E0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + + Real sie_out = 0.0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_out); + nw += !isClose(sie_out, sie, 1e-12); + + // and the recovered energy must reproduce the pressure + nw += + !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + + THEN("A supplied initial guess does not change the answer") { + int nwrong = 0; + portableReduce( + "Initial guess independence for DavisProducts", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); + const Real sie = E0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + // the analytic inverse should ignore the guess entirely + Real sie_lo = 0.1 * E0; + Real sie_hi = 10.0 * E0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_lo); + eos.InternalEnergyFromDensityPressure(rho, P, sie_hi); + nw += !isClose(sie_lo, sie_hi, 1e-12); + nw += !isClose(sie_lo, sie, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + } + eos.Finalize(); + } +} \ No newline at end of file From 68b7605fc812df2cb8c0dee48342a6fb9b18dee2 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 17:52:28 -0700 Subject: [PATCH 08/16] Change the new usup test to stay away from the pole --- test/test_eos_mgusup.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/test_eos_mgusup.cpp b/test/test_eos_mgusup.cpp index bdf347384ee..7c53c3986bd 100644 --- a/test/test_eos_mgusup.cpp +++ b/test/test_eos_mgusup.cpp @@ -555,15 +555,22 @@ SCENARIO("MGUsup EOS SetUp", "PofRE EofRP are inverse operations") { // Create the EOS EOS eos = MGUsup(rho0, T0, Cs, s, G0, Cv0, E0, S0); + // The MGUsup Hugoniot has a (1 - s*eta)^2 in the denominator, so the + // reference curve blows up as rho -> rho0 / (1 - 1/s), which is about + // 2.87 * rho0 here. Keep the sweep well below that, and scale the energies + // to the local reference energy: a fixed absolute sie becomes a vanishing + // fraction of Es(rho) at high compression, and recovering it from P is then + // a difference of two much larger numbers. WHEN("Internal energy is computed from density and pressure") { THEN("It inverts the pressure lookup over a range of states") { int nwrong = 0; portableReduce( - "Round trip sie -> P -> sie for DavisProducts", 0, N, + "Round trip sie -> P -> sie for MGUsup", 0, N, PORTABLE_LAMBDA(const int i, int &nw) { // sweep both density and energy across the grid - const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); - const Real sie = E0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real rho = rho0 * (0.5 + 2.0 * i / (N - 1.0)); + const Real es = eos.InternalEnergyFromDensityTemperature(rho, T0); + const Real sie = es * (0.25 + 1.75 * i / (N - 1.0)); const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); Real sie_out = 0.0; @@ -581,14 +588,15 @@ SCENARIO("MGUsup EOS SetUp", "PofRE EofRP are inverse operations") { THEN("A supplied initial guess does not change the answer") { int nwrong = 0; portableReduce( - "Initial guess independence for DavisProducts", 0, N, + "Initial guess independence for MGUsup", 0, N, PORTABLE_LAMBDA(const int i, int &nw) { - const Real rho = rho0 * (0.5 + 2.5 * i / (N - 1.0)); - const Real sie = E0 * (0.25 + 1.75 * i / (N - 1.0)); + const Real rho = rho0 * (0.5 + 2.0 * i / (N - 1.0)); + const Real es = eos.InternalEnergyFromDensityTemperature(rho, T0); + const Real sie = es * (0.25 + 1.75 * i / (N - 1.0)); const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); // the analytic inverse should ignore the guess entirely - Real sie_lo = 0.1 * E0; - Real sie_hi = 10.0 * E0; + Real sie_lo = 0.1 * es; + Real sie_hi = 10.0 * es; eos.InternalEnergyFromDensityPressure(rho, P, sie_lo); eos.InternalEnergyFromDensityPressure(rho, P, sie_hi); nw += !isClose(sie_lo, sie_hi, 1e-12); From 065babc3f894ed7ccd17dcdaf414becd5f5cf955 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 18:00:03 -0700 Subject: [PATCH 09/16] Add an analytic InternalEnergyFromDensityPressure to powerMG --- singularity-eos/eos/eos_powermg.hpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index 822f35bab7a..5fd69841a61 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -70,6 +70,18 @@ class PowerMG : public EosBase { const Real rho, const Real sie, Indexer_t &&lambda = static_cast(nullptr)) const; template + PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, + Indexer_t &&lambda = static_cast(nullptr)) const; + template + PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( + const Real rho, const Real P, + Indexer_t &&lambda = static_cast(nullptr)) const { + Real sie; + InternalEnergyFromDensityPressure(rho, P, sie, lambda); + return sie; + } + template PORTABLE_INLINE_FUNCTION Real EntropyFromDensityTemperature(const Real rho, const Real temp, Indexer_t &&lambda = static_cast(nullptr)) const; @@ -400,7 +412,6 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::BulkModulusFromDensityInternalEnergy( } return value; } - template PORTABLE_INLINE_FUNCTION Real PowerMG::TemperatureFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { @@ -421,6 +432,13 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::PressureFromDensityInternalEnergy( _rho0 * _G0 * (sie - AllHugInternalEnergyFromDensity(rho)); return value; } +template +PORTABLE_INLINE_FUNCTION void PowerMG::InternalEnergyFromDensityPressure( + const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { + sie = AllHugInternalEnergyFromDensity(rho) + + robust::ratio(P - AllHugPressureFromDensity(rho), _rho0 * _G0); +} + template PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityInternalEnergy( const Real rho, const Real sie, Indexer_t &&lambda) const { From 39c8e1b5e8400adad7d453177716c2069cd7f9bb Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 18:11:08 -0700 Subject: [PATCH 10/16] Add a test for InternalEnergyFromDensityPressure in test_eos_powermg.cpp --- test/test_eos_mgusup.cpp | 2 +- test/test_eos_powermg.cpp | 82 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/test/test_eos_mgusup.cpp b/test/test_eos_mgusup.cpp index 7c53c3986bd..f201abd20ed 100644 --- a/test/test_eos_mgusup.cpp +++ b/test/test_eos_mgusup.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2024. Triad National Security, LLC. All rights reserved. This +// © 2021-2026. 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_powermg.cpp b/test/test_eos_powermg.cpp index 2c0e7e7eace..2e7df54d640 100644 --- a/test/test_eos_powermg.cpp +++ b/test/test_eos_powermg.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// © 2021-2024. Triad National Security, LLC. All rights reserved. This +// © 2021-2026. 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 @@ -680,3 +680,83 @@ SCENARIO("PowerMG EOS SetUp", "[VectorEOS][PowerMGEOS]") { } } } + +SCENARIO("PowerMG EOS rho P", "[VectorEOS][PowerMGEOS]") { + GIVEN("Parameters for a PowerMG EOS") { + constexpr int N = 100; + // Unit conversions + constexpr Real Mbcc_per_g = 1e12; + // PowerMG parameters for tin beta phase + constexpr Real rho0 = 7.285; + constexpr Real T0 = 298.0; + constexpr Real Cs = 2766.0e2; + constexpr Real s = 1.5344; + constexpr Real G0 = 2.4659; + constexpr Real Cv0 = 0.2149e-05 * Mbcc_per_g; + constexpr Real E0 = 0.658e-03 * Mbcc_per_g; + constexpr Real S0 = 0.4419e-05 * Mbcc_per_g; + constexpr Real Pmin = -0.001; + Real K0toK40[41] = {Cs * Cs * rho0}; + for (int ind = 1; ind <= 20; ind++) { + K0toK40[ind] = (ind + 1) * pow(s, ind); + } + EOS host_eos = PowerMG(rho0, T0, G0, Cv0, E0, S0, Pmin, K0toK40); + EOS eos = host_eos.GetOnDevice(); + + // PressureFromDensityInternalEnergy is affine in sie, so + // InternalEnergyFromDensityPressure is analytic rather than a root find. + // Energies are scaled to the local e(rho, T0): a fixed absolute sie becomes + // a vanishing fraction of the reference energy under compression, and + // recovering it from P is then a difference of two much larger numbers. + // The sweep starts at 0.2 * rho0 so the Pmin-clamped branch of + // AllHugPressureFromDensity is exercised too; that clamp is a function of + // density only, so it does not spoil the inversion. + WHEN("Internal energy is computed from density and pressure") { + THEN("It inverts the pressure lookup over a range of states") { + int nwrong = 0; + portableReduce( + "Round trip sie -> P -> sie for PowerMG", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + // sweep both density and energy across the grid + const Real rho = rho0 * (0.2 + 2.3 * i / (N - 1.0)); + const Real es = eos.InternalEnergyFromDensityTemperature(rho, T0); + const Real sie = es * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + + Real sie_out = 0.0; + eos.InternalEnergyFromDensityPressure(rho, P, sie_out); + nw += !isClose(sie_out, sie, 1e-12); + + // and the recovered energy must reproduce the pressure + nw += + !isClose(eos.PressureFromDensityInternalEnergy(rho, sie_out), P, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + + THEN("A supplied initial guess does not change the answer") { + int nwrong = 0; + portableReduce( + "Initial guess independence for PowerMG", 0, N, + PORTABLE_LAMBDA(const int i, int &nw) { + const Real rho = rho0 * (0.2 + 2.3 * i / (N - 1.0)); + const Real es = eos.InternalEnergyFromDensityTemperature(rho, T0); + const Real sie = es * (0.25 + 1.75 * i / (N - 1.0)); + const Real P = eos.PressureFromDensityInternalEnergy(rho, sie); + // the analytic inverse should ignore the guess entirely + Real sie_lo = 0.1 * es; + Real sie_hi = 10.0 * es; + eos.InternalEnergyFromDensityPressure(rho, P, sie_lo); + eos.InternalEnergyFromDensityPressure(rho, P, sie_hi); + nw += !isClose(sie_lo, sie_hi, 1e-12); + nw += !isClose(sie_lo, sie, 1e-12); + }, + nwrong); + REQUIRE(nwrong == 0); + } + } + + eos.Finalize(); + } +} From 6a1e76929c0fba964676536f8161c92f9fe76eee Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Sun, 15 Nov 2026 18:28:55 -0700 Subject: [PATCH 11/16] Format --- singularity-eos/eos/eos_mgusup.hpp | 5 +++-- singularity-eos/eos/eos_powermg.hpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index e0a89c2492c..a929768f95a 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -342,8 +342,9 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityInternalEnergy( return value; } template -PORTABLE_INLINE_FUNCTION void MGUsup::InternalEnergyFromDensityPressure( - const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { +PORTABLE_INLINE_FUNCTION void +MGUsup::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, + Indexer_t &&lambda) const { sie = HugInternalEnergyFromDensity(rho) + robust::ratio(P - HugPressureFromDensity(rho), _rho0 * _G0); } diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index 5fd69841a61..a4e8f2e3fc9 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -433,8 +433,9 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::PressureFromDensityInternalEnergy( return value; } template -PORTABLE_INLINE_FUNCTION void PowerMG::InternalEnergyFromDensityPressure( - const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { +PORTABLE_INLINE_FUNCTION void +PowerMG::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, + Indexer_t &&lambda) const { sie = AllHugInternalEnergyFromDensity(rho) + robust::ratio(P - AllHugPressureFromDensity(rho), _rho0 * _G0); } From 2080d617f9c937ce177ed7c3274aaee3f1afdfe8 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Mon, 16 Nov 2026 06:14:01 -0700 Subject: [PATCH 12/16] Update the changelog --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e1c07ce1a4..e934c0e823d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,9 @@ ## Current develop ### Added (new features/APIs/variables/...) -- [[PR658]](https://github.com/lanl/singularity-eos/pull/658) Add `MinimumInternalEnergy`/`MaximumInternalEnergy` to the EOS introspection API, so energy bounds are reachable through modifiers and the `singularity::EOS` variant +- [[PR668]](https://github.com/lanl/singularity-eos/pull/668) Add analytic `InternalEnergyFromDensityPressure` methods to Davis Reactants, Davis Products, MGUsup, and powerMG overriding the iterative solve previously used. - [[PR659]](https://github.com/lanl/singularity-eos/pull/659) Add `sesame2spiner::saveAllMaterials` overloads taking a list of matids instead of a list of input files, with optional per-material `Params` overrides, so host codes can generate an sp5 file without writing input decks to disk. Also added an overload taking an already-open `hid_t`, plus `writeSP5RootAttributes`, so a single sp5 file can be built up one material at a time. -- [[PR659]](https://github.com/lanl/singularity-eos/pull/659) Added `sesame2spiner::saveAllMaterials` overloads taking a list of matids instead of a list of input files, with optional per-material `Params` overrides, so host codes can generate an sp5 file without writing input decks to disk. Also added an overload taking an already-open `hid_t`, plus `writeSP5RootAttributes`, so a single sp5 file can be built up one material at a time. -- [[PRXXX]]() Added analytic `InternalEnergyFromDensityPressure` methods to Davis Reactants and Products, overriding the iterative solve previously used. +- [[PR658]](https://github.com/lanl/singularity-eos/pull/658) Add `MinimumInternalEnergy`/`MaximumInternalEnergy` to the EOS introspection API, so energy bounds are reachable through modifiers and the `singularity::EOS` variant ### Fixed (Repair bugs, etc) - [[PR667]](https://github.com/lanl/singularity-eos/pull/667) Various fixes to shift/unit/scale EOS modifiers. From 4ed622b92863efc384015bd024ebdb2b9bc340a9 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Mon, 16 Nov 2026 12:58:00 -0700 Subject: [PATCH 13/16] Extract local vars for potential future debugging --- singularity-eos/eos/eos_davis.hpp | 6 +++++- singularity-eos/eos/eos_mgusup.hpp | 3 ++- singularity-eos/eos/eos_powermg.hpp | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index 697a8485b39..36c52bc2f7e 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -86,7 +86,11 @@ class DavisReactants : public EosBase { PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure( const Real rho, const Real P, Real &sie, Indexer_t &&lambda = static_cast(nullptr)) const { - sie = Es(rho) + robust::ratio(P - Ps(rho), Gamma(rho) * rho); + + const Real Es_ = Es(rho); + const Real Ps_ = Ps(rho); + const Real Gamma_ = Gamma(rho); + sie = Es_ + robust::ratio(P - Ps_, Gamma_* rho); } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index a929768f95a..62f68979321 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -345,8 +345,9 @@ template PORTABLE_INLINE_FUNCTION void MGUsup::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { + const Real Ph_ = HugPressureFromDensity(rho); sie = HugInternalEnergyFromDensity(rho) + - robust::ratio(P - HugPressureFromDensity(rho), _rho0 * _G0); + robust::ratio(P - Ph_, _rho0 * _G0); } template PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy( diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index a4e8f2e3fc9..efbca410f48 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -436,8 +436,9 @@ template PORTABLE_INLINE_FUNCTION void PowerMG::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { + const Real Ph_ = AllHugPressureFromDensity(rho); sie = AllHugInternalEnergyFromDensity(rho) + - robust::ratio(P - AllHugPressureFromDensity(rho), _rho0 * _G0); + robust::ratio(P - Ph_, _rho0 * _G0); } template From e9e8d95c91c94e378458515536d27779fdd61873 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Mon, 16 Nov 2026 12:59:57 -0700 Subject: [PATCH 14/16] Format --- singularity-eos/eos/eos_davis.hpp | 2 +- singularity-eos/eos/eos_mgusup.hpp | 3 +-- singularity-eos/eos/eos_powermg.hpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/singularity-eos/eos/eos_davis.hpp b/singularity-eos/eos/eos_davis.hpp index 36c52bc2f7e..56cb3742b02 100644 --- a/singularity-eos/eos/eos_davis.hpp +++ b/singularity-eos/eos/eos_davis.hpp @@ -90,7 +90,7 @@ class DavisReactants : public EosBase { const Real Es_ = Es(rho); const Real Ps_ = Ps(rho); const Real Gamma_ = Gamma(rho); - sie = Es_ + robust::ratio(P - Ps_, Gamma_* rho); + sie = Es_ + robust::ratio(P - Ps_, Gamma_ * rho); } template PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure( diff --git a/singularity-eos/eos/eos_mgusup.hpp b/singularity-eos/eos/eos_mgusup.hpp index 62f68979321..78b35623376 100644 --- a/singularity-eos/eos/eos_mgusup.hpp +++ b/singularity-eos/eos/eos_mgusup.hpp @@ -346,8 +346,7 @@ PORTABLE_INLINE_FUNCTION void MGUsup::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { const Real Ph_ = HugPressureFromDensity(rho); - sie = HugInternalEnergyFromDensity(rho) + - robust::ratio(P - Ph_, _rho0 * _G0); + sie = HugInternalEnergyFromDensity(rho) + robust::ratio(P - Ph_, _rho0 * _G0); } template PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy( diff --git a/singularity-eos/eos/eos_powermg.hpp b/singularity-eos/eos/eos_powermg.hpp index efbca410f48..c7110e70acc 100644 --- a/singularity-eos/eos/eos_powermg.hpp +++ b/singularity-eos/eos/eos_powermg.hpp @@ -437,8 +437,7 @@ PORTABLE_INLINE_FUNCTION void PowerMG::InternalEnergyFromDensityPressure(const Real rho, const Real P, Real &sie, Indexer_t &&lambda) const { const Real Ph_ = AllHugPressureFromDensity(rho); - sie = AllHugInternalEnergyFromDensity(rho) + - robust::ratio(P - Ph_, _rho0 * _G0); + sie = AllHugInternalEnergyFromDensity(rho) + robust::ratio(P - Ph_, _rho0 * _G0); } template From 771dd51bf83a2780e81e6335a569eebf911e50d0 Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Mon, 16 Nov 2026 13:42:29 -0700 Subject: [PATCH 15/16] Replace blanket macro with explicit imports so local MinInternalEnergyFromDensity isn't overwritten --- test/test_eos_modifiers_minimal.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_eos_modifiers_minimal.cpp b/test/test_eos_modifiers_minimal.cpp index f7f4563bc89..f5b40154202 100644 --- a/test/test_eos_modifiers_minimal.cpp +++ b/test/test_eos_modifiers_minimal.cpp @@ -57,7 +57,21 @@ namespace { template class ModifierTestEOS : public singularity::EosBase> { public: - SG_ADD_BASE_CLASS_USINGS(ModifierTestEOS) + using Base = EosBase>; + + using Base::InternalEnergyFromDensityTemperature; + using Base::TemperatureFromDensityInternalEnergy; + using Base::PressureFromDensityTemperature; + using Base::PressureFromDensityInternalEnergy; + using Base::SpecificHeatFromDensityTemperature; + using Base::SpecificHeatFromDensityInternalEnergy; + using Base::EntropyFromDensityTemperature; + using Base::EntropyFromDensityInternalEnergy; + using Base::BulkModulusFromDensityTemperature; + using Base::BulkModulusFromDensityInternalEnergy; + using Base::GruneisenParamFromDensityTemperature; + using Base::GruneisenParamFromDensityInternalEnergy; +// Intentionally no: using Base::MinInternalEnergyFromDensity; PORTABLE_FUNCTION void CheckParams() const {} static constexpr unsigned long PreferredInput() { return thermalqs::density | (EnergyPreferred ? thermalqs::specific_internal_energy From 4d95f1384378f96701e44537a9421fdb9d4339cd Mon Sep 17 00:00:00 2001 From: Miles Buechler Date: Mon, 16 Nov 2026 13:44:48 -0700 Subject: [PATCH 16/16] Format --- test/test_eos_modifiers_minimal.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/test_eos_modifiers_minimal.cpp b/test/test_eos_modifiers_minimal.cpp index f5b40154202..76690a3527b 100644 --- a/test/test_eos_modifiers_minimal.cpp +++ b/test/test_eos_modifiers_minimal.cpp @@ -57,21 +57,21 @@ namespace { template class ModifierTestEOS : public singularity::EosBase> { public: - using Base = EosBase>; + using Base = EosBase>; - using Base::InternalEnergyFromDensityTemperature; - using Base::TemperatureFromDensityInternalEnergy; - using Base::PressureFromDensityTemperature; - using Base::PressureFromDensityInternalEnergy; - using Base::SpecificHeatFromDensityTemperature; - using Base::SpecificHeatFromDensityInternalEnergy; - using Base::EntropyFromDensityTemperature; - using Base::EntropyFromDensityInternalEnergy; - using Base::BulkModulusFromDensityTemperature; - using Base::BulkModulusFromDensityInternalEnergy; - using Base::GruneisenParamFromDensityTemperature; - using Base::GruneisenParamFromDensityInternalEnergy; -// Intentionally no: using Base::MinInternalEnergyFromDensity; + using Base::BulkModulusFromDensityInternalEnergy; + using Base::BulkModulusFromDensityTemperature; + using Base::EntropyFromDensityInternalEnergy; + using Base::EntropyFromDensityTemperature; + using Base::GruneisenParamFromDensityInternalEnergy; + using Base::GruneisenParamFromDensityTemperature; + using Base::InternalEnergyFromDensityTemperature; + using Base::PressureFromDensityInternalEnergy; + using Base::PressureFromDensityTemperature; + using Base::SpecificHeatFromDensityInternalEnergy; + using Base::SpecificHeatFromDensityTemperature; + using Base::TemperatureFromDensityInternalEnergy; + // Intentionally not: using Base::MinInternalEnergyFromDensity; PORTABLE_FUNCTION void CheckParams() const {} static constexpr unsigned long PreferredInput() { return thermalqs::density | (EnergyPreferred ? thermalqs::specific_internal_energy