Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior between CPU and GPU for liebendorf deleptonization and cooling #184

Merged
merged 15 commits into from
Dec 13, 2023
37 changes: 27 additions & 10 deletions src/radiation/cooling_function.cpp
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ TaskStatus LightBulbCalcTau(MeshBlockData<Real> *rc) {

auto &unit_conv =
pmb->packages.Get("phoebus")->Param<phoebus::UnitConversions>("unit_conv");

const Real density_conversion_factor = unit_conv.GetMassDensityCodeToCGS();

parthenon::par_for(
DEFAULT_LOOP_PATTERN, "CalcTau", DevExecSpace(), kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int k, const int j, const int i) {
const Real rho =
v(prho, k, j, i) * unit_conv.GetMassDensityCodeToCGS(); // Density in CGS
v(prho, k, j, i) * density_conversion_factor; // Density in CGS
const Real lRho = std::log10(rho);
// Calculate tau
constexpr Real xl1 = LightBulb::HeatAndCool::XL1;
Expand Down Expand Up @@ -154,6 +157,13 @@ TaskStatus CoolingFunctionCalculateFourForce(MeshBlockData<Real> *rc, const doub
rad->Param<bool>("do_nu_electron_anti"),
rad->Param<bool>("do_nu_heavy")};

const Real density_conversion_factor = unit_conv.GetMassDensityCodeToCGS();
const Real temperature_conversion_factor = unit_conv.GetTemperatureCodeToCGS();
const Real length_conversion_factor = unit_conv.GetLengthCodeToCGS();
const Real energy_conversion_factor = unit_conv.GetEnergyCodeToCGS();
const Real mass_conversion_factor = unit_conv.GetMassCodeToCGS();
const Real time_conversion_factor = unit_conv.GetTimeCodeToCGS();

parthenon::par_for(
DEFAULT_LOOP_PATTERN, "CoolingFunctionCalculateFourForce", DevExecSpace(), kb.s,
kb.e, jb.s, jb.e, ib.s, ib.e, KOKKOS_LAMBDA(const int k, const int j, const int i) {
Expand All @@ -177,13 +187,20 @@ TaskStatus CoolingFunctionCalculateFourForce(MeshBlockData<Real> *rc, const doub
const parthenon::AllReduce<bool> *pdo_gain_reducer =
rad->MutableParam<parthenon::AllReduce<bool>>("do_gain_reducer");
const bool do_gain = pdo_gain_reducer->val;
const Real density_conversion_factor = unit_conv.GetMassDensityCodeToCGS();
const Real temperature_conversion_factor = unit_conv.GetTemperatureCodeToCGS();
const Real length_conversion_factor = unit_conv.GetLengthCodeToCGS();
const Real energy_conversion_factor = unit_conv.GetEnergyCodeToCGS();
const Real mass_conversion_factor = unit_conv.GetMassCodeToCGS();
const Real time_conversion_factor = unit_conv.GetTimeCodeToCGS();

parthenon::par_for(
DEFAULT_LOOP_PATTERN, "CoolingFunctionCalculateFourForce", DevExecSpace(), kb.s,
kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int k, const int j, const int i) {
const Real r = std::abs(coords.Xc<1>(k, j, i)); // TODO(MG) coord transform game
const Real rho =
v(prho, k, j, i) * unit_conv.GetMassDensityCodeToCGS(); // Density in CGS
v(prho, k, j, i) * density_conversion_factor; // Density in CGS
const Real cdensity = v(crho, k, j, i); // conserved density
Real Gcov[4][4];
geom.SpacetimeMetric(CellLocation::Cent, k, j, i, Gcov);
Expand Down Expand Up @@ -243,17 +260,17 @@ TaskStatus CoolingFunctionCalculateFourForce(MeshBlockData<Real> *rc, const doub
Real lambda[2];
lambda[0] = Ye;
eos_sc.MassFractionsFromDensityTemperature(
rho, v(ptemp, k, j, i) * unit_conv.GetTemperatureCodeToCGS(), Xa, Xh, Xn,
rho, v(ptemp, k, j, i) * temperature_conversion_factor, Xa, Xh, Xn,
Xp, Abar, Zbar, lambda);
heat = do_gain * (Xn + Xp) * hfac * std::exp(-tau) *
pow((rnorm / (r * unit_conv.GetLengthCodeToCGS())), 2);
pow((rnorm / (r * length_conversion_factor)), 2);
cool =
(Xn + Xp) * cfac * std::exp(-tau) *
pow((v(ptemp, k, j, i) * unit_conv.GetTemperatureCodeToCGS() / Tnorm), 6);
pow((v(ptemp, k, j, i) * temperature_conversion_factor / Tnorm), 6);

Real CGSToCodeFact = unit_conv.GetEnergyCGSToCode() /
unit_conv.GetMassCGSToCode() /
unit_conv.GetTimeCGSToCode();
Real CGSToCodeFact = energy_conversion_factor /
mass_conversion_factor /
time_conversion_factor;

Real tempr = 1 / 30.76 / 9e20;
Real H = heat * CGSToCodeFact;
Expand All @@ -267,9 +284,9 @@ TaskStatus CoolingFunctionCalculateFourForce(MeshBlockData<Real> *rc, const doub
Kokkos::atomic_add(&(v(mu, k, j, i)), -Gcov_coord[mu - Gcov_lo]);
}
v(GcovHeat, k, j, i) =
v(prho, k, j, i) * unit_conv.GetMassDensityCodeToCGS() * heat;
v(prho, k, j, i) * density_conversion_factor * heat;
v(GcovCool, k, j, i) =
v(prho, k, j, i) * unit_conv.GetMassDensityCodeToCGS() * cool;
v(prho, k, j, i) * density_conversion_factor * cool;
Kokkos::atomic_add(&(v(Gye, k, j, i)), Jye);
});
#else
Expand Down
Loading