18#ifndef PECLET_AMR_ASSEMBLY_HPP
19#define PECLET_AMR_ASSEMBLY_HPP
28#include "peclet/core/common/view.hpp"
35template <
int Dim,
unsigned Bits = (Dim == 2 ? 32u : (Dim == 3 ? 21u : 16u))>
50 static constexpr int kFaces = 2 * Dim;
52 return 2 * axis + (dir > 0 ? 0 : 1);
62 for (
int d = 0; d < Dim; ++d)
72 const long e =
static_cast<long>(
fineExt[axis]);
73 return static_cast<Coord>(((
c %
e) +
e) %
e);
82 for (
int d = 0; d < Dim; ++d)
91 std::array<Coord, Dim>
lo = M::from_code(
ov.
codes(
i)).decode();
94 for (
int axis = 0; axis < Dim; ++axis) {
96 for (
int dir = -1; dir <= 1; dir += 2) {
97 const long pc = (dir > 0) ?
static_cast<long>(
lo[axis]) +
static_cast<long>(
si)
98 :
static_cast<long>(
lo[axis]) - 1;
111 template <
class Sink>
113 std::array<Coord, Dim>
lo = M::from_code(
ov.
codes(
i)).decode();
116 for (
int axis = 0; axis < Dim; ++axis)
117 for (
int dir = -1; dir <= 1; dir += 2) {
118 const long pc = (dir > 0) ?
static_cast<long>(
lo[axis]) +
static_cast<long>(
si)
119 :
static_cast<long>(
lo[axis]) - 1;
122 std::array<Coord, Dim>
p =
lo;
130 const int nsub = 1 << (Dim - 1);
131 for (
int k = 0; k <
nsub; ++k) {
132 std::array<Coord, Dim>
q =
lo;
135 for (
int t = 0;
t < Dim; ++
t) {
139 q[
t] =
wrap(
static_cast<long>(
lo[
t]) +
static_cast<long>(off),
t);
154template <
int Dim,
unsigned Bits>
158 for (
int d = 0; d < Dim; ++d)
163 for (
int d = 0; d < Dim; ++d)
175 op.
invVol =
View<double>(Kokkos::view_alloc(
"amr::invVol", Kokkos::WithoutInitializing),
176 static_cast<std::size_t
>(op.
n));
177 op.
bcDiag =
View<double>(Kokkos::view_alloc(
"amr::bcDiag", Kokkos::WithoutInitializing),
178 static_cast<std::size_t
>(op.
n));
182 Kokkos::parallel_for(
184 invVol(
i) = 1.0 /
e.cellVolume(
i);
185 bcDiag(
i) =
e.bcDiag(
i);
Cell-centered FV Poisson operator on one (periodic) block octree.
const std::array< Coord, Dim > & fineExt() const
Per-axis fine-grid extent (brick·2^lmax) — the periodic wrap modulus.
const Vec< Dim > & h0() const
bool immersedWall() const
const std::vector< double > & opennessRaw() const
Csr buildFaceCsr(Index n, const Emit &emit)
Build a face-CSR on device from a per-cell emit functor.
FvOp assembleFv(const AmrPoisson< Dim, Bits > &ap, const BlockOctreeView< Dim, Bits > &ov)
Assemble the FvOp entirely on the device from a host AmrPoisson's geometry (h0, periodicity,...
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,...
View< std::uint8_t > levels
Index locate(Code p) const
Leaf containing Morton code p, or -1. Callable in a device kernel.
typename Host::Coord Coord
An assembled face-CSR: row offsets (size n+1), neighbour index + coefficient per face (size nFaces).
Device-callable reproduction of AmrPoisson's per-cell face walk + geometry.
static constexpr int kFaces
typename View_t::Code Code
void operator()(Index i, Sink &sink) const
Emit each face of leaf i as sink(neighbourLeaf, coef=openness·A_f/d_f) — the exact enumeration (axis-...
double bcDiag(Index i) const
Σ over leaf i's Dirichlet-wall faces of A_f/(½·cellWidth) — mirrors AmrPoisson::boundaryDiag.
Real areaOf(Coord s, int axis) const
Area of a face NORMAL TO axis (Phase 3: the product over the OTHER axes).
Real cellWidth(Index i, int axis) const
typename View_t::Coord Coord
Real cellVolume(Index i) const
Real coeff(Coord si, Coord sj, int axis) const
Real cellWidth(Index i) const
Coord fineExt[Dim]
periodic-wrap modulus per axis
View_t ov
device octree (codes/levels/locate)
View< const double > alpha
per-leaf·(2·Dim) openness, or empty when !hasOpen
double openness(Index leaf, int axis, int dir) const
Coord wrap(long c, int axis) const
Real h0[Dim]
finest cell width PER AXIS (Phase 3); set by the emitters
static int faceIndex(int axis, int dir)
View< Index > faceStart
CSR row offsets, size n+1.
View< double > bcDiag
Dirichlet boundary diagonal per cell (0 if periodic), size n.
View< double > invVol
1/V_i, size n
View< Index > faceNbr
neighbour leaf per face, size nFaces
View< double > faceW
w_f = openness·A_f/d_f per face, size nFaces