core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
leaf_field.hpp
Go to the documentation of this file.
1// core — leaf-indexed fields and world geometry for a BlockOctree.
2//
3// A BlockOctree addresses leaves in integer *fine units* relative to the block
4// origin. AmrGeometry maps those to world coordinates (origin + h0 * fine), and
5// LeafField<T> is a value-per-leaf array in the octree's leaf (Z-order) slot
6// order — the simulation field the device kernels and the VTU writer operate on.
7// The on-device counterpart is simply a peclet::core::View<T> of length numLeaves(); this
8// host container is the I/O / setup form.
9//
10// Header-only, guarded by PECLET_CORE_HAVE_MORTON (so it tracks block_octree.hpp).
11#ifndef PECLET_CORE_AMR_LEAF_FIELD_HPP
12#define PECLET_CORE_AMR_LEAF_FIELD_HPP
13
14#ifdef PECLET_CORE_HAVE_MORTON
15
16#include <array>
17#include <cstddef>
18#include <vector>
19
22
23namespace peclet::core::amr {
24
27template <int Dim>
30 Real h0 = 1.0;
31
33 Real leafSize(unsigned level) const { return h0 * static_cast<Real>(Index(1) << level); }
34
36 template <class Coord>
37 Vec<Dim> lowerCorner(const std::array<Coord, Dim>& lo) const {
38 Vec<Dim> p{};
39 for (int d = 0; d < Dim; ++d)
40 p[d] = origin[d] + static_cast<Real>(lo[d]) * h0;
41 return p;
42 }
43
45 template <class Coord>
46 Vec<Dim> center(const std::array<std::array<Coord, Dim>, 2>& b) const {
47 Vec<Dim> p{};
48 for (int d = 0; d < Dim; ++d)
49 p[d] = origin[d] +
50 (static_cast<Real>(b[0][d]) + 0.5 * (static_cast<Real>(b[1][d] - b[0][d]) + 1.0)) * h0;
51 return p;
52 }
53};
54
56template <class T>
57struct LeafField {
58 std::vector<T> values;
59
60 LeafField() = default;
61 explicit LeafField(Index n, T init = T{}) : values(static_cast<std::size_t>(n), init) {}
62
63 template <int Dim, unsigned Bits>
64 explicit LeafField(const BlockOctree<Dim, Bits>& t, T init = T{})
65 : values(static_cast<std::size_t>(t.numLeaves()), init) {}
66
67 Index size() const { return static_cast<Index>(values.size()); }
68 T& operator[](Index i) { return values[static_cast<std::size_t>(i)]; }
69 const T& operator[](Index i) const { return values[static_cast<std::size_t>(i)]; }
70 T* data() { return values.data(); }
71 const T* data() const { return values.data(); }
72};
73
74} // namespace peclet::core::amr
75
76#endif // PECLET_CORE_HAVE_MORTON
77#endif // PECLET_CORE_AMR_LEAF_FIELD_HPP
Kokkos::View< T *, MemSpace > View
1D device array.
Definition view.hpp:26
double Real
Default host floating type. Device kernels may use float; conversions happen at the boundary.
Definition types.hpp:18
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
Definition types.hpp:15
World-space placement of a block-local octree: fine coordinate (0,..,0) sits at origin,...
Real leafSize(unsigned level) const
World width of a leaf at level (covers 2^level fine cells).
Vec< Dim > center(const std::array< std::array< Coord, Dim >, 2 > &b) const
World coordinate of a leaf centre, from its integer bounds [lo,hi] (inclusive, fine units).
Vec< Dim > lowerCorner(const std::array< Coord, Dim > &lo) const
World coordinate of a leaf's lower corner, given its integer lower bound (fine units).
A value per leaf, in the octree's Z-order leaf slot order.
LeafField(const BlockOctree< Dim, Bits > &t, T init=T{})
LeafField(Index n, T init=T{})
const T & operator[](Index i) const