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;
51 KOKKOS_INLINE_FUNCTION
static int faceIndex(
int axis,
int dir) {
52 return 2 * axis + (dir > 0 ? 0 : 1);
54 KOKKOS_INLINE_FUNCTION
double openness(Index leaf,
int axis,
int dir)
const {
62 for (
int d = 0; d < Dim; ++d)
64 a *=
static_cast<Real
>(s) *
h0[d];
68 const Real dist = 0.5 * (
static_cast<Real
>(si) +
static_cast<Real
>(sj)) *
h0[axis];
69 return areaOf(si < sj ? si : sj, axis) / dist;
71 KOKKOS_INLINE_FUNCTION
Coord wrap(
long c,
int axis)
const {
72 const long e =
static_cast<long>(
fineExt[axis]);
73 return static_cast<Coord>(((c % e) + e) % e);
75 KOKKOS_INLINE_FUNCTION Real
cellWidth(Index i,
int axis)
const {
76 return h0[axis] *
static_cast<Real
>(Index(1) <<
ov.levels(i));
80 const Real f =
static_cast<Real
>(Index(1) <<
ov.levels(i));
82 for (
int d = 0; d < Dim; ++d)
88 KOKKOS_INLINE_FUNCTION
double bcDiag(Index i)
const {
91 std::array<Coord, Dim> lo = M::from_code(
ov.codes(i)).decode();
94 for (
int axis = 0; axis < Dim; ++axis) {
95 const double wall =
areaOf(si, axis) / (0.5 *
static_cast<Real
>(si) *
h0[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;
99 const bool domainBoundary = !
periodic && (pc < 0 || pc >=
static_cast<long>(
fineExt[axis]));
103 s += (1.0 -
openness(i, axis, dir)) * wall;
111 template <
class Sink>
112 KOKKOS_INLINE_FUNCTION
void operator()(Index i, Sink& sink)
const {
113 std::array<Coord, Dim> lo = M::from_code(
ov.codes(i)).decode();
114 const unsigned Li =
ov.levels(i);
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;
123 p[axis] =
wrap(pc, axis);
124 const Index j =
ov.locate(M::encode(p).code());
125 const unsigned Lj =
ov.levels(j);
130 const int nsub = 1 << (Dim - 1);
131 for (
int k = 0; k < nsub; ++k) {
132 std::array<Coord, Dim> q = lo;
133 q[axis] =
wrap(pc, axis);
135 for (
int t = 0; t < Dim; ++t) {
138 const Coord off = ((k >> bit) & 1) ? sj :
Coord(0);
139 q[t] =
wrap(
static_cast<long>(lo[t]) +
static_cast<long>(off), t);
142 const Index jj =
ov.locate(M::encode(q).code());
154template <
int Dim,
unsigned Bits>
158 for (
int d = 0; d < Dim; ++d)
159 emit.
h0[d] = ap.
h0()[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));
179 View<double> invVol = op.
invVol;
180 View<double> bcDiag = op.
bcDiag;
182 Kokkos::parallel_for(
183 "amr::fv_diag", op.
n, KOKKOS_LAMBDA(
const Index 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,...
Device mirror of a BlockOctree's leaf arrays + device-callable queries.
typename Host::Coord Coord
An assembled face-CSR: row offsets (size n+1), neighbour index + coefficient per face (size nFaces).
View< Index > nbr
neighbour leaf per face, size nFaces
View< double > coef
coefficient per face, size nFaces
View< Index > start
CSR row offsets, size n+1; start(n) == 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
BlockOctreeView< Dim, Bits > View_t
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