Skip to content

Commit

Permalink
Merge branch 'main' into jmm/document-versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurlungur authored Nov 30, 2023
2 parents 576695c + 6fe168d commit 4ead7a5
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 42 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,8 @@ if(SINGULARITY_BUILD_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
# MAUNEYC: On my side, this version works. The ones pinned onto upstream
# codes do not like to play with clang and/or newer compilers.
GIT_TAG v2.13.7)
# or later is fine too
GIT_TAG v3.0.1)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib)
endif()
Expand Down
18 changes: 18 additions & 0 deletions singularity-eos/base/robust_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifndef SINGULARITY_EOS_BASE_ROBUST_UTILS_HPP_
#define SINGULARITY_EOS_BASE_ROBUST_UTILS_HPP_

#include <cmath>
#include <limits>
#include <ports-of-call/portability.hpp>

Expand All @@ -31,6 +32,16 @@ PORTABLE_FORCEINLINE_FUNCTION constexpr auto EPS() {
return 10 * std::numeric_limits<T>::epsilon();
}

template <typename T = Real>
PORTABLE_FORCEINLINE_FUNCTION constexpr T min_exp_arg() {
return (std::numeric_limits<T>::min_exponent - 1) * M_LN2;
}

template <typename T = Real>
PORTABLE_FORCEINLINE_FUNCTION constexpr T max_exp_arg() {
return std::numeric_limits<T>::max_exponent * M_LN2;
}

template <typename T>
PORTABLE_FORCEINLINE_FUNCTION auto make_positive(const T val) {
return std::max(val, EPS<T>());
Expand All @@ -51,6 +62,13 @@ PORTABLE_FORCEINLINE_FUNCTION auto ratio(const A &a, const B &b) {
return a / (b + sgn(b) * SMALL<B>());
}

template <typename T>
PORTABLE_FORCEINLINE_FUNCTION T safe_arg_exp(const T &x) {
return x < min_exp_arg<T>() ? 0.0
: x > max_exp_arg<T>() ? std::numeric_limits<T>::infinity()
: std::exp(x);
}

} // namespace robust
} // namespace singularity

Expand Down
34 changes: 21 additions & 13 deletions singularity-eos/eos/eos_jwl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define _SINGULARITY_EOS_EOS_EOS_JWL_HPP_

// stdlib
#include <cassert>
#include <cmath>
#include <cstdio>
#include <string>
Expand All @@ -40,7 +41,14 @@ class JWL : public EosBase<JWL> {
JWL() = default;
PORTABLE_INLINE_FUNCTION JWL(const Real A, const Real B, const Real R1, const Real R2,
const Real w, const Real rho0, const Real Cv)
: _A(A), _B(B), _R1(R1), _R2(R2), _w(w), _rho0(rho0), _Cv(Cv) {}
: _A(A), _B(B), _R1(R1), _R2(R2), _w(w), _rho0(rho0), _Cv(Cv),
_c1(robust::ratio(A, rho0 * R1)), _c2(robust::ratio(B, rho0 * R2)) {
assert(R1 > 0.0);
assert(R2 > 0.0);
assert(w > 0.0);
assert(rho0 > 0.0);
assert(Cv > 0.0);
}
JWL GetOnDevice() { return *this; }
PORTABLE_INLINE_FUNCTION Real TemperatureFromDensityInternalEnergy(
const Real rho, const Real sie, Real *lambda = nullptr) const;
Expand Down Expand Up @@ -98,22 +106,21 @@ class JWL : public EosBase<JWL> {
static std::string EosPyType() { return EosType(); }

private:
Real _A, _B, _R1, _R2, _w, _rho0, _Cv;
Real _A, _B, _R1, _R2, _w, _rho0, _Cv, _c1, _c2;
PORTABLE_INLINE_FUNCTION Real ReferenceEnergy(const Real rho) const;
PORTABLE_INLINE_FUNCTION Real ReferencePressure(const Real rho) const;
// static constexpr const char _eos_type[] = "JWL";
static constexpr const unsigned long _preferred_input =
thermalqs::density | thermalqs::specific_internal_energy;
};

PORTABLE_INLINE_FUNCTION Real JWL::ReferencePressure(const Real rho) const {
const Real x = _rho0 / rho;
return _A * std::exp(-_R1 * x) + _B * std::exp(-_R2 * x);
PORTABLE_FORCEINLINE_FUNCTION Real JWL::ReferencePressure(const Real rho) const {
const Real x = robust::ratio(_rho0, rho);
return _A * robust::safe_arg_exp(-_R1 * x) + _B * robust::safe_arg_exp(-_R2 * x);
}
PORTABLE_INLINE_FUNCTION Real JWL::ReferenceEnergy(const Real rho) const {
const Real x = _rho0 / rho;
return _A / (_rho0 * _R1) * std::exp(-_R1 * x) +
_B / (_rho0 * _R2) * std::exp(-_R2 * x);
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);
}
PORTABLE_INLINE_FUNCTION Real JWL::InternalEnergyFromDensityTemperature(
const Real rho, const Real temp, Real *lambda) const {
Expand All @@ -137,19 +144,20 @@ PORTABLE_INLINE_FUNCTION Real JWL::EntropyFromDensityInternalEnergy(const Real r
}
PORTABLE_INLINE_FUNCTION Real JWL::TemperatureFromDensityInternalEnergy(
const Real rho, const Real sie, Real *lambda) const {
return (sie - ReferenceEnergy(rho)) / _Cv;
return robust::ratio((sie - ReferenceEnergy(rho)), _Cv);
}
PORTABLE_INLINE_FUNCTION Real JWL::SpecificHeatFromDensityInternalEnergy(
const Real rho, const Real sie, Real *lambda) const {
return _Cv;
}
PORTABLE_INLINE_FUNCTION Real JWL::BulkModulusFromDensityInternalEnergy(
const Real rho, const Real sie, Real *lambda) const {
const Real x = _rho0 / rho;
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));
return (_w + 1) * _w * rho * (sie - ReferenceEnergy(rho)) +
x * (_A * _R1 * std::exp(-_R1 * x) + _B * _R2 * std::exp(-_R2 * x));
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,
Expand Down Expand Up @@ -232,7 +240,7 @@ void JWL::ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press,
dpde = _w * _rho0;
// TODO: chad please fix this one for me. This is wrong.
Real gm1 = GruneisenParamFromDensityInternalEnergy(rho, sie, lambda) * rho;
dvdt = gm1 * cv / bmod;
dvdt = robust::ratio(gm1 * cv, bmod);
}

} // namespace singularity
Expand Down
3 changes: 2 additions & 1 deletion spack-repo/packages/singularity-eos/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class SingularityEos(CMakePackage, CudaPackage):

# building/testing/docs
depends_on("[email protected]:")
depends_on("[email protected]", when="+tests")
depends_on("[email protected]:", when="@main +tests")
depends_on("[email protected]", when="@:1.8.0 +tests")
depends_on("python@3:", when="+python")
depends_on("py-numpy", when="+python+tests")
depends_on("[email protected]:", when="+python")
Expand Down
5 changes: 4 additions & 1 deletion spack-repo/packages/spiner/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ class Spiner(CMakePackage, CudaPackage):

variant("python", default=False, description="Python, Numpy & Matplotlib Support")

variant("test", default=False, description="Build tests")

depends_on("[email protected]:", when="@:1.5.1")
depends_on("[email protected]:", when="@1.6.0:")
depends_on("[email protected]:2.13.9")
depends_on("[email protected]:", when="@main +test")
depends_on("[email protected]:2.13.9", when="@:1.6.2 +test")
depends_on("[email protected]:", when="@:1.5.1")
depends_on("[email protected]:", when="@1.6.0:")
depends_on("ports-of-call@main", when="@main")
Expand Down
7 changes: 1 addition & 6 deletions test/catch2_define.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
// publicly and display publicly, and to permit others to do so.
//------------------------------------------------------------------------------

#include <catch2/catch_session.hpp>
#include <ports-of-call/portability.hpp>

#ifndef CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_RUNNER
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#endif

int main(int argc, char *argv[]) {

#ifdef PORTABILITY_STRATEGY_KOKKOS
Expand Down
2 changes: 1 addition & 1 deletion test/eos_unit_test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif
#include <cmath>
#include <cstdio>
Expand Down
6 changes: 2 additions & 4 deletions test/test_eos_gruneisen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <limits>
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <singularity-eos/base/constants.hpp>
Expand Down Expand Up @@ -56,9 +56,7 @@ SCENARIO("Gruneisen EOS entropy is disabled", "[GruneisenEOS][Entropy]") {
EOS host_eos = Gruneisen(C0, S1, S2, S3, Gamma0, b, rho0, T0, P0, Cv);
EOS eos = host_eos.GetOnDevice();
THEN("A call to the entropy should throw an exception") {
using Catch::Matchers::Contains;
auto msg_matcher = Contains("Entropy is not enabled");
REQUIRE_THROWS_WITH(eos.EntropyFromDensityTemperature(1.0, 1.0), msg_matcher);
REQUIRE_THROWS(eos.EntropyFromDensityTemperature(1.0, 1.0));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/test_eos_helmholtz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <ports-of-call/portability.hpp>
Expand All @@ -34,7 +34,6 @@
#include <singularity-eos/eos/eos.hpp>
#include <test/eos_unit_test_helpers.hpp>

using Catch::Matchers::WithinRel;
using singularity::Helmholtz;
const std::string filename = "../data/helmholtz/helm_table.dat";
SCENARIO("Helmholtz equation of state - Table interpolation (tgiven)", "[HelmholtzEOS]") {
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_ideal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_modifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_noble_abel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <limits>
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <singularity-eos/base/constants.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_sap_polynomial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <limits>
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <singularity-eos/base/constants.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_stellar_collapse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_stiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <cstdlib>
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <singularity-eos/base/constants.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_tabulated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_eos_vinet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <cstdlib>
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <ports-of-call/portability.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_math_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

#include <test/eos_unit_test_helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion test/test_variadic_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include "catch2/catch.hpp"
#include <catch2/catch_test_macros.hpp>
#endif

using singularity::Gruneisen;
Expand Down

0 comments on commit 4ead7a5

Please sign in to comment.