16#ifndef PECLET_AMR_FACEGEOM_ASSEMBLY_HPP
17#define PECLET_AMR_FACEGEOM_ASSEMBLY_HPP
27#include "peclet/core/common/view.hpp"
34template <
unsigned Bits = 21u>
42 std::array<Coord, 3> lo = M::from_code(
g.ov.codes(i)).decode();
44 const long pc = (dir > 0) ?
static_cast<long>(lo[axis]) +
static_cast<long>(si)
45 :
static_cast<long>(lo[axis]) - 1;
46 std::array<Coord, 3> p = lo;
47 p[axis] =
g.wrap(pc, axis);
48 return g.ov.locate(M::encode(p).code());
55 std::array<Coord, 3> lo = M::from_code(
g.ov.codes(i)).decode();
56 const unsigned Li =
g.ov.levels(i);
58 for (
int axis = 0; axis < 3; ++axis)
59 for (
int dir = -1; dir <= 1; dir += 2) {
60 const long pc = (dir > 0) ?
static_cast<long>(lo[axis]) +
static_cast<long>(si)
61 :
static_cast<long>(lo[axis]) - 1;
62 std::array<Coord, 3> p = lo;
63 p[axis] =
g.wrap(pc, axis);
64 const Index j =
g.ov.locate(M::encode(p).code());
65 const unsigned Lj =
g.ov.levels(j);
68 cb(j, axis, dir,
g.areaOf(si, axis),
69 0.5 * (
static_cast<Real
>(si) +
static_cast<Real
>(sj)) *
g.h0[axis],
70 g.openness(i, axis, dir));
73 const int nsub = 1 << 2;
74 for (
int k = 0; k < nsub; ++k) {
75 std::array<Coord, 3> q = lo;
76 q[axis] =
g.wrap(pc, axis);
78 for (
int t = 0; t < 3; ++t) {
81 const Coord off = ((k >> bit) & 1) ? sj :
Coord(0);
82 q[t] =
g.wrap(
static_cast<long>(lo[t]) +
static_cast<long>(off), t);
85 const Index jj =
g.ov.locate(M::encode(q).code());
86 cb(jj, axis, dir,
g.areaOf(sj, axis),
87 0.5 * (
static_cast<Real
>(si) +
static_cast<Real
>(sj)) *
g.h0[axis],
88 g.openness(jj, axis, -dir));
94 KOKKOS_INLINE_FUNCTION Index
count(Index i)
const {
97 KOKKOS_INLINE_FUNCTION
void operator()(Index,
int,
int,
double,
double,
double) { ++c; }
106template <
unsigned Bits>
111 for (
int d = 0; d < 3; ++d)
112 emit.
g.h0[d] = ap.
h0()[d];
115 for (
int d = 0; d < 3; ++d)
116 emit.
g.fineExt[d] = ap.
fineExt()[d];
122 View<Index> start =
scanOffsets(n, KOKKOS_LAMBDA(
const Index i) {
return emit.
count(i); }, nf);
129 auto mk = [&](
const char* lbl, std::size_t m) {
130 return View<double>(Kokkos::view_alloc(std::string(lbl), Kokkos::WithoutInitializing), m);
132 auto mkI = [&](
const char* lbl, std::size_t m) {
133 return View<Index>(Kokkos::view_alloc(std::string(lbl), Kokkos::WithoutInitializing), m);
135 const std::size_t F =
static_cast<std::size_t
>(nf);
136 fg.nbr = mkI(
"fg::nbr", F);
137 fg.axis = View<int>(Kokkos::view_alloc(
"fg::axis", Kokkos::WithoutInitializing), F);
138 fg.dir = View<int>(Kokkos::view_alloc(
"fg::dir", Kokkos::WithoutInitializing), F);
139 fg.alphaArea = mk(
"fg::aArea", F);
140 fg.rawArea = mk(
"fg::rArea", F);
141 fg.dist = mk(
"fg::dist", F);
142 fg.alpha = mk(
"fg::alpha", F);
143 fg.upupI = mkI(
"fg::upupI", F);
144 fg.upupJ = mkI(
"fg::upupJ", F);
145 fg.invVol = mk(
"fg::invVol",
static_cast<std::size_t
>(n));
146 fg.fluid = View<char>(Kokkos::view_alloc(
"fg::fluid", Kokkos::WithoutInitializing),
147 static_cast<std::size_t
>(n));
149 View<char> fluidDev = toDevice(fluidHost,
"fg::fluidIn");
152 Kokkos::parallel_for(
153 "amr::facegeom_fill", n, KOKKOS_LAMBDA(
const Index i) {
154 out.
invVol(i) = 1.0 / e.
g.cellVolume(i);
155 out.
fluid(i) = fluidDev(i);
162 KOKKOS_INLINE_FUNCTION
void operator()(Index j,
int axis,
int dir,
double area,
163 double dist,
double alpha) {
175 } cb{&e, &out, i, out.
start(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
const std::vector< double > & opennessRaw() const
View< Index > scanOffsets(Index n, const CountFn &countFn, Index &nTotal)
CSR row offsets (size n+1) from a per-cell count functor, via one exclusive prefix scan,...
FaceGeom assembleFaceGeom(const AmrPoisson< 3, Bits > &ap, const std::vector< char > &fluidHost, const BlockOctreeView< 3, Bits > &ov)
Assemble the collocated FaceGeom entirely on device from a built AmrPoisson (openness set) + a per-ce...
Device mirror of a BlockOctree's leaf arrays + device-callable queries.
typename Host::Coord Coord
The device face-geometry walker: replicates AmrPoisson::forEachFaceFull + periodicNeighbor over the d...
Index count(Index i) const
Index periodicNeighbor(Index i, int axis, int dir) const
Single-leaf periodic face neighbour (AmrPoisson::periodicNeighbor) — the SOU upstream probe.
typename BlockOctreeView< 3, Bits >::M M
void forEachFaceFull(Index i, CB &cb) const
Visit each (sub)face of leaf i: cb(neighbour, axis, dir, area, dist, alpha) in forEachFaceFull order.
typename BlockOctreeView< 3, Bits >::Coord Coord
View< double > alphaArea
α·area (physical) per face, size nFaces
View< int > dir
face direction +1/-1, size nFaces
View< double > invVol
1/V_i per cell, size n
View< double > rawArea
raw face area (physical, no openness) per face — advection flux
View< int > axis
face axis 0/1/2, size nFaces
View< Index > upupJ
upstream-of-j probe (periodicNeighbor(j,axis,+dir)) — SOU, size nFaces
View< Index > nbr
neighbour leaf per face, size nFaces
View< double > alpha
openness per face (gradient gate), size nFaces
View< double > dist
face-normal distance (physical) per face, size nFaces
View< Index > start
CSR row offsets, size n+1.
View< Index > upupI
upstream-of-i probe (periodicNeighbor(i,axis,−dir)) — SOU, size nFaces
View< char > fluid
per-cell fluid flag, size n
Device-callable reproduction of AmrPoisson's per-cell face walk + geometry.