peclet-amr 0.2.0
Block-local-Morton AMR octree + collocated cut-cell Navier–Stokes solver (header-only C++20, Kokkos + MPI)
Loading...
Searching...
No Matches
block_octree_view.hpp
Go to the documentation of this file.
1// core — device-resident view of a BlockOctree (portable Kokkos).
2//
3// BlockOctree (block_octree.hpp) owns the topology on the host: refine / coarsen /
4// 2:1 balance rebuild its sorted leaf arrays. BlockOctreeView mirrors those
5// arrays into Kokkos Views and exposes the *queries* (point location, and the
6// face-neighbour step) as KOKKOS_INLINE_FUNCTIONs over the same code, so field
7// kernels and the (later) octree multigrid can locate / walk leaves on device on
8// any backend (CUDA / HIP / OpenMP). This mirrors the host-vs-device split the
9// halo already uses (grid_halo.hpp vs grid_halo_kokkos.hpp): topology on host,
10// the per-leaf hot path on device, bit-for-bit identical results.
11//
12// Including this header requires Kokkos (build with -DPECLET_CORE_ENABLE_KOKKOS=ON) and
13// MORTON_HD == KOKKOS_FUNCTION).
14#ifndef PECLET_AMR_BLOCK_OCTREE_VIEW_HPP
15#define PECLET_AMR_BLOCK_OCTREE_VIEW_HPP
16
17#include <cstdint>
18
20#include "peclet/amr/common.hpp"
21#include "peclet/core/common/view.hpp"
22
23namespace peclet::amr {
24
26template <int Dim, unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
29 using M = typename Host::M;
30 using Code = typename Host::Code;
31 using Coord = typename Host::Coord;
32
33 View<Code> codes; // leaf origin codes, ascending (Z-order)
34 View<std::uint8_t> levels; // parallel to codes
35 Index n = 0;
36
38 void upload(const Host& t) {
39 codes = toDevice(t.codes(), "amr_codes");
40 levels = toDevice(t.levels(), "amr_levels");
41 n = t.numLeaves();
42 }
43
44 Index numLeaves() const { return n; }
45
48 return amrLocate<M>(codes.data(), levels.data(), n, p);
49 }
50
53 KOKKOS_INLINE_FUNCTION Index faceNeighbor(Index i, int axis, int dir) const {
54 M probe = M::from_code(codes(i));
55 const Coord step = Coord(Coord(1) << levels(i));
56 if (dir >= 0) {
57 if (!probe.try_add(static_cast<unsigned>(axis), step))
58 return -1;
59 } else {
60 if (!probe.try_sub(static_cast<unsigned>(axis), 1))
61 return -1;
62 }
63 return locate(probe.code());
64 }
65};
66
67} // namespace peclet::amr
68
69#endif // PECLET_AMR_BLOCK_OCTREE_VIEW_HPP
morton::Morton< Dim, Bits > M
std::vector< std::array< double, Dim > > transferFieldGradients(const BlockOctree< Dim, Bits > &oldT, const std::vector< double > &oldF)
Per-old-leaf minmod prolongation gradients (per fine-coordinate unit) — transferField's stencil,...
Definition adapt.hpp:51
Device mirror of a BlockOctree's leaf arrays + device-callable queries.
Index faceNeighbor(Index i, int axis, int dir) const
Leaf across leaf i's face on axis in direction dir (±1), or -1 if it lies outside the block.
Index locate(Code p) const
Leaf containing Morton code p, or -1. Callable in a device kernel.
void upload(const Host &t)
(Re)upload the host octree's current leaf set to the device.