Skip to content
Open
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
f93634e
Use EosType() member function for name
jhp-lanl Mar 14, 2025
9f5ad0b
Add multi EOS modifier
jhp-lanl Mar 14, 2025
316674e
Move scratch_size and max_scratch_size into base class
jhp-lanl Apr 4, 2025
e04b7dd
Merge branch 'jhp/move_scratch_to_base' of github.com:lanl/singularit…
jhp-lanl Apr 4, 2025
cd32d8f
Add model name and scratch size member functions
jhp-lanl Apr 4, 2025
c7a65b1
Add templated mass fraction indexable type
jhp-lanl Apr 4, 2025
cf7f849
Add tuple utils file
jhp-lanl Apr 4, 2025
53b029b
Build multi-eos and tuple_utils
jhp-lanl Apr 4, 2025
2a0b737
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Apr 8, 2025
be52b2e
Merge branch 'jhp/closure_info' of github.com:lanl/singularity-eos in…
jhp-lanl Apr 8, 2025
5b4803f
Does not compile, but more progress on the multi-eos modifier
jhp-lanl Apr 8, 2025
c2bc3ed
Move nlambda default behavior into base class
jhp-lanl Apr 9, 2025
f700df3
Remove extraneous remnants of nlamda
jhp-lanl Apr 9, 2025
34d62fc
Merge branch 'jhp/nlambda' of github.com:lanl/singularity-eos into jh…
jhp-lanl Apr 9, 2025
7f9452a
Merge branch 'jhp/nlambda' of github.com:lanl/singularity-eos into jh…
jhp-lanl Apr 9, 2025
ba98a17
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Apr 10, 2025
dae1bda
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Jul 22, 2025
1e210a8
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Jul 23, 2025
272f80a
Add back in reference
jhp-lanl Jul 23, 2025
8c37791
Add _many_ updates and address todos
jhp-lanl Aug 20, 2025
fbd57b4
Add test for multi_eos if closures are enabled
jhp-lanl Aug 20, 2025
ff2fba4
Merge branch 'main' into jhp/two_eos
Yurlungur Aug 21, 2025
6497e28
Merge branch 'jhp/two_eos' of github.com:lanl/singularity-eos into jh…
jhp-lanl Aug 22, 2025
85896b2
Won't compile: add a lot more machinery for averaging quantities
jhp-lanl Aug 22, 2025
a72921b
Add generic indexer class to its own file
jhp-lanl Aug 28, 2025
70333ec
Add macros for easier SFINAE of concepts
jhp-lanl Aug 28, 2025
be5b1b0
Add universal references to functions
jhp-lanl Aug 28, 2025
3360196
DOES NOT COMPILE -- Address github comments and make more progress
jhp-lanl Aug 28, 2025
7fa785d
Move Kahan summation to shared math utils
jhp-lanl Aug 29, 2025
c875f87
Add include guard
jhp-lanl Aug 29, 2025
a83e3e2
Finish filling out the MultiEOS capability
jhp-lanl Aug 29, 2025
f5994a0
Rename to be more in-line with other test names
jhp-lanl Aug 29, 2025
789af12
Move MultiEOS out of modifiers since it really isn't a modifier
jhp-lanl Aug 29, 2025
db0948f
Add include guard
jhp-lanl Aug 29, 2025
079e069
Reflect moved multi_eos.hpp
jhp-lanl Aug 29, 2025
d0bd0d1
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Aug 29, 2025
f198079
Clang format
jhp-lanl Aug 29, 2025
a4d1a26
Update name for floored energy modifier test
jhp-lanl Aug 29, 2025
469d7d1
A couple more changes with moving the multi_eos.hpp file
jhp-lanl Aug 29, 2025
950efea
Opps... missed conflict and bad find/replace
jhp-lanl Aug 29, 2025
03cbf35
Missed a new feature for Kahan summation
jhp-lanl Aug 29, 2025
88b7dc0
Rename multi_eos test
jhp-lanl Aug 29, 2025
3d7d06d
Update kahan sum location
jhp-lanl Aug 29, 2025
8c60e76
Remove extra > from macro definition
jhp-lanl Aug 29, 2025
b5234f4
Various typos fixed to compile
jhp-lanl Aug 29, 2025
f131397
Clang format
jhp-lanl Aug 29, 2025
ad8203b
Add missing cmath header (how did this compile before?)
jhp-lanl Aug 29, 2025
d208d77
Add basic tests for MultiEOS (adding more)
jhp-lanl Aug 29, 2025
a93b0ce
Clang format
jhp-lanl Aug 29, 2025
e85828c
Fix logic for preferred input checks
jhp-lanl Aug 30, 2025
579b017
Clang format
jhp-lanl Aug 30, 2025
b823d23
Fix clang sanitize issues
jhp-lanl Aug 30, 2025
9096623
Merge branch 'jmm/variant-introspection' of github.com:lanl/singulari…
jhp-lanl Sep 2, 2025
b638600
Make VariadicIndexerBase constexpr and correct logic in SINGULARITY_I…
jhp-lanl Sep 2, 2025
0dfd834
Make CheckParams() throw exceptions so that it's easier to test
jhp-lanl Sep 2, 2025
c95ebf6
Correct error with SINGULARITY_INDEXER_HAS_INDEXABLE_TYPE
jhp-lanl Sep 3, 2025
bf383db
Add test for MassFraction<N> type
jhp-lanl Sep 3, 2025
4adae40
Make SINGULARITY_EOSPAC_USE_MODERN_ERROR_CODES dependent
jhp-lanl Sep 3, 2025
9024dd3
Merge branch 'jhp/eospac_option' of github.com:lanl/singularity-eos i…
jhp-lanl Sep 3, 2025
2147015
Fix dependent option logic and add to shared memory
jhp-lanl Sep 3, 2025
eab2098
Merge branch 'jhp/eospac_option' of github.com:lanl/singularity-eos i…
jhp-lanl Sep 3, 2025
850d425
Const correctness and remove pointer type for variant because it does…
jhp-lanl Sep 3, 2025
5f2e5ff
Add more tests to excerise P-T, mass fraction cutoff, CreateEOSArray,…
jhp-lanl Sep 3, 2025
6e1eeed
Clang format
jhp-lanl Sep 3, 2025
baacd22
Make throws test only run when kokkos is off
jhp-lanl Sep 3, 2025
dd3dbf5
Add more info to failing tests... will debug later
jhp-lanl Sep 3, 2025
63f1dba
Fix pass by value, argument ordering, and make sure lambda is passed …
jhp-lanl Sep 3, 2025
b0ef51e
Fix array filling and test mass fraction filling separately
jhp-lanl Sep 3, 2025
5130751
Clang format
jhp-lanl Sep 3, 2025
1a16407
Add noexcept
jhp-lanl Sep 3, 2025
a93b18f
Remove extraneous this from lambda capture
jhp-lanl Sep 3, 2025
f98e2a3
Add explicit arguments to REQUIRE_THROWS_WITH
jhp-lanl Sep 3, 2025
709b711
Satisfy clang unused issues and try not using REQUIRE_THROWS_WITH
jhp-lanl Sep 3, 2025
049bc59
Clang format
jhp-lanl Sep 3, 2025
c63ada4
Remove REQUIRE_THROWS_WITH since it doesn't appear to be working at p…
jhp-lanl Sep 3, 2025
90aa42b
Don't force references in order to accomodate many container return v…
jhp-lanl Sep 4, 2025
264bfd1
Bug fixes and tune tolerance of RE lookup PTE solve
jhp-lanl Sep 4, 2025
9746606
Add FillEos test and other lookup tests
jhp-lanl Sep 4, 2025
11e5388
Add some TODO comments for the future
jhp-lanl Sep 4, 2025
98d72e3
Clang doesn't like if constexpr for PreferredInput
jhp-lanl Sep 4, 2025
9551270
Add parentheses around bit comparisons for clarity
jhp-lanl Sep 4, 2025
15f1f20
Add SFINAE helpers for tuples
jhp-lanl Sep 5, 2025
1dca750
Correct lambda references, make sure bulk modulus calls bulk modulus,…
jhp-lanl Sep 5, 2025
ac6bd64
Correct CV bug
jhp-lanl Sep 5, 2025
dec5179
Add checks for averaging other thermo quantities (derivatives, etc.)
jhp-lanl Sep 5, 2025
0a4ed3c
Avoid GCC warnings relating to unused variables
jhp-lanl Sep 5, 2025
ad11bbd
Add tests for basic functions
jhp-lanl Sep 5, 2025
de6ed3b
Evaluate 3T properties at multiple densities, and correct MaximumPres…
jhp-lanl Sep 5, 2025
86c45c3
Remove zbar_func for now... use it when we actually test 3T
jhp-lanl Sep 5, 2025
5a492fd
Add ability to check if a type accepts an whole number index
jhp-lanl Sep 12, 2025
02a7396
Add safeSet() and safeGet() helpers
jhp-lanl Sep 12, 2025
8895d80
Add safeGet and safeSet that don't take numerical indices
jhp-lanl Sep 12, 2025
58a920b
Switch to safeGet and safeSet for indexable types
jhp-lanl Sep 12, 2025
fce8f7c
Whoops... forgot comment
jhp-lanl Sep 12, 2025
4959500
Clang format
jhp-lanl Sep 12, 2025
c2b1dbb
Update changelog
jhp-lanl Sep 12, 2025
589e1dc
Update doc
jhp-lanl Sep 12, 2025
fd74c25
Make functions PORTABLE and add required get/set
jhp-lanl Sep 12, 2025
a3d71fc
Make code more DRY and rename things a bit
jhp-lanl Sep 13, 2025
856531f
Add int index check
jhp-lanl Sep 13, 2025
220df73
Rename safeGet/Set to SafeGet/Set and remove direct indexing or regular
jhp-lanl Sep 13, 2025
271e52e
Make indexer const correct
jhp-lanl Sep 13, 2025
63d5a39
Rename safeGet/Set
jhp-lanl Sep 13, 2025
8a893a7
Clang format
jhp-lanl Sep 13, 2025
d6a9f68
Switch to template-based decision to use integer index or not
jhp-lanl Sep 13, 2025
cf8bf93
Whoops... forgot to return
jhp-lanl Sep 13, 2025
2d4153a
Clang format
jhp-lanl Sep 13, 2025
0a4baa1
Add docs for SafeMustGet() and SafeMustSet()
jhp-lanl Sep 13, 2025
4c89631
Get rid of Get and have wrappers use GetSet. Also update comments and…
jhp-lanl Sep 17, 2025
9d52960
Switch Get for Safe versions and expand tests
jhp-lanl Sep 17, 2025
69b56ab
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/spine…
jhp-lanl Sep 17, 2025
0feb8e4
Remove last Get in favor of SafeSet
jhp-lanl Sep 17, 2025
c245728
Remove a few more instances of Get in favor of the Safe variety for I…
jhp-lanl Sep 17, 2025
734d55b
Clang format
jhp-lanl Sep 17, 2025
efd9a9f
Whoops... void was a bad choice for a type index
jhp-lanl Sep 17, 2025
d8dbccc
Let's try an unreachable return to make decltype(auto) happy
jhp-lanl Sep 17, 2025
bfacaac
Add dependent_false_v for if constexpr static asserts
jhp-lanl Sep 17, 2025
36d4286
Move throw into SafeGet/SafeSet wrappers and provide helpful compile …
jhp-lanl Sep 17, 2025
c783623
Can't test for a runtime throw when compile-time error will be used
jhp-lanl Sep 17, 2025
dc2a3a8
Make internal variant type robust to multiple EOS of the same type an…
jhp-lanl Sep 17, 2025
f88c017
Add static assert to variant to make sure there are no duplicate types
jhp-lanl Sep 17, 2025
11da97c
Split tabular and analytic tests of MultiEOS
jhp-lanl Sep 17, 2025
dbcb72a
Add tests for unique typelists
jhp-lanl Sep 17, 2025
fe6ad15
Merge branch 'jhp/spiner_indexable_types' of github.com:lanl/singular…
jhp-lanl Sep 17, 2025
d16bb0c
Whoops... forgot to commit the variadic utilities that enable the uni…
jhp-lanl Sep 17, 2025
07f4a72
Clang format
jhp-lanl Sep 17, 2025
4a60616
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 17, 2025
e70e071
Add ifdef guards to make sure we don't compile without spiner
jhp-lanl Sep 17, 2025
b09d64d
Add some debugging to try to figure out why the reference state and F…
jhp-lanl Sep 17, 2025
323f0d0
Add constant checks for correct input/output in FillEos
jhp-lanl Sep 17, 2025
2d75238
Add LogDensity and LogTemperature since they stabilize spiner r(P,T) …
jhp-lanl Sep 17, 2025
1b79a06
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 18, 2025
1654471
Switch to finite differences for mixture derivatives
jhp-lanl Sep 18, 2025
6acd078
Switch testing to account for finite difference derivatives now
jhp-lanl Sep 18, 2025
301bdd7
Merge branch 'main' into jhp/two_eos
Yurlungur Sep 18, 2025
3899052
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 19, 2025
2d5abb7
Redo derivatives to use finite differences for mixtures
jhp-lanl Sep 20, 2025
9d11b8b
Small cosmetic changes
jhp-lanl Sep 23, 2025
a2063b5
Updates to test to try to track down PTE convergence issue and stagin…
jhp-lanl Sep 23, 2025
0881391
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 23, 2025
f0f5c70
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 23, 2025
3e920c2
PTE settings for finite differences or normal lookups
jhp-lanl Sep 23, 2025
a9703fb
Settle in on tolerances and convergence
jhp-lanl Sep 23, 2025
8af5ac5
Merge branch 'jhp/two_eos' of github.com:lanl/singularity-eos into jh…
jhp-lanl Sep 23, 2025
b9e056c
Clang format
jhp-lanl Sep 23, 2025
a941c33
Refactor SetDynamicMemory logic and get rid of extra template arguments
jhp-lanl Sep 23, 2025
4e4769f
Clean up using statements
jhp-lanl Sep 23, 2025
6247f90
Test 3T functions and debug
jhp-lanl Sep 23, 2025
11893ff
Initial stab at serialization and device tests (probably won't compile)
jhp-lanl Sep 24, 2025
7c70789
Now it compiles...
jhp-lanl Sep 24, 2025
24fa0be
Clang format
jhp-lanl Sep 24, 2025
f1fd3fd
Correct SFINAE
jhp-lanl Sep 25, 2025
06c40fd
Fix some segfaults
jhp-lanl Sep 25, 2025
0d91dac
Create CMake option to enable address and undefined behavior sanitizing
jhp-lanl Sep 25, 2025
053da60
Add static-libasan
jhp-lanl Sep 25, 2025
64de92c
Remove extraneous comma and move compile options down with other options
jhp-lanl Sep 25, 2025
f6a4ee4
Update CMakeLists.txt
jhp-lanl Sep 25, 2025
d3364e3
Update CHANGELOG.md
jhp-lanl Sep 25, 2025
13464b2
Merge branch 'jhp/cmake_sanitize' into jhp/two_eos
jhp-lanl Sep 25, 2025
70b0b1c
Merge branch 'jhp/cmake_sanitize' into jhp/two_eos
jhp-lanl Sep 25, 2025
de5b5c0
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Sep 25, 2025
3216a73
Change shared to dynamic names
jhp-lanl Sep 25, 2025
8a32e53
Merge branch 'main' of github.com:lanl/singularity-eos into jhp/two_eos
jhp-lanl Oct 9, 2025
a50eb4e
Explain zero shared memory size
jhp-lanl Oct 10, 2025
03bf38e
Comment that serialization doesn't work
jhp-lanl Oct 10, 2025
c027b4c
Comment out serialization test since it isn't working yet
jhp-lanl Oct 10, 2025
6de1f9e
Update changelog
jhp-lanl Oct 10, 2025
7988572
add period
jhp-lanl Oct 10, 2025
5e7d452
Rename variables to be more logical
jhp-lanl Oct 10, 2025
918fe7b
Add documentation for MultiEOS
jhp-lanl Oct 10, 2025
89f50d1
Clang format
jhp-lanl Oct 10, 2025
9aed19f
Whoops... too many dots
jhp-lanl Oct 10, 2025
7190289
Merge branch 'main' into jhp/two_eos
Yurlungur Oct 10, 2025
f9de181
Address most comments
jhp-lanl Oct 11, 2025
bdf8811
Merge branch 'jhp/two_eos' of github.com:lanl/singularity-eos into jh…
jhp-lanl Oct 11, 2025
5b72590
Missing semicolon
jhp-lanl Oct 11, 2025
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
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ cmake_dependent_option(SINGULARITY_BUILD_FORTRAN_BACKEND

option(SINGULARITY_USE_KOKKOS "Use Kokkos for portability" OFF)
option(SINGULARITY_USE_EOSPAC "Enable eospac backend" OFF)
option(SINGULARITY_EOSPAC_ENABLE_SHMEM
cmake_dependent_option(SINGULARITY_EOSPAC_ENABLE_SHMEM
"Support shared memory with EOSPAC backend. Requires EOSPAC version 6.5.7."
OFF)
option(SINGULARITY_EOSPAC_USE_MODERN_ERROR_CODES
OFF "SINGULARITY_USE_EOSPAC" OFF)
cmake_dependent_option(SINGULARITY_EOSPAC_USE_MODERN_ERROR_CODES
"Use the current eospac implementation of error codes, which must be compared with a function. Requires EOSPAC version 6.3.0 or greater."
ON)
ON "SINGULARITY_USE_EOSPAC" OFF)

# TODO This should be dependent option (or fortran option)
option(SINGULARITY_BUILD_CLOSURE "Mixed Cell Closure" ON)
Expand Down
3 changes: 3 additions & 0 deletions singularity-eos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ register_headers(

# Normal files
base/fast-math/logs.hpp
base/generic_indexer.hpp
base/indexable_types.hpp
base/robust_utils.hpp
base/root-finding-1d/root_finding.hpp
Expand All @@ -38,6 +39,7 @@ register_headers(
base/sp5/singularity_eos_sp5.hpp
eos/default_variant.hpp
base/hermite.hpp
base/tuple_utils.hpp
eos/eos_variant.hpp
eos/eos_stellar_collapse.hpp
eos/eos_ideal.hpp
Expand Down Expand Up @@ -72,6 +74,7 @@ register_headers(
eos/variant_utils.hpp
eos/eos_carnahan_starling.hpp
eos/eos_electrons.hpp
eos/eos_multi_eos.hpp
)

if (SINGULARITY_BUILD_CLOSURE)
Expand Down
48 changes: 48 additions & 0 deletions singularity-eos/base/generic_indexer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
// © 2021-2025. 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
// Nuclear Security Administration. All rights in the program are
// reserved by Triad National Security, LLC, and the U.S. Department of
// Energy/National Nuclear Security Administration. The Government is
// granted for itself and others acting on its behalf a nonexclusive,
// paid-up, irrevocable worldwide license in this material to reproduce,
// prepare derivative works, distribute copies to the public, perform
// publicly and display publicly, and to permit others to do so.
//------------------------------------------------------------------------------

#ifndef SINGULARITY_EOS_BASE_GENERIC_INDEXER_HPP_
#define SINGULARITY_EOS_BASE_GENERIC_INDEXER_HPP_

#include <utility>

namespace singularity {

// Index into an arbitrary array with an arbitrary map
template <typename arrT, typename mapT>
struct GenericIndexer {
arrT arr_;
mapT map_;

template <typename arrT_, typename mapT_>
constexpr GenericIndexer(arrT_ &&arr_in, mapT_ &&map_in)
: arr_{std::forward<arrT_>(arr_in)}, map_{std::forward<mapT_>(map_in)} {}

template <typename idxT>
constexpr auto &operator[](const idxT i) {
return arr_[map_[i]];
}

template <typename idxT>
constexpr const auto &operator[](const idxT i) const {
return arr_[map_[i]];
}
};
// CTAD
template <typename arrT_, typename mapT_>
GenericIndexer(arrT_ &&arr_in, mapT_ &&map_in) -> GenericIndexer<arrT_, mapT_>;

} // namespace singularity

#endif // #ifndef SINGULARITY_EOS_BASE_GENERIC_INDEXER_HPP_
32 changes: 23 additions & 9 deletions singularity-eos/base/indexable_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@
#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/variadic_utils.hpp>

// SFINAE helper macro that checks if a given indexer object has the requested
// indexable type.
// TODO: The error is a simple template substitution failure error, but there
// are ways short of C++20 concepts to add more readability to the error. We may
// want to add this at some point
#define SINGULARITY_INDEXER_HAS_INDEXABLE_TYPE(Indexer, IndexableType) \
typename = std::enable_if_t< \
singularity::variadic_utils::is_indexable_v<Indexer, IndexableType>>

// Just a small wrapper for the above macro specifically for mass fractions
// NOTE: it's assumed that matnum is a count, not an index (hence the minus 1)
#define SINGULARITY_INDEXER_HAS_MASS_FRAC(Indexer, matnum) \
SINGULARITY_INDEXER_HAS_INDEXABLE_TYPE( \
Indexer, singularity::IndexableTypes::MassFraction<matnum - 1>)

namespace singularity {
namespace IndexerUtils {
// Convenience function for accessing an indexer by either type or
Expand All @@ -40,25 +55,22 @@ PORTABLE_FORCEINLINE_FUNCTION auto &Get(Indexer_t &&lambda, std::size_t idx = 0)
template <typename Data_t, typename... Ts>
class VariadicIndexerBase {
public:
VariadicIndexerBase() = default;
PORTABLE_FORCEINLINE_FUNCTION
VariadicIndexerBase(const Data_t &data) : data_(data) {}
constexpr VariadicIndexerBase() = default;
constexpr VariadicIndexerBase(const Data_t &data) : data_(data) {}
template <typename T,
typename = std::enable_if_t<variadic_utils::contains<T, Ts...>::value>>
PORTABLE_FORCEINLINE_FUNCTION Real &operator[](const T &t) {
constexpr Real &operator[](const T &t) {
Comment thread
mauneyc-LANL marked this conversation as resolved.
Outdated
constexpr std::size_t idx = variadic_utils::GetIndexInTL<T, Ts...>();
return data_[idx];
}
PORTABLE_FORCEINLINE_FUNCTION
Real &operator[](const std::size_t idx) { return data_[idx]; }
constexpr Real &operator[](const std::size_t idx) { return data_[idx]; }
template <typename T,
typename = std::enable_if_t<variadic_utils::contains<T, Ts...>::value>>
PORTABLE_FORCEINLINE_FUNCTION const Real &operator[](const T &t) const {
constexpr const Real &operator[](const T &t) const {
constexpr std::size_t idx = variadic_utils::GetIndexInTL<T, Ts...>();
return data_[idx];
}
PORTABLE_FORCEINLINE_FUNCTION
const Real &operator[](const std::size_t idx) const { return data_[idx]; }
constexpr const Real &operator[](const std::size_t idx) const { return data_[idx]; }
static inline constexpr std::size_t size() { return sizeof...(Ts); }

private:
Expand All @@ -81,6 +93,8 @@ struct MeanAtomicNumber {};
struct ElectronFraction {};
struct RootStatus {};
struct TableStatus {};
template <int mat_idx>
struct MassFraction {};
} // namespace IndexableTypes
} // namespace singularity
#endif // SINGULARITY_EOS_BASE_INDEXABLE_TYPES_
29 changes: 29 additions & 0 deletions singularity-eos/base/math_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef SINGULARITY_EOS_BASE_MATH_UTILS_HPP_
#define SINGULARITY_EOS_BASE_MATH_UTILS_HPP_

#include <cmath>

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

namespace singularity {
Expand Down Expand Up @@ -58,6 +60,33 @@ PORTABLE_FORCEINLINE_FUNCTION auto pow10(const Real x) {
return std::exp(ln10 * x);
}

/*
* Kahan summation, with the Neumaier correction
* https://onlinelibrary.wiley.com/doi/10.1002/zamm.19740540106
*/
struct IdentityOperator {
PORTABLE_FORCEINLINE_FUNCTION Real operator()(const Real x) const { return x; }
};
template <typename Data_t, typename Operator_t = IdentityOperator>
PORTABLE_FORCEINLINE_FUNCTION Real
sum_neumaier(Data_t &&data, std::size_t n, std::size_t offset = 0, std::size_t iskip = -1,
const Operator_t &op = IdentityOperator()) {
Real sum = 0;
Real c = 0; // correction
for (std::size_t i = 0; i < n; ++i) {
if (i == iskip) continue;
Real x = op(data[i + offset]);
Real t = sum + x;
if (std::abs(sum) >= std::abs(x)) {
c += (sum - t) + x;
} else {
c += (x - t) + sum;
}
sum = t;
}
return sum + c;
}

} // namespace math_utils
} // namespace singularity

Expand Down
47 changes: 47 additions & 0 deletions singularity-eos/base/tuple_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
// © 2021-2025. 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
// Nuclear Security Administration. All rights in the program are
// reserved by Triad National Security, LLC, and the U.S. Department of
// Energy/National Nuclear Security Administration. The Government is
// granted for itself and others acting on its behalf a nonexclusive,
// paid-up, irrevocable worldwide license in this material to reproduce,
// prepare derivative works, distribute copies to the public, perform
// publicly and display publicly, and to permit others to do so.
//------------------------------------------------------------------------------

#ifndef SINGULARITY_EOS_BASE_TUPLE_UTILS_HPP_
#define SINGULARITY_EOS_BASE_TUPLE_UTILS_HPP_

#include <tuple>

namespace singularity {
namespace tuple_utils {

namespace impl {

// Helper that copies a tuple into a new tuple while also applying a
// transformation function to each element. Wrapped in `impl` namespace due to
// index sequence and called below with a more normal function signature
template <typename TupleT, typename FunctionT, std::size_t... I>
constexpr auto tuple_transform_iteration(TupleT &&tup, FunctionT &&function,
std::index_sequence<I...>) {
return std::make_tuple(function(std::get<I>(std::forward<TupleT>(tup)))...);
}
} // namespace impl

// Returns a copy of the tuple with a transform function called on each element
template <typename TupleT, typename FunctionT>
constexpr auto tuple_transform(TupleT &&tup, FunctionT &&function) {
constexpr std::size_t N = std::tuple_size_v<std::remove_reference_t<TupleT>>;
return impl::tuple_transform_iteration(std::forward<TupleT>(tup),
std::forward<FunctionT>(function),
std::make_index_sequence<N>{});
}

} // namespace tuple_utils
} // namespace singularity

#endif // #ifndef SINGULARITY_EOS_BASE_TUPLE_UTILS_HPP_
61 changes: 18 additions & 43 deletions singularity-eos/closure/mixed_cell_models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <ports-of-call/portability.hpp>
#include <ports-of-call/portable_errors.hpp>
#include <singularity-eos/base/fast-math/logs.hpp>
#include <singularity-eos/base/math_utils.hpp>
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-eos/base/variadic_utils.hpp>
#include <singularity-eos/eos/eos.hpp>
Expand Down Expand Up @@ -213,33 +214,6 @@ bool solve_Ax_b_wscr(const std::size_t n, Real *a, Real *b, Real *scr) {
return retval;
}

/*
* Kahan summation, with the Neumaier correction
* https://onlinelibrary.wiley.com/doi/10.1002/zamm.19740540106
*/
struct IdentityOperator {
PORTABLE_FORCEINLINE_FUNCTION Real operator()(const Real x) const { return x; }
};
template <typename Data_t, typename Operator_t = IdentityOperator>
PORTABLE_FORCEINLINE_FUNCTION Real
sum_neumaier(Data_t &&data, std::size_t n, std::size_t offset = 0, std::size_t iskip = -1,
const Operator_t &op = IdentityOperator()) {
Real sum = 0;
Real c = 0; // correction
for (std::size_t i = 0; i < n; ++i) {
if (i == iskip) continue;
Real x = op(data[i + offset]);
Real t = sum + x;
if (std::abs(sum) >= std::abs(x)) {
c += (sum - t) + x;
} else {
c += (x - t) + sum;
}
sum = t;
}
return sum + c;
}

class CacheAccessor {
public:
CacheAccessor() = default;
Expand Down Expand Up @@ -323,12 +297,12 @@ class PTESolverBase {
PORTABLE_REQUIRE(rho[m] > 0., "Non-positive density provided to PTE solver");
rhobar[m] = rho[m] * vfrac[m];
}
rho_total = sum_neumaier(rhobar, nmat);
rho_total = math_utils::sum_neumaier(rhobar, nmat);
}

PORTABLE_FORCEINLINE_FUNCTION
void NormalizeVfrac() const {
Real vfrac_sum = sum_neumaier(vfrac, nmat);
void NormalizeVfrac() {
Real vfrac_sum = math_utils::sum_neumaier(vfrac, nmat);
for (std::size_t m = 0; m < nmat; ++m) {
vfrac[m] *= robust::ratio(vfrac_total, vfrac_sum);
}
Expand Down Expand Up @@ -559,7 +533,8 @@ class PTESolverBase {

PORTABLE_INLINE_FUNCTION
Real ResidualNorm() const {
return 0.5 * sum_neumaier(residual, neq, 0, -1, [](const Real x) { return x * x; });
return 0.5 * math_utils::sum_neumaier(residual, neq, 0, -1,
[](const Real x) { return x * x; });
}

PORTABLE_FORCEINLINE_FUNCTION
Expand Down Expand Up @@ -900,7 +875,7 @@ class PTESolverRhoT

PORTABLE_INLINE_FUNCTION
void Residual() const {
Real esum = mix_impl::sum_neumaier(u, nmat);
Real esum = math_utils::sum_neumaier(u, nmat);
residual[0] = utotal_scale - esum;
std::size_t ires = 1;
for (std::size_t m = 0; m < nmat; ++m) {
Expand All @@ -916,8 +891,8 @@ class PTESolverRhoT
for (std::size_t m = 0; m < nmat; ++m) {
mean_p += vfrac[m] * press[m];
}
Real error_p = std::sqrt(
sum_neumaier(residual, neq - 1, 1, -1, [](const Real x) { return x * x; }));
Real error_p = std::sqrt(math_utils::sum_neumaier(
residual, neq - 1, 1, -1, [](const Real x) { return x * x; }));
Real error_u = std::abs(residual[0]);
// Check for convergence
bool converged_p = (error_p < params_.pte_rel_tolerance_p * std::abs(mean_p) ||
Expand Down Expand Up @@ -1002,7 +977,7 @@ class PTESolverRhoT
// control how big of a step toward vfrac = 0 is allowed
// 0th material is special as delta volume fraction for it is
// minus the sum of the deltas for the others
Real dalphaskip = -mix_impl::sum_neumaier(dx, nmat - 1, 1);
Real dalphaskip = -math_utils::sum_neumaier(dx, nmat - 1, 1);
std::size_t idx = 1;
for (std::size_t m = 0; m < nmat; ++m) {
Real mydx = (m == ms) ? dalphaskip : dx[idx++];
Expand Down Expand Up @@ -1058,7 +1033,7 @@ class PTESolverRhoT
if (ms == m) continue;
vfrac[m] = vtemp[m] + scale * dx[idx++];
}
vfrac[ms] = mix_impl::sum_neumaier(vfrac, nmat, 0, ms);
vfrac[ms] = math_utils::sum_neumaier(vfrac, nmat, 0, ms);
vfrac[ms] = 1 - vfrac[ms];
for (std::size_t m = 0; m < nmat; ++m) {
rho[m] = robust::ratio(rhobar[m], vfrac[m]);
Expand Down Expand Up @@ -1165,7 +1140,7 @@ class PTESolverPT
// always approach from >0 side
Pequil += std::abs(press[m]) * vfrac[m];
}
Real vsum = mix_impl::sum_neumaier(vfrac, nmat);
Real vsum = math_utils::sum_neumaier(vfrac, nmat);
Pequil /= vsum;
Tequil = 1; // Because it's = Tnorm = initial guess

Expand Down Expand Up @@ -1201,8 +1176,8 @@ class PTESolverPT

PORTABLE_INLINE_FUNCTION
void Residual() const {
Real vsum = mix_impl::sum_neumaier(vfrac, nmat);
Real esum = mix_impl::sum_neumaier(u, nmat);
Real vsum = math_utils::sum_neumaier(vfrac, nmat);
Real esum = math_utils::sum_neumaier(u, nmat);
residual[RV] = vfrac_total - vsum;
residual[RSIE] = utotal_scale - esum;
}
Expand Down Expand Up @@ -1433,7 +1408,7 @@ class PTESolverFixedT

PORTABLE_INLINE_FUNCTION
void Residual() const {
Real vsum = mix_impl::sum_neumaier(vfrac, nmat);
Real vsum = math_utils::sum_neumaier(vfrac, nmat);
residual[0] = vfrac_total - vsum;
for (std::size_t m = 0; m < nmat - 1; ++m) {
residual[1 + m] = press[m] - press[m + 1];
Expand Down Expand Up @@ -1657,7 +1632,7 @@ class PTESolverFixedP

PORTABLE_INLINE_FUNCTION
void Residual() const {
Real vsum = mix_impl::sum_neumaier(vfrac, nmat);
Real vsum = math_utils::sum_neumaier(vfrac, nmat);
for (std::size_t m = 0; m < nmat; ++m) {
residual[m] = robust::ratio(Pequil, uscale) - press[m];
}
Expand Down Expand Up @@ -1878,8 +1853,8 @@ class PTESolverRhoU

PORTABLE_INLINE_FUNCTION
void Residual() const {
Real vsum = mix_impl::sum_neumaier(vfrac, nmat);
Real esum = mix_impl::sum_neumaier(u, nmat);
Real vsum = math_utils::sum_neumaier(vfrac, nmat);
Real esum = math_utils::sum_neumaier(u, nmat);
residual[0] = vfrac_total - vsum;
residual[1] = utotal_scale - esum;
for (std::size_t m = 0; m < nmat - 1; ++m) {
Expand Down
Loading
Loading