Skip to content

Commit

Permalink
Start adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Dec 10, 2024
1 parent 06c62e3 commit 49fc726
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 1 addition & 2 deletions singularity-opac/photons/photon_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class Variant {
GetRuntimePhysicalConstants() const {
return mpark::visit(
[](auto &opac) {
using PC = typename std::decay_t<decltype(opac)>::PC;
return RuntimePhysicalConstants(PC());
return opac.GetRuntimePhysicalConstants();
},
opac_);
}
Expand Down
5 changes: 5 additions & 0 deletions singularity-opac/photons/powerlaw_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions test/test_gray_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 49fc726

Please sign in to comment.