From c4b42bc2b8bce6ceebccdedce35245d96c39b285 Mon Sep 17 00:00:00 2001 From: Ben Ryan Date: Tue, 10 Dec 2024 15:33:23 -0700 Subject: [PATCH] Test constants --- singularity-opac/constants/constants.hpp | 18 +++++------ test/test_gray_opacities.cpp | 38 +++++++++++++++++------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/singularity-opac/constants/constants.hpp b/singularity-opac/constants/constants.hpp index 9599a4a..f5bbede 100644 --- a/singularity-opac/constants/constants.hpp +++ b/singularity-opac/constants/constants.hpp @@ -180,26 +180,26 @@ struct PhysicalConstants { struct RuntimePhysicalConstants { template PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants(T pc) - : length(1.), time(1.), mass(1.), 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), + : length(1.), time(1.), mass(1.), temp(1.), 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), me(pc.me), mp(pc.mp), mn(pc.mn), amu(pc.amu), sb(pc.sb), ar(pc.ar), eV(pc.eV), Fc(pc.Fc), nu_sigma0(pc.nu_sigma0), gA(pc.gA) {} template - PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants(T pc, const Real time_, - const Real mass_, - const Real length_, - const Real temp_) - : time(time_), mass(mass_), length(length_), temp(temp_), na(pc.na), alpha(pc.alpha), - h(pc.h * time / mass * std::pow(length, -2)), + PORTABLE_INLINE_FUNCTION + RuntimePhysicalConstants(T pc, const Real time_, const Real mass_, + const Real length_, const Real temp_) + : time(time_), mass(mass_), length(length_), temp(temp_), na(pc.na), + alpha(pc.alpha), h(pc.h * time / mass * std::pow(length, -2)), hbar(pc.hbar * time / mass * std::pow(length, -2)), kb(pc.kb * std::pow(time, 2) / mass * std::pow(length, -2) * temp), r_gas(pc.r_gas * std::pow(time, 2) / mass * std::pow(length, -2)), qe(pc.qe), c(pc.c * time / length), g_newt(pc.g_newt * std::pow(length, -3) / mass * std::pow(time, 2)), me(pc.me / mass), mp(pc.mp / mass), mn(pc.mn / mass), - amu(pc.amu / mass), sb(pc.sb * std::pow(time, 3) / mass * std::pow(temp, 4)), + amu(pc.amu / mass), + sb(pc.sb * std::pow(time, 3) / mass * std::pow(temp, 4)), ar(pc.ar * std::pow(time, 2) * length / mass * std::pow(temp, 4)), eV(pc.eV * std::pow(time, 2) / mass * std::pow(length, -2)), Fc(pc.Fc * std::pow(time, 2) * length / mass), diff --git a/test/test_gray_opacities.cpp b/test/test_gray_opacities.cpp index 9c71163..dff31ff 100644 --- a/test/test_gray_opacities.cpp +++ b/test/test_gray_opacities.cpp @@ -271,16 +271,34 @@ TEST_CASE("Gray photon opacities", "[GrayPhotons]") { THEN("We can retrieve physical constants in code units") { auto noncgs_rpc = funny_units.GetRuntimePhysicalConstants(); - REQUIRE(FractionalDifference(noncgs_rpc.length, length_unit) < EPS_TEST); - REQUIRE(FractionalDifference(noncgs_rpc.time, length_unit) < EPS_TEST); - REQUIRE(FractionalDifference(noncgs_rpc.length, length_unit) < EPS_TEST); - REQUIRE(FractionalDifference(noncgs_rpc.ar, 1.980493e-10) < EPS_TEST); - printf("ltm %e %e %e\n", noncgs_rpc.length, noncgs_rpc.time, noncgs_rpc.mass); - printf("%e %e %e %e\n", noncgs_rpc.na, noncgs_rpc.alpha, noncgs_rpc.h, noncgs_rpc.hbar); - printf("%e %e %e %e\n", noncgs_rpc.kb, noncgs_rpc.r_gas, noncgs_rpc.qe, noncgs_rpc.c); - printf("%e %e %e %e\n", noncgs_rpc.g_newt, noncgs_rpc.me, noncgs_rpc.mp, noncgs_rpc.mn); - printf("%e %e %e %e\n", noncgs_rpc.amu, noncgs_rpc.sb, noncgs_rpc.ar, noncgs_rpc.eV); - printf("%e %e %e\n", noncgs_rpc.Fc, noncgs_rpc.nu_sigma0, noncgs_rpc.gA); + REQUIRE(FractionalDifference(noncgs_rpc.length, length_unit) < + EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.time, time_unit) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.mass, mass_unit) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.temp, temp_unit) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.na, 6.022141e+23) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.alpha, 7.297353e-03) < + EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.h, 2.871060e-33) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.hbar, 4.569434e-34) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.kb, 2.030877e-18) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.r_gas, 4.431243e+03) < + EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.qe, 4.803205e-10) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.c, 4.673571e+09) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.g_newt, 4.508065e-15) < + EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.me, 1.997672e-30) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.mp, 3.668030e-27) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.mn, 3.673086e-27) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.amu, 3.641533e-27) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.sb, 1.342760e+09) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.ar, 1.149237e+00) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.eV, 8.538896e-17) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.Fc, 1.189435e-09) < EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.nu_sigma0, 2.829094e-74) < + EPS_TEST); + REQUIRE(FractionalDifference(noncgs_rpc.gA, -1.23) < EPS_TEST); } THEN("We can convert meaningfully into and out of funny units") {