22#ifndef PECLET_FLOW_STAR_ELIMINATION_HPP
23#define PECLET_FLOW_STAR_ELIMINATION_HPP
25#include <Kokkos_Core.hpp>
37 Kokkos::View<int*, CCMem>
cell;
42 Kokkos::View<double*, CCMem>
a;
47 ov.
cell = Kokkos::View<int*, CCMem>(
"star_cell", n);
48 ov.
a = Kokkos::View<double*, CCMem>(
"star_a", 6 * n);
56 const double v = ov.
a(k);
59 return exact ? v : (double)(
float)v;
62KOKKOS_INLINE_FUNCTION
int starWrap(
int v,
int n) {
64 return v < 0 ? v + n : v;
73 const StarOverlay& ov, Kokkos::View<int, CCMem> counter) {
75 Kokkos::deep_copy(counter, 0);
76 const bool fill = ov.
cell.extent(0) > 0;
79 "peclet::flow::star_build", MD(space, {0, 0, 0}, {nn.
x, nn.
y, nn.
z}),
80 KOKKOS_LAMBDA(
int x,
int y,
int z) {
81 const long sx = 1, sy = ext.
x, sz = (long)ext.
x * ext.
y;
82 const long st[3] = {sx, sy, sz};
83 const long i = (long)(x + g) + (long)(y + g) * sy + (long)(z + g) * sz;
89 for (
int a2 = 0; a2 < 3; ++a2) {
90 const double op = oa[a2](i + st[a2]), om = oa[a2](i);
91 const bool fp = sdf(i + st[a2]) >= 0.0, fm = sdf(i - st[a2]) >= 0.0;
92 av[2 * a2] = (fp && op > 0.0) ? op : 0.0;
93 av[2 * a2 + 1] = (fm && om > 0.0) ? om : 0.0;
94 D += av[2 * a2] + av[2 * a2 + 1];
98 const int slot = Kokkos::atomic_fetch_add(&counter(), 1);
100 ov.
cell(slot) = x + y * nn.
x + z * nn.
x * nn.
y;
101 for (
int k = 0; k < 6; ++k)
102 ov.
a(slot * 6 + k) = av[k];
106 auto h = Kokkos::create_mirror_view(counter);
107 Kokkos::deep_copy(h, counter);
115 int gY,
C3 extX,
int gX,
bool exact) {
119 Kokkos::parallel_for(
120 "peclet::flow::star_apply", Kokkos::RangePolicy<CCExec>(space, 0, nOv), KOKKOS_LAMBDA(
int s) {
121 const int inner = ov.
cell(s);
122 const int ix = inner % nn.
x, iy = (inner / nn.
x) % nn.
y, iz = inner / (nn.
x * nn.
y);
123 auto idx = [&](
int cx,
int cy,
int cz,
C3 ext,
int gb) {
125 (
long)(
starWrap(cz, nn.
z) + gb) * (
long)ext.x * ext.y;
127 const int nb[6][3] = {{ix + 1, iy, iz}, {ix - 1, iy, iz}, {ix, iy + 1, iz},
128 {ix, iy - 1, iz}, {ix, iy, iz + 1}, {ix, iy, iz - 1}};
129 double D = 0.0, num = 0.0;
131 for (
int k = 0; k < 6; ++k) {
132 av[k] =
starAval(ov, (
long)s * 6 + k, exact);
135 xv[k] = x(idx(nb[k][0], nb[k][1], nb[k][2], extX, gX));
137 num += av[k] * xv[k];
149 for (
int k = 0; k < 6; ++k) {
153 for (
int j = 0; j < 6; ++j)
155 acc += av[j] * (xv[k] - xv[j]);
156 Kokkos::atomic_add(&y(idx(nb[k][0], nb[k][1], nb[k][2], extY, gY)), (av[k] / D) * acc);
160 const double phibar = num / D;
161 for (
int k = 0; k < 6; ++k) {
164 Kokkos::atomic_add(&y(idx(nb[k][0], nb[k][1], nb[k][2], extY, gY)),
165 av[k] * (xv[k] - phibar));
182 int nOv,
C3 nn,
C3 ext,
int g,
C3 extP,
int gP,
bool exact,
183 double wx = 1.0,
double wy = 1.0,
double wz = 1.0) {
187 Kokkos::parallel_for(
188 "peclet::flow::star_correct_faces", Kokkos::RangePolicy<CCExec>(space, 0, nOv),
189 KOKKOS_LAMBDA(
int s) {
190 const int inner = ov.
cell(s);
191 const int ix = inner % nn.
x, iy = (inner / nn.
x) % nn.
y, iz = inner / (nn.
x * nn.
y);
192 auto idxP = [&](
int cx,
int cy,
int cz) {
194 (
long)(
starWrap(cz, nn.
z) + gP) * (
long)extP.
x * extP.
y;
196 auto idxF = [&](
int cx,
int cy,
int cz) {
198 (
long)(
starWrap(cz, nn.
z) + g) * (
long)ext.
x * ext.
y;
200 const int nb[6][3] = {{ix + 1, iy, iz}, {ix - 1, iy, iz}, {ix, iy + 1, iz},
201 {ix, iy - 1, iz}, {ix, iy, iz + 1}, {ix, iy, iz - 1}};
202 double D = 0.0, num = 0.0;
203 for (
int k = 0; k < 6; ++k) {
204 const double a =
starAval(ov, (
long)s * 6 + k, exact);
208 num += a * phi(idxP(nb[k][0], nb[k][1], nb[k][2]));
213 const double phibar = num / D;
215 const double wv[3] = {wx, wy, wz};
216 for (
int k = 0; k < 6; ++k) {
217 if (
starAval(ov, (
long)s * 6 + k, exact) <= 0.0)
219 const int a2 = k / 2;
222 fa[a2](idxF(nb[k][0], nb[k][1], nb[k][2])) += wv[a2] * phibar;
225 fa[a2](idxF(ix, iy, iz)) -= wv[a2] * phibar;
flow — portable (Kokkos) cut-cell pressure-operator face openness from an SDF.
Kokkos::DefaultExecutionSpace CCExec
Kokkos::MDRangePolicy< Exec, Kokkos::Rank< 3, Kokkos::Iterate::Left, Kokkos::Iterate::Left > > MDRange3
3-D range, x (the first index) fastest (both the tile order and the order within a tile).
Kokkos::View< const double *, CCMem > CCConst
StarOverlay starMakeOverlay(long n)
int buildStarOverlay(CCConst sdf, CCConst ox, CCConst oy, CCConst oz, C3 ext, int g, C3 nn, const StarOverlay &ov, Kokkos::View< int, CCMem > counter)
Count + fill the star overlay from the cell-centered sdf and the ORIGINAL (unfiltered) apertures on t...
void starCorrectFaces(CCField uf, CCField vf, CCField wf, CCConst phi, const StarOverlay &ov, int nOv, C3 nn, C3 ext, int g, C3 extP, int gP, bool exact, double wx=1.0, double wy=1.0, double wz=1.0)
Fix the face correction at fluid|solid faces: projectCorrect applied -(phi_hi - phi_lo) with the soli...
Kokkos::View< double *, CCMem > CCField
int starWrap(int v, int n)
double starAval(const StarOverlay &ov, long k, bool exact)
One stored aperture, at the precision the gate selects.
void starApplyDelta(CCField y, CCConst x, const StarOverlay &ov, int nOv, C3 nn, C3 extY, int gY, C3 extX, int gX, bool exact)
y += S_star x over the inner cells of the (extY, gY) block, x read from the (extX,...
flow — the multidimensional iteration policies: iteration order follows storage.
One entry per eliminated solid-centered cell: packed INNER flat index + the apertures of its (up to 6...
Kokkos::View< double *, CCMem > a
Kokkos::View< int *, CCMem > cell