Skip to content

Commit

Permalink
well it works with HDF5 turned off now at least...
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahm-LANL committed Dec 8, 2023
1 parent f597c8b commit d5115e1
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 19 deletions.
15 changes: 13 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2021. Triad National Security, LLC. All rights reserved. This
# © 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
Expand All @@ -12,6 +12,7 @@
# publicly, and to permit others to do so.

cmake_minimum_required(VERSION 3.14)
set(CMAKE_CXX_STANDARD 17 CACHE BOOL "")

project("singularity-opac"
VERSION 0.0.1
Expand Down Expand Up @@ -53,11 +54,21 @@ target_include_directories(singularity-opac::flags
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)

include (SetupDeps)
include (SetupOptions)
include (SetupDeps)
include (SetupCompilers)
include (SetupFlags)

if (SINGULARITY_USE_HDF5)
message(STATUS "HDF5 enabled. Requesting it in spiner")
set(SPINER_USE_HDF ON CACHE BOOL "")
else()
message(STATUS "HDF5 not enabled. Turning it off in spiner")
set(SPINER_USE_HDF OFF CACHE BOOL "")
endif()
add_subdirectory(utils/spiner)
target_link_libraries(singularity-opac::flags INTERFACE spiner)

include(GNUInstallDirs)
include(CTest)

Expand Down
4 changes: 4 additions & 0 deletions cmake/SetupDeps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ endif()
#=======================================
# Can't play the target games above unless using
# cmake 3.20+, so leave this one for now.
# JMM: DO NOT SEARCH FOR HDF5 IF WE DON'T NEED IT
# HDF5 WILL SUCK US ALL INTO HELL
if (SPINER_USE_HDF)
find_package(HDF5 COMPONENTS C HL QUIET)

# findpackage doesnt export an interface for HDF5,
Expand Down Expand Up @@ -66,6 +69,7 @@ if (HDF5_FOUND)
endif()
endif()
endif()
endif()

#=======================================
# Setup Catch2
Expand Down
10 changes: 6 additions & 4 deletions singularity-opac/base/indexers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Identity {

class Linear {
public:
using DataBox = Spiner::DataBox<Real>;
Linear() = default;

PORTABLE_INLINE_FUNCTION
Expand All @@ -58,7 +59,7 @@ class Linear {
SetRange_(numin, numax, N);
}

PORTABLE_INLINE_FUNCTION Linear(const Spiner::DataBox &data, Real numin,
PORTABLE_INLINE_FUNCTION Linear(const DataBox &data, Real numin,
Real numax, int N)
: data_(data) {
SetRange_(numin, numax, N);
Expand All @@ -79,11 +80,12 @@ class Linear {
void SetRange_(Real numin, Real numax, int N) {
data_.setRange(0, numin, numax, N);
}
Spiner::DataBox data_;
DataBox data_;
};

class LogLinear {
public:
using DataBox = Spiner::DataBox<Real>;
LogLinear() = default;

PORTABLE_INLINE_FUNCTION
Expand All @@ -97,7 +99,7 @@ class LogLinear {
}

PORTABLE_INLINE_FUNCTION
LogLinear(const Spiner::DataBox &data, Real numin, Real numax, int N)
LogLinear(const DataBox &data, Real numin, Real numax, int N)
: data_(data) {
SetRange_(numin, numax, N);
}
Expand All @@ -119,7 +121,7 @@ class LogLinear {
void SetRange_(Real numin, Real numax, int N) {
data_.setRange(0, BDMath::log10(numin), BDMath::log10(numax), N);
}
Spiner::DataBox data_;
DataBox data_;
};

template <int N, typename Data_t>
Expand Down
5 changes: 3 additions & 2 deletions singularity-opac/neutrinos/mean_s_opacity_neutrinos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace impl {
template <typename ThermalDistribution, typename pc = PhysicalConstantsCGS>
class MeanSOpacity {
public:
using DataBox = Spiner::DataBox<Real>;
MeanSOpacity() = default;
template <typename SOpacity>
MeanSOpacity(const SOpacity &s_opac, const Real lRhoMin, const Real lRhoMax,
Expand Down Expand Up @@ -211,8 +212,8 @@ class MeanSOpacity {
PORTABLE_INLINE_FUNCTION Real fromLog_(const Real lx) const {
return std::pow(10., lx);
}
Spiner::DataBox lkappaPlanck_;
Spiner::DataBox lkappaRosseland_;
DataBox lkappaPlanck_;
DataBox lkappaRosseland_;
const char *filename_;
};

Expand Down
7 changes: 4 additions & 3 deletions singularity-opac/neutrinos/spiner_opac_neutrinos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ enum class DataStatus { Deallocated, OnDevice, OnHost };
template <typename ThermalDistribution, typename pc = PhysicalConstantsCGS>
class SpinerOpacity {
public:
using DataBox = Spiner::DataBox<Real>;
static constexpr Real EPS = 10.0 * std::numeric_limits<Real>::min();
static constexpr Real Hz2MeV = pc::h / (1e6 * pc::eV);
static constexpr Real MeV2Hz = 1 / Hz2MeV;
Expand Down Expand Up @@ -130,8 +131,8 @@ class SpinerOpacity {

// DataBox constructor. Note that this constructor *shallow* copies
// the databoxes, so they must be managed externally.
SpinerOpacity(const Spiner::DataBox &lalphanu, const Spiner::DataBox ljnu,
const Spiner::DataBox lJ, const Spiner::DataBox lJYe)
SpinerOpacity(const DataBox &lalphanu, const DataBox ljnu,
const DataBox lJ, const DataBox lJYe)
: memoryStatus_(impl::DataStatus::OnHost), lalphanu_(lalphanu),
ljnu_(ljnu), lJ_(lJ), lJYe_(lJYe) {}

Expand Down Expand Up @@ -391,7 +392,7 @@ class SpinerOpacity {
impl::DataStatus memoryStatus_ = impl::DataStatus::Deallocated;
// TODO(JMM): Integrating J and JYe seems wise.
// We can add more things here as needed.
Spiner::DataBox lalphanu_, ljnu_, lJ_, lJYe_;
DataBox lalphanu_, ljnu_, lJ_, lJYe_;
// TODO(JMM): Should we add table bounds? Given they're recorded in
// each spiner table, I lean towards no, but could be convinced
// otherwise if we need to do extrapolation, etc.
Expand Down
6 changes: 4 additions & 2 deletions singularity-opac/photons/mean_s_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ template <typename ThermalDistribution, typename pc = PhysicalConstantsCGS>
class MeanSOpacity {

public:
using DataBox = Spiner::DataBox<Real>;

MeanSOpacity() = default;
template <typename SOpacity>
MeanSOpacity(const SOpacity &s_opac, const Real lRhoMin, const Real lRhoMax,
Expand Down Expand Up @@ -192,8 +194,8 @@ class MeanSOpacity {
PORTABLE_INLINE_FUNCTION Real fromLog_(const Real lx) const {
return std::pow(10., lx);
}
Spiner::DataBox lkappaPlanck_;
Spiner::DataBox lkappaRosseland_;
DataBox lkappaPlanck_;
DataBox lkappaRosseland_;
const char *filename_;
};

Expand Down
3 changes: 2 additions & 1 deletion test/test_brt_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using namespace singularity;

using pc = PhysicalConstantsCGS;
using DataBox = Spiner::DataBox<Real>;

#ifdef PORTABILITY_STRATEGY_KOKKOS
using atomic_view = Kokkos::MemoryTraits<Kokkos::Atomic>;
Expand Down Expand Up @@ -169,7 +170,7 @@ TEST_CASE("BRT neutrino opacities", "[BRTNeutrinos]") {
nu_coeffs, nu_min, nu_max);
opac.EmissivityPerNu(rho, temp, Ye, type, nu_bins, J_cheb, nbins);
Real Jtrue = opac.EmissivityPerNu(rho, temp, Ye, type, nu);
J_cheb.SetInterpCoeffs(Spiner::DataBox(vm9, 9, 9));
J_cheb.SetInterpCoeffs(DataBox(vm9, 9, 9));
if (std::isnan(J_cheb(nu)) ||
((std::abs(Jtrue) >= 1e-14 || J_cheb(nu) >= 1e-14) &&
FractionalDifference(J_cheb(nu), Jtrue) > EPS_TEST)) {
Expand Down
4 changes: 3 additions & 1 deletion test/test_chebyshev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <singularity-opac/chebyshev/chebyshev.hpp>
using namespace singularity::chebyshev;

using DataBox = Spiner::DataBox<Real>;

#ifdef PORTABILITY_STRATEGY_KOKKOS
using atomic_view = Kokkos::MemoryTraits<Kokkos::Atomic>;
#endif
Expand Down Expand Up @@ -62,7 +64,7 @@ TEST_CASE("Chebyshev Polynomials", "[Chebyshev]") {
Real *ycoeffs = (Real *)PORTABLE_MALLOC(sizeof(Real) * N);
portableFor(
"Compute Cheb polynomial", 0, 1, PORTABLE_LAMBDA(const int &i) {
MatMultiply(Spiner::DataBox(vm9, 9, 9), y, ycoeffs, N);
MatMultiply(DataBox(vm9, 9, 9), y, ycoeffs, N);
});
AND_THEN("The chebyshev polynomials fit") {
int n_wrong_h = 0;
Expand Down
3 changes: 2 additions & 1 deletion test/test_epbremsstrahlung_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using namespace singularity;

using pc = PhysicalConstantsCGS;
using DataBox = Spiner::DataBox<Real>;

#ifdef PORTABILITY_STRATEGY_KOKKOS
using atomic_view = Kokkos::MemoryTraits<Kokkos::Atomic>;
Expand Down Expand Up @@ -132,7 +133,7 @@ TEST_CASE("E-P bremsstrahlung photon opacities", "[EPBremsstrahlungPhotons]") {

Real *nu_bins = (Real *)PORTABLE_MALLOC(nbins * sizeof(Real));
Real *temp_bins = (Real *)PORTABLE_MALLOC(ntemps * sizeof(Real));
Spiner::DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps,
DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps,
nbins);

portableFor(
Expand Down
5 changes: 3 additions & 2 deletions test/test_gray_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using namespace singularity;

using pc = PhysicalConstantsCGS;
using DataBox = Spiner::DataBox<Real>;

#ifdef PORTABILITY_STRATEGY_KOKKOS
using atomic_view = Kokkos::MemoryTraits<Kokkos::Atomic>;
Expand Down Expand Up @@ -167,7 +168,7 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") {
nu_coeffs, nu_min, nu_max);
opac.EmissivityPerNu(rho, temp, Ye, type, nu_bins, J_cheb, nbins);
Real Jtrue = opac.EmissivityPerNu(rho, temp, Ye, type, nu);
J_cheb.SetInterpCoeffs(Spiner::DataBox(vm9, 9, 9));
J_cheb.SetInterpCoeffs(DataBox(vm9, 9, 9));
if (std::isnan(J_cheb(nu)) ||
((std::abs(Jtrue) >= 1e-14 || J_cheb(nu) >= 1e-14) &&
FractionalDifference(J_cheb(nu), Jtrue) > EPS_TEST)) {
Expand Down Expand Up @@ -282,7 +283,7 @@ TEST_CASE("Gray photon opacities", "[GrayPhotons]") {

Real *nu_bins = (Real *)PORTABLE_MALLOC(nbins * sizeof(Real));
Real *temp_bins = (Real *)PORTABLE_MALLOC(ntemps * sizeof(Real));
Spiner::DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps,
DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps,
nbins);

portableFor(
Expand Down
2 changes: 1 addition & 1 deletion test/test_spiner_opac_neutrinos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST_CASE("Spiner opacities, filled with gray data",
const std::string grayname = "gray.sp5";

WHEN("We initialize a gray neutrino opacity and tabulate it") {
using Grid_t = Spiner::RegularGrid1D;
using Grid_t = Spiner::RegularGrid1D<Real>;

// Offset the frequencies to hopefully get over the point
// where the power laws transition
Expand Down

0 comments on commit d5115e1

Please sign in to comment.