From 49fc726d6529b63f7acf79ffca71fb59551d2023 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 10 Dec 2024 12:51:19 -0700 Subject: [PATCH] Start adding tests --- singularity-opac/photons/photon_variant.hpp | 3 +-- singularity-opac/photons/powerlaw_opacity_photons.hpp | 5 +++++ test/test_gray_opacities.cpp | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/singularity-opac/photons/photon_variant.hpp b/singularity-opac/photons/photon_variant.hpp index 0754000..fb694c2 100644 --- a/singularity-opac/photons/photon_variant.hpp +++ b/singularity-opac/photons/photon_variant.hpp @@ -75,8 +75,7 @@ class Variant { GetRuntimePhysicalConstants() const { return mpark::visit( [](auto &opac) { - using PC = typename std::decay_t::PC; - return RuntimePhysicalConstants(PC()); + return opac.GetRuntimePhysicalConstants(); }, opac_); } diff --git a/singularity-opac/photons/powerlaw_opacity_photons.hpp b/singularity-opac/photons/powerlaw_opacity_photons.hpp index 33a4c3f..c971eea 100644 --- a/singularity-opac/photons/powerlaw_opacity_photons.hpp +++ b/singularity-opac/photons/powerlaw_opacity_photons.hpp @@ -174,6 +174,11 @@ class PowerLawOpacity { return dist_.NumberDensityFromTemperature(temp, lambda); } + PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants + GetRuntimePhysicalConstants() const { + return RuntimePhysicalConstants(PC()); + } + private: Real kappa0_; // Opacity scale. Units of cm^2/g Real rho_exp_; // Power law index of density diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index 9d9a375..3614d50 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -109,9 +109,6 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") { neutrinos::Gray(1), time_unit, mass_unit, length_unit, temp_unit); auto funny_units = funny_units_host.GetOnDevice(); - auto noncgs_rpc = funny_units.GetRuntimePhysicalConstants(); - printf("ar: %e\n", noncgs_rpc.ar); - THEN("We can convert meaningfully into and out of funny units") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS @@ -272,6 +269,11 @@ TEST_CASE("Gray photon opacities", "[GrayPhotons]") { photons::Gray(1), time_unit, mass_unit, length_unit, temp_unit); auto funny_units = funny_units_host.GetOnDevice(); + THEN("We can retrieve physical constants in code units") { + auto noncgs_rpc = funny_units.GetRuntimePhysicalConstants(); + REQUIRE(FractionalDifference(noncgs_rpc.ar, 1.980493e-10) < EPS_TEST); + } + THEN("We can convert meaningfully into and out of funny units") { int n_wrong_h = 0; #ifdef PORTABILITY_STRATEGY_KOKKOS