@@ -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
0 commit comments