Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +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.
- [[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.
Expand Down
32 changes: 32 additions & 0 deletions singularity-eos/eos/eos_davis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ class DavisReactants : public EosBase<DavisReactants> {
_Cv0 * t_s * _i1pa * (std::pow(robust::ratio(temp, t_s), 1.0 + _alpha) - 1.0);
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure(
const Real rho, const Real P, Real &sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {

const Real Es_ = Es(rho);
const Real Ps_ = Ps(rho);
const Real Gamma_ = Gamma(rho);
sie = Es_ + robust::ratio(P - Ps_, Gamma_ * rho);
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure(
const Real rho, const Real P,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Real sie;
InternalEnergyFromDensityPressure(rho, P, sie, lambda);
return sie;
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature(
const Real rho, const Real temp,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Expand Down Expand Up @@ -239,6 +257,20 @@ class DavisProducts : public EosBase<DavisProducts> {
return _Cv * (temp - Ts(rho)) + Es(rho);
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure(
const Real rho, const Real P, Real &sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
sie = Es(rho) + robust::ratio(P - Ps(rho), rho * Gamma(rho));
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure(
const Real rho, const Real P,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Real sie;
InternalEnergyFromDensityPressure(rho, P, sie, lambda);
return sie;
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real PressureFromDensityTemperature(
const Real rho, const Real temp,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Expand Down
19 changes: 19 additions & 0 deletions singularity-eos/eos/eos_mgusup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ class MGUsup : public EosBase<MGUsup> {
const Real rho, const Real sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure(
const Real rho, const Real P, Real &sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure(
const Real rho, const Real P,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Real sie;
InternalEnergyFromDensityPressure(rho, P, sie, lambda);
return sie;
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real
EntropyFromDensityTemperature(const Real rho, const Real temp,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
Expand Down Expand Up @@ -330,6 +342,13 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::PressureFromDensityInternalEnergy(
return value;
}
template <typename Indexer_t>
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);
}
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION Real MGUsup::EntropyFromDensityInternalEnergy(
const Real rho, const Real sie, Indexer_t &&lambda) const {
Real eta = 1.0 - robust::ratio(_rho0, rho);
Expand Down
21 changes: 20 additions & 1 deletion singularity-eos/eos/eos_powermg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ class PowerMG : public EosBase<PowerMG> {
const Real rho, const Real sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void InternalEnergyFromDensityPressure(
const Real rho, const Real P, Real &sie,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityPressure(
const Real rho, const Real P,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
Real sie;
InternalEnergyFromDensityPressure(rho, P, sie, lambda);
return sie;
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION Real
EntropyFromDensityTemperature(const Real rho, const Real temp,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;
Expand Down Expand Up @@ -400,7 +412,6 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::BulkModulusFromDensityInternalEnergy(
}
return value;
}

template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION Real PowerMG::TemperatureFromDensityInternalEnergy(
const Real rho, const Real sie, Indexer_t &&lambda) const {
Expand All @@ -421,6 +432,14 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::PressureFromDensityInternalEnergy(
_rho0 * _G0 * (sie - AllHugInternalEnergyFromDensity(rho));
return value;
}
template <typename Indexer_t>
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);
}

template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityInternalEnergy(
const Real rho, const Real sie, Indexer_t &&lambda) const {
Expand Down
88 changes: 88 additions & 0 deletions test/test_eos_davis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,50 @@ 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);

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 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();
}
Expand Down Expand Up @@ -194,6 +238,50 @@ 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);

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_host.Finalize();
eos.Finalize();
}
Expand Down
75 changes: 74 additions & 1 deletion test/test_eos_mgusup.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -536,3 +536,76 @@ 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);

// 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 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.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;
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 MGUsup", 0, N,
PORTABLE_LAMBDA(const int i, int &nw) {
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 * 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();
}
}
16 changes: 15 additions & 1 deletion test/test_eos_modifiers_minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,21 @@ namespace {
template <bool EnergyPreferred = false>
class ModifierTestEOS : public singularity::EosBase<ModifierTestEOS<EnergyPreferred>> {
public:
SG_ADD_BASE_CLASS_USINGS(ModifierTestEOS<EnergyPreferred>)
using Base = EosBase<ModifierTestEOS<EnergyPreferred>>;

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
Expand Down
Loading
Loading