Skip to content

Commit

Permalink
fix: proper copy by value for Bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroBarker committed Mar 20, 2024
1 parent ed064de commit 21a1753
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
27 changes: 15 additions & 12 deletions src/fixup/fixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,13 @@ TaskStatus ApplyFloorsImpl(T *rc, IndexDomain domain = IndexDomain::entire) {

auto eos = eos_pkg->Param<EOS>("d.EOS");
auto geom = Geometry::GetCoordinateSystem(rc);
Bounds *bounds = fix_pkg->MutableParam<Bounds>("bounds");
Bounds *pbounds = fix_pkg->MutableParam<Bounds>("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<Real>("c2p_tol");
const int c2p_max_iter = fluid_pkg->Param<int>("c2p_max_iter");
Expand All @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/fluid/con2prim_robust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -224,7 +224,7 @@ struct CellGeom {
template <typename Data_t, typename T>
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)),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -456,7 +456,7 @@ class ConToPrim {
using C2P_Block_t = ConToPrim<MeshBlockData<Real>, VariablePack<Real>>;
using C2P_Mesh_t = ConToPrim<MeshData<Real>, MeshBlockPack<Real>>;

inline C2P_Block_t ConToPrimSetup(MeshBlockData<Real> *rc, fixup::Bounds *bounds,
inline C2P_Block_t ConToPrimSetup(MeshBlockData<Real> *rc, fixup::Bounds bounds,
const Real tol, const int max_iter,
const Real c2p_floor_scale_fac,
const bool fail_on_floors,
Expand Down
5 changes: 3 additions & 2 deletions src/fluid/fluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fixup::Bounds>("bounds");
bounds->SetEOSBnds(eos_pkg);
fixup::Bounds *pbounds = fix_pkg->MutableParam<fixup::Bounds>("bounds");
pbounds->SetEOSBnds(eos_pkg);
fixup::Bounds bounds = *pbounds;

StateDescriptor *pkg = pmb->packages.Get("fluid").get();
const Real c2p_tol = pkg->Param<Real>("c2p_tol");
Expand Down
2 changes: 1 addition & 1 deletion src/microphysics/eos_phoebus/eos_phoebus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
params.Add("d.EOS", eos_device);
params.Add("h.EOS", eos_host);

// Can specify rho_min, etc, in <eos>
// Can specify rho_min, etc, in <eos>
rho_min = pin->GetOrAddReal("eos", "rho_min", 0.0);
sie_min = pin->GetOrAddReal("eos", "sie_min", 0.0);
lambda[2] = {0.};
Expand Down
6 changes: 4 additions & 2 deletions src/radiation/moments_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ TaskStatus MomentFluidSourceImpl(T *rc, Real dt, bool update_fluid) {
species_d[s] = species[s];
}

Bounds *bounds = fix_pkg->MutableParam<fixup::Bounds>("bounds");
Bounds *pbounds = fix_pkg->MutableParam<fixup::Bounds>("bounds");
pbounds->SetEOSBnds(eos_pkg);
Bounds bounds = *pbounds;

const parthenon::Coordinates_t &coords = pmb->coords;

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 21a1753

Please sign in to comment.