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) {
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));
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)
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));
152 Kokkos::parallel_for(
154 out.invVol(
i) = 1.0 /
e.g.cellVolume(
i);
163 double dist,
double alpha) {
167 o->alphaArea(k) = alpha *
area;
168 o->rawArea(k) =
area;
171 o->upupI(k) =
e->periodicNeighbor(
i, axis, -dir);
172 o->upupJ(k) =
e->periodicNeighbor(
j, axis, dir);
176 e.forEachFaceFull(
i,
cb);
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...
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,...
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< Index > nbr
neighbour leaf per face, size nFaces
Device-callable reproduction of AmrPoisson's per-cell face walk + geometry.