Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test hdf5 logic #287

Merged
merged 4 commits into from
Aug 4, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [[PR269]](https://github.com/lanl/singularity-eos/pull/269) Add SAP Polynomial EoS

### Fixed (Repair bugs, etc)
- [[PR287]](https://github.com/lanl/singularity-eos/pull/287) Fix testing logic with new HDF5 options
- [[PR282]](https://github.com/lanl/singularity-eos/pull/282) Fix missing deep copy in sap polynomial tests
- [[PR281]](https://github.com/lanl/singularity-eos/pull/281) Pin spiner in spackage to a specific, tested version
- [[PR267]](https://github.com/lanl/singularity-eos/pull/267) Add missing eosSafeDestroy call in EOSPAC::Finalize
Expand All @@ -30,6 +31,7 @@
- [[PR177]](https://github.com/lanl/singularity-eos/pull/177) added EOSPAC vector functions

### Changed (changing behavior/API/variables/...)
- [[PR246]](https://github.com/lanl/singularity-eos/pull/246) Update CMake with upstream changes
- [[PR223]](https://github.com/lanl/singularity-eos/pull/223) Update ports-of-call and add portable error handling
- [[PR234]](https://github.com/lanl/singularity-eos/pull/234) update ports-of-call to correct for undefined behavior in error handling
- [[PR219]](https://github.com/lanl/singularity-eos/pull/219) Removed static analysis from re-git pipeline
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ cmake_dependent_option(
"SINGULARITY_BUILD_TESTS;SINGULARITY_BUILD_SESAME2SPINER" OFF)
cmake_dependent_option(
SINGULARITY_TEST_STELLAR_COLLAPSE "Test stellar collapse table readers" ON
"SINGULARITY_BUILD_TESTS;SINGULARITY_BUILD_STELLARCOLLAPSE2SPINER" OFF)
"SINGULARITY_BUILD_TESTS;SINGUALRITY_BUILD_STELLARCOLLAPSE2SPINER" OFF)
cmake_dependent_option(SINGULARITY_TEST_PYTHON "Test the Python bindings" ON
"SINGULARITY_BUILD_TESTS;SINGULARITY_BUILD_PYTHON" OFF)

Expand Down
146 changes: 73 additions & 73 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,115 +1,115 @@
#------------------------------------------------------------------------------
# © 2021-2023. 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
# ------------------------------------------------------------------------------
# © 2021-2023. 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.
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

add_executable(eos_unit_tests
add_executable(
eos_unit_tests
catch2_define.cpp
eos_unit_test_helpers.hpp
test_eos_unit.cpp
test_eos_gruneisen.cpp
test_eos_sap_polynomial.cpp
test_eos_vinet.cpp
test_eos_stiff.cpp
)
test_eos_stiff.cpp)

if(SINGULARITY_USE_HDF5)
if(SINGULARITY_TEST_SESAME)
target_compile_definitions(eos_unit_tests PRIVATE SINGULARITY_TEST_SESAME)
endif()
if(SINGULARITY_TEST_STELLAR_COLLAPSE)
target_compile_definitions(eos_unit_tests PRIVATE SINGULARITY_TEST_STELLAR_COLLAPSE)
endif()
if(SINGULARITY_TEST_SESAME)
target_compile_definitions(eos_unit_tests PRIVATE SINGULARITY_TEST_SESAME)
endif()
if(SINGULARITY_TEST_STELLAR_COLLAPSE)
target_compile_definitions(eos_unit_tests
PRIVATE SINGULARITY_TEST_STELLAR_COLLAPSE)
endif()

target_link_libraries(eos_unit_tests
PRIVATE
Catch2::Catch2
singularity-eos::singularity-eos
)
target_link_libraries(eos_unit_tests PRIVATE Catch2::Catch2
singularity-eos::singularity-eos)
include(Catch)
catch_discover_tests(eos_unit_tests PROPERTIES TIMEOUT 60)

if(SINGULARITY_USE_EOSPAC AND SINGULARITY_USE_HDF5 AND SINGULARITY_TEST_SESAME)
add_executable(compare_to_eospac
compare_to_eospac.cpp)
if(SINGULARITY_USE_EOSPAC AND SINGULARITY_TEST_SESAME)
add_executable(compare_to_eospac compare_to_eospac.cpp)
target_link_libraries(compare_to_eospac
PRIVATE
Catch2::Catch2
singularity-eos::singularity-eos
)
PRIVATE Catch2::Catch2 singularity-eos::singularity-eos)
endif()

if (SINGULARITY_BUILD_CLOSURE)
add_executable(test_pte
test_pte.cpp)
target_link_libraries(test_pte PRIVATE
Catch2::Catch2
singularity-eos::singularity-eos)
if(SINGULARITY_BUILD_CLOSURE)
add_executable(test_pte test_pte.cpp)
target_link_libraries(test_pte PRIVATE Catch2::Catch2
singularity-eos::singularity-eos)
add_test(pte test_pte)
endif()

if (SINGULARITY_USE_HDF5 AND SINGULARITY_TEST_STELLAR_COLLAPSE)
if(SINGULARITY_TEST_STELLAR_COLLAPSE)
set(SINGULARITY_GOLDFILE_URL
https://github.com/lanl/singularity-eos/releases/download/${SINGULARITY_GOLDFILES_VERSION}/goldfiles.tar.gz)
message(STATUS "Attempting to download gold files for regression tests. "
"File is located at ${SINGULARITY_GOLDFILE_URL} "
"If you do not want to use the gold file, you can set -DSINGULARITY_TEST_STELLAR_COLLAPSE=OFF."
)
https://github.com/lanl/singularity-eos/releases/download/${SINGULARITY_GOLDFILES_VERSION}/goldfiles.tar.gz
)
message(
STATUS
"Attempting to download gold files for regression tests. "
"File is located at ${SINGULARITY_GOLDFILE_URL} "
"If you do not want to use the gold file, you can set -DSINGULARITY_TEST_STELLAR_COLLAPSE=OFF."
)
include(FetchContent)
FetchContent_Declare(goldfiles
FetchContent_Declare(
goldfiles
URL ${SINGULARITY_GOLDFILE_URL}
URL_HASH SHA256=${SINGULARITY_GOLDFILE_HASH}
SOURCE_DIR goldfiles
)
SOURCE_DIR goldfiles)
FetchContent_MakeAvailable(goldfiles)

add_executable(profile_stellar_collapse
profile_stellar_collapse.cpp)
target_link_libraries(profile_stellar_collapse singularity-eos::singularity-eos)
add_executable(profile_stellar_collapse profile_stellar_collapse.cpp)
target_link_libraries(profile_stellar_collapse
singularity-eos::singularity-eos)
endif()

if (SINGULARITY_BUILD_PYTHON AND SINGULARITY_TEST_PYTHON)
find_package(Python COMPONENTS Interpreter Development REQUIRED)
set(PYTHON_TEST_ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH})
if(SINGULARITY_BUILD_PYTHON AND SINGULARITY_TEST_PYTHON)
find_package(
Python
COMPONENTS Interpreter Development
REQUIRED)
set(PYTHON_TEST_ENVIRONMENT
PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH})

add_test(NAME PythonBindings
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/python_bindings.py -v)
set_tests_properties(PythonBindings PROPERTIES ENVIRONMENT "${PYTHON_TEST_ENVIRONMENT}")
COMMAND ${Python_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/python_bindings.py -v)
set_tests_properties(PythonBindings PROPERTIES ENVIRONMENT
"${PYTHON_TEST_ENVIRONMENT}")
endif()

add_executable(profile_eos profile_eos.cpp)
target_link_libraries(profile_eos singularity-eos::singularity-eos)

if(SINGULARITY_USE_EOSPAC AND SINGULARITY_TEST_SESAME AND NOT SINGULARITY_USE_CUDA)
if(SINGULARITY_USE_EOSPAC
AND SINGULARITY_TEST_SESAME
AND NOT SINGULARITY_USE_CUDA)
set(METHODS_TO_TEST
TemperatureFromDensityInternalEnergy
PressureFromDensityTemperature
InternalEnergyFromDensityTemperature
PressureFromDensityInternalEnergy
SpecificHeatFromDensityTemperature
SpecificHeatFromDensityInternalEnergy
BulkModulusFromDensityTemperature
BulkModulusFromDensityInternalEnergy
GruneisenParamFromDensityTemperature
GruneisenParamFromDensityInternalEnergy
)
TemperatureFromDensityInternalEnergy
PressureFromDensityTemperature
InternalEnergyFromDensityTemperature
PressureFromDensityInternalEnergy
SpecificHeatFromDensityTemperature
SpecificHeatFromDensityInternalEnergy
BulkModulusFromDensityTemperature
BulkModulusFromDensityInternalEnergy
GruneisenParamFromDensityTemperature
GruneisenParamFromDensityInternalEnergy)

foreach(MUT IN LISTS METHODS_TO_TEST)
add_executable(profile_eospac_${MUT} profile_eospac.cpp)
target_compile_definitions(profile_eospac_${MUT} PUBLIC METHOD_UNDER_TEST=${MUT})
target_link_libraries(profile_eospac_${MUT} singularity-eos::singularity-eos)
target_compile_definitions(profile_eospac_${MUT}
PUBLIC METHOD_UNDER_TEST=${MUT})
target_link_libraries(profile_eospac_${MUT}
singularity-eos::singularity-eos)

add_test(NAME Profile_EOSPAC_${MUT}
COMMAND profile_eospac_${MUT} 100 16)
add_test(NAME Profile_EOSPAC_${MUT} COMMAND profile_eospac_${MUT} 100 16)
endforeach()
endif()
85 changes: 43 additions & 42 deletions test/compare_to_eospac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ constexpr char diffFileName[] = "diffs.sp5";
constexpr int NTIMES = 10;

class Bounds {

public:
Bounds() {}

Bounds(Real min, Real max, int N, Real offset)
: grid(RegularGrid1D(min, max, N)), offset(offset) {}
: grid(RegularGrid1D<Real>(min, max, N)), offset(offset) {}

Bounds(Real min, Real max, int N) : offset(0) {
constexpr Real epsilon = std::numeric_limits<float>::epsilon();
Expand All @@ -70,7 +71,7 @@ class Bounds {
max += offset;
min = std::log10(std::abs(min));
max = std::log10(std::abs(max));
grid = RegularGrid1D(min, max, N);
grid = RegularGrid1D<Real>(min, max, N);
}

PORTABLE_INLINE_FUNCTION Real log2lin(Real xl) const { return pow(10., xl) - offset; }
Expand All @@ -85,7 +86,7 @@ class Bounds {
}

public:
RegularGrid1D grid;
RegularGrid1D<Real> grid;
Real offset;
};

Expand Down Expand Up @@ -145,59 +146,59 @@ int main(int argc, char *argv[]) {

constexpr int NT = 3;
EOS_INTEGER nXYPairs = (nFineRho) * (nFineT);
DataBox xVals(nFineRho, nFineT);
DataBox yVals(nFineRho, nFineT);
DataBox vars(nFineRho, nFineT);
DataBox dx(nFineRho, nFineT);
DataBox dy(nFineRho, nFineT);
DataBox pressEOSPAC(nFineRho, nFineT);
DataBox pressDiff_h(nFineRho, nFineT);
DataBox pressDiff_d(nFineRho, nFineT);
DataBox<Real> xVals(nFineRho, nFineT);
DataBox<Real> yVals(nFineRho, nFineT);
DataBox<Real> vars(nFineRho, nFineT);
DataBox<Real> dx(nFineRho, nFineT);
DataBox<Real> dy(nFineRho, nFineT);
DataBox<Real> pressEOSPAC(nFineRho, nFineT);
DataBox<Real> pressDiff_h(nFineRho, nFineT);
DataBox<Real> pressDiff_d(nFineRho, nFineT);

#ifdef PORTABILITY_STRATEGY_KOKKOS
using RView = Kokkos::View<Real *>;
RView pressSpinerDView("pressSpinerDevice", nFineRho * nFineT);
typename RView::HostMirror pressSpinerHView =
Kokkos::create_mirror_view(pressSpinerDView);
DataBox pressSpiner_d(pressSpinerDView.data(), nFineRho, nFineT);
DataBox pressSpiner_hm(pressSpinerHView.data(), nFineRho, nFineT);
DataBox<Real> pressSpiner_d(pressSpinerDView.data(), nFineRho, nFineT);
DataBox<Real> pressSpiner_hm(pressSpinerHView.data(), nFineRho, nFineT);
#else
DataBox pressSpiner_d(nFineRho, nFineT);
DataBox pressSpiner_hm = pressSpiner_d.slice(2, 0, nFineRho);
DataBox<Real> pressSpiner_d(nFineRho, nFineT);
DataBox<Real> pressSpiner_hm = pressSpiner_d.slice(2, 0, nFineRho);
#endif

DataBox pressSpiner_h(nFineRho, nFineT);
DataBox tempSpiner_h(nFineRho, nFineT);
DataBox tempSpinerE_h(nFineRho, nFineT);
DataBox tempEOSPAC(nFineRho, nFineT);
DataBox tempDiff_h(nFineRho, nFineT);
DataBox tempDiff_d(nFineRho, nFineT);
DataBox tempDiffE_h(nFineRho, nFineT);
DataBox tempDiffE_d(nFineRho, nFineT);
DataBox<Real> pressSpiner_h(nFineRho, nFineT);
DataBox<Real> tempSpiner_h(nFineRho, nFineT);
DataBox<Real> tempSpinerE_h(nFineRho, nFineT);
DataBox<Real> tempEOSPAC(nFineRho, nFineT);
DataBox<Real> tempDiff_h(nFineRho, nFineT);
DataBox<Real> tempDiff_d(nFineRho, nFineT);
DataBox<Real> tempDiffE_h(nFineRho, nFineT);
DataBox<Real> tempDiffE_d(nFineRho, nFineT);

#ifdef PORTABILITY_STRATEGY_KOKKOS
RView tempSpinerDView("tempSpinerDevice", nFineRho * nFineT);
RView tempSpinerDViewE("tempSpinerSieDevice", nFineRho * nFineT);
RView::HostMirror tempSpinerHView = Kokkos::create_mirror_view(tempSpinerDView);
RView::HostMirror tempSpinerHViewE = Kokkos::create_mirror_view(tempSpinerDViewE);
DataBox tempSpiner_d(tempSpinerDView.data(), nFineRho, nFineT);
DataBox tempSpiner_hm(tempSpinerHView.data(), nFineRho, nFineT);
DataBox tempSpinerE_d(tempSpinerDViewE.data(), nFineRho, nFineT);
DataBox tempSpinerE_hm(tempSpinerHViewE.data(), nFineRho, nFineT);
DataBox<Real> tempSpiner_d(tempSpinerDView.data(), nFineRho, nFineT);
DataBox<Real> tempSpiner_hm(tempSpinerHView.data(), nFineRho, nFineT);
DataBox<Real> tempSpinerE_d(tempSpinerDViewE.data(), nFineRho, nFineT);
DataBox<Real> tempSpinerE_hm(tempSpinerHViewE.data(), nFineRho, nFineT);
RView rhos_v("rhos", nFineRho);
RView Ts_v("Ts", nFineT);
RView sies_v("sies", nFineT);
DataBox rhos(rhos_v.data(), nFineRho);
DataBox Ts(Ts_v.data(), nFineT);
DataBox sies(sies_v.data(), nFineT);
DataBox<Real> rhos(rhos_v.data(), nFineRho);
DataBox<Real> Ts(Ts_v.data(), nFineT);
DataBox<Real> sies(sies_v.data(), nFineT);
#else
DataBox tempSpiner_d(nFineRho, nFineT);
DataBox tempSpiner_hm = tempSpiner_d.slice(2, 0, nFineRho);
DataBox tempSpinerE_d(nFineRho, nFineT);
DataBox tempSpinerE_hm = tempSpiner_h.slice(2, 0, nFineRho);
DataBox rhos(nFineRho);
DataBox Ts(nFineT);
DataBox sies(nFineT);
DataBox<Real> tempSpiner_d(nFineRho, nFineT);
DataBox<Real> tempSpiner_hm = tempSpiner_d.slice(2, 0, nFineRho);
DataBox<Real> tempSpinerE_d(nFineRho, nFineT);
DataBox<Real> tempSpinerE_hm = tempSpiner_h.slice(2, 0, nFineRho);
DataBox<Real> rhos(nFineRho);
DataBox<Real> Ts(nFineT);
DataBox<Real> sies(nFineT);
#endif

std::cout << "Comparing to EOSPAC for materials..." << std::endl;
Expand Down Expand Up @@ -238,8 +239,8 @@ int main(int argc, char *argv[]) {
(Real *)PORTABLE_MALLOC(sizeof(Real) * nFineRho * nFineT * eos_host.nlambda());
Real *lambda_hp =
(Real *)malloc(sizeof(Real) * nFineRho * nFineT * eos_host.nlambda());
DataBox lambda_h(lambda_hp, nFineRho, nFineT, eos_host.nlambda());
DataBox lambda_d(lambda_dp, nFineRho, nFineT, eos_host.nlambda());
DataBox<Real> lambda_h(lambda_hp, nFineRho, nFineT, eos_host.nlambda());
DataBox<Real> lambda_d(lambda_dp, nFineRho, nFineT, eos_host.nlambda());

Real rhoMin = eosE_host.rhoMin();
Real rhoMax = eosE_host.rhoMax();
Expand Down Expand Up @@ -460,10 +461,10 @@ int main(int argc, char *argv[]) {
for (int n = 0; n < NTIMES; n++) {
for (int j = 0; j < nFineRho; j++) {
Real rho = lRhoBounds.i2lin(j);
DataBox lambda_hj = lambda_h.slice(j);
DataBox<Real> lambda_hj = lambda_h.slice(j);
for (int i = 0; i < nFineT; i++) {
Real sie = leBounds.i2lin(i);
DataBox lambda = lambda_hj.slice(i);
DataBox<Real> lambda = lambda_hj.slice(i);
tempSpiner_h(j, i) =
eos_host.TemperatureFromDensityInternalEnergy(rho, sie, lambda.data());
}
Expand All @@ -483,7 +484,7 @@ int main(int argc, char *argv[]) {
PORTABLE_LAMBDA(const int &j, const int &i) {
Real rho = rhos(j);
Real sie = sies(i);
DataBox lambda = lambda_d.slice(j).slice(i);
DataBox<Real> lambda = lambda_d.slice(j).slice(i);
tempSpiner_d(j, i) = eos_device.TemperatureFromDensityInternalEnergy(
rho, sie, lambda.data());
});
Expand Down
Loading
Loading