29 static constexpr u32 splts_count = 1U << dim;
32 [[nodiscard]]
inline static auto get_split_coord(Tcoord bmin, Tcoord bmax) -> Tcoord {
33 return (bmax - bmin) / 2 + bmin;
36 inline static auto get_split(Tcoord bmin, Tcoord bmax)
37 -> std::array<AMRBlockCoord, splts_count> {
39 std::array<AMRBlockCoord, splts_count> ret;
41 Tcoord splts = get_split_coord(bmin, bmax);
42 std::array<Tcoord, 3> szs = {bmin, splts, bmax};
44 auto get_coord = [](
u32 i) -> std::array<u32, dim> {
45 constexpr u32 NsideBlockPow = 1;
46 constexpr u32 Nside = 1U << NsideBlockPow;
47 constexpr u32 side_size = Nside;
50 if constexpr (dim == 3) {
51 const u32 tmp = i >> NsideBlockPow;
52 return {i % Nside, (tmp) % Nside, (tmp) >> NsideBlockPow};
56 for (
u32 i = 0; i < splts_count; i++) {
57 auto [lx, ly, lz] = get_coord(i);
60 ret[i].bmin = Tcoord{szs[lx].x(), szs[ly].y(), szs[lz].z()};
61 ret[i].bmax = Tcoord{szs[lx + 1].x(), szs[ly + 1].y(), szs[lz + 1].z()};
67 inline auto split() {
return AMRBlockCoord::get_split(bmin, bmax); }
70 return AMRBlockCoord{sycl::min(c1.bmin, c2.bmin), sycl::max(c1.bmax, c2.bmax)};
73 inline static AMRBlockCoord get_merge(std::array<AMRBlockCoord, splts_count> others) {
74 return AMRBlockCoord::get_merge(
75 AMRBlockCoord::get_merge(
76 AMRBlockCoord::get_merge(others[0], others[1]),
77 AMRBlockCoord::get_merge(others[2], others[3])),
78 AMRBlockCoord::get_merge(
79 AMRBlockCoord::get_merge(others[4], others[5]),
80 AMRBlockCoord::get_merge(others[6], others[7])));
83 inline static bool are_mergeable(std::array<AMRBlockCoord, splts_count> others) {
87 std::array<AMRBlockCoord, splts_count> splitted = merged.split();
91 static_assert(dim == 3,
"only dim 3 is handled");
93 if constexpr (dim == 3) {
94 for (
u32 i = 0; i < splts_count; i++) {
95 are_same = are_same && sham::equals(others[i].bmin, splitted[i].bmin)
96 && sham::equals(others[i].bmax, splitted[i].bmax);