Skip to content

Commit

Permalink
working on units
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Dec 10, 2024
1 parent 49fc726 commit 001e390
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 10 additions & 8 deletions singularity-opac/constants/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,29 @@ struct RuntimePhysicalConstants {
gA(pc.gA) {}

template <typename T>
PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants(T pc, const Real length_,
const Real time_,
const Real mass_)
: length(length_), time(time_), mass(mass_), na(pc.na), alpha(pc.alpha),
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)),
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),
ar(pc.ar * std::pow(time, 2) * length / mass),
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),
nu_sigma0(pc.nu_sigma0 / std::pow(length, 2)), gA(pc.gA) {}

// Conversion factors to the T pc unit system from code units
const Real length;
const Real time;
const Real mass;
const Real length;
const Real temp;

const Real na;
const Real alpha;
Expand Down
2 changes: 1 addition & 1 deletion singularity-opac/photons/non_cgs_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class NonCGSUnits {

PORTABLE_INLINE_FUNCTION RuntimePhysicalConstants
GetRuntimePhysicalConstants() const {
return RuntimePhysicalConstants(PC(), length_unit_, time_unit_, mass_unit_);
return RuntimePhysicalConstants(PC(), time_unit_, mass_unit_, length_unit_, temp_unit_);
}

private:
Expand Down
9 changes: 9 additions & 0 deletions test/test_gray_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,16 @@ 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);
}

THEN("We can convert meaningfully into and out of funny units") {
Expand Down

0 comments on commit 001e390

Please sign in to comment.