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
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#ifndef PECLET_AMR_LEAF_FIELD_HPP
11#define PECLET_AMR_LEAF_FIELD_HPP
12
13#include <array>
14#include <cstddef>
15#include <vector>
16
18#include "peclet/amr/common.hpp"
19#include "peclet/core/common/types.hpp"
20
21namespace peclet::amr {
22
23namespace detail {
25template <int Dim>
27 Vec<Dim> x{};
28 for (int d = 0; d < Dim; ++d)
29 x[d] = v;
30 return x;
31}
32} // namespace detail
33
46template <int Dim>
49 Vec<Dim> h0 = detail::filledVec<Dim>(1.0);
50
54 g.origin = o;
55 g.h0 = detail::filledVec<Dim>(h);
56 return g;
57 }
59 void setIsotropic(Real h) { h0 = detail::filledVec<Dim>(h); }
60
61 Real hMin() const {
62 Real m = h0[0];
63 for (int d = 1; d < Dim; ++d)
64 m = h0[d] < m ? h0[d] : m;
65 return m;
66 }
67 Real hMax() const {
68 Real m = h0[0];
69 for (int d = 1; d < Dim; ++d)
70 m = h0[d] > m ? h0[d] : m;
71 return m;
72 }
73 bool isotropic() const {
74 for (int d = 1; d < Dim; ++d)
75 if (h0[d] != h0[0])
76 return false;
77 return true;
78 }
80 Real cellVolume() const {
81 Real v = h0[0];
82 for (int d = 1; d < Dim; ++d)
83 v *= h0[d];
84 return v;
85 }
86
88 Real leafSize(unsigned level, int d) const {
89 return h0[d] * static_cast<Real>(Index(1) << level);
90 }
92 Vec<Dim> leafSize(unsigned level) const {
93 Vec<Dim> s{};
94 const Real f = static_cast<Real>(Index(1) << level);
95 for (int d = 0; d < Dim; ++d)
96 s[d] = h0[d] * f;
97 return s;
98 }
99
101 template <class Coord>
102 Vec<Dim> lowerCorner(const std::array<Coord, Dim>& lo) const {
103 Vec<Dim> p{};
104 for (int d = 0; d < Dim; ++d)
105 p[d] = origin[d] + static_cast<Real>(lo[d]) * h0[d];
106 return p;
107 }
108
110 template <class Coord>
111 Vec<Dim> center(const std::array<std::array<Coord, Dim>, 2>& b) const {
112 Vec<Dim> p{};
113 for (int d = 0; d < Dim; ++d)
114 p[d] =
115 origin[d] +
116 (static_cast<Real>(b[0][d]) + 0.5 * (static_cast<Real>(b[1][d] - b[0][d]) + 1.0)) * h0[d];
117 return p;
118 }
119};
120
122template <class T>
123struct LeafField {
124 std::vector<T> values;
125
126 LeafField() = default;
127 explicit LeafField(Index n, T init = T{}) : values(static_cast<std::size_t>(n), init) {}
128
129 template <int Dim, unsigned Bits>
130 explicit LeafField(const BlockOctree<Dim, Bits>& t, T init = T{})
131 : values(static_cast<std::size_t>(t.numLeaves()), init) {}
132
133 Index size() const { return static_cast<Index>(values.size()); }
134 T& operator[](Index i) { return values[static_cast<std::size_t>(i)]; }
135 const T& operator[](Index i) const { return values[static_cast<std::size_t>(i)]; }
136 T* data() { return values.data(); }
137 const T* data() const { return values.data(); }
138};
139
140} // namespace peclet::amr
141
142#endif // PECLET_AMR_LEAF_FIELD_HPP
Per-block adaptive octree over block-local Morton codes.
Vec< Dim > filledVec(Real v)
Vec<Dim> with every component set to v (C++ has no aggregate-fill initializer).
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
World-space placement of a block-local octree: fine coordinate (0,..,0) sits at origin,...
void setIsotropic(Real h)
Set all axes to one spacing (the cubic case), in place.
Real cellVolume() const
World volume of a level-0 fine cell.
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).
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).
static AmrGeometry isotropicAt(const Vec< Dim > &o, Real h)
Cubic-cell convenience: the pre-Phase-3 {origin, h} construction.
Real leafSize(unsigned level, int d) const
World width of a leaf at level on axis d (it covers 2^level fine cells).
Vec< Dim > leafSize(unsigned level) const
World widths of a leaf at level, per axis.
A value per leaf, in the octree's Z-order leaf slot order.
std::vector< T > values
LeafField(Index n, T init=T{})
const T * data() const
const T & operator[](Index i) const
LeafField(const BlockOctree< Dim, Bits > &t, T init=T{})