17#ifndef PECLET_CORE_AMR_FACEGEOM_ASSEMBLY_HPP
18#define PECLET_CORE_AMR_FACEGEOM_ASSEMBLY_HPP
20#ifdef PECLET_CORE_HAVE_MORTON
36template <
unsigned Bits = 21u>
44 std::array<Coord, 3>
lo = M::from_code(
g.ov.codes(
i)).decode();
46 const long pc = (dir > 0) ?
static_cast<long>(
lo[axis]) +
static_cast<long>(
si)
47 :
static_cast<long>(
lo[axis]) - 1;
48 std::array<Coord, 3> p =
lo;
49 p[axis] =
g.wrap(
pc, axis);
50 return g.ov.locate(M::encode(p).code());
57 std::array<Coord, 3>
lo = M::from_code(
g.ov.codes(
i)).decode();
58 const unsigned Li =
g.ov.levels(
i);
60 for (
int axis = 0; axis < 3; ++axis)
61 for (
int dir = -1; dir <= 1; dir += 2) {
62 const long pc = (dir > 0) ?
static_cast<long>(
lo[axis]) +
static_cast<long>(
si)
63 :
static_cast<long>(
lo[axis]) - 1;
64 std::array<Coord, 3> p =
lo;
65 p[axis] =
g.wrap(
pc, axis);
66 const Index j =
g.ov.locate(M::encode(p).code());
67 const unsigned Lj =
g.ov.levels(
j);
70 cb(
j, axis, dir,
g.areaOf(
si),
72 g.openness(
i, axis, dir));
75 const int nsub = 1 << 2;
76 for (
int k = 0; k <
nsub; ++k) {
77 std::array<Coord, 3>
q =
lo;
78 q[axis] =
g.wrap(
pc, axis);
80 for (
int t = 0;
t < 3; ++
t) {
84 q[
t] =
g.wrap(
static_cast<long>(
lo[
t]) +
static_cast<long>(off),
t);
87 const Index jj =
g.ov.locate(M::encode(
q).code());
90 g.openness(
jj, axis, -dir));
108template <
unsigned Bits>
114 emit.g.periodic =
ap.periodic();
115 emit.g.hasOpen =
ap.hasOpenness();
116 for (
int d = 0; d < 3; ++d)
117 emit.g.fineExt[d] =
ap.fineExt()[d];
118 if (
ap.hasOpenness())
130 auto mk = [&](
const char*
lbl, std::size_t m) {
131 return View<double>(Kokkos::view_alloc(std::string(
lbl), Kokkos::WithoutInitializing), m);
133 auto mkI = [&](
const char*
lbl, std::size_t m) {
134 return View<Index>(Kokkos::view_alloc(std::string(
lbl), Kokkos::WithoutInitializing), m);
136 const std::size_t
F =
static_cast<std::size_t
>(
nf);
137 fg.nbr =
mkI(
"fg::nbr",
F);
138 fg.axis =
View<int>(Kokkos::view_alloc(
"fg::axis", Kokkos::WithoutInitializing),
F);
139 fg.dir =
View<int>(Kokkos::view_alloc(
"fg::dir", Kokkos::WithoutInitializing),
F);
140 fg.alphaArea =
mk(
"fg::aArea",
F);
141 fg.rawArea =
mk(
"fg::rArea",
F);
142 fg.dist =
mk(
"fg::dist",
F);
143 fg.alpha =
mk(
"fg::alpha",
F);
144 fg.upupI =
mkI(
"fg::upupI",
F);
145 fg.upupJ =
mkI(
"fg::upupJ",
F);
146 fg.invVol =
mk(
"fg::invVol",
static_cast<std::size_t
>(n));
147 fg.fluid =
View<char>(Kokkos::view_alloc(
"fg::fluid", Kokkos::WithoutInitializing),
148 static_cast<std::size_t
>(n));
153 Kokkos::parallel_for(
155 out.invVol(
i) = 1.0 /
e.g.cellVolume(
i);
164 double dist,
double alpha) {
168 o->alphaArea(k) = alpha *
area;
169 o->rawArea(k) =
area;
172 o->upupI(k) =
e->periodicNeighbor(
i, axis, -dir);
173 o->upupJ(k) =
e->periodicNeighbor(
j, axis, dir);
177 e.forEachFaceFull(
i,
cb);
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...
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,...
View< T > toDevice(const std::vector< T > &h, const std::string &label)
Upload a host std::vector into a freshly-sized device View (empty vector => empty view).
Kokkos::View< T *, MemSpace > View
1D device array.
double Real
Default host floating type. Device kernels may use float; conversions happen at the boundary.
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
typename Host::Coord Coord
The device face-geometry walker: replicates AmrPoisson::forEachFaceFull + periodicNeighbor over the d...
typename BlockOctreeView< 3, Bits >::Coord Coord
Index periodicNeighbor(Index i, int axis, int dir) const
Single-leaf periodic face neighbour (AmrPoisson::periodicNeighbor) — the SOU upstream probe.
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 >::M M
Index count(Index i) const
View< Index > nbr
neighbour leaf per face, size nFaces