Skip to content
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ cmake_dependent_option(
cmake_dependent_option(
SINGULARITY_USE_HELMHOLTZ "Include Helmholtz equation of state" OFF
"SINGULARITY_USE_SPINER;SINGULARITY_USE_SPINER_WITH_HDF5" OFF)
cmake_dependent_option(
SINGULARITY_USE_STELLAR_COLLAPSE "Include StellarCollapse equation of state" OFF
"SINGULARITY_USE_SPINER;SINGULARITY_USE_SPINER_WITH_HDF5" OFF)

# Enables polynomial, carnahan starling, and NobleAbel in variant.
# Off by default, as they are not in the default python bindings or used
Expand Down Expand Up @@ -115,6 +118,12 @@ option(SINGULARITY_BETTER_DEBUG_FLAGS "Better debug flags for singularity" ON)
option(SINGULARITY_HIDE_MORE_WARNINGS "hide more warnings" OFF)
option(SINGULARITY_STRICT_WARNINGS "Make warnings strict" OFF)

# This enables explicit instantiation of EOS classes, which can
# significantly speed up compilation
option(SINGULARITY_INSTANTIATE_CLASSES
"Instantiate classes and common templates. Speeds up compilation but can reduce runtime performance."
OFF)

# toggle code options
option(SINGULARITY_USE_TRUE_LOG_GRIDDING
"Use grids that conform to log spacing." OFF)
Expand All @@ -140,7 +149,7 @@ option(SINGULARITY_FORCE_SUBMODULE_MODE "Submodule mode" OFF)
# TODO This should depend on using offloading (`SINGULARITY_USE_CUDA` &t) Also,
# patching in the source tree is messy, this should be done in the build dir
option(SINGULARITY_PATCH_MPARK_VARIANT
"Apply GPU patch to mpark-variant submodule" ON)
"Apply GPU patch to mpark-variant submodule" ON)

# Plugins
set(SINGULARITY_PLUGINS "" CACHE STRING "List of paths to plugin directories")
Expand Down Expand Up @@ -320,6 +329,10 @@ target_compile_definitions(singularity-eos_Interface INTERFACE
)

# defines
if (SINGULARITY_INSTANTIATE_CLASSES)
target_compile_definitions(singularity-eos_Interface
INTERFACE SINGULARITY_INSTANTIATE_CLASSES)
endif()
if (SINGULARITY_USE_TRUE_LOG_GRIDDING)
target_compile_definitions(singularity-eos_Interface
INTERFACE SINGULARITY_USE_TRUE_LOG_GRIDDING)
Expand Down
5 changes: 5 additions & 0 deletions cmake/singularity-eos/kokkos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ macro(singularity_import_kokkos)
set(Kokkos_ENABLE_CUDA_LAMBDA
ON
CACHE BOOL "" FORCE)
if (SINGULARITY_INSTANTIATE_CLASSES)
set(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE
ON
CACHE BOOL "" FORCE)
endif()
endif()

if(NOT TARGET Kokkos::kokkos)
Expand Down
25 changes: 25 additions & 0 deletions singularity-eos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ register_headers(
eos/eos_electrons.hpp
)

if (SINGULARITY_INSTANTIATE_CLASSES)
register_srcs(
eos/eos.cpp
eos/eos_carnahan_starling.cpp
eos/eos_davis.cpp
eos/eos_electrons.cpp
eos/eos_eospac.cpp
eos/eos_gruneisen.cpp
eos/eos_helmholtz.cpp
eos/eos_ideal.cpp
eos/eos_jwl.cpp
eos/eos_mgusup.cpp
eos/eos_noble_abel.cpp
eos/eos_powermg.cpp
eos/eos_sap_polynomial.cpp
eos/eos_spiner.cpp
eos/eos_stellar_collapse.cpp
eos/eos_stiff.cpp
eos/eos_vinet.cpp
eos/modifiers/shifted_eos.cpp
eos/modifiers/scaled_eos.cpp
)
endif()

if (SINGULARITY_BUILD_CLOSURE)
register_headers(
closure/mixed_cell_models.hpp
Expand All @@ -81,6 +105,7 @@ if (SINGULARITY_BUILD_CLOSURE)
# while these are C++ files, they
# are only needed for the fortran backend or unit testing
register_srcs(eos/singularity_eos.cpp)
register_srcs(eos/get_sg_eos_misc.cpp)
register_headers(eos/singularity_eos.hpp)
endif()
if (SINGULARITY_BUILD_FORTRAN_BACKEND)
Expand Down
9 changes: 9 additions & 0 deletions singularity-eos/base/indexable_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#include <singularity-eos/base/variadic_utils.hpp>

namespace singularity {
// Provide default functionality when lambda isn't passed to vector
// functions
struct NullIndexer {
PORTABLE_FORCEINLINE_FUNCTION
Real *operator[](int i) { return nullptr; }
PORTABLE_FORCEINLINE_FUNCTION
Real *operator[](int i) const { return nullptr; }
};

namespace IndexerUtils {
// Convenience function for accessing an indexer by either type or
// natural number index depending on what is available
Expand Down
36 changes: 4 additions & 32 deletions singularity-eos/eos/eos.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// © 2021-2023. Triad National Security, LLC. All rights reserved. This
// © 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
Expand All @@ -12,34 +12,6 @@
// publicly and display publicly, and to permit others to do so.
//------------------------------------------------------------------------------

// JMM: This is a dummy file to provide a source file for cmake to
// compile when built without fortran.
//
// The main reason to do this is that when we build without fortran
// bindings, the library is completely header only. However WITH
// fortran bindings, it is not.
//
// cmake supports a build mode for header only libraries by marking
// those libraries INTERFACE. Without this flag, a few things will go
// wrong:
// 1. CMake will be unable to infer a proper linker
// so one must be specified by hand.
// 2. no dynamic library file (e.g., "*.a") will be generated,
// but dependencies that link against it, such as another library,
// or in our case, tests, will look for it. This will lead to
// a failure of the downstream library at link time.
//
// On the other hand, a library with implementation files
// CANNOT be marked INTERFACE, as otherwise source files will
// not be compiled.
//
// Unfortunately, switching the INTERFACE tag on and off in cmake
// is very cumbersome, as if a library is marked INTERFACE
// all its dependencies must ALSO be slurped in with an INTERFACE
// flag. This introduces significant branching in the cmake code
// and a lot of builer plate. For now, then, I simply include this
// empty source file.
//
// In the future, we could include centralized code here that we
// always want compiled, such as template instantiations or
// convenience functions.
#include <singularity-eos/eos/eos.hpp>

template void singularity::impl::ConcretizeType<singularity::EOS>(EOS);
13 changes: 13 additions & 0 deletions singularity-eos/eos/eos.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@

#include <@SINGULARITY_VARIANT@>

#ifdef SINGULARITY_INSTANTIATE_CLASSES
namespace singularity {
namespace impl {
template<typename T>
void ConcretizeType(T eos) {
eos.CheckParams();
eos.PrintParams();
}
extern template void ConcretizeType<EOS>(EOS);
} // namespace impl
} // namespace singularity
#endif // SINGULARITY_INSTANTIATE_CLASSES

#endif // _SINGULARITY_EOS_EOS_EOS_HPP_
65 changes: 65 additions & 0 deletions singularity-eos/eos/eos_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ports-of-call/portability.hpp>
#include <ports-of-call/portable_errors.hpp>
#include <singularity-eos/base/constants.hpp>
#include <singularity-eos/base/indexable_types.hpp>
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-eos/base/root-finding-1d/root_finding.hpp>
#include <singularity-eos/base/variadic_utils.hpp>
Expand Down Expand Up @@ -123,6 +124,70 @@ char *StrCat(char *destination, const char *source) {
PORTABLE_INLINE_FUNCTION \
Real MeanAtomicNumber() const { return t_.MeanAtomicNumber(); }

// These are used when SINGULARITY_INSTANTIATE_CLASSES is
// active. Requires relocatable device code.
#define SG_ADD_TEMPLATE_EXTERNS(T, S) \
extern template class eos_base::EosBase<T>; \
extern template PORTABLE_FUNCTION Real T::TemperatureFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::InternalEnergyFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::PressureFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::PressureFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::MinInternalEnergyFromDensity<S>(const Real, \
S &&) const; \
extern template PORTABLE_FUNCTION Real T::EntropyFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::EntropyFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::SpecificHeatFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::SpecificHeatFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::BulkModulusFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::BulkModulusFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::GruneisenParamFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION Real T::GruneisenParamFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
extern template PORTABLE_FUNCTION void T::ValuesAtReferenceState( \
Real &, Real &, Real &, Real &, Real &, Real &, Real &, Real &, S &&) const;

#define SG_ADD_TEMPLATE_INSTANTIATIONS(T, S) \
template class eos_base::EosBase<T>; \
template PORTABLE_FUNCTION Real T::TemperatureFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::InternalEnergyFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::PressureFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::PressureFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::MinInternalEnergyFromDensity<S>(const Real, S &&) \
const; \
template PORTABLE_FUNCTION Real T::EntropyFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::EntropyFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::SpecificHeatFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::SpecificHeatFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::BulkModulusFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::BulkModulusFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::GruneisenParamFromDensityTemperature<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION Real T::GruneisenParamFromDensityInternalEnergy<S>( \
const Real, const Real, S &&) const; \
template PORTABLE_FUNCTION void T::ValuesAtReferenceState( \
Real &, Real &, Real &, Real &, Real &, Real &, Real &, Real &, S &&) const;

class Factor {
Real value_ = 1.0;
bool is_set_ = false;
Expand Down
19 changes: 19 additions & 0 deletions singularity-eos/eos/eos_carnahan_starling.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//------------------------------------------------------------------------------
// © 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.
//------------------------------------------------------------------------------

#include <singularity-eos/eos/eos_carnahan_starling.hpp>

namespace singularity {
SG_ADD_TEMPLATE_INSTANTIATIONS(CarnahanStarling, Real *)
} // namespace singularity
6 changes: 5 additions & 1 deletion singularity-eos/eos/eos_carnahan_starling.hpp
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-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
Expand Down Expand Up @@ -295,6 +295,10 @@ PORTABLE_INLINE_FUNCTION void CarnahanStarling::FillEos(Real &rho, Real &temp, R
cv = SpecificHeatFromDensityInternalEnergy(rho, sie);
}

#ifdef SINGULARITY_INSTANTIATE_CLASSES
SG_ADD_TEMPLATE_EXTERNS(CarnahanStarling, Real *)
#endif // SINGULARITY_INSTANTIATE_CLASSES

} // namespace singularity

#endif // _SINGULARITY_EOS_EOS_EOS_CARNAHAN_STARLING_HPP_
20 changes: 20 additions & 0 deletions singularity-eos/eos/eos_davis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//------------------------------------------------------------------------------
// © 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.
//------------------------------------------------------------------------------

#include <singularity-eos/eos/eos_davis.hpp>

namespace singularity {
SG_ADD_TEMPLATE_INSTANTIATIONS(DavisReactants, Real *)
SG_ADD_TEMPLATE_INSTANTIATIONS(DavisProducts, Real *)
} // namespace singularity
Loading