From 55be7e9dbc2fa06e749e9d61691eae00768161c9 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Thu, 14 Mar 2024 19:45:11 +0000 Subject: [PATCH 01/14] feat: threaded eos bounds into floors/ceilings. tweak ye logic --- src/fixup/fixup.cpp | 52 +++++++++++-------- src/fixup/fixup.hpp | 54 +++++++++++++++++--- src/fixup/fixup_c2p.cpp | 6 +-- src/fixup/fixup_radc2p.cpp | 6 +-- src/fixup/fixup_src.cpp | 10 ++-- src/fluid/con2prim_robust.hpp | 20 ++++---- src/fluid/fluid.cpp | 23 +-------- src/fluid/fluid.hpp | 10 ---- src/fluid/riemann.hpp | 14 ++--- src/microphysics/eos_phoebus/eos_phoebus.cpp | 9 ++++ src/pgen/torus.cpp | 4 +- 11 files changed, 121 insertions(+), 87 deletions(-) diff --git a/src/fixup/fixup.cpp b/src/fixup/fixup.cpp index f6980de1..5465ad08 100644 --- a/src/fixup/fixup.cpp +++ b/src/fixup/fixup.cpp @@ -49,6 +49,7 @@ namespace fixup { std::shared_ptr Initialize(ParameterInput *pin) { auto fix = std::make_shared("fixup"); Params ¶ms = fix->AllParams(); + auto mutable_param = parthenon::Params::Mutability::Mutable; const bool enable_mhd = pin->GetOrAddBoolean("fluid", "mhd", false); const bool enable_rad = pin->GetOrAddBoolean("physics", "rad", false); @@ -273,7 +274,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { Bounds(params.Get("floor"), params.Get("ceiling"), params.Get("mhd_ceiling"), params.Get("rad_floor"), - params.Get("rad_ceiling"))); + params.Get("rad_ceiling")), + mutable_param); return fix; } @@ -307,6 +309,9 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { if (!enable_floors) return TaskStatus::complete; + const Real ye_min = eos_pkg->Param("ye_min"); + const Real ye_max = eos_pkg->Param("ye_max"); + const std::vector vars( {p::density::name(), c::density::name(), p::velocity::name(), c::momentum::name(), p::energy::name(), c::energy::name(), p::bfield::name(), p::ye::name(), @@ -344,7 +349,10 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { auto eos = eos_pkg->Param("d.EOS"); auto geom = Geometry::GetCoordinateSystem(rc); - auto bounds = fix_pkg->Param("bounds"); + Bounds *bounds = fix_pkg->MutableParam("bounds"); + + // BLB: Setting EOS bnds for Ceilings/Floors here. + bounds->SetEOSBnds(eos_pkg); const Real c2p_tol = fluid_pkg->Param("c2p_tol"); const int c2p_max_iter = fluid_pkg->Param("c2p_max_iter"); @@ -367,21 +375,21 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { eos_lambda[1] = std::log10(v(b, tmp, k, j, i)); // use last temp as initial guess double rho_floor, sie_floor; - bounds.GetFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), rho_floor, sie_floor); + bounds->GetFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), rho_floor, sie_floor); double gamma_max, e_max; - bounds.GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), gamma_max, e_max); + bounds->GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), gamma_max, e_max); Real bsqorho_max, bsqou_max; - bounds.GetMHDCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), bsqorho_max, bsqou_max); + bounds->GetMHDCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), bsqorho_max, bsqou_max); Real J_floor; - bounds.GetRadiationFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), J_floor); + bounds->GetRadiationFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), J_floor); Real xi_max; Real garbage; - bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), xi_max, garbage); + bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), xi_max, garbage); Real rho_floor_max = rho_floor; Real u_floor_max = rho_floor * sie_floor; @@ -437,16 +445,18 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { if (floor_applied) { Real vp_normalobs[3] = {0}; // Inject floors at rest in normal observer frame - Real ye_prim_default = 0.5; - eos_lambda[0] = ye_prim_default; + Real ye = 0.5; + if (pye > 0) { + ye = v(b, cye, k, j, i); + } + eos_lambda[0] = ye; Real dprs = eos.PressureFromDensityInternalEnergy(drho, ratio(du, drho), eos_lambda); Real dgm1 = ratio( eos.BulkModulusFromDensityInternalEnergy(drho, ratio(du, drho), eos_lambda), dprs); - prim2con::p2c(drho, vp_normalobs, bp, du, ye_prim_default, dprs, dgm1, gcov, - gammacon, betacon, alpha, sdetgam, dcrho, dS, dBcons, dtau, - dyecons); + prim2con::p2c(drho, vp_normalobs, bp, du, ye, dprs, dgm1, gcov, gammacon, + betacon, alpha, sdetgam, dcrho, dS, dBcons, dtau, dyecons); // Update cons vars (not B field) v(b, crho, k, j, i) += dcrho; @@ -464,7 +474,7 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { SPACELOOP(ii) { v(b, pvel_lo + ii, k, j, i) = vp_normalobs[ii]; } v(b, peng, k, j, i) = du; if (pye > 0) { - v(b, pye, k, j, i) = ye_prim_default; + v(b, pye, k, j, i) = ye_min; } // Update auxiliary primitives @@ -476,9 +486,9 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { eos_lambda); // Update cons vars (not B field) - prim2con::p2c(drho, vp_normalobs, bp, du, ye_prim_default, dprs, dgm1, gcov, - gammacon, betacon, alpha, sdetgam, v(b, crho, k, j, i), dS, - dBcons, v(b, ceng, k, j, i), dyecons); + prim2con::p2c(drho, vp_normalobs, bp, du, ye, dprs, dgm1, gcov, gammacon, + betacon, alpha, sdetgam, v(b, crho, k, j, i), dS, dBcons, + v(b, ceng, k, j, i), dyecons); SPACELOOP(ii) { v(b, cmom_lo + ii, k, j, i) = dS[ii]; } if (pye > 0) { v(b, cye, k, j, i) = dyecons; diff --git a/src/fixup/fixup.hpp b/src/fixup/fixup.hpp index 88806725..c3411abe 100644 --- a/src/fixup/fixup.hpp +++ b/src/fixup/fixup.hpp @@ -91,37 +91,60 @@ class Floors { KOKKOS_INLINE_FUNCTION void GetFloors(const Real x1, const Real x2, const Real x3, Real &rflr, Real &sflr) const { + if (!eos_bnds_set_) { + PARTHENON_FAIL("EOS bounds not set in floors."); + } + switch (floor_flag_) { case FloorFlag::ConstantRhoSie: rflr = r0_; sflr = s0_; + rflr = std::max(rflr, rho_min_eos_); + sflr = std::max(sflr, sie_min_eos_); break; case FloorFlag::ExpX1RhoSie: rflr = r0_ * std::exp(ralpha_ * x1); sflr = s0_ * std::exp(salpha_ * x1); + rflr = std::max(rflr, rho_min_eos_); + sflr = std::max(sflr, sie_min_eos_); break; case FloorFlag::ExpX1RhoU: { Real scratch = r0_ * std::exp(ralpha_ * x1); sflr = s0_ * std::exp(salpha_ * x1) / std::max(rflr, scratch); rflr = scratch; + rflr = std::max(rflr, rho_min_eos_); + sflr = std::max(sflr, sie_min_eos_); } break; case FloorFlag::X1RhoSie: rflr = r0_ * std::min(1.0, std::pow(x1, ralpha_)); sflr = s0_ * std::min(1.0, std::pow(x1, salpha_)); + rflr = std::max(rflr, rho_min_eos_); + sflr = std::max(sflr, sie_min_eos_); break; case FloorFlag::RRhoSie: { Real r = std::sqrt(x1 * x1 + x2 * x2 + x3 * x3); rflr = r0_ * std::min(1.0, std::pow(r, ralpha_)); sflr = s0_ * std::min(1.0, std::pow(r, salpha_)); + rflr = std::max(rflr, rho_min_eos_); + sflr = std::max(sflr, sie_min_eos_); } break; default: PARTHENON_FAIL("No valid floor set."); } } + void SetEOSBnds(StateDescriptor *eos_pkg) { + if (!eos_bnds_set_) { + rho_min_eos_ = eos_pkg->Param("rho_min"); + sie_min_eos_ = eos_pkg->Param("sie_min"); + eos_bnds_set_ = true; + } + } + private: - Real r0_, s0_, ralpha_, salpha_; + Real r0_, s0_, ralpha_, salpha_, rho_min_eos_, sie_min_eos_; const FloorFlag floor_flag_; + bool eos_bnds_set_; }; static struct ConstantJFloor { @@ -173,19 +196,30 @@ class Ceilings { KOKKOS_INLINE_FUNCTION void GetCeilings(const Real x1, const Real x2, const Real x3, Real &gmax, Real &smax) const { + if (!eos_bnds_set_) { + PARTHENON_FAIL("EOS bounds not set in ceilings."); + } switch (ceiling_flag_) { case 1: gmax = g0_; - smax = s0_; + smax = std::min(s0_, sie_max_eos_); break; default: PARTHENON_FAIL("No valid ceiling set."); } } + void SetEOSBnds(StateDescriptor *eos_pkg) { + if (!eos_bnds_set_) { + sie_max_eos_ = eos_pkg->Param("sie_max"); + eos_bnds_set_ = true; + } + } + private: - Real g0_, s0_; + Real g0_, s0_, sie_max_eos_; const int ceiling_flag_; + bool eos_bnds_set_; }; static struct ConstantBsqRatCeiling { @@ -257,13 +291,19 @@ class Bounds { const RadiationFloors &rfl, const RadiationCeilings &rcl) : floors_(fl), ceilings_(cl), mhd_ceilings_(mcl), radiation_floors_(rfl), radiation_ceilings_(rcl) {} - explicit Bounds(const Floors &fl) + explicit Bounds(Floors &fl) : floors_(fl), ceilings_(Ceilings()), mhd_ceilings_(MHDCeilings()), radiation_floors_(RadiationFloors()), radiation_ceilings_(RadiationCeilings()) {} - explicit Bounds(const Ceilings &cl) + explicit Bounds(Ceilings &cl) : floors_(Floors()), ceilings_(cl), mhd_ceilings_(MHDCeilings()), radiation_floors_(RadiationFloors()), radiation_ceilings_(RadiationCeilings()) {} + template + KOKKOS_INLINE_FUNCTION void SetEOSBnds(Args &&...args) { + floors_.SetEOSBnds(std::forward(args)...); + ceilings_.SetEOSBnds(std::forward(args)...); + } + template KOKKOS_INLINE_FUNCTION void GetFloors(Args &&...args) const { floors_.GetFloors(std::forward(args)...); @@ -290,8 +330,8 @@ class Bounds { } private: - const Floors floors_; - const Ceilings ceilings_; + Floors floors_; + Ceilings ceilings_; const MHDCeilings mhd_ceilings_; const RadiationFloors radiation_floors_; const RadiationCeilings radiation_ceilings_; diff --git a/src/fixup/fixup_c2p.cpp b/src/fixup/fixup_c2p.cpp index 70ed43e2..bde4d65e 100644 --- a/src/fixup/fixup_c2p.cpp +++ b/src/fixup/fixup_c2p.cpp @@ -155,7 +155,7 @@ TaskStatus ConservedToPrimitiveFixupImpl(T *rc) { auto eos = eos_pkg->Param("d.EOS"); auto geom = Geometry::GetCoordinateSystem(rc); - auto bounds = fix_pkg->Param("bounds"); + Bounds *bounds = fix_pkg->MutableParam("bounds"); Coordinates_t coords = rc->GetParentPointer()->coords; @@ -176,8 +176,8 @@ TaskStatus ConservedToPrimitiveFixupImpl(T *rc) { eos_lambda[1] = std::log10(v(b, tmp, k, j, i)); Real gamma_max, e_max; - bounds.GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), gamma_max, e_max); + bounds->GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), gamma_max, e_max); if (c2p_failure_force_fixup_both && rad_active) { if (v(b, ifail, k, j, i) == con2prim_robust::FailFlags::fail || diff --git a/src/fixup/fixup_radc2p.cpp b/src/fixup/fixup_radc2p.cpp index 200f6505..3ec3b3d7 100644 --- a/src/fixup/fixup_radc2p.cpp +++ b/src/fixup/fixup_radc2p.cpp @@ -113,7 +113,7 @@ TaskStatus RadConservedToPrimitiveFixupImpl(T *rc) { } auto geom = Geometry::GetCoordinateSystem(rc); - auto bounds = fix_pkg->Param("bounds"); + Bounds *bounds = fix_pkg->MutableParam("bounds"); Coordinates_t coords = rc->GetParentPointer()->coords; @@ -129,8 +129,8 @@ TaskStatus RadConservedToPrimitiveFixupImpl(T *rc) { KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) { Real xi_max; Real garbage; - bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), xi_max, garbage); + bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), xi_max, garbage); // It is assumed that the fluid is already fixed up auto fail = [&](const int k, const int j, const int i) { diff --git a/src/fixup/fixup_src.cpp b/src/fixup/fixup_src.cpp index a3867f96..54f7feac 100644 --- a/src/fixup/fixup_src.cpp +++ b/src/fixup/fixup_src.cpp @@ -73,7 +73,7 @@ TaskStatus SourceFixupImpl(T *rc) { } auto eos = eos_pkg->Param("d.EOS"); - auto bounds = fix_pkg->Param("bounds"); + Bounds *bounds = fix_pkg->MutableParam("bounds"); const std::vector vars( {p::density::name(), c::density::name(), p::velocity::name(), c::momentum::name(), @@ -151,12 +151,12 @@ TaskStatus SourceFixupImpl(T *rc) { kb.e, jb.s, jb.e, ib.s, ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) { double gamma_max, e_max; - bounds.GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), gamma_max, e_max); + bounds->GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), gamma_max, e_max); Real xi_max; Real garbage; - bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), xi_max, garbage); + bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), xi_max, garbage); double eos_lambda[2]; // used for stellarcollapse eos and other EOS's that require // root finding. diff --git a/src/fluid/con2prim_robust.hpp b/src/fluid/con2prim_robust.hpp index 79db255a..46a2dc73 100644 --- a/src/fluid/con2prim_robust.hpp +++ b/src/fluid/con2prim_robust.hpp @@ -48,15 +48,15 @@ class Residual { KOKKOS_FUNCTION Residual(const Real D, const Real q, const Real bsq, const Real bsq_rpsq, const Real rsq, const Real rbsq, const Real v0sq, const Real Ye, - const Microphysics::EOS::EOS &eos, const fixup::Bounds &bnds, const Real x1, + const Microphysics::EOS::EOS &eos, const fixup::Bounds *bnds, const Real x1, const Real x2, const Real x3, const Real floor_scale_fac) : D_(D), q_(q), bsq_(bsq), bsq_rpsq_(bsq_rpsq), rsq_(rsq), rbsq_(rbsq), v0sq_(v0sq), eos_(eos), bounds_(bnds), x1_(x1), x2_(x2), x3_(x3), floor_scale_fac_(floor_scale_fac) { lambda_[0] = Ye; Real garbage = 0.0; - bounds_.GetFloors(x1_, x2_, x3_, rho_floor_, garbage); - bounds_.GetCeilings(x1_, x2_, x3_, gam_max_, e_max_); + bounds_->GetFloors(x1_, x2_, x3_, rho_floor_, garbage); + bounds_->GetCeilings(x1_, x2_, x3_, gam_max_, e_max_); rho_floor_ *= floor_scale_fac_; } @@ -100,7 +100,7 @@ class Residual { Real ehat_mu(const Real mu, const Real qbar, const Real rbarsq, const Real vhatsq, const Real What) { Real rho = rhohat_mu(1.0 / What); - bounds_.GetFloors(x1_, x2_, x3_, rho, e_floor_); + bounds_->GetFloors(x1_, x2_, x3_, rho, e_floor_); e_floor_ *= floor_scale_fac_; const Real ehat_trial = What * (qbar - mu * rbarsq) + vhatsq * What * What / (1.0 + What); @@ -164,7 +164,7 @@ class Residual { private: const Real D_, q_, bsq_, bsq_rpsq_, rsq_, rbsq_, v0sq_; const Microphysics::EOS::EOS &eos_; - const fixup::Bounds &bounds_; + const fixup::Bounds *bounds_; const Real x1_, x2_, x3_; const Real floor_scale_fac_; Real lambda_[2]; @@ -224,7 +224,7 @@ struct CellGeom { template class ConToPrim { public: - ConToPrim(Data_t *rc, fixup::Bounds bnds, const Real tol, const int max_iterations, + ConToPrim(Data_t *rc, fixup::Bounds *bnds, const Real tol, const int max_iterations, const Real floor_scale_fac, const bool fail_on_floors, const bool fail_on_ceilings) : bounds(bnds), var(rc->PackVariables(Vars(), imap)), @@ -278,7 +278,7 @@ class ConToPrim { int NumBlocks() { return var.GetDim(5); } private: - fixup::Bounds bounds; + fixup::Bounds *bounds; PackIndexMap imap; const T var; const int prho, crho; @@ -306,11 +306,11 @@ class ConToPrim { Real rhoflr = 0.0; Real epsflr; - bounds.GetFloors(x1, x2, x3, rhoflr, epsflr); + bounds->GetFloors(x1, x2, x3, rhoflr, epsflr); rhoflr *= floor_scale_fac_; epsflr *= floor_scale_fac_; Real gam_max, eps_max; - bounds.GetCeilings(x1, x2, x3, gam_max, eps_max); + bounds->GetCeilings(x1, x2, x3, gam_max, eps_max); const Real D = v(crho) * igdet; #if USE_VALENCIA @@ -456,7 +456,7 @@ class ConToPrim { using C2P_Block_t = ConToPrim, VariablePack>; using C2P_Mesh_t = ConToPrim, MeshBlockPack>; -inline C2P_Block_t ConToPrimSetup(MeshBlockData *rc, fixup::Bounds bounds, +inline C2P_Block_t ConToPrimSetup(MeshBlockData *rc, fixup::Bounds *bounds, const Real tol, const int max_iter, const Real c2p_floor_scale_fac, const bool fail_on_floors, diff --git a/src/fluid/fluid.cpp b/src/fluid/fluid.cpp index cddff16f..7693749c 100644 --- a/src/fluid/fluid.cpp +++ b/src/fluid/fluid.cpp @@ -13,7 +13,6 @@ #include "fluid.hpp" -#include "analysis/analysis.hpp" #include "analysis/history.hpp" #include "con2prim.hpp" #include "con2prim_robust.hpp" @@ -208,8 +207,6 @@ std::shared_ptr Initialize(ParameterInput *pin) { physics->AddField(p::entropy::name(), mprim_scalar); physics->AddField(p::cs::name(), mprim_scalar); physics->AddField(diag::ratio_divv_cs::name(), mprim_scalar); - // physics->AddField(diag::localization_function::name(), mprim_scalar); - // (MG) currently not in use, turn on when needed. physics->AddField(diag::entropy_z_0::name(), mprim_scalar); physics->AddField(p::gamma1::name(), mprim_scalar); if (ye) { @@ -312,8 +309,6 @@ std::shared_ptr Initialize(ParameterInput *pin) { // Reductions // By default compute integrated value of scalar conserved vars auto HstSum = parthenon::UserHistoryOperation::sum; - auto HstMax = parthenon::UserHistoryOperation::max; - using History::ReduceInGain; using History::ReduceOneVar; using parthenon::HistoryOutputVar; parthenon::HstVar_list hst_vars = {}; @@ -324,11 +319,6 @@ std::shared_ptr Initialize(ParameterInput *pin) { auto ReduceEn = [](MeshData *md) { return ReduceOneVar>(md, fluid_cons::energy::name(), 0); }; - auto MaxDensity = [](MeshData *md) { - return ReduceOneVar>(md, fluid_prim::density::name(), 0); - }; - - hst_vars.emplace_back(HistoryOutputVar(HstMax, MaxDensity, "maximum density")); hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceMass, "total baryon number")); hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceEn, "total conserved energy tau")); @@ -451,15 +441,6 @@ TaskStatus ConservedToPrimitiveRegion(T *rc, const IndexRange &ib, const IndexRa auto c2p = pkg->Param>("c2p_func"); return c2p(rc, ib, jb, kb); } -// JMM: Must specialize function for both potential use cases so we -// can keep it in this file. -template TaskStatus ConservedToPrimitiveRegion>(MeshData *rc, - const IndexRange &ib, - const IndexRange &jb, - const IndexRange &kb); -template TaskStatus ConservedToPrimitiveRegion>( - MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, - const IndexRange &kb); template TaskStatus ConservedToPrimitive(T *rc) { @@ -476,7 +457,7 @@ TaskStatus ConservedToPrimitiveRobust(T *rc, const IndexRange &ib, const IndexRa auto *pmb = rc->GetParentPointer(); StateDescriptor *fix_pkg = pmb->packages.Get("fixup").get(); - auto bounds = fix_pkg->Param("bounds"); + fixup::Bounds *bounds = fix_pkg->MutableParam("bounds"); StateDescriptor *pkg = pmb->packages.Get("fluid").get(); const Real c2p_tol = pkg->Param("c2p_tol"); @@ -516,7 +497,7 @@ TaskStatus ConservedToPrimitiveClassic(T *rc, const IndexRange &ib, const IndexR auto *pmesh = rc->GetMeshPointer(); StateDescriptor *fix_pkg = pmesh->packages.Get("fixup").get(); - auto bounds = fix_pkg->Param("bounds"); + fixup::Bounds *bounds = fix_pkg->MutableParam("bounds"); StateDescriptor *pkg = pmesh->packages.Get("fluid").get(); const Real c2p_tol = pkg->Param("c2p_tol"); diff --git a/src/fluid/fluid.hpp b/src/fluid/fluid.hpp index 702d1ab3..fa206f8e 100644 --- a/src/fluid/fluid.hpp +++ b/src/fluid/fluid.hpp @@ -29,19 +29,9 @@ std::shared_ptr Initialize(ParameterInput *pin); TaskStatus PrimitiveToConserved(MeshBlockData *rc); TaskStatus PrimitiveToConservedRegion(MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, const IndexRange &kb); -// JMM: Not sure how the templated value here worked in the first -// place. But proper solution is need to tell the linker it's -// available elsewhere. template TaskStatus ConservedToPrimitiveRegion(T *rc, const IndexRange &ib, const IndexRange &jb, const IndexRange &kb); -extern template TaskStatus -ConservedToPrimitiveRegion>(MeshData *rc, const IndexRange &ib, - const IndexRange &jb, const IndexRange &kb); -extern template TaskStatus ConservedToPrimitiveRegion>( - MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, - const IndexRange &kb); - template TaskStatus ConservedToPrimitive(T *rc); template diff --git a/src/fluid/riemann.hpp b/src/fluid/riemann.hpp index c2c43b94..2290bda9 100644 --- a/src/fluid/riemann.hpp +++ b/src/fluid/riemann.hpp @@ -83,7 +83,7 @@ class FluxState { const int dir = d - 1; Real rho_floor = q(dir, prho, k, j, i); Real sie_floor; - bounds.GetFloors(g.X[1], g.X[2], g.X[3], rho_floor, sie_floor); + bounds->GetFloors(g.X[1], g.X[2], g.X[3], rho_floor, sie_floor); const Real rho = std::max(q(dir, prho, k, j, i), rho_floor); Real vpcon[] = {q(dir, pvel_lo, k, j, i), q(dir, pvel_lo + 1, k, j, i), q(dir, pvel_lo + 2, k, j, i)}; @@ -205,7 +205,7 @@ class FluxState { const ParArrayND qr; const Geometry::CoordSysMeshBlock geom; const Coordinates_t coords; - fixup::Bounds bounds; + fixup::Bounds *bounds; private: const int prho, pvel_lo, peng, pb_lo, pb_hi, pye, prs, gm1; @@ -216,8 +216,10 @@ class FluxState { ql(rc->Get("ql").data), qr(rc->Get("qr").data), geom(Geometry::GetCoordinateSystem(rc)), coords(rc->GetParentPointer()->coords), // problem for packs - bounds(rc->GetParentPointer()->packages.Get("fixup").get()->Param( - "bounds")), + bounds(rc->GetParentPointer() + ->packages.Get("fixup") + .get() + ->MutableParam("bounds")), prho(imap[fluid_prim::density::name()].first), pvel_lo(imap[fluid_prim::velocity::name()].first), peng(imap[fluid_prim::energy::name()].first), @@ -251,7 +253,7 @@ Real llf(const FluxState &fs, const int d, const int k, const int j, const int i CellLocation loc = DirectionToFaceID(d); FaceGeom g(fs.coords, fs.geom, loc, d, k, j, i); Real gam_max, sie_max; - fs.bounds.GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); + fs.bounds->GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); fs.prim_to_flux(d, k, j, i, g, fs.ql, vml, vpl, Ul, Fl, sie_max, gam_max); fs.prim_to_flux(d, k, j, i, g, fs.qr, vmr, vpr, Ur, Fr, sie_max, gam_max); @@ -273,7 +275,7 @@ Real hll(const FluxState &fs, const int d, const int k, const int j, const int i CellLocation loc = DirectionToFaceID(d); FaceGeom g(fs.coords, fs.geom, loc, d, k, j, i); Real gam_max, sie_max; - fs.bounds.GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); + fs.bounds->GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); fs.prim_to_flux(d, k, j, i, g, fs.ql, vml, vpl, Ul, Fl, sie_max, gam_max); fs.prim_to_flux(d, k, j, i, g, fs.qr, vmr, vpr, Ur, Fr, sie_max, gam_max); diff --git a/src/microphysics/eos_phoebus/eos_phoebus.cpp b/src/microphysics/eos_phoebus/eos_phoebus.cpp index a44bf52a..64249773 100644 --- a/src/microphysics/eos_phoebus/eos_phoebus.cpp +++ b/src/microphysics/eos_phoebus/eos_phoebus.cpp @@ -63,6 +63,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { Real rho_max; Real sie_max; Real T_max; + Real ye_min; + Real ye_max; std::string eos_type = pin->GetString(block_name, std::string("type")); params.Add("type", eos_type); @@ -89,6 +91,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { rho_max = pin->GetOrAddReal("fixup", "rho0_ceiling", 1e18); sie_max = pin->GetOrAddReal("fixup", "sie0_ceiling", 1e35); T_max = eos_host.TemperatureFromDensityInternalEnergy(rho_max, sie_max, lambda); + ye_min = 0.5; + ye_max = 0.5; #ifdef SPINER_USE_HDF } else if (eos_type == StellarCollapse::EosType()) { // We request that Ye and temperature exist, but do not provide them. @@ -147,7 +151,10 @@ std::shared_ptr Initialize(ParameterInput *pin) { T_min = eos_sc.TMin() / T_unit; T_max = eos_sc.TMax() / T_unit; rho_min = eos_sc.rhoMin() / rho_unit; + std::printf("rho_min code = %e\n", rho_min); rho_max = eos_sc.rhoMax() / rho_unit; + ye_min = eos_sc.YeMin(); + ye_max = eos_sc.YeMax(); #endif } else { std::stringstream error_mesg; @@ -169,6 +176,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { params.Add("T_max", T_max); params.Add("rho_min", rho_min); params.Add("rho_max", rho_max); + params.Add("ye_min", ye_min); + params.Add("ye_max", ye_max); return pkg; } diff --git a/src/pgen/torus.cpp b/src/pgen/torus.cpp index 7ef332e7..6db236c9 100644 --- a/src/pgen/torus.cpp +++ b/src/pgen/torus.cpp @@ -198,9 +198,11 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) { const Real &minx_k = pmb->coords.Xf<3>(kb.s); auto coords = pmb->coords; - auto eos = pmb->packages.Get("eos")->Param("d.EOS"); + StateDescriptor *eos_pkg = pmb->packages.Get("eos").get(); + auto eos = eos_pkg->Param("d.EOS"); auto eos_h = pmb->packages.Get("eos")->Param("h.EOS"); auto floor = pmb->packages.Get("fixup")->Param("floor"); + floor.SetEOSBnds(eos_pkg); auto &unit_conv = pmb->packages.Get("phoebus")->Param("unit_conv"); S *= unit_conv.GetEntropyCGSToCode(); From 7e7883483650a9c2af98420a8a3237fac34a8d3e Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Thu, 14 Mar 2024 19:46:15 +0000 Subject: [PATCH 02/14] leftover print --- src/microphysics/eos_phoebus/eos_phoebus.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/microphysics/eos_phoebus/eos_phoebus.cpp b/src/microphysics/eos_phoebus/eos_phoebus.cpp index 64249773..9e4f07df 100644 --- a/src/microphysics/eos_phoebus/eos_phoebus.cpp +++ b/src/microphysics/eos_phoebus/eos_phoebus.cpp @@ -151,7 +151,6 @@ std::shared_ptr Initialize(ParameterInput *pin) { T_min = eos_sc.TMin() / T_unit; T_max = eos_sc.TMax() / T_unit; rho_min = eos_sc.rhoMin() / rho_unit; - std::printf("rho_min code = %e\n", rho_min); rho_max = eos_sc.rhoMax() / rho_unit; ye_min = eos_sc.YeMin(); ye_max = eos_sc.YeMax(); From 4e1391aefa0ab8714f3ebdd2a5e94f1a6a62a87d Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Thu, 14 Mar 2024 21:47:10 +0000 Subject: [PATCH 03/14] feat: pull ideal gas eos bounds from not from fixup --- src/microphysics/eos_phoebus/eos_phoebus.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/microphysics/eos_phoebus/eos_phoebus.cpp b/src/microphysics/eos_phoebus/eos_phoebus.cpp index 9e4f07df..90a7a3cb 100644 --- a/src/microphysics/eos_phoebus/eos_phoebus.cpp +++ b/src/microphysics/eos_phoebus/eos_phoebus.cpp @@ -84,15 +84,16 @@ std::shared_ptr Initialize(ParameterInput *pin) { params.Add("d.EOS", eos_device); params.Add("h.EOS", eos_host); - rho_min = pin->GetOrAddReal("fixup", "rho0_floor", 0.0); - sie_min = pin->GetOrAddReal("fixup", "sie0_floor", 0.0); + // Can specify rho_min, etc, in + rho_min = pin->GetOrAddReal("eos", "rho_min", 0.0); + sie_min = pin->GetOrAddReal("eos", "sie_min", 0.0); lambda[2] = {0.}; T_min = eos_host.TemperatureFromDensityInternalEnergy(rho_min, sie_min, lambda); - rho_max = pin->GetOrAddReal("fixup", "rho0_ceiling", 1e18); - sie_max = pin->GetOrAddReal("fixup", "sie0_ceiling", 1e35); + rho_max = pin->GetOrAddReal("eos", "rho_max", 1e18); + sie_max = pin->GetOrAddReal("eos", "sie_max", 1e35); T_max = eos_host.TemperatureFromDensityInternalEnergy(rho_max, sie_max, lambda); - ye_min = 0.5; - ye_max = 0.5; + ye_min = 0.01; + ye_max = 1.0; #ifdef SPINER_USE_HDF } else if (eos_type == StellarCollapse::EosType()) { // We request that Ye and temperature exist, but do not provide them. From 003d75c22e41815e1cc2cf6374e32697f6035284 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Thu, 14 Mar 2024 21:59:30 +0000 Subject: [PATCH 04/14] bounds in moments_source --- src/radiation/moments_source.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/radiation/moments_source.cpp b/src/radiation/moments_source.cpp index 5e641ed6..bfdc052e 100644 --- a/src/radiation/moments_source.cpp +++ b/src/radiation/moments_source.cpp @@ -269,7 +269,7 @@ TaskStatus MomentFluidSourceImpl(T *rc, Real dt, bool update_fluid) { species_d[s] = species[s]; } - auto bounds = fix_pkg->Param("bounds"); + Bounds *bounds = fix_pkg->MutableParam("bounds"); const parthenon::Coordinates_t &coords = pmb->coords; @@ -315,7 +315,7 @@ TaskStatus MomentFluidSourceImpl(T *rc, Real dt, bool update_fluid) { // Bounds Real xi_max; Real tau_max; - bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), coords.Xc<3>(k, j, i), xi_max, tau_max); const Real alpha_max = tau_max / (alpha * dt); From ed064ded1f3328ce74408cf15c38cb85fd2cf141 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Tue, 19 Mar 2024 20:47:10 +0000 Subject: [PATCH 05/14] feat: call SetEOSBnds --- src/fluid/fluid.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fluid/fluid.cpp b/src/fluid/fluid.cpp index 7693749c..0ea12f4d 100644 --- a/src/fluid/fluid.cpp +++ b/src/fluid/fluid.cpp @@ -457,7 +457,9 @@ TaskStatus ConservedToPrimitiveRobust(T *rc, const IndexRange &ib, const IndexRa auto *pmb = rc->GetParentPointer(); StateDescriptor *fix_pkg = pmb->packages.Get("fixup").get(); + StateDescriptor *eos_pkg = pmb->packages.Get("eos").get(); fixup::Bounds *bounds = fix_pkg->MutableParam("bounds"); + bounds->SetEOSBnds(eos_pkg); StateDescriptor *pkg = pmb->packages.Get("fluid").get(); const Real c2p_tol = pkg->Param("c2p_tol"); @@ -469,7 +471,6 @@ TaskStatus ConservedToPrimitiveRobust(T *rc, const IndexRange &ib, const IndexRa c2p_floor_scale_fac, c2p_fail_on_floors, c2p_fail_on_ceilings); - StateDescriptor *eos_pkg = pmb->packages.Get("eos").get(); auto eos = eos_pkg->Param("d.EOS"); auto geom = Geometry::GetCoordinateSystem(rc); auto coords = pmb->coords; From 21a175398d4a21a521753318369f3abc30443c62 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 16:54:43 +0000 Subject: [PATCH 06/14] fix: proper copy by value for Bounds --- src/fixup/fixup.cpp | 27 +++++++++++--------- src/fluid/con2prim_robust.hpp | 20 +++++++-------- src/fluid/fluid.cpp | 5 ++-- src/microphysics/eos_phoebus/eos_phoebus.cpp | 2 +- src/radiation/moments_source.cpp | 6 +++-- 5 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/fixup/fixup.cpp b/src/fixup/fixup.cpp index 5465ad08..f2dbc0c4 100644 --- a/src/fixup/fixup.cpp +++ b/src/fixup/fixup.cpp @@ -349,10 +349,13 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { auto eos = eos_pkg->Param("d.EOS"); auto geom = Geometry::GetCoordinateSystem(rc); - Bounds *bounds = fix_pkg->MutableParam("bounds"); + Bounds *pbounds = fix_pkg->MutableParam("bounds"); // BLB: Setting EOS bnds for Ceilings/Floors here. - bounds->SetEOSBnds(eos_pkg); + pbounds->SetEOSBnds(eos_pkg); + + // copy bounds by value for kernel + Bounds bounds = *pbounds; const Real c2p_tol = fluid_pkg->Param("c2p_tol"); const int c2p_max_iter = fluid_pkg->Param("c2p_max_iter"); @@ -375,21 +378,21 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) { eos_lambda[1] = std::log10(v(b, tmp, k, j, i)); // use last temp as initial guess double rho_floor, sie_floor; - bounds->GetFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), rho_floor, sie_floor); + bounds.GetFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), rho_floor, sie_floor); double gamma_max, e_max; - bounds->GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), gamma_max, e_max); + bounds.GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), gamma_max, e_max); Real bsqorho_max, bsqou_max; - bounds->GetMHDCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), bsqorho_max, bsqou_max); + bounds.GetMHDCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), bsqorho_max, bsqou_max); Real J_floor; - bounds->GetRadiationFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), J_floor); + bounds.GetRadiationFloors(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), J_floor); Real xi_max; Real garbage; - bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), xi_max, garbage); + bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), xi_max, garbage); Real rho_floor_max = rho_floor; Real u_floor_max = rho_floor * sie_floor; diff --git a/src/fluid/con2prim_robust.hpp b/src/fluid/con2prim_robust.hpp index 46a2dc73..59d7e46c 100644 --- a/src/fluid/con2prim_robust.hpp +++ b/src/fluid/con2prim_robust.hpp @@ -48,15 +48,15 @@ class Residual { KOKKOS_FUNCTION Residual(const Real D, const Real q, const Real bsq, const Real bsq_rpsq, const Real rsq, const Real rbsq, const Real v0sq, const Real Ye, - const Microphysics::EOS::EOS &eos, const fixup::Bounds *bnds, const Real x1, + const Microphysics::EOS::EOS &eos, const fixup::Bounds &bnds, const Real x1, const Real x2, const Real x3, const Real floor_scale_fac) : D_(D), q_(q), bsq_(bsq), bsq_rpsq_(bsq_rpsq), rsq_(rsq), rbsq_(rbsq), v0sq_(v0sq), eos_(eos), bounds_(bnds), x1_(x1), x2_(x2), x3_(x3), floor_scale_fac_(floor_scale_fac) { lambda_[0] = Ye; Real garbage = 0.0; - bounds_->GetFloors(x1_, x2_, x3_, rho_floor_, garbage); - bounds_->GetCeilings(x1_, x2_, x3_, gam_max_, e_max_); + bounds_.GetFloors(x1_, x2_, x3_, rho_floor_, garbage); + bounds_.GetCeilings(x1_, x2_, x3_, gam_max_, e_max_); rho_floor_ *= floor_scale_fac_; } @@ -100,7 +100,7 @@ class Residual { Real ehat_mu(const Real mu, const Real qbar, const Real rbarsq, const Real vhatsq, const Real What) { Real rho = rhohat_mu(1.0 / What); - bounds_->GetFloors(x1_, x2_, x3_, rho, e_floor_); + bounds_.GetFloors(x1_, x2_, x3_, rho, e_floor_); e_floor_ *= floor_scale_fac_; const Real ehat_trial = What * (qbar - mu * rbarsq) + vhatsq * What * What / (1.0 + What); @@ -164,7 +164,7 @@ class Residual { private: const Real D_, q_, bsq_, bsq_rpsq_, rsq_, rbsq_, v0sq_; const Microphysics::EOS::EOS &eos_; - const fixup::Bounds *bounds_; + const fixup::Bounds bounds_; const Real x1_, x2_, x3_; const Real floor_scale_fac_; Real lambda_[2]; @@ -224,7 +224,7 @@ struct CellGeom { template class ConToPrim { public: - ConToPrim(Data_t *rc, fixup::Bounds *bnds, const Real tol, const int max_iterations, + ConToPrim(Data_t *rc, fixup::Bounds bnds, const Real tol, const int max_iterations, const Real floor_scale_fac, const bool fail_on_floors, const bool fail_on_ceilings) : bounds(bnds), var(rc->PackVariables(Vars(), imap)), @@ -278,7 +278,7 @@ class ConToPrim { int NumBlocks() { return var.GetDim(5); } private: - fixup::Bounds *bounds; + fixup::Bounds bounds; PackIndexMap imap; const T var; const int prho, crho; @@ -306,11 +306,11 @@ class ConToPrim { Real rhoflr = 0.0; Real epsflr; - bounds->GetFloors(x1, x2, x3, rhoflr, epsflr); + bounds.GetFloors(x1, x2, x3, rhoflr, epsflr); rhoflr *= floor_scale_fac_; epsflr *= floor_scale_fac_; Real gam_max, eps_max; - bounds->GetCeilings(x1, x2, x3, gam_max, eps_max); + bounds.GetCeilings(x1, x2, x3, gam_max, eps_max); const Real D = v(crho) * igdet; #if USE_VALENCIA @@ -456,7 +456,7 @@ class ConToPrim { using C2P_Block_t = ConToPrim, VariablePack>; using C2P_Mesh_t = ConToPrim, MeshBlockPack>; -inline C2P_Block_t ConToPrimSetup(MeshBlockData *rc, fixup::Bounds *bounds, +inline C2P_Block_t ConToPrimSetup(MeshBlockData *rc, fixup::Bounds bounds, const Real tol, const int max_iter, const Real c2p_floor_scale_fac, const bool fail_on_floors, diff --git a/src/fluid/fluid.cpp b/src/fluid/fluid.cpp index 0ea12f4d..6ac3fd04 100644 --- a/src/fluid/fluid.cpp +++ b/src/fluid/fluid.cpp @@ -458,8 +458,9 @@ TaskStatus ConservedToPrimitiveRobust(T *rc, const IndexRange &ib, const IndexRa StateDescriptor *fix_pkg = pmb->packages.Get("fixup").get(); StateDescriptor *eos_pkg = pmb->packages.Get("eos").get(); - fixup::Bounds *bounds = fix_pkg->MutableParam("bounds"); - bounds->SetEOSBnds(eos_pkg); + fixup::Bounds *pbounds = fix_pkg->MutableParam("bounds"); + pbounds->SetEOSBnds(eos_pkg); + fixup::Bounds bounds = *pbounds; StateDescriptor *pkg = pmb->packages.Get("fluid").get(); const Real c2p_tol = pkg->Param("c2p_tol"); diff --git a/src/microphysics/eos_phoebus/eos_phoebus.cpp b/src/microphysics/eos_phoebus/eos_phoebus.cpp index 90a7a3cb..8fa9def8 100644 --- a/src/microphysics/eos_phoebus/eos_phoebus.cpp +++ b/src/microphysics/eos_phoebus/eos_phoebus.cpp @@ -84,7 +84,7 @@ std::shared_ptr Initialize(ParameterInput *pin) { params.Add("d.EOS", eos_device); params.Add("h.EOS", eos_host); - // Can specify rho_min, etc, in + // Can specify rho_min, etc, in rho_min = pin->GetOrAddReal("eos", "rho_min", 0.0); sie_min = pin->GetOrAddReal("eos", "sie_min", 0.0); lambda[2] = {0.}; diff --git a/src/radiation/moments_source.cpp b/src/radiation/moments_source.cpp index bfdc052e..38173b8d 100644 --- a/src/radiation/moments_source.cpp +++ b/src/radiation/moments_source.cpp @@ -269,7 +269,9 @@ TaskStatus MomentFluidSourceImpl(T *rc, Real dt, bool update_fluid) { species_d[s] = species[s]; } - Bounds *bounds = fix_pkg->MutableParam("bounds"); + Bounds *pbounds = fix_pkg->MutableParam("bounds"); + pbounds->SetEOSBnds(eos_pkg); + Bounds bounds = *pbounds; const parthenon::Coordinates_t &coords = pmb->coords; @@ -315,7 +317,7 @@ TaskStatus MomentFluidSourceImpl(T *rc, Real dt, bool update_fluid) { // Bounds Real xi_max; Real tau_max; - bounds->GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + bounds.GetRadiationCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), coords.Xc<3>(k, j, i), xi_max, tau_max); const Real alpha_max = tau_max / (alpha * dt); From 1162e412a5622d1a206198bcca44671aecfe04fb Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 17:01:58 +0000 Subject: [PATCH 07/14] feat: remove eos from Ceilings --- src/fixup/fixup.hpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/fixup/fixup.hpp b/src/fixup/fixup.hpp index c3411abe..553852d0 100644 --- a/src/fixup/fixup.hpp +++ b/src/fixup/fixup.hpp @@ -196,26 +196,17 @@ class Ceilings { KOKKOS_INLINE_FUNCTION void GetCeilings(const Real x1, const Real x2, const Real x3, Real &gmax, Real &smax) const { - if (!eos_bnds_set_) { - PARTHENON_FAIL("EOS bounds not set in ceilings."); - } + switch (ceiling_flag_) { case 1: gmax = g0_; - smax = std::min(s0_, sie_max_eos_); + smax = s0_; break; default: PARTHENON_FAIL("No valid ceiling set."); } } - void SetEOSBnds(StateDescriptor *eos_pkg) { - if (!eos_bnds_set_) { - sie_max_eos_ = eos_pkg->Param("sie_max"); - eos_bnds_set_ = true; - } - } - private: Real g0_, s0_, sie_max_eos_; const int ceiling_flag_; @@ -301,7 +292,6 @@ class Bounds { template KOKKOS_INLINE_FUNCTION void SetEOSBnds(Args &&...args) { floors_.SetEOSBnds(std::forward(args)...); - ceilings_.SetEOSBnds(std::forward(args)...); } template From f1af909ce7376bf1593ce2c204b543ffbb49f3f5 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 19:52:07 +0000 Subject: [PATCH 08/14] fix: pull package outside of kernel in UserWorkBeforeOutput --- src/phoebus_driver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/phoebus_driver.cpp b/src/phoebus_driver.cpp index 226bbc2c..998c9679 100644 --- a/src/phoebus_driver.cpp +++ b/src/phoebus_driver.cpp @@ -1049,6 +1049,8 @@ void UserWorkBeforeOutput(MeshBlock *pmb, ParameterInput *pin) { IndexRange kb = rc->GetBoundsK(IndexDomain::interior); auto eos = pmb->packages.Get("eos")->Param("d.EOS"); + auto analysis = pmb->packages.Get("analysis").get(); + const Real sigma = analysis->Param("sigma"); parthenon::par_for( DEFAULT_LOOP_PATTERN, "UserWorkBeforeOutput::H5", DevExecSpace(), kb.s, kb.e, jb.s, jb.e, ib.s, ib.e, KOKKOS_LAMBDA(const int k, const int j, const int i) { @@ -1071,9 +1073,7 @@ void UserWorkBeforeOutput(MeshBlock *pmb, ParameterInput *pin) { Real gam1[3][3]; Real gam2[3][3]; Real gam3[3][3]; - auto analysis = pmb->packages.Get("analysis").get(); const Real z = coords.Xc<3>(k, j, i); - const Real sigma = analysis->Param("sigma"); const Real pi = 3.14; const Real s0 = s * std::exp(-z * z / sigma / sigma) / std::sqrt(pi) / sigma; // sigma > 0 From 72a317ea02121b524bef3fee1556783fc9ad035b Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 19:52:40 +0000 Subject: [PATCH 09/14] fix: missed some -> to . --- src/fluid/riemann.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fluid/riemann.hpp b/src/fluid/riemann.hpp index 2290bda9..3e6f2ee5 100644 --- a/src/fluid/riemann.hpp +++ b/src/fluid/riemann.hpp @@ -83,7 +83,7 @@ class FluxState { const int dir = d - 1; Real rho_floor = q(dir, prho, k, j, i); Real sie_floor; - bounds->GetFloors(g.X[1], g.X[2], g.X[3], rho_floor, sie_floor); + bounds.GetFloors(g.X[1], g.X[2], g.X[3], rho_floor, sie_floor); const Real rho = std::max(q(dir, prho, k, j, i), rho_floor); Real vpcon[] = {q(dir, pvel_lo, k, j, i), q(dir, pvel_lo + 1, k, j, i), q(dir, pvel_lo + 2, k, j, i)}; @@ -253,7 +253,7 @@ Real llf(const FluxState &fs, const int d, const int k, const int j, const int i CellLocation loc = DirectionToFaceID(d); FaceGeom g(fs.coords, fs.geom, loc, d, k, j, i); Real gam_max, sie_max; - fs.bounds->GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); + fs.bounds.GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); fs.prim_to_flux(d, k, j, i, g, fs.ql, vml, vpl, Ul, Fl, sie_max, gam_max); fs.prim_to_flux(d, k, j, i, g, fs.qr, vmr, vpr, Ur, Fr, sie_max, gam_max); @@ -275,7 +275,7 @@ Real hll(const FluxState &fs, const int d, const int k, const int j, const int i CellLocation loc = DirectionToFaceID(d); FaceGeom g(fs.coords, fs.geom, loc, d, k, j, i); Real gam_max, sie_max; - fs.bounds->GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); + fs.bounds.GetCeilings(g.X[1], g.X[2], g.X[3], gam_max, sie_max); fs.prim_to_flux(d, k, j, i, g, fs.ql, vml, vpl, Ul, Fl, sie_max, gam_max); fs.prim_to_flux(d, k, j, i, g, fs.qr, vmr, vpr, Ur, Fr, sie_max, gam_max); From 26b5971af56b7e808cde7030a6c8e5063b4b7d6a Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 20:53:59 +0000 Subject: [PATCH 10/14] fix: some missed bounds copies --- src/fixup/fixup.hpp | 2 +- src/fixup/fixup_c2p.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fixup/fixup.hpp b/src/fixup/fixup.hpp index 553852d0..f13f4dc0 100644 --- a/src/fixup/fixup.hpp +++ b/src/fixup/fixup.hpp @@ -290,7 +290,7 @@ class Bounds { radiation_floors_(RadiationFloors()), radiation_ceilings_(RadiationCeilings()) {} template - KOKKOS_INLINE_FUNCTION void SetEOSBnds(Args &&...args) { + void SetEOSBnds(Args &&...args) { floors_.SetEOSBnds(std::forward(args)...); } diff --git a/src/fixup/fixup_c2p.cpp b/src/fixup/fixup_c2p.cpp index bde4d65e..5e7147bc 100644 --- a/src/fixup/fixup_c2p.cpp +++ b/src/fixup/fixup_c2p.cpp @@ -155,7 +155,8 @@ TaskStatus ConservedToPrimitiveFixupImpl(T *rc) { auto eos = eos_pkg->Param("d.EOS"); auto geom = Geometry::GetCoordinateSystem(rc); - Bounds *bounds = fix_pkg->MutableParam("bounds"); + Bounds *pbounds = fix_pkg->MutableParam("bounds"); + Bounds bounds = *pbounds; Coordinates_t coords = rc->GetParentPointer()->coords; @@ -176,8 +177,8 @@ TaskStatus ConservedToPrimitiveFixupImpl(T *rc) { eos_lambda[1] = std::log10(v(b, tmp, k, j, i)); Real gamma_max, e_max; - bounds->GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), - coords.Xc<3>(k, j, i), gamma_max, e_max); + bounds.GetCeilings(coords.Xc<1>(k, j, i), coords.Xc<2>(k, j, i), + coords.Xc<3>(k, j, i), gamma_max, e_max); if (c2p_failure_force_fixup_both && rad_active) { if (v(b, ifail, k, j, i) == con2prim_robust::FailFlags::fail || From ad10726d04954b6a1438b3f52266582eb3286a48 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 20:54:22 +0000 Subject: [PATCH 11/14] fix/feat: copy bounds into FluxState for riemann solve --- src/fluid/riemann.hpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fluid/riemann.hpp b/src/fluid/riemann.hpp index 3e6f2ee5..02500d4e 100644 --- a/src/fluid/riemann.hpp +++ b/src/fluid/riemann.hpp @@ -205,7 +205,8 @@ class FluxState { const ParArrayND qr; const Geometry::CoordSysMeshBlock geom; const Coordinates_t coords; - fixup::Bounds *bounds; + fixup::Bounds *pbounds; + fixup::Bounds bounds; private: const int prho, pvel_lo, peng, pb_lo, pb_hi, pye, prs, gm1; @@ -216,11 +217,11 @@ class FluxState { ql(rc->Get("ql").data), qr(rc->Get("qr").data), geom(Geometry::GetCoordinateSystem(rc)), coords(rc->GetParentPointer()->coords), // problem for packs - bounds(rc->GetParentPointer() - ->packages.Get("fixup") - .get() - ->MutableParam("bounds")), - prho(imap[fluid_prim::density::name()].first), + pbounds(rc->GetParentPointer() + ->packages.Get("fixup") + .get() + ->MutableParam("bounds")), + bounds(*pbounds), prho(imap[fluid_prim::density::name()].first), pvel_lo(imap[fluid_prim::velocity::name()].first), peng(imap[fluid_prim::energy::name()].first), pb_lo(imap[fluid_prim::bfield::name()].first), From ecd49fa1bb1f12bef8fd28c04753315633ab7005 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 21:34:12 +0000 Subject: [PATCH 12/14] fix: remove unused vars --- src/fixup/fixup.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fixup/fixup.hpp b/src/fixup/fixup.hpp index f13f4dc0..d9cf27f8 100644 --- a/src/fixup/fixup.hpp +++ b/src/fixup/fixup.hpp @@ -208,9 +208,8 @@ class Ceilings { } private: - Real g0_, s0_, sie_max_eos_; + Real g0_, s0_; const int ceiling_flag_; - bool eos_bnds_set_; }; static struct ConstantBsqRatCeiling { From e445b095b1f61d83e6c3b58b171b6f9aa09ff15d Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 21:53:52 +0000 Subject: [PATCH 13/14] fix: revert mystery unintended changes.... --- src/fluid/fluid.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/fluid/fluid.cpp b/src/fluid/fluid.cpp index 6ac3fd04..6e8be2b3 100644 --- a/src/fluid/fluid.cpp +++ b/src/fluid/fluid.cpp @@ -13,6 +13,7 @@ #include "fluid.hpp" +#include "analysis/analysis.hpp" #include "analysis/history.hpp" #include "con2prim.hpp" #include "con2prim_robust.hpp" @@ -207,6 +208,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { physics->AddField(p::entropy::name(), mprim_scalar); physics->AddField(p::cs::name(), mprim_scalar); physics->AddField(diag::ratio_divv_cs::name(), mprim_scalar); + // physics->AddField(diag::localization_function::name(), mprim_scalar); + // (MG) currently not in use, turn on when needed. physics->AddField(diag::entropy_z_0::name(), mprim_scalar); physics->AddField(p::gamma1::name(), mprim_scalar); if (ye) { @@ -309,6 +312,8 @@ std::shared_ptr Initialize(ParameterInput *pin) { // Reductions // By default compute integrated value of scalar conserved vars auto HstSum = parthenon::UserHistoryOperation::sum; + auto HstMax = parthenon::UserHistoryOperation::max; + using History::ReduceInGain; using History::ReduceOneVar; using parthenon::HistoryOutputVar; parthenon::HstVar_list hst_vars = {}; @@ -319,6 +324,11 @@ std::shared_ptr Initialize(ParameterInput *pin) { auto ReduceEn = [](MeshData *md) { return ReduceOneVar>(md, fluid_cons::energy::name(), 0); }; + auto MaxDensity = [](MeshData *md) { + return ReduceOneVar>(md, fluid_prim::density::name(), 0); + }; + + hst_vars.emplace_back(HistoryOutputVar(HstMax, MaxDensity, "maximum density")); hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceMass, "total baryon number")); hst_vars.emplace_back(HistoryOutputVar(HstSum, ReduceEn, "total conserved energy tau")); @@ -441,6 +451,15 @@ TaskStatus ConservedToPrimitiveRegion(T *rc, const IndexRange &ib, const IndexRa auto c2p = pkg->Param>("c2p_func"); return c2p(rc, ib, jb, kb); } +// JMM: Must specialize function for both potential use cases so we +// can keep it in this file. +template TaskStatus ConservedToPrimitiveRegion>(MeshData *rc, + const IndexRange &ib, + const IndexRange &jb, + const IndexRange &kb); +template TaskStatus ConservedToPrimitiveRegion>( + MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, + const IndexRange &kb); template TaskStatus ConservedToPrimitive(T *rc) { @@ -499,7 +518,7 @@ TaskStatus ConservedToPrimitiveClassic(T *rc, const IndexRange &ib, const IndexR auto *pmesh = rc->GetMeshPointer(); StateDescriptor *fix_pkg = pmesh->packages.Get("fixup").get(); - fixup::Bounds *bounds = fix_pkg->MutableParam("bounds"); + fixup::Bounds *pbounds = fix_pkg->MutableParam("bounds"); StateDescriptor *pkg = pmesh->packages.Get("fluid").get(); const Real c2p_tol = pkg->Param("c2p_tol"); From e6d5b4aa77950bc72761033b78369358e6dba230 Mon Sep 17 00:00:00 2001 From: Brandon Barker Date: Wed, 20 Mar 2024 21:57:56 +0000 Subject: [PATCH 14/14] merge main fluid.hpp .... --- src/fluid/fluid.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fluid/fluid.hpp b/src/fluid/fluid.hpp index fa206f8e..702d1ab3 100644 --- a/src/fluid/fluid.hpp +++ b/src/fluid/fluid.hpp @@ -29,9 +29,19 @@ std::shared_ptr Initialize(ParameterInput *pin); TaskStatus PrimitiveToConserved(MeshBlockData *rc); TaskStatus PrimitiveToConservedRegion(MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, const IndexRange &kb); +// JMM: Not sure how the templated value here worked in the first +// place. But proper solution is need to tell the linker it's +// available elsewhere. template TaskStatus ConservedToPrimitiveRegion(T *rc, const IndexRange &ib, const IndexRange &jb, const IndexRange &kb); +extern template TaskStatus +ConservedToPrimitiveRegion>(MeshData *rc, const IndexRange &ib, + const IndexRange &jb, const IndexRange &kb); +extern template TaskStatus ConservedToPrimitiveRegion>( + MeshBlockData *rc, const IndexRange &ib, const IndexRange &jb, + const IndexRange &kb); + template TaskStatus ConservedToPrimitive(T *rc); template