Skip to content

Commit 8cc311a

Browse files
authored
Merge branch 'main' into bgclayton_simple_macaw
2 parents 49ffdf2 + 019405e commit 8cc311a

File tree

5 files changed

+103
-52
lines changed

5 files changed

+103
-52
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
## Current develop
44

55
### Added (new features/APIs/variables/...)
6-
- [[PR556](https://github.com/lanl/singularity-eos/pull/556) Add introspection into types available in the variant
6+
- [[PR556]](https://github.com/lanl/singularity-eos/pull/556) Add introspection into types available in the variant
77

88
### Fixed (Repair bugs, etc)
9+
- [[PR561]](https://github.com/lanl/singularity-eos/pull/561) Fix logic for kokkos-kernels in spackage so that it is only required for closure models on GPU
10+
- [[PR563]](https://github.com/lanl/singularity-eos/pull/563) Fixed DensityFromPressureTemperature for the Carnahan-Starling EOS.
911

1012
### Changed (changing behavior/API/variables/...)
1113

1214
### Infrastructure (changes irrelevant to downstream codes)
13-
- [[559]](https://github.com/lanl/singularity-eos/pull/559) Document the intent of the virtual keyword in solvers
14-
- [[558]](https://github.com/lanl/singularity-eos/pull/558) Make EOSPAC CMake options depend on SINGULARITY_USE_EOSPAC option
15+
- [[PR559]](https://github.com/lanl/singularity-eos/pull/559) Document the intent of the virtual keyword in solvers
16+
- [[PR558]](https://github.com/lanl/singularity-eos/pull/558) Make EOSPAC CMake options depend on SINGULARITY_USE_EOSPAC option
1517

1618
### Removed (removing behavior/API/varaibles/...)
1719

@@ -61,7 +63,7 @@ Date: 4/7/2025
6163
- [[PR444]](https://github.com/lanl/singularity-eos/pull/444) Add Z split modifier and electron ideal gas EOS
6264

6365
### Fixed (Repair bugs, etc)
64-
- [PR492](https://github.com/lanl/singularity-eos/pull/492) Fix import issue in spack's package.py.
66+
- [[PR492]](https://github.com/lanl/singularity-eos/pull/492) Fix import issue in spack's package.py.
6567
- [[PR485]](https://github.com/lanl/singularity-eos/pull/485) Fix segfault in Fortran interface related to EOSPAC initialization
6668
- [[PR478]](https://github.com/lanl/singularity-eos/pull/478) Fix bug in KPT test. Add more extensive clang build to github CI matrix.
6769
- [[PR473]](https://github.com/lanl/singularity-eos/pull/473) Resolve memory issue. Thanks for the catch, Richard!

singularity-eos/eos/eos_carnahan_starling.hpp

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class CarnahanStarling : public EosBase<CarnahanStarling> {
7171
return std::max(robust::SMALL(), (sie - _qq) / _Cv);
7272
}
7373
PORTABLE_INLINE_FUNCTION void CheckParams() const {
74-
PORTABLE_ALWAYS_REQUIRE(_Cv >= 0, "Heat capacity must be positive");
75-
PORTABLE_ALWAYS_REQUIRE(_gm1 >= 0, "Gruneisen parameter must be positive");
76-
PORTABLE_ALWAYS_REQUIRE(_bb >= 0, "Covolume must be positive");
74+
PORTABLE_ALWAYS_REQUIRE(_Cv > 0, "Heat capacity must be strictly positive");
75+
PORTABLE_ALWAYS_REQUIRE(_gm1 > 0, "Gruneisen parameter must be positive");
76+
PORTABLE_ALWAYS_REQUIRE(_bb >= 0, "Covolume must be strictly non-negative");
7777
_AZbar.CheckParams();
7878
}
7979
template <typename Indexer_t = Real *>
@@ -94,24 +94,51 @@ class CarnahanStarling : public EosBase<CarnahanStarling> {
9494
PORTABLE_INLINE_FUNCTION Real DensityFromPressureTemperature(
9595
const Real press, const Real temperature, const Real guess = robust::SMALL(),
9696
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const {
97-
Real real_root;
98-
auto poly = [=](Real dens) {
99-
return _Cv * temperature * _gm1 * dens * ZedFromDensity(dens);
97+
static constexpr Real rho_low = 0.;
98+
// Need to identify an appropriate density scaling for the tolerances.
99+
// Note: cannot use `_rho0` since `_rho0` is computed from this function itself.
100+
const Real xtol = 1.0e-9;
101+
const Real ytol = 1.0e-9;
102+
103+
// At absolute zero, P = 0, so assumed vacuum state (no cold curve exists).
104+
if (temperature <= std::numeric_limits<Real>::min()) {
105+
return rho_low;
106+
}
107+
108+
// Use ideal gas value when _bb is zero
109+
if (_bb <= std::numeric_limits<Real>::min()) {
110+
return robust::ratio(press, _Cv * _gm1 * temperature);
111+
}
112+
const Real rho_high = 1.0 / _bb;
113+
114+
// Setup lambda function for finding rho.
115+
// The equation has been rewritten to avoid division by zero (polynomial equation).
116+
auto f = [=](const Real x /* density */) {
117+
const Real eta = _bb * x;
118+
const Real term1 = x * (1. + eta + eta * eta - eta * eta * eta);
119+
const Real term2 =
120+
robust::ratio(press * math_utils::pow<3>(1. - eta), _Cv * _gm1 * temperature);
121+
return term1 - term2;
100122
};
101-
using RootFinding1D::findRoot;
102-
using RootFinding1D::Status;
103-
static constexpr Real xtol = 1.0e-12;
104-
static constexpr Real ytol = 1.0e-12;
105-
static constexpr Real lo_bound = robust::SMALL();
106-
const Real hi_bound = robust::ratio(1.0, _bb);
107-
auto status = findRoot(poly, press, guess, lo_bound, hi_bound, xtol, ytol, real_root);
108-
if (status != Status::SUCCESS) {
123+
124+
const RootFinding1D::RootCounts root_info;
125+
Real rho; // `rho` will be the root of the equation $f=0$.
126+
127+
/* The regula falsi method should always return a unique real root in the interval (0,
128+
* b^{-1}) since f(0) < 0 and f(b^{-1}) > 0. It can be shown that the derivative of f
129+
* (as a function of \eta) is always positive since \eta \in (0,1) hence the root is
130+
* unique. */
131+
auto status =
132+
regula_falsi(f, 0.0 /*target*/, guess, rho_low /*left bracket*/,
133+
rho_high /*right bracket*/, xtol, ytol, rho, &root_info, true);
134+
135+
if (status != RootFinding1D::Status::SUCCESS) {
109136
// Root finder failed even though the solution was bracketed... this is an error
110137
EOS_ERROR("*** (Warning) DensityFromPressureTemperature :: Convergence not met in "
111-
"Carnahan-Starling EoS (root finder util) ***\n");
112-
real_root = -1.0;
138+
"Carnahan-Starling EoS (root finder `regula_falsi`) ***\n");
139+
rho = -1.0; // guarantees zero density is returned on convergence failure.
113140
}
114-
return std::max(robust::SMALL(), real_root);
141+
return std::max(rho_low, rho);
115142
}
116143
template <typename Indexer_t = Real *>
117144
PORTABLE_INLINE_FUNCTION Real InternalEnergyFromDensityTemperature(

spack-repo/v1/packages/singularity-eos/package.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SingularityEos(CMakePackage, CudaPackage, ROCmPackage):
5757
# build with kokkos, kokkos-kernels for offloading support
5858
variant("kokkos", default=False, description="Enable kokkos")
5959
variant(
60-
"kokkos-kernels", default=False, description="Enable kokkos-kernals for linear algebra"
60+
"kokkos-kernels", default=False, description="Enable kokkos-kernels for linear algebra"
6161
)
6262

6363
# for compatibility with downstream projects
@@ -120,10 +120,13 @@ class SingularityEos(CMakePackage, CudaPackage, ROCmPackage):
120120
depends_on("catch2@3.0.1:", when="@1.9.0: +tests")
121121
depends_on("py-numpy", when="+python+tests")
122122

123-
# linear algebra when not using GPUs
124-
depends_on("eigen@3.3.8:", when="~kokkos-kernels")
125-
requires("+kokkos-kernels", when="+cuda")
126-
requires("+kokkos-kernels", when="+rocm")
123+
# Require kokkos for device/offloading support
124+
requires("+kokkos", when="+cuda")
125+
requires("+kokkos", when="+rocm")
126+
127+
# linear algebra when using closure models. Eigen without kokkos
128+
depends_on("eigen@3.3.8:", when="~kokkos-kernels+closure")
129+
requires("+kokkos-kernels", when="+kokkos+closure")
127130

128131
depends_on("eospac", when="+eospac")
129132

spack-repo/v2/spack_repo/singularity_eos/packages/singularity_eos/package.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SingularityEos(CMakePackage, CudaPackage, ROCmPackage):
6060
# build with kokkos, kokkos-kernels for offloading support
6161
variant("kokkos", default=False, description="Enable kokkos")
6262
variant(
63-
"kokkos-kernels", default=False, description="Enable kokkos-kernals for linear algebra"
63+
"kokkos-kernels", default=False, description="Enable kokkos-kernels for linear algebra"
6464
)
6565

6666
# for compatibility with downstream projects
@@ -123,10 +123,13 @@ class SingularityEos(CMakePackage, CudaPackage, ROCmPackage):
123123
depends_on("catch2@3.0.1:", when="@1.9.0: +tests")
124124
depends_on("py-numpy", when="+python+tests")
125125

126-
# linear algebra when not using GPUs
127-
depends_on("eigen@3.3.8:", when="~kokkos-kernels")
128-
requires("+kokkos-kernels", when="+cuda")
129-
requires("+kokkos-kernels", when="+rocm")
126+
# Require kokkos for device/offloading support
127+
requires("+kokkos", when="+cuda")
128+
requires("+kokkos", when="+rocm")
129+
130+
# linear algebra when using closure models. Eigen without kokkos
131+
depends_on("eigen@3.3.8:", when="~kokkos-kernels+closure")
132+
requires("+kokkos-kernels", when="+kokkos+closure")
130133

131134
depends_on("eospac", when="+eospac")
132135

0 commit comments

Comments
 (0)