From eddf3b303ec8d6f3279ed5625a45d6062ea8ce34 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Thu, 26 Sep 2024 13:41:28 -0600 Subject: [PATCH 1/8] Return physical constants object from opacities --- .../neutrinos/gray_opacity_neutrinos.hpp | 3 +++ .../neutrinos/mean_neutrino_variant.hpp | 12 +++++++++- .../neutrinos/mean_opacity_neutrinos.hpp | 4 ++++ .../photons/gray_opacity_photons.hpp | 3 +++ .../photons/mean_opacity_photons.hpp | 3 +++ .../photons/mean_photon_variant.hpp | 7 +++++- singularity-opac/photons/photon_variant.hpp | 7 +++++- test/test_gray_opacities.cpp | 6 +++-- test/test_mean_opacities.cpp | 24 +++++++++++++++---- 9 files changed, 60 insertions(+), 9 deletions(-) diff --git a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp index fc9a57e..b1f527b 100644 --- a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp @@ -173,6 +173,9 @@ class GrayOpacity { return dist_.NumberDensityFromTemperature(temp, type, lambda); } + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + private: Real kappa_; // Opacity. Units of cm^2/g ThermalDistribution dist_; diff --git a/singularity-opac/neutrinos/mean_neutrino_variant.hpp b/singularity-opac/neutrinos/mean_neutrino_variant.hpp index fd50081..079e463 100644 --- a/singularity-opac/neutrinos/mean_neutrino_variant.hpp +++ b/singularity-opac/neutrinos/mean_neutrino_variant.hpp @@ -28,7 +28,7 @@ namespace singularity { namespace neutrinos { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -88,6 +88,16 @@ class MeanVariant { opac_); } + PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, + opac_); + } + // static CONSTANTS GetPhysicalConstants() { + // return mpark::visit( + // [](auto &opac) { return decltype(opac)::GetPhysicalConstants(); }, + // opac_); + // } + inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index 61a6396..4124319 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -102,6 +102,10 @@ class MeanOpacity { return other; } + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + // static pc GetPhysicalConstants() { return pc(); } + void Finalize() { lkappaPlanck_.finalize(); lkappaRosseland_.finalize(); diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index 9bc0358..434df97 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -165,6 +165,9 @@ class GrayOpacity { return dist_.NumberDensityFromTemperature(temp, lambda); } + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + private: Real kappa_; // Opacity. Units of cm^2/g PlanckDistribution dist_; diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index 8a58859..4e0b410 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -119,6 +119,9 @@ class MeanOpacity { return rho * fromLog_(lkappaRosseland_.interpToReal(lRho, lT)); } + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + private: template void MeanOpacityImpl_(const Opacity &opac, const Real lRhoMin, diff --git a/singularity-opac/photons/mean_photon_variant.hpp b/singularity-opac/photons/mean_photon_variant.hpp index af292ea..604d061 100644 --- a/singularity-opac/photons/mean_photon_variant.hpp +++ b/singularity-opac/photons/mean_photon_variant.hpp @@ -28,7 +28,7 @@ namespace singularity { namespace photons { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -86,6 +86,11 @@ class MeanVariant { opac_); } + PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, + opac_); + } + inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index 440e5e8..b0c9979 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -30,7 +30,7 @@ namespace impl { template using opac_variant = mpark::variant; -template +template class Variant { private: opac_variant opac_; @@ -275,6 +275,11 @@ class Variant { opac_); } + PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, + opac_); + } + inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index 464dbd1..a26ad73 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -57,6 +57,9 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") { neutrinos::Gray opac_host(1); neutrinos::Opacity opac = opac_host.GetOnDevice(); + auto constants = opac_host.GetPhysicalConstants(); + printf("cl: %e\n", constants.c); + THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS @@ -283,8 +286,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)); - DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps, - nbins); + DataBox loglin_bins(Spiner::AllocationTarget::Device, ntemps, nbins); portableFor( "set nu bins", 0, nbins, PORTABLE_LAMBDA(const int &i) { diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index b6ad91f..467f583 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2022. Triad National Security, LLC. All rights reserved. This +// © 2022-2024. 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. @@ -46,7 +46,7 @@ using atomic_view = Kokkos::MemoryTraits; template PORTABLE_INLINE_FUNCTION T FractionalDifference(const T &a, const T &b) { - return 2 * std::abs(b - a) / (std::abs(a) + std::abs(b) + 1e-20); + return 2 * std::abs(b - a) / (std::abs(a) + std::abs(b) + 1e-100); } constexpr Real EPS_TEST = 1e-3; template @@ -89,9 +89,24 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") { neutrinos::MeanOpacityCGS mean_opac_host( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe); - // neutrinos::MeanOpacity mean_opac = mean_opac_host.GetOnDevice(); auto mean_opac = mean_opac_host.GetOnDevice(); + // Check constants from mean opacity + THEN("Check constants from mean opacity for consistency") { + auto constants = mean_opac_host.GetPhysicalConstants(); + int n_wrong = 0; + if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { + n_wrong += 1; + } + REQUIRE(n_wrong == 0); + } + THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS @@ -611,7 +626,8 @@ TEST_CASE("Mean photon scattering opacities", "[MeanPhotonS]") { int n_wrong = 0; portableReduce( "rebuilt table vs gray", 0, NRho, 0, NT, 0, 0, - PORTABLE_LAMBDA(const int iRho, const int iT, const int igarbage, int &accumulate) { + PORTABLE_LAMBDA(const int iRho, const int iT, const int igarbage, + int &accumulate) { const Real lRho = lRhoMin + (lRhoMax - lRhoMin) / (NRho - 1) * iRho; const Real rho = std::pow(10, lRho); From 6d5323c44e3b21a067ade777840567b7ec4121dd Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Thu, 26 Sep 2024 16:02:37 -0600 Subject: [PATCH 2/8] variant cant deduce template argument for different types across variants --- singularity-opac/neutrinos/brt_neutrinos.hpp | 4 +++ .../neutrinos/mean_neutrino_variant.hpp | 9 ++--- .../neutrinos/mean_opacity_neutrinos.hpp | 1 - .../neutrinos/neutrino_variant.hpp | 6 ++++ .../neutrinos/non_cgs_neutrinos.hpp | 15 +++++--- .../neutrinos/tophat_emissivity_neutrinos.hpp | 4 +++ .../epbremsstrahlung_opacity_photons.hpp | 4 +++ .../photons/gray_opacity_photons.hpp | 7 ++-- .../photons/mean_opacity_photons.hpp | 2 +- .../photons/mean_photon_variant.hpp | 6 ++-- singularity-opac/photons/non_cgs_photons.hpp | 12 +++++-- singularity-opac/photons/photon_variant.hpp | 5 +-- .../photons/powerlaw_opacity_photons.hpp | 4 +++ test/test_gray_opacities.cpp | 36 +++++++++++++++++-- test/test_mean_opacities.cpp | 17 ++++++++- 15 files changed, 104 insertions(+), 28 deletions(-) diff --git a/singularity-opac/neutrinos/brt_neutrinos.hpp b/singularity-opac/neutrinos/brt_neutrinos.hpp index 5721021..33ce8a7 100644 --- a/singularity-opac/neutrinos/brt_neutrinos.hpp +++ b/singularity-opac/neutrinos/brt_neutrinos.hpp @@ -42,6 +42,10 @@ class BRTOpacity { void PrintParams() const noexcept { printf("Burrows-Reddy-Thompson analytic neutrino opacity.\n"); } + + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/neutrinos/mean_neutrino_variant.hpp b/singularity-opac/neutrinos/mean_neutrino_variant.hpp index 079e463..0ee0b72 100644 --- a/singularity-opac/neutrinos/mean_neutrino_variant.hpp +++ b/singularity-opac/neutrinos/mean_neutrino_variant.hpp @@ -28,7 +28,7 @@ namespace singularity { namespace neutrinos { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -88,15 +88,10 @@ class MeanVariant { opac_); } - PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + PORTABLE_INLINE_FUNCTION PC GetPhysicalConstants() const { return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, opac_); } - // static CONSTANTS GetPhysicalConstants() { - // return mpark::visit( - // [](auto &opac) { return decltype(opac)::GetPhysicalConstants(); }, - // opac_); - // } inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index 4124319..047935b 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -104,7 +104,6 @@ class MeanOpacity { PORTABLE_INLINE_FUNCTION pc GetPhysicalConstants() const { return pc(); } - // static pc GetPhysicalConstants() { return pc(); } void Finalize() { lkappaPlanck_.finalize(); diff --git a/singularity-opac/neutrinos/neutrino_variant.hpp b/singularity-opac/neutrinos/neutrino_variant.hpp index ae14525..137ce93 100644 --- a/singularity-opac/neutrinos/neutrino_variant.hpp +++ b/singularity-opac/neutrinos/neutrino_variant.hpp @@ -290,6 +290,12 @@ class Variant { opac_); } + template + PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { + return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, + opac_); + } + inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp index 7a760c7..02f8bce 100644 --- a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp +++ b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp @@ -47,6 +47,12 @@ class NonCGSUnits { return NonCGSUnits(opac_.GetOnDevice(), time_unit_, mass_unit_, length_unit_, temp_unit_); } + + template + PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { + return opac_.GetPhysicalConstants(); + } + inline void Finalize() noexcept { opac_.Finalize(); } PORTABLE_INLINE_FUNCTION @@ -66,10 +72,11 @@ class NonCGSUnits { } template - PORTABLE_INLINE_FUNCTION void AbsorptionCoefficient( - const Real rho, const Real temp, const Real Ye, RadiationType type, - FrequencyIndexer &nu_bins, DataIndexer &coeffs, const int nbins, - Real *lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION void + AbsorptionCoefficient(const Real rho, const Real temp, const Real Ye, + RadiationType type, FrequencyIndexer &nu_bins, + DataIndexer &coeffs, const int nbins, + Real *lambda = nullptr) const { for (int i = 0; i < nbins; ++i) { nu_bins[i] *= freq_unit_; } diff --git a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp index ee7b9b1..a5cd724 100644 --- a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp +++ b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp @@ -46,6 +46,10 @@ class TophatEmissivity { printf("Tophat emissivity. C, numin, numax = %g, %g, %g\n", C_, numin_, numax_); } + + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp index e4e9ccc..fe99261 100644 --- a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp +++ b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp @@ -42,6 +42,10 @@ class EPBremsstrahlungOpacity { void PrintParams() const noexcept { printf("Electron-proton bremsstrahlung opacity.\n"); } + + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index 434df97..ff9f5bc 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -42,6 +42,10 @@ class GrayOpacity { void PrintParams() const noexcept { printf("Gray opacity. kappa = %g\n", kappa_); } + + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION @@ -165,9 +169,6 @@ class GrayOpacity { return dist_.NumberDensityFromTemperature(temp, lambda); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - private: Real kappa_; // Opacity. Units of cm^2/g PlanckDistribution dist_; diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index 4e0b410..ebbde58 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2022. Triad National Security, LLC. All rights reserved. This +// © 2022-2024. 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. diff --git a/singularity-opac/photons/mean_photon_variant.hpp b/singularity-opac/photons/mean_photon_variant.hpp index 604d061..e1f2941 100644 --- a/singularity-opac/photons/mean_photon_variant.hpp +++ b/singularity-opac/photons/mean_photon_variant.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2022. Triad National Security, LLC. All rights reserved. This +// © 2022-2024. 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. @@ -28,7 +28,7 @@ namespace singularity { namespace photons { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -86,7 +86,7 @@ class MeanVariant { opac_); } - PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + PORTABLE_INLINE_FUNCTION PC GetPhysicalConstants() const { return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, opac_); } diff --git a/singularity-opac/photons/non_cgs_photons.hpp b/singularity-opac/photons/non_cgs_photons.hpp index a63df14..034b0e0 100644 --- a/singularity-opac/photons/non_cgs_photons.hpp +++ b/singularity-opac/photons/non_cgs_photons.hpp @@ -65,9 +65,10 @@ class NonCGSUnits { } template - PORTABLE_INLINE_FUNCTION void AbsorptionCoefficient( - const Real rho, const Real temp, FrequencyIndexer &nu_bins, - DataIndexer &coeffs, const int nbins, Real *lambda = nullptr) const { + PORTABLE_INLINE_FUNCTION void + AbsorptionCoefficient(const Real rho, const Real temp, + FrequencyIndexer &nu_bins, DataIndexer &coeffs, + const int nbins, Real *lambda = nullptr) const { for (int i = 0; i < nbins; ++i) { nu_bins[i] *= freq_unit_; } @@ -219,6 +220,11 @@ class NonCGSUnits { return NoH * mass_unit_ / rho_unit_; } + template + PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { + return opac_.GetPhysicalConstants(); + } + private: Opac opac_; Real time_unit_, mass_unit_, length_unit_, temp_unit_; diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index b0c9979..61efad5 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -30,7 +30,7 @@ namespace impl { template using opac_variant = mpark::variant; -template +template class Variant { private: opac_variant opac_; @@ -275,7 +275,8 @@ class Variant { opac_); } - PORTABLE_INLINE_FUNCTION CONSTANTS GetPhysicalConstants() const { + template + PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, opac_); } diff --git a/singularity-opac/photons/powerlaw_opacity_photons.hpp b/singularity-opac/photons/powerlaw_opacity_photons.hpp index 7efe5e6..8612936 100644 --- a/singularity-opac/photons/powerlaw_opacity_photons.hpp +++ b/singularity-opac/photons/powerlaw_opacity_photons.hpp @@ -45,6 +45,10 @@ class PowerLawOpacity { printf("Power law opacity. kappa0 = %g rho_exp = %g temp_exp = %g\n", kappa0_, rho_exp_, temp_exp_); } + + PORTABLE_INLINE_FUNCTION + pc GetPhysicalConstants() const { return pc(); } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index a26ad73..166331c 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. @@ -57,8 +57,21 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") { neutrinos::Gray opac_host(1); neutrinos::Opacity opac = opac_host.GetOnDevice(); - auto constants = opac_host.GetPhysicalConstants(); - printf("cl: %e\n", constants.c); + // Check constants from mean opacity + THEN("Check constants from mean opacity for consistency") { + auto constants = opac_host.GetPhysicalConstants(); + int n_wrong = 0; + if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { + n_wrong += 1; + } + REQUIRE(n_wrong == 0); + } THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; @@ -206,6 +219,23 @@ TEST_CASE("Gray photon opacities", "[GrayPhotons]") { photons::Opacity opac_host = photons::Gray(1); photons::Opacity opac = opac_host.GetOnDevice(); + + // Check constants from mean opacity + THEN("Check constants from mean opacity for consistency") { + auto constants = opac_host.GetPhysicalConstants(); + int n_wrong = 0; + if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { + n_wrong += 1; + } + REQUIRE(n_wrong == 0); + } + THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index 467f583..6d35c06 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -268,7 +268,6 @@ TEST_CASE("Mean neutrino scattering opacities", "[MeanNeutrinosS]") { neutrinos::MeanSOpacityCGS mean_opac_host( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe); - // neutrinos::MeanOpacity mean_opac = mean_opac_host.GetOnDevice(); auto mean_opac = mean_opac_host.GetOnDevice(); THEN("The emissivity per nu omega is consistent with the emissity per nu") { @@ -433,6 +432,22 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { lTMin, lTMax, NT); auto mean_opac = mean_opac_host.GetOnDevice(); + // Check constants from mean opacity + THEN("Check constants from mean opacity for consistency") { + auto constants = mean_opac_host.GetPhysicalConstants(); + int n_wrong = 0; + if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { + n_wrong += 1; + } + if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { + n_wrong += 1; + } + REQUIRE(n_wrong == 0); + } + THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS From abbef3c2d0278b5a395a435de38b8f5510a0ef81 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 15:10:21 -0600 Subject: [PATCH 3/8] Constants now work, runtime only --- singularity-opac/constants/constants.hpp | 39 +++++++++++++++++++ singularity-opac/neutrinos/brt_neutrinos.hpp | 2 + .../neutrinos/gray_opacity_neutrinos.hpp | 12 +++++- .../neutrinos/neutrino_variant.hpp | 21 +++++++--- .../neutrinos/non_cgs_neutrinos.hpp | 7 +--- .../neutrinos/spiner_opac_neutrinos.hpp | 12 +++--- .../neutrinos/tophat_emissivity_neutrinos.hpp | 2 + .../epbremsstrahlung_opacity_photons.hpp | 2 + .../photons/gray_opacity_photons.hpp | 2 + singularity-opac/photons/non_cgs_photons.hpp | 2 + singularity-opac/photons/photon_variant.hpp | 21 +++++++--- .../photons/powerlaw_opacity_photons.hpp | 2 + test/test_gray_opacities.cpp | 9 +++-- 13 files changed, 107 insertions(+), 26 deletions(-) diff --git a/singularity-opac/constants/constants.hpp b/singularity-opac/constants/constants.hpp index 580037a..58feff9 100644 --- a/singularity-opac/constants/constants.hpp +++ b/singularity-opac/constants/constants.hpp @@ -194,6 +194,45 @@ struct PhysicalConstants { static constexpr Real gA = axial_vector_coupling_constant; }; +struct RuntimePhysicalConstants { + template + RuntimePhysicalConstants(T pc) + : na(pc.na), alpha(pc.alpha), h(pc.h), hbar(pc.hbar), kb(pc.kb), + r_gas(pc.r_gas), qe(pc.qe), c(pc.c), g_newt(pc.g_newt), + g_accel(pc.g_accel), me(pc.me), mp(pc.mp), mn(pc.mn), amu(pc.amu), + sb(pc.sb), ar(pc.ar), faraday(pc.faraday), mu0(pc.mu0), eps0(pc.eps0), + eV(pc.eV), Fc(pc.Fc), nu_sigma0(pc.nu_sigma0), gA(pc.gA) {} + + const Real na; + const Real alpha; + const Real h; + const Real hbar; + const Real kb; + const Real r_gas; + const Real qe; + const Real c; + const Real g_newt; + const Real g_accel; + const Real me; + const Real mp; + const Real mn; + const Real amu; + const Real sb; + const Real ar; + const Real faraday; + const Real mu0; + const Real eps0; + const Real eV; + const Real Fc; + const Real nu_sigma0; + const Real gA; +}; + +template +RuntimePhysicalConstants GetRuntimePhysicalConstants(T phys_constants) { + return RuntimePhysicalConstants(phys_constants); +} + using PhysicalConstantsUnity = PhysicalConstants; using PhysicalConstantsSI = diff --git a/singularity-opac/neutrinos/brt_neutrinos.hpp b/singularity-opac/neutrinos/brt_neutrinos.hpp index 33ce8a7..fc37c57 100644 --- a/singularity-opac/neutrinos/brt_neutrinos.hpp +++ b/singularity-opac/neutrinos/brt_neutrinos.hpp @@ -32,6 +32,8 @@ namespace neutrinos { template class BRTOpacity { public: + using PC = pc; + BRTOpacity() = default; BRTOpacity(const ThermalDistribution &dist) : dist_(dist) {} BRTOpacity GetOnDevice() { return *this; } diff --git a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp index b1f527b..81a831a 100644 --- a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp @@ -30,6 +30,8 @@ namespace neutrinos { template class GrayOpacity { public: + using PC = pc; + GrayOpacity() = default; GrayOpacity(const Real kappa) : kappa_(kappa) {} GrayOpacity(const ThermalDistribution &dist, const Real kappa) @@ -42,6 +44,12 @@ class GrayOpacity { void PrintParams() const noexcept { printf("Gray opacity. kappa = %g\n", kappa_); } + + PORTABLE_INLINE_FUNCTION + RuntimePhysicalConstants GetPhysicalConstants() const { + return GetRuntimePhysicalConstants(pc()); + } + inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION @@ -173,8 +181,8 @@ class GrayOpacity { return dist_.NumberDensityFromTemperature(temp, type, lambda); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } + // PORTABLE_INLINE_FUNCTION + // pc GetPhysicalConstants() const { return pc(); } private: Real kappa_; // Opacity. Units of cm^2/g diff --git a/singularity-opac/neutrinos/neutrino_variant.hpp b/singularity-opac/neutrinos/neutrino_variant.hpp index 137ce93..4660c3b 100644 --- a/singularity-opac/neutrinos/neutrino_variant.hpp +++ b/singularity-opac/neutrinos/neutrino_variant.hpp @@ -71,6 +71,16 @@ class Variant { opac_); } + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return mpark::visit( + [=](const auto &opac) { + using PC = typename std::decay_t::PC; + return singularity::GetRuntimePhysicalConstants(PC()); + }, + opac_); + } + // Directional absorption coefficient with units of 1/length // Signature should be at least // rho, temp, Ye, type, nu, lambda @@ -290,11 +300,12 @@ class Variant { opac_); } - template - PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { - return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, - opac_); - } + // template + // PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { + // return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); + // }, + // opac_); + //} inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); diff --git a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp index 02f8bce..4167f72 100644 --- a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp +++ b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp @@ -29,6 +29,8 @@ namespace neutrinos { template class NonCGSUnits { public: + using PC = typename Opac::PC; + NonCGSUnits() = default; NonCGSUnits(Opac &&opac, const Real time_unit, const Real mass_unit, const Real length_unit, const Real temp_unit) @@ -48,11 +50,6 @@ class NonCGSUnits { length_unit_, temp_unit_); } - template - PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { - return opac_.GetPhysicalConstants(); - } - inline void Finalize() noexcept { opac_.Finalize(); } PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp b/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp index 07c6a7b..2b26dbd 100644 --- a/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp +++ b/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp @@ -61,6 +61,7 @@ enum class DataStatus { Deallocated, OnDevice, OnHost }; template class SpinerOpacity { public: + using PC = pc; using DataBox = Spiner::DataBox; static constexpr Real EPS = 10.0 * std::numeric_limits::min(); static constexpr Real Hz2MeV = pc::h / (1e6 * pc::eV); @@ -110,7 +111,8 @@ class SpinerOpacity { Real J = std::max(opac.Emissivity(rho, T * MeV2K, Ye, type), 0.0); Real lJ = toLog_(J); lJ_(iRho, iT, iYe, idx) = lJ; - Real JYe = std::max(opac.NumberEmissivity(rho, T * MeV2K, Ye, type), 0.0); + Real JYe = + std::max(opac.NumberEmissivity(rho, T * MeV2K, Ye, type), 0.0); lJYe_(iRho, iT, iYe, idx) = toLog_(JYe); for (int ie = 0; ie < Ne; ++ie) { Real lE = lalphanu_.range(0).x(ie); @@ -119,8 +121,8 @@ class SpinerOpacity { Real alpha = std::max( opac.AbsorptionCoefficient(rho, T, Ye, type, nu), 0.0); lalphanu_(iRho, iT, iYe, idx, ie) = toLog_(alpha); - Real j = std::max(opac.EmissivityPerNuOmega(rho, T * MeV2K, Ye, type, nu), - 0.0); + Real j = std::max( + opac.EmissivityPerNuOmega(rho, T * MeV2K, Ye, type, nu), 0.0); ljnu_(iRho, iT, iYe, idx, ie) = toLog_(j); } } @@ -131,8 +133,8 @@ class SpinerOpacity { // DataBox constructor. Note that this constructor *shallow* copies // the databoxes, so they must be managed externally. - SpinerOpacity(const DataBox &lalphanu, const DataBox ljnu, - const DataBox lJ, const 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) {} diff --git a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp index a5cd724..894d007 100644 --- a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp +++ b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp @@ -32,6 +32,8 @@ namespace neutrinos { template class TophatEmissivity { public: + using PC = pc; + TophatEmissivity(const Real C, const Real numin, const Real numax) : C_(C), numin_(numin), numax_(numax) {} TophatEmissivity(const ThermalDistribution &dist, const Real C, diff --git a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp index fe99261..077f629 100644 --- a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp +++ b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp @@ -32,6 +32,8 @@ namespace photons { template class EPBremsstrahlungOpacity { public: + using PC = pc; + EPBremsstrahlungOpacity() = default; EPBremsstrahlungOpacity(const PlanckDistribution &dist) : dist_(dist) {} diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index ff9f5bc..9a6f68c 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -30,6 +30,8 @@ namespace photons { template class GrayOpacity { public: + using PC = pc; + GrayOpacity() = default; GrayOpacity(const Real kappa) : kappa_(kappa) {} GrayOpacity(const PlanckDistribution &dist, const Real kappa) diff --git a/singularity-opac/photons/non_cgs_photons.hpp b/singularity-opac/photons/non_cgs_photons.hpp index 034b0e0..e22c3e7 100644 --- a/singularity-opac/photons/non_cgs_photons.hpp +++ b/singularity-opac/photons/non_cgs_photons.hpp @@ -29,6 +29,8 @@ namespace photons { template class NonCGSUnits { public: + using PC = typename Opac::PC; + NonCGSUnits() = default; NonCGSUnits(Opac &&opac, const Real time_unit, const Real mass_unit, const Real length_unit, const Real temp_unit) diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index 61efad5..4a3efe8 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -71,6 +71,16 @@ class Variant { opac_); } + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return mpark::visit( + [=](const auto &opac) { + using PC = typename std::decay_t::PC; + return singularity::GetRuntimePhysicalConstants(PC()); + }, + opac_); + } + // Directional absorption coefficient with units of 1/length // Signature should be at least // rho, temp, nu, lambda @@ -275,11 +285,12 @@ class Variant { opac_); } - template - PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { - return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, - opac_); - } + // template + // PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { + // return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); + // }, + // opac_); + //} inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); diff --git a/singularity-opac/photons/powerlaw_opacity_photons.hpp b/singularity-opac/photons/powerlaw_opacity_photons.hpp index 8612936..2794e2c 100644 --- a/singularity-opac/photons/powerlaw_opacity_photons.hpp +++ b/singularity-opac/photons/powerlaw_opacity_photons.hpp @@ -30,6 +30,8 @@ namespace photons { template class PowerLawOpacity { public: + using PC = pc; + PowerLawOpacity() = default; PowerLawOpacity(const Real kappa0, const Real rho_exp, const Real temp_exp) : kappa0_(kappa0), rho_exp_(rho_exp), temp_exp_(temp_exp) {} diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index 166331c..cb069be 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -54,12 +54,13 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") { constexpr RadiationType type = RadiationType::NU_ELECTRON; constexpr Real nu = 1.25 * MeV2Hz; // 1 MeV - neutrinos::Gray opac_host(1); + // neutrinos::Gray opac_host(1); + neutrinos::Opacity opac_host = neutrinos::Gray(1); neutrinos::Opacity opac = opac_host.GetOnDevice(); - // Check constants from mean opacity + // Check constants from opacity THEN("Check constants from mean opacity for consistency") { - auto constants = opac_host.GetPhysicalConstants(); + auto constants = opac_host.GetRuntimePhysicalConstants(); int n_wrong = 0; if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { n_wrong += 1; @@ -222,7 +223,7 @@ TEST_CASE("Gray photon opacities", "[GrayPhotons]") { // Check constants from mean opacity THEN("Check constants from mean opacity for consistency") { - auto constants = opac_host.GetPhysicalConstants(); + auto constants = opac_host.GetRuntimePhysicalConstants(); int n_wrong = 0; if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { n_wrong += 1; From 2a26ada0a12cef5de0843a9c746382bd081e1c9f Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 15:18:18 -0600 Subject: [PATCH 4/8] cleanup --- singularity-opac/neutrinos/brt_neutrinos.hpp | 3 --- singularity-opac/neutrinos/gray_opacity_neutrinos.hpp | 5 ----- singularity-opac/neutrinos/neutrino_variant.hpp | 7 ------- singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp | 3 --- singularity-opac/photons/gray_opacity_photons.hpp | 3 --- singularity-opac/photons/photon_variant.hpp | 7 ------- 6 files changed, 28 deletions(-) diff --git a/singularity-opac/neutrinos/brt_neutrinos.hpp b/singularity-opac/neutrinos/brt_neutrinos.hpp index fc37c57..0c90e90 100644 --- a/singularity-opac/neutrinos/brt_neutrinos.hpp +++ b/singularity-opac/neutrinos/brt_neutrinos.hpp @@ -45,9 +45,6 @@ class BRTOpacity { printf("Burrows-Reddy-Thompson analytic neutrino opacity.\n"); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp index 81a831a..b64f09d 100644 --- a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp @@ -45,11 +45,6 @@ class GrayOpacity { printf("Gray opacity. kappa = %g\n", kappa_); } - PORTABLE_INLINE_FUNCTION - RuntimePhysicalConstants GetPhysicalConstants() const { - return GetRuntimePhysicalConstants(pc()); - } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/neutrinos/neutrino_variant.hpp b/singularity-opac/neutrinos/neutrino_variant.hpp index 4660c3b..8e3a745 100644 --- a/singularity-opac/neutrinos/neutrino_variant.hpp +++ b/singularity-opac/neutrinos/neutrino_variant.hpp @@ -300,13 +300,6 @@ class Variant { opac_); } - // template - // PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { - // return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); - // }, - // opac_); - //} - inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp index 894d007..2831052 100644 --- a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp +++ b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp @@ -49,9 +49,6 @@ class TophatEmissivity { numax_); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index 9a6f68c..417f10c 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -45,9 +45,6 @@ class GrayOpacity { printf("Gray opacity. kappa = %g\n", kappa_); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index 4a3efe8..ef53b4d 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -285,13 +285,6 @@ class Variant { opac_); } - // template - // PORTABLE_INLINE_FUNCTION T GetPhysicalConstants() const { - // return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); - // }, - // opac_); - //} - inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } From bfaeb1d1fcd2f3c520921785c87b393d854d9a2b Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 19:40:18 -0600 Subject: [PATCH 5/8] Constants returned from opacities but not mean opacities; developer beware --- singularity-opac/neutrinos/brt_neutrinos.hpp | 1 - .../neutrinos/gray_opacity_neutrinos.hpp | 4 -- .../neutrinos/mean_neutrino_variant.hpp | 17 ++++--- .../neutrinos/mean_opacity_neutrinos.hpp | 12 +++-- .../photons/mean_opacity_photons.hpp | 17 +++---- .../photons/mean_photon_variant.hpp | 17 ++++--- test/test_mean_opacities.cpp | 46 +++++-------------- 7 files changed, 49 insertions(+), 65 deletions(-) diff --git a/singularity-opac/neutrinos/brt_neutrinos.hpp b/singularity-opac/neutrinos/brt_neutrinos.hpp index 0c90e90..35b086a 100644 --- a/singularity-opac/neutrinos/brt_neutrinos.hpp +++ b/singularity-opac/neutrinos/brt_neutrinos.hpp @@ -44,7 +44,6 @@ class BRTOpacity { void PrintParams() const noexcept { printf("Burrows-Reddy-Thompson analytic neutrino opacity.\n"); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp index b64f09d..93c6d15 100644 --- a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp @@ -44,7 +44,6 @@ class GrayOpacity { void PrintParams() const noexcept { printf("Gray opacity. kappa = %g\n", kappa_); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION @@ -176,9 +175,6 @@ class GrayOpacity { return dist_.NumberDensityFromTemperature(temp, type, lambda); } - // PORTABLE_INLINE_FUNCTION - // pc GetPhysicalConstants() const { return pc(); } - private: Real kappa_; // Opacity. Units of cm^2/g ThermalDistribution dist_; diff --git a/singularity-opac/neutrinos/mean_neutrino_variant.hpp b/singularity-opac/neutrinos/mean_neutrino_variant.hpp index 0ee0b72..d6c77c3 100644 --- a/singularity-opac/neutrinos/mean_neutrino_variant.hpp +++ b/singularity-opac/neutrinos/mean_neutrino_variant.hpp @@ -28,7 +28,7 @@ namespace singularity { namespace neutrinos { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -69,6 +69,16 @@ class MeanVariant { opac_); } + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return mpark::visit( + [=](const auto &opac) { + using PC = typename std::decay_t::PC; + return singularity::GetRuntimePhysicalConstants(PC()); + }, + opac_); + } + PORTABLE_INLINE_FUNCTION Real PlanckMeanAbsorptionCoefficient( const Real rho, const Real temp, const Real Ye, const RadiationType type) const { @@ -88,11 +98,6 @@ class MeanVariant { opac_); } - PORTABLE_INLINE_FUNCTION PC GetPhysicalConstants() const { - return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, - opac_); - } - inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index 047935b..ba7dbe8 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -41,6 +41,8 @@ template class MeanOpacity { public: + using PC = pc; + MeanOpacity() = default; template MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax, @@ -102,9 +104,6 @@ class MeanOpacity { return other; } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - void Finalize() { lkappaPlanck_.finalize(); lkappaRosseland_.finalize(); @@ -137,6 +136,9 @@ class MeanOpacity { const Real lTMax, const int NT, const Real YeMin, const Real YeMax, const int NYe, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { + static_assert(std::is_same::value, + "Mean opacity constants must match opacity constants"); + lkappaPlanck_.resize(NRho, NT, NYe, NEUTRINO_NTYPES); // index 0 is the species and is not interpolatable lkappaPlanck_.setRange(1, YeMin, YeMax, NYe); @@ -162,8 +164,8 @@ class MeanOpacity { // Choose default temperature-specific frequency grid if frequency // grid not specified if (AUTOFREQ) { - lNuMin = toLog_(1.e-3 * pc::kb * fromLog_(lTMin) / pc::h); - lNuMax = toLog_(1.e3 * pc::kb * fromLog_(lTMax) / pc::h); + lNuMin = toLog_(1.e-3 * PC::kb * fromLog_(lTMin) / PC::h); + lNuMax = toLog_(1.e3 * PC::kb * fromLog_(lTMax) / PC::h); } const Real dlnu = (lNuMax - lNuMin) / (NNu - 1); // Integrate over frequency diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index ebbde58..98b81a3 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -41,7 +41,8 @@ template class MeanOpacity { public: - using DataBox = Spiner::DataBox; + using PC = pc; + MeanOpacity() = default; template MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax, @@ -119,15 +120,15 @@ class MeanOpacity { return rho * fromLog_(lkappaRosseland_.interpToReal(lRho, lT)); } - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - private: template void MeanOpacityImpl_(const Opacity &opac, const Real lRhoMin, const Real lRhoMax, const int NRho, const Real lTMin, const Real lTMax, const int NT, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { + static_assert(std::is_same::value, + "Mean opacity constants must match opacity constants"); + lkappaPlanck_.resize(NRho, NT); lkappaPlanck_.setRange(0, lTMin, lTMax, NT); lkappaPlanck_.setRange(1, lRhoMin, lRhoMax, NRho); @@ -145,8 +146,8 @@ class MeanOpacity { Real kappaRosselandNum = 0.; Real kappaRosselandDenom = 0.; if (AUTOFREQ) { - lNuMin = toLog_(1.e-3 * pc::kb * fromLog_(lTMin) / pc::h); - lNuMax = toLog_(1.e3 * pc::kb * fromLog_(lTMax) / pc::h); + lNuMin = toLog_(1.e-3 * PC::kb * fromLog_(lTMin) / PC::h); + lNuMax = toLog_(1.e3 * PC::kb * fromLog_(lTMax) / PC::h); } const Real dlnu = (lNuMax - lNuMin) / (NNu - 1); // Integrate over frequency @@ -190,8 +191,8 @@ class MeanOpacity { PORTABLE_INLINE_FUNCTION Real fromLog_(const Real lx) const { return std::pow(10., lx); } - DataBox lkappaPlanck_; - DataBox lkappaRosseland_; + Spiner::DataBox lkappaPlanck_; + Spiner::DataBox lkappaRosseland_; const char *filename_; }; diff --git a/singularity-opac/photons/mean_photon_variant.hpp b/singularity-opac/photons/mean_photon_variant.hpp index e1f2941..857efc3 100644 --- a/singularity-opac/photons/mean_photon_variant.hpp +++ b/singularity-opac/photons/mean_photon_variant.hpp @@ -28,7 +28,7 @@ namespace singularity { namespace photons { namespace impl { -template +template class MeanVariant { private: opac_variant opac_; @@ -86,14 +86,19 @@ class MeanVariant { opac_); } - PORTABLE_INLINE_FUNCTION PC GetPhysicalConstants() const { - return mpark::visit([](auto &opac) { return opac.GetPhysicalConstants(); }, - opac_); - } - inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } + + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return mpark::visit( + [=](const auto &opac) { + using PC = typename std::decay_t::PC; + return singularity::GetRuntimePhysicalConstants(PC()); + }, + opac_); + } }; } // namespace impl diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index 6d35c06..9b556ab 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -87,26 +87,10 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") { neutrinos::Gray opac_host(kappa); neutrinos::Opacity opac = opac_host.GetOnDevice(); - neutrinos::MeanOpacityCGS mean_opac_host( + neutrinos::MeanOpacity mean_opac_host = neutrinos::MeanOpacityCGS( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe); auto mean_opac = mean_opac_host.GetOnDevice(); - // Check constants from mean opacity - THEN("Check constants from mean opacity for consistency") { - auto constants = mean_opac_host.GetPhysicalConstants(); - int n_wrong = 0; - if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { - n_wrong += 1; - } - if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { - n_wrong += 1; - } - if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { - n_wrong += 1; - } - REQUIRE(n_wrong == 0); - } - THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS @@ -138,7 +122,7 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") { #ifdef SPINER_USE_HDF THEN("We can save to disk and reload") { mean_opac.Save(grayname); - neutrinos::MeanOpacityCGS mean_opac_host_load(grayname); + neutrinos::MeanOpacity mean_opac_host_load(grayname); AND_THEN("The reloaded table matches the gray opacities") { auto mean_opac_load = mean_opac_host_load.GetOnDevice(); @@ -428,26 +412,14 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { photons::Gray opac_host(kappa); photons::Opacity opac = opac_host.GetOnDevice(); + // photons::MeanOpacity mean_opac_host = photons::MeanOpacityCGS( + // opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT); + // auto mean_opac = mean_opac_host.GetOnDevice(); + photons::MeanOpacityCGS mean_opac_host(opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT); auto mean_opac = mean_opac_host.GetOnDevice(); - // Check constants from mean opacity - THEN("Check constants from mean opacity for consistency") { - auto constants = mean_opac_host.GetPhysicalConstants(); - int n_wrong = 0; - if (FractionalDifference(pc::eV, constants.eV) > EPS_TEST) { - n_wrong += 1; - } - if (FractionalDifference(pc::kb, constants.kb) > EPS_TEST) { - n_wrong += 1; - } - if (FractionalDifference(pc::h, constants.h) > EPS_TEST) { - n_wrong += 1; - } - REQUIRE(n_wrong == 0); - } - THEN("The emissivity per nu omega is consistent with the emissity per nu") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS @@ -479,7 +451,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { #ifdef SPINER_USE_HDF THEN("We can save to disk and reload") { mean_opac.Save(grayname); - photons::MeanOpacityCGS mean_opac_host_load(grayname); + photons::MeanOpacity mean_opac_host_load(grayname); AND_THEN("The reloaded table matches the gray opacities") { auto mean_opac_load = mean_opac_host_load.GetOnDevice(); @@ -526,6 +498,10 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { constexpr Real rho_unit = mass_unit / (length_unit * length_unit * length_unit); + // auto funny_units_host = + // photons::MeanNonCGSUnits( + // std::forward(mean_opac_host), time_unit, + // mean_opac_host, time_unit, mass_unit, length_unit, temp_unit); auto funny_units_host = photons::MeanNonCGSUnits( std::forward(mean_opac_host), time_unit, mass_unit, length_unit, temp_unit); From b7668f28e9ec0f9a7902610b69217f5c5c926ffe Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 19:56:11 -0600 Subject: [PATCH 6/8] Tests pass but ugly impl:: usage --- .../neutrinos/mean_opacity_neutrinos.hpp | 14 ++++---------- .../photons/gray_opacity_photons.hpp | 1 - .../photons/mean_opacity_photons.hpp | 12 +++--------- .../photons/powerlaw_opacity_photons.hpp | 4 ---- test/test_gray_opacities.cpp | 3 +-- test/test_mean_opacities.cpp | 16 ++++------------ 6 files changed, 12 insertions(+), 38 deletions(-) diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index ba7dbe8..71c5033 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2022. Triad National Security, LLC. All rights reserved. This +// © 2022-2024. 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. @@ -37,12 +37,9 @@ namespace impl { // TODO(BRR) Note: It is assumed that lambda is constant for all densities, // temperatures, and Ye -template class MeanOpacity { public: - using PC = pc; - MeanOpacity() = default; template MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax, @@ -136,8 +133,7 @@ class MeanOpacity { const Real lTMax, const int NT, const Real YeMin, const Real YeMax, const int NYe, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { - static_assert(std::is_same::value, - "Mean opacity constants must match opacity constants"); + using PC = typename Opacity::PC; lkappaPlanck_.resize(NRho, NT, NYe, NEUTRINO_NTYPES); // index 0 is the species and is not interpolatable @@ -224,10 +220,8 @@ class MeanOpacity { } // namespace impl -using MeanOpacityScaleFree = impl::MeanOpacity; -using MeanOpacityCGS = impl::MeanOpacity; -using MeanOpacity = impl::MeanVariant>; +using MeanOpacity = + impl::MeanVariant>; } // namespace neutrinos } // namespace singularity diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index 417f10c..c6bb1a0 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -44,7 +44,6 @@ class GrayOpacity { void PrintParams() const noexcept { printf("Gray opacity. kappa = %g\n", kappa_); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index 98b81a3..1ca9ce2 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -37,12 +37,9 @@ namespace impl { // TODO(BRR) Note: It is assumed that lambda is constant for all densities and // temperatures -template class MeanOpacity { public: - using PC = pc; - MeanOpacity() = default; template MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax, @@ -126,8 +123,7 @@ class MeanOpacity { const Real lRhoMax, const int NRho, const Real lTMin, const Real lTMax, const int NT, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { - static_assert(std::is_same::value, - "Mean opacity constants must match opacity constants"); + using PC = typename Opacity::PC; lkappaPlanck_.resize(NRho, NT); lkappaPlanck_.setRange(0, lTMin, lTMax, NT); @@ -200,10 +196,8 @@ class MeanOpacity { } // namespace impl -using MeanOpacityScaleFree = impl::MeanOpacity; -using MeanOpacityCGS = impl::MeanOpacity; -using MeanOpacity = impl::MeanVariant>; +using MeanOpacity = + impl::MeanVariant>; } // namespace photons } // namespace singularity diff --git a/singularity-opac/photons/powerlaw_opacity_photons.hpp b/singularity-opac/photons/powerlaw_opacity_photons.hpp index 2794e2c..33a4c3f 100644 --- a/singularity-opac/photons/powerlaw_opacity_photons.hpp +++ b/singularity-opac/photons/powerlaw_opacity_photons.hpp @@ -47,10 +47,6 @@ class PowerLawOpacity { printf("Power law opacity. kappa0 = %g rho_exp = %g temp_exp = %g\n", kappa0_, rho_exp_, temp_exp_); } - - PORTABLE_INLINE_FUNCTION - pc GetPhysicalConstants() const { return pc(); } - inline void Finalize() noexcept {} PORTABLE_INLINE_FUNCTION diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index cb069be..aba0158 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -54,8 +54,7 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") { constexpr RadiationType type = RadiationType::NU_ELECTRON; constexpr Real nu = 1.25 * MeV2Hz; // 1 MeV - // neutrinos::Gray opac_host(1); - neutrinos::Opacity opac_host = neutrinos::Gray(1); + neutrinos::Opacity opac_host = neutrinos::Gray(1.); neutrinos::Opacity opac = opac_host.GetOnDevice(); // Check constants from opacity diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index 9b556ab..026114a 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -87,7 +87,7 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") { neutrinos::Gray opac_host(kappa); neutrinos::Opacity opac = opac_host.GetOnDevice(); - neutrinos::MeanOpacity mean_opac_host = neutrinos::MeanOpacityCGS( + neutrinos::MeanOpacity mean_opac_host = neutrinos::impl::MeanOpacity( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe); auto mean_opac = mean_opac_host.GetOnDevice(); @@ -412,12 +412,8 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { photons::Gray opac_host(kappa); photons::Opacity opac = opac_host.GetOnDevice(); - // photons::MeanOpacity mean_opac_host = photons::MeanOpacityCGS( - // opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT); - // auto mean_opac = mean_opac_host.GetOnDevice(); - - photons::MeanOpacityCGS mean_opac_host(opac_host, lRhoMin, lRhoMax, NRho, - lTMin, lTMax, NT); + photons::MeanOpacity mean_opac_host = photons::impl::MeanOpacity( + opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT); auto mean_opac = mean_opac_host.GetOnDevice(); THEN("The emissivity per nu omega is consistent with the emissity per nu") { @@ -451,7 +447,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { #ifdef SPINER_USE_HDF THEN("We can save to disk and reload") { mean_opac.Save(grayname); - photons::MeanOpacity mean_opac_host_load(grayname); + photons::MeanOpacityCGS mean_opac_host_load(grayname); AND_THEN("The reloaded table matches the gray opacities") { auto mean_opac_load = mean_opac_host_load.GetOnDevice(); @@ -498,10 +494,6 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { constexpr Real rho_unit = mass_unit / (length_unit * length_unit * length_unit); - // auto funny_units_host = - // photons::MeanNonCGSUnits( - // std::forward(mean_opac_host), time_unit, - // mean_opac_host, time_unit, mass_unit, length_unit, temp_unit); auto funny_units_host = photons::MeanNonCGSUnits( std::forward(mean_opac_host), time_unit, mass_unit, length_unit, temp_unit); From 6d3317d9b74958d550773e50d33d6847957d0441 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 20:09:32 -0600 Subject: [PATCH 7/8] Fix copyright and Save() method --- singularity-opac/constants/constants.hpp | 2 +- singularity-opac/neutrinos/brt_neutrinos.hpp | 2 +- .../neutrinos/gray_opacity_neutrinos.hpp | 2 +- .../neutrinos/mean_neutrino_variant.hpp | 8 ++++++- .../neutrinos/neutrino_variant.hpp | 2 +- .../neutrinos/non_cgs_neutrinos.hpp | 8 ++++++- .../neutrinos/spiner_opac_neutrinos.hpp | 3 ++- .../neutrinos/tophat_emissivity_neutrinos.hpp | 2 +- .../epbremsstrahlung_opacity_photons.hpp | 2 +- .../photons/gray_opacity_photons.hpp | 2 +- .../photons/mean_photon_variant.hpp | 22 ++++++++++++------- singularity-opac/photons/non_cgs_photons.hpp | 6 +++++ singularity-opac/photons/photon_variant.hpp | 2 +- test/test_mean_opacities.cpp | 3 ++- 14 files changed, 46 insertions(+), 20 deletions(-) diff --git a/singularity-opac/constants/constants.hpp b/singularity-opac/constants/constants.hpp index 58feff9..b99fe95 100644 --- a/singularity-opac/constants/constants.hpp +++ b/singularity-opac/constants/constants.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/neutrinos/brt_neutrinos.hpp b/singularity-opac/neutrinos/brt_neutrinos.hpp index 35b086a..9138084 100644 --- a/singularity-opac/neutrinos/brt_neutrinos.hpp +++ b/singularity-opac/neutrinos/brt_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp index 93c6d15..830615e 100644 --- a/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/gray_opacity_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/neutrinos/mean_neutrino_variant.hpp b/singularity-opac/neutrinos/mean_neutrino_variant.hpp index d6c77c3..488085b 100644 --- a/singularity-opac/neutrinos/mean_neutrino_variant.hpp +++ b/singularity-opac/neutrinos/mean_neutrino_variant.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. @@ -101,6 +101,12 @@ class MeanVariant { inline void Finalize() noexcept { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } + +#ifdef SPINER_USE_HDF + void Save(const std::string &filename) const { + return mpark::visit([=](auto &opac) { return opac.Save(filename); }, opac_); + } +#endif }; } // namespace impl diff --git a/singularity-opac/neutrinos/neutrino_variant.hpp b/singularity-opac/neutrinos/neutrino_variant.hpp index 8e3a745..5736077 100644 --- a/singularity-opac/neutrinos/neutrino_variant.hpp +++ b/singularity-opac/neutrinos/neutrino_variant.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp index 4167f72..400cb2b 100644 --- a/singularity-opac/neutrinos/non_cgs_neutrinos.hpp +++ b/singularity-opac/neutrinos/non_cgs_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. @@ -266,6 +266,12 @@ class MeanNonCGSUnits { PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return mean_opac_.nlambda(); } +#ifdef SPINER_USE_HDF + void Save(const std::string &filename) const { + return mean_opac_.Save(filename); + } +#endif + PORTABLE_INLINE_FUNCTION Real PlanckMeanAbsorptionCoefficient(const Real rho, const Real temp, const Real Ye, diff --git a/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp b/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp index 2b26dbd..906bb20 100644 --- a/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp +++ b/singularity-opac/neutrinos/spiner_opac_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. @@ -63,6 +63,7 @@ class SpinerOpacity { public: using PC = pc; using DataBox = Spiner::DataBox; + static constexpr Real EPS = 10.0 * std::numeric_limits::min(); static constexpr Real Hz2MeV = pc::h / (1e6 * pc::eV); static constexpr Real MeV2Hz = 1 / Hz2MeV; diff --git a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp index 2831052..bfb024b 100644 --- a/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp +++ b/singularity-opac/neutrinos/tophat_emissivity_neutrinos.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp index 077f629..725681d 100644 --- a/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp +++ b/singularity-opac/photons/epbremsstrahlung_opacity_photons.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2022. Triad National Security, LLC. All rights reserved. This +// © 2022-2024. 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. diff --git a/singularity-opac/photons/gray_opacity_photons.hpp b/singularity-opac/photons/gray_opacity_photons.hpp index c6bb1a0..dcca68c 100644 --- a/singularity-opac/photons/gray_opacity_photons.hpp +++ b/singularity-opac/photons/gray_opacity_photons.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/singularity-opac/photons/mean_photon_variant.hpp b/singularity-opac/photons/mean_photon_variant.hpp index 857efc3..a259db4 100644 --- a/singularity-opac/photons/mean_photon_variant.hpp +++ b/singularity-opac/photons/mean_photon_variant.hpp @@ -69,6 +69,16 @@ class MeanVariant { opac_); } + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return mpark::visit( + [=](const auto &opac) { + using PC = typename std::decay_t::PC; + return singularity::GetRuntimePhysicalConstants(PC()); + }, + opac_); + } + PORTABLE_INLINE_FUNCTION Real PlanckMeanAbsorptionCoefficient(const Real rho, const Real temp) const { return mpark::visit( @@ -90,15 +100,11 @@ class MeanVariant { return mpark::visit([](auto &opac) { return opac.Finalize(); }, opac_); } - PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants - GetRuntimePhysicalConstants() const { - return mpark::visit( - [=](const auto &opac) { - using PC = typename std::decay_t::PC; - return singularity::GetRuntimePhysicalConstants(PC()); - }, - opac_); +#ifdef SPINER_USE_HDF + void Save(const std::string &filename) const { + return mpark::visit([=](auto &opac) { return opac.Save(filename); }, opac_); } +#endif }; } // namespace impl diff --git a/singularity-opac/photons/non_cgs_photons.hpp b/singularity-opac/photons/non_cgs_photons.hpp index e22c3e7..e128cf9 100644 --- a/singularity-opac/photons/non_cgs_photons.hpp +++ b/singularity-opac/photons/non_cgs_photons.hpp @@ -254,6 +254,12 @@ class MeanNonCGSUnits { PORTABLE_INLINE_FUNCTION int nlambda() const noexcept { return mean_opac_.nlambda(); } +#ifdef SPINER_USE_HDF + void Save(const std::string &filename) const { + return mean_opac_.Save(filename); + } +#endif + PORTABLE_INLINE_FUNCTION Real PlanckMeanAbsorptionCoefficient(const Real rho, const Real temp) const { const Real alpha = mean_opac_.PlanckMeanAbsorptionCoefficient( diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index ef53b4d..3386b8d 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -1,5 +1,5 @@ // ====================================================================== -// © 2021. Triad National Security, LLC. All rights reserved. This +// © 2021-2024. 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. diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index 026114a..ad0fa40 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -447,7 +447,8 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { #ifdef SPINER_USE_HDF THEN("We can save to disk and reload") { mean_opac.Save(grayname); - photons::MeanOpacityCGS mean_opac_host_load(grayname); + photons::MeanOpacity mean_opac_host_load = + photons::impl::MeanOpacity(grayname); AND_THEN("The reloaded table matches the gray opacities") { auto mean_opac_load = mean_opac_host_load.GetOnDevice(); From 5d180ee4052e0608c039df1571817646dfb125b3 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Fri, 27 Sep 2024 20:26:50 -0600 Subject: [PATCH 8/8] Fix naming --- singularity-opac/neutrinos/mean_opacity_neutrinos.hpp | 3 ++- singularity-opac/photons/mean_opacity_photons.hpp | 3 ++- test/test_mean_opacities.cpp | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index 71c5033..52e9485 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -220,8 +220,9 @@ class MeanOpacity { } // namespace impl +using MeanOpacityBase = impl::MeanOpacity; using MeanOpacity = - impl::MeanVariant>; + impl::MeanVariant>; } // namespace neutrinos } // namespace singularity diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index 1ca9ce2..d4ac76b 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -196,8 +196,9 @@ class MeanOpacity { } // namespace impl +using MeanOpacityBase = impl::MeanOpacity; using MeanOpacity = - impl::MeanVariant>; + impl::MeanVariant>; } // namespace photons } // namespace singularity diff --git a/test/test_mean_opacities.cpp b/test/test_mean_opacities.cpp index ad0fa40..932d3d1 100644 --- a/test/test_mean_opacities.cpp +++ b/test/test_mean_opacities.cpp @@ -87,7 +87,7 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") { neutrinos::Gray opac_host(kappa); neutrinos::Opacity opac = opac_host.GetOnDevice(); - neutrinos::MeanOpacity mean_opac_host = neutrinos::impl::MeanOpacity( + neutrinos::MeanOpacity mean_opac_host = neutrinos::MeanOpacityBase( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe); auto mean_opac = mean_opac_host.GetOnDevice(); @@ -412,7 +412,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { photons::Gray opac_host(kappa); photons::Opacity opac = opac_host.GetOnDevice(); - photons::MeanOpacity mean_opac_host = photons::impl::MeanOpacity( + photons::MeanOpacity mean_opac_host = photons::MeanOpacityBase( opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT); auto mean_opac = mean_opac_host.GetOnDevice(); @@ -448,7 +448,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") { THEN("We can save to disk and reload") { mean_opac.Save(grayname); photons::MeanOpacity mean_opac_host_load = - photons::impl::MeanOpacity(grayname); + photons::MeanOpacityBase(grayname); AND_THEN("The reloaded table matches the gray opacities") { auto mean_opac_load = mean_opac_host_load.GetOnDevice();