Skip to content

Commit 7a85162

Browse files
author
fournier2
committed
Merge branch 'mfournier01/cubicAMR' into mfournier01/sloshing
Merge cubicAMR into sloshing setup
2 parents 291e245 + be4463d commit 7a85162

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

src/hydro/hydro.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,13 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
816816
pkg->AddParam<Real>("refinement/maxdensity_refine_above", refine_above);
817817
} else if (refine_str == "user") {
818818
pkg->CheckRefinementBlock = Hydro::ProblemCheckRefinementBlock;
819+
} else if (refine_str == "cubic") {
820+
pkg->CheckRefinementBlock = refinement::other::Cubic;
821+
const auto active = pin->GetOrAddBoolean("refinement", "active", false);
822+
const auto refinement_width =
823+
pin->GetOrAddReal("refinement", "refinement_width", 0.0);
824+
pkg->AddParam<>("refinement/active", active);
825+
pkg->AddParam<>("refinement/refinement_width", refinement_width);
819826
}
820827

821828
if (ProblemInitPackageData != nullptr) {

src/refinement/other.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,60 @@ parthenon::AmrTag MaxDensity(MeshBlockData<Real> *rc) {
4040
return parthenon::AmrTag::same;
4141
}
4242

43+
// refinement condition: cubic refinement with activation check
44+
parthenon::AmrTag Cubic(MeshBlockData<Real> *rc) {
45+
46+
auto pmb = rc->GetBlockPointer();
47+
auto &coords = pmb->coords;
48+
49+
// Check if refinement is active
50+
const bool active = pmb->packages.Get("Hydro")->Param<bool>("refinement/active");
51+
52+
if (!active) {
53+
return parthenon::AmrTag::same; // Skip refinement if inactive
54+
}
55+
56+
const Real refinement_width =
57+
pmb->packages.Get("Hydro")->Param<Real>("refinement/refinement_width");
58+
const Real half_width = refinement_width / 2.0;
59+
60+
// Retrieve bounds
61+
IndexRange ib = pmb->cellbounds.GetBoundsI(IndexDomain::interior);
62+
IndexRange jb = pmb->cellbounds.GetBoundsJ(IndexDomain::interior);
63+
IndexRange kb = pmb->cellbounds.GetBoundsK(IndexDomain::interior);
64+
65+
// Fast bounding box check (block-level)
66+
const Real x_min = coords.Xc<1>(ib.s);
67+
const Real x_max = coords.Xc<1>(ib.e);
68+
const Real y_min = coords.Xc<2>(jb.s);
69+
const Real y_max = coords.Xc<2>(jb.e);
70+
const Real z_min = coords.Xc<3>(kb.s);
71+
const Real z_max = coords.Xc<3>(kb.e);
72+
73+
if (x_min > half_width || x_max < -half_width || y_min > half_width ||
74+
y_max < -half_width || z_min > half_width || z_max < -half_width) {
75+
return parthenon::AmrTag::same; // Fully outside, no refinement needed
76+
}
77+
78+
// If the block intersects the cubic region, perform detailed check
79+
bool inside_cubic_region = false;
80+
81+
pmb->par_reduce(
82+
"cubic check refinement", kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
83+
KOKKOS_LAMBDA(const int k, const int j, const int i, bool &inside) {
84+
const Real x = coords.Xc<1>(i);
85+
const Real y = coords.Xc<2>(j);
86+
const Real z = coords.Xc<3>(k);
87+
88+
if (std::abs(x) <= half_width && std::abs(y) <= half_width &&
89+
std::abs(z) <= half_width) {
90+
inside = true;
91+
}
92+
},
93+
Kokkos::LOr<bool>(inside_cubic_region));
94+
95+
return inside_cubic_region ? parthenon::AmrTag::refine : parthenon::AmrTag::same;
96+
}
97+
4398
} // namespace other
4499
} // namespace refinement

src/refinement/refinement.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ AmrTag VelocityGradient(MeshBlockData<Real> *rc);
2020
} // namespace gradient
2121
namespace other {
2222
parthenon::AmrTag MaxDensity(MeshBlockData<Real> *rc);
23-
}
23+
parthenon::AmrTag Cubic(MeshBlockData<Real> *rc);
24+
} // namespace other
2425

2526
} // namespace refinement
2627

0 commit comments

Comments
 (0)