38#ifndef PECLET_FLOW_VOF_SHARP_VISCOUS_HPP
39#define PECLET_FLOW_VOF_SHARP_VISCOUS_HPP
42#include <Kokkos_Core.hpp>
47#include "peclet/core/vof/plic_regions.hpp"
55using SvByte = Kokkos::View<std::uint8_t*, CCMem>;
86 return s * s * (3.0 - 2.0 * s);
90using SvList = Kokkos::View<long*, CCMem>;
95 long st[3] = {1, 0, 0};
96 long st3[3] = {1, 0, 0};
108 double ell[3] = {1.0, 1.0, 1.0};
111 KOKKOS_INLINE_FUNCTION
long idx(
const int q[3])
const {
112 return (
long)q[0] + (long)q[1] *
st[1] + (
long)q[2] *
st[2];
114 KOKKOS_INLINE_FUNCTION
long idx3(
const int q[3])
const {
115 return (
long)(q[0] +
d) + (
long)(q[1] +
d) *
st3[1] + (
long)(q[2] +
d) *
st3[2];
117 KOKKOS_INLINE_FUNCTION
bool inDomain(
const int q[3])
const {
118 return q[0] >=
dlo[0] && q[0] <
dhi[0] && q[1] >=
dlo[1] && q[1] <
dhi[1] && q[2] >=
dlo[2] &&
121 KOKKOS_INLINE_FUNCTION
double colour(
const int q[3])
const {
return col(
idx3(q)); }
122 KOKKOS_INLINE_FUNCTION
int cellClass(
const int q[3])
const {
return (
int)
cls(
idx(q)); }
123 KOKKOS_INLINE_FUNCTION
double mu(
double f)
const {
return p0 +
p1 * f; }
124 KOKKOS_INLINE_FUNCTION
double res(
double f)
const {
return f /
muA + (1.0 - f) /
muB; }
129 KOKKOS_INLINE_FUNCTION
void plane(
const int q[3],
int k,
double m[3],
double& al)
const {
131 const long j =
idx3(q);
138 const int v = k -
kSvVirtual0, ax = v >> 1, side = v & 1;
140 const double s = (side == 0) ? (one ? -1.0 : 1.0) : (one ? 1.0 : -1.0);
141 m[0] = m[1] = m[2] = 0.0;
143 al = (side == 0) ? 0.0 : s;
147 KOKKOS_INLINE_FUNCTION
static void edgeCells(
int a,
int c,
int da[4],
int dc[4]) {
168 KOKKOS_INLINE_FUNCTION
int edgeDistances(
const int k[3],
int a,
int c,
double dist[4])
const {
171 const int b = 3 - a - c;
173 for (
int t = 0; t < 4; ++t) {
174 int q[3] = {k[0], k[1], k[2]};
181 plane(q, kc, mm, aa);
183 xi[a] = (double)da[t];
184 xi[c] = (double)dc[t];
186 const double nrm = Kokkos::sqrt(mm[0] * mm[0] + mm[1] * mm[1] + mm[2] * mm[2]);
187 dist[t] = Kokkos::fabs(mm[0] * xi[0] + mm[1] * xi[1] + mm[2] * xi[2] - aa) / nrm;
200 KOKKOS_INLINE_FUNCTION
int edgeOwnerSet(
const int k[3],
int a,
int c,
double dist[4],
201 double& dmin,
double w[4])
const {
206 for (
int t = 0; t < 4; ++t)
207 if (((kmask >> t) & 1) && (best < 0 || dist[t] < dmin)) {
212 for (
int t = 0; t < 4; ++t) {
214 if (!((kmask >> t) & 1))
216 const double g = dist[t] - dmin;
221 return kmask | (tmask << 4);
229 KOKKOS_INLINE_FUNCTION
int edgeTieKeys(
const int k[3],
int ac,
double& spread,
double& gap,
230 bool& blended)
const {
231 const int a = (ac == 2) ? 1 : 0, c = (ac == 0) ? 1 : 2;
234 double dist[4], dmin, w[4];
237 for (
int t = 0; t < 4; ++t) {
240 const double g = dist[t] - dmin;
241 if ((m >> (4 + t)) & 1) {
243 spread = Kokkos::fmax(spread, g);
245 gap = (gap < 0.0) ? g : Kokkos::fmin(gap, g);
266 KOKKOS_INLINE_FUNCTION
double forEachOwner(
const int k[3],
int a,
int c,
F&& f)
const {
267 double dist[4], dmin, w[4];
272 for (
int t = 0; t < 4; ++t)
278 for (
int j = 0; j < n; ++j) {
279 const int t = (ts >> (2 * j)) & 3;
280 const double wt =
pick4(w, t);
281 int q[3] = {k[0], k[1], k[2]};
282 q[a] -=
pick4(da, t);
283 q[c] -=
pick4(dc, t);
294 KOKKOS_INLINE_FUNCTION
static T
pick4(
const T v[4],
int t) {
295 return (t == 0) ? v[0] : (t == 1) ? v[1] : (t == 2) ? v[2] : v[3];
304 forEachOwner(k, a, c, [&](
const int o[3],
const double m[3],
double al,
double w) {
318 double sac = 0.0, sca = 0.0;
320 forEachOwner(k, a, c, [&](
const int o[3],
const double m[3],
double al,
double w) {
335 const int o[3],
const double m[3],
337 const int p = (row == c) ? a : c;
338 const int b = 3 - a - c;
339 const double xiP = (double)(k[p] - o[p]);
340 const double lr = (double)(k[row] - o[row]) - 0.5, lb = (double)(k[b] - o[b]);
341 const int q = (p == 0) ? 1 : 0;
342 return plicFaceFraction(m, al, p, xiP, (q == row) ? lr : lb, (q == row) ? lb : lr);
347 KOKKOS_INLINE_FUNCTION
double linkFraction(
const int k[3],
int dd,
int cc,
const int o[3],
348 const double m[3],
double al)
const {
349 const int b = 3 - dd - cc;
350 return plicHatBoxFraction(m, al, cc, (
double)(k[cc] - o[cc]), dd, (
double)(k[dd] - o[dd]),
351 (
double)(k[b] - o[b]));
356 KOKKOS_INLINE_FUNCTION
bool edgeInDomain(
const int k[3],
int a,
int c)
const {
357 const int b = 3 - a - c;
358 return k[b] >=
dlo[b] && k[b] <
dhi[b] && k[a] >=
dlo[a] && k[a] <=
dhi[a] && k[c] >=
dlo[c] &&
364 KOKKOS_INLINE_FUNCTION
double edgePhase(
const int k[3],
int a,
int c)
const {
367 for (
int t = 0; t < 4; ++t) {
368 int q[3] = {k[0], k[1], k[2]};
372 return colour(q) >= 1.0 -
eps ? 1.0 : 0.0;
379 KOKKOS_INLINE_FUNCTION
void edgeTau(
const int k[3],
int a,
int c,
const CCConst (&tau)[3],
385 for (
int s = 0; s < 4; ++s) {
386 int q[3] = {k[0], k[1], k[2]};
392 t[0] = t[1] = t[2] = 0.0;
393 const double w = (double)nI;
394 for (
int s = 0; s < nI; ++s) {
395 t[0] += tau[0](js[s]) / w;
396 t[1] += tau[1](js[s]) / w;
397 t[2] += tau[2](js[s]) / w;
406 KOKKOS_INLINE_FUNCTION
double edgeTraction(
const int k[3],
int a,
int c,
int row,
407 const CCConst (&tau)[3])
const {
408 double t[3] = {0.0, 0.0, 0.0}, acc = 0.0;
409 bool haveTau =
false;
411 forEachOwner(k, a, c, [&](
const int o[3],
const double m[3],
double al,
double w) {
416 double n[3] = {0.0, 0.0, 0.0};
417 vofPhysNormal(m,
gm, n);
421 acc += w * (n[a] * t[c] * (1.0 - mub * rac) + n[c] * t[a] * (1.0 - mub * rca));
438 double n[3] = {0.0, 0.0, 0.0};
439 vofPhysNormal(m,
gm, n);
440 const double cb = plicMidsectionFraction(m, al, c), cc =
colour(q);
441 const long j =
idx(q);
442 const double mcc = v[c](j +
st[c]) - v[c](j);
443 return 2.0 * (
muA -
muB) * (cb - cc) * (mcc - dnn(j)) +
444 2.0 * n[c] * tau[c](j) * (1.0 -
mu(cb) *
res(cc));
451 KOKKOS_INLINE_FUNCTION
void fitCoef(
int a,
int c,
double thA,
const double n[3],
452 double co[9])
const {
453 const double thlo =
lowA ? thA : 1.0 - thA;
454 const double kk = (1.0 - thlo) * (
r - 1.0) * n[a];
456 for (
int p = 0; p < 3; ++p)
457 pc[p] = ((p == c) ? 1.0 : 0.0) - n[c] * n[p];
458 for (
int p = 0; p < 3; ++p)
459 for (
int q = 0; q < 3; ++q)
460 co[3 * p + q] = ((p == a && q == c) ? 1.0 : 0.0) + kk * (pc[p] * n[q] + pc[q] * n[p]);
462 KOKKOS_INLINE_FUNCTION
void fitRow(
int a,
int c,
double thA,
double mv,
const double n[3],
463 double N[81],
double rhs[9])
const {
466 for (
int s = 0; s < 9; ++s) {
467 rhs[s] += co[s] * mv;
468 for (
int t = s; t < 9; ++t)
469 N[9 * s + t] += co[s] * co[t];
479 KOKKOS_INLINE_FUNCTION
int fitItem(
const int K[3],
int it,
const CCConst (&v)[3],
int ra[3],
480 int rc[3],
double th[3],
double mv[3])
const {
482 const int q[3] = {K[0] + it % 3 - 1, K[1] + (it / 3) % 3 - 1, K[2] + it / 9 - 1};
485 const double tq =
colour(q);
486 const long j =
idx(q);
487 for (
int c = 0; c < 3; ++c) {
490 mv[c] = v[c](j +
st[c]) - v[c](j);
495 const int a = (pr == 2) ? 1 : 0, c = (pr == 0) ? 1 : 2, b = 3 - a - c;
496 const int ex = (b == 0) ? 3 : 4, ey = (b == 1) ? 3 : 4;
497 const int k[3] = {K[0] - 1 + l % ex, K[1] - 1 + (l / ex) % ey, K[2] - 1 + l / (ex * ey)};
500 double tac = 0.0, tca = 0.0;
503 const long j =
idx(k);
507 mv[0] = (
ell[c] /
ell[a]) * (v[c](j) - v[c](j -
st[a]));
511 mv[1] = (
ell[a] /
ell[c]) * (v[a](j) - v[a](j -
st[c]));
520 KOKKOS_INLINE_FUNCTION
bool fitCell(
const int K[3],
const CCConst (&v)[3],
double tau[3],
522 double n[3] = {0.0, 0.0, 0.0};
524 double N[81], rhs[9];
525 for (
int s = 0; s < 81; ++s)
527 for (
int s = 0; s < 9; ++s)
529 for (
int it = 0; it <
kSvItems; ++it) {
532 const int nr =
fitItem(K, it, v, ra, rc, th, mv);
533 for (
int q = 0; q < nr; ++q)
534 fitRow(ra[q], rc[q], th[q], mv[q], n,
N, rhs);
540 KOKKOS_INLINE_FUNCTION
void fitNormal(
const int K[3],
double n[3])
const {
543 vofPhysNormal(m,
gm, n);
548 KOKKOS_INLINE_FUNCTION
static bool fitSolve(
double N[81],
const double rhs[9],
const double n[3],
549 double mulo,
double tau[3],
double& dnn) {
552 for (
int s = 0; s < 9; ++s)
554 const double pmin = 1
e-10 * tr / 9.0;
555 for (
int s = 0; s < 9; ++s) {
556 double dpiv =
N[9 * s + s];
557 for (
int t = 0; t < s; ++t)
558 dpiv -=
N[9 * t + s] *
N[9 * t + s];
559 if (!(dpiv >= pmin) || !(dpiv > 0.0))
561 const double rd = Kokkos::sqrt(dpiv);
563 for (
int u = s + 1; u < 9; ++u) {
564 double x =
N[9 * s + u];
565 for (
int t = 0; t < s; ++t)
566 x -=
N[9 * t + s] *
N[9 * t + u];
567 N[9 * s + u] = x / rd;
571 for (
int s = 0; s < 9; ++s) {
573 for (
int t = 0; t < s; ++t)
574 x -=
N[9 * t + s] * y[t];
575 y[s] = x /
N[9 * s + s];
577 for (
int s = 8; s >= 0; --s) {
579 for (
int t = s + 1; t < 9; ++t)
580 x -=
N[9 * s + t] * L[t];
581 L[s] = x /
N[9 * s + s];
584 double sn[3], nsn = 0.0;
586 for (
int p = 0; p < 3; ++p) {
588 for (
int q = 0; q < 3; ++q) {
589 x += (L[3 * p + q] + L[3 * q + p]) * n[q];
590 dnn += n[p] * L[3 * p + q] * n[q];
595 for (
int p = 0; p < 3; ++p)
596 tau[p] =
mulo * (sn[p] - n[p] * nsn);
617 KOKKOS_INLINE_FUNCTION
double idiag(
long i)
const {
return base.idiag(i); }
618 KOKKOS_INLINE_FUNCTION
double beta(
long i,
long j)
const {
619 const long dd = j - i, ad = (dd < 0) ? -dd : dd;
620 if (ad ==
geo.st[
c]) {
621 const long q = (dd > 0) ? i : j;
623 return base.beta(i, j);
626 const int a = (ad == 1) ? 0 : ((ad ==
geo.st[1]) ? 1 : 2);
627 const long kk = (dd > 0) ? j : i;
630 const long sa =
geo.st[a], sc =
geo.st[
c];
633 return base.beta(i, j);
634 const long z = kk /
geo.st[2], rr = kk - z *
geo.st[2], y = rr /
geo.st[1];
635 const int k[3] = {(int)(rr - y *
geo.st[1]), (int)y, (
int)z};
637 if (!
geo.edgeFaceFraction(k, a,
c,
c, f))
638 return base.beta(i, j);
648 Kokkos::parallel_for(
649 "peclet::flow::vof::sharp_classify",
651 KOKKOS_LAMBDA(
int x,
int y,
int z) {
652 const int q[3] = {x, y, z};
653 const long i = g.idx(q);
654 if (!g.inDomain(q)) {
658 const double cq = g.colour(q);
663 const bool one = cq >= 1.0 - g.eps;
664 for (
int a = 0; a < 3; ++a)
665 for (
int side = 0; side < 2; ++side) {
666 int nb[3] = {x, y, z};
667 nb[a] += side ? 1 : -1;
670 const double cn = g.colour(nb);
673 if ((cn >= 1.0 - g.eps) != one) {
674 cls(i) = (std::uint8_t)(
kSvVirtual0 + 2 * a + side);
693using SvScrD = Kokkos::View<double*, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged>;
694using SvScrI = Kokkos::View<int*, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged>;
702 template <
class Member>
720template <
class Member>
725 double n[3] = {0.0, 0.0, 0.0};
727 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm,
kSvEntries),
728 [&](
const int e) { sc.ent(e) = 0.0; });
732 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm, i0, i1), [&](
const int it) {
735 const int nr = g.fitItem(K, it, v, ra, rc, th, mv);
737 for (
int q = 0; q < nmax; ++q) {
738 sc.ok(r0 + q) = (q < nr) ? 1 : 0;
741 g.fitCoef(ra[q], rc[q], th[q], n, co);
742 for (
int e = 0; e < 9; ++e)
743 sc.co(9 * (r0 + q) + e) = co[e];
744 sc.mv(r0 + q) = mv[q];
749 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm,
kSvEntries), [&](
const int e) {
750 double acc = sc.ent(e);
752 const int s = e - 45;
753 for (
int r = 0; r < nrow; ++r)
755 acc += sc.co(9 * r + s) * sc.mv(r);
763 for (
int r = 0; r < nrow; ++r)
765 acc += sc.co(9 * r + s) * sc.co(9 * r + t);
771 Kokkos::single(Kokkos::PerTeam(tm), [&]() {
772 double N[81], rhs[9];
773 for (
int s = 0; s < 81; ++s)
776 for (
int s = 0; s < 9; ++s)
777 for (
int t = s; t < 9; ++t)
778 N[9 * s + t] = sc.ent(e++);
779 for (
int s = 0; s < 9; ++s)
780 rhs[s] = sc.ent(45 + s);
781 double t[3] = {0.0, 0.0, 0.0}, dn = 0.0;
784 t[0] = t[1] = t[2] = 0.0;
806 const CCConst v0 = v[0], v1 = v[1], v2 = v[2];
808 const int nx = hi.
x - lo.x, ny = hi.
y - lo.y, nz = hi.
z - lo.z;
809 if (nx <= 0 || ny <= 0 || nz <= 0)
811 const long region = (long)nx * ny * nz;
813 Kokkos::parallel_scan(
814 "peclet::flow::vof::sharp_fit_compact", Kokkos::RangePolicy<CCExec>(space, 0, region),
815 KOKKOS_LAMBDA(
const long r,
long& upd,
const bool final) {
816 const int q[3] = {lo.x + (int)(r % nx), lo.y + (int)((r / nx) % ny),
817 lo.z + (int)(r / ((
long)nx * ny))};
818 const long i = g.idx(q);
826 if (g.cellClass(q) !=
kSvNone) {
837 if constexpr (!Kokkos::SpaceAccessibility<CCExec, Kokkos::HostSpace>::accessible) {
838 using Policy = Kokkos::TeamPolicy<CCExec>;
839 Policy pol(space, (
int)nb,
kVofWarp);
841 Kokkos::parallel_for(
842 "peclet::flow::vof::sharp_fit", pol, KOKKOS_LAMBDA(
const Policy::member_type& tm) {
843 const long i = list(tm.league_rank());
844 const long z = i / g.st[2], rr = i - z * g.st[2], y = rr / g.st[1];
845 const int K[3] = {(int)(rr - y * g.st[1]), (int)y, (
int)z};
846 const CCConst vv[3] = {v0, v1, v2};
848 sharpFitTeam(tm, sc, g, K, vv, i, t0, t1, t2, dnn,
fb);
851 Kokkos::parallel_for(
852 "peclet::flow::vof::sharp_fit", Kokkos::RangePolicy<CCExec>(space, 0, nb),
853 KOKKOS_LAMBDA(
long r) {
854 const long i = list(r);
855 const long z = i / g.st[2], rr = i - z * g.st[2], y = rr / g.st[1];
856 const int q[3] = {(int)(rr - y * g.st[1]), (int)y, (
int)z};
857 const CCConst vv[3] = {v0, v1, v2};
858 double t[3] = {0.0, 0.0, 0.0}, dn = 0.0;
859 if (!g.fitCell(q, vv, t, dn)) {
874 const long cells = (long)(hi.
x - lo.x) * (hi.
y - lo.y) * (hi.
z - lo.z);
876 Kokkos::view_alloc(
CCExec(),
"peclet::flow::vof::sharp_list", Kokkos::WithoutInitializing),
877 cells > 0 ? cells : 1);
878 sharpFit(gg, v, t0, t1, t2, dnn,
fb, lo, hi, list);
890 double wc,
bool skipLoC,
SvList list,
long nl) {
892 const int a1 = (c == 0) ? 1 : 0, a2 = (c == 2) ? 1 : 2;
893 const double f1 = 1.0 / (geo.ell[a1] * geo.ell[c]), f2 = 1.0 / (geo.ell[a2] * geo.ell[c]);
894 const CCConst v0 = v[0], v1 = v[1], v2 = v[2], t0 = tau[0], t1 = tau[1], t2 = tau[2];
895 const int lo[3] = {g + ((skipLoC && c == 0) ? 1 : 0), g + ((skipLoC && c == 1) ? 1 : 0),
896 g + ((skipLoC && c == 2) ? 1 : 0)};
897 const auto body = KOKKOS_LAMBDA(
int x,
int y,
int z) {
898 const CCConst vv[3] = {v0, v1, v2}, tt[3] = {t0, t1, t2};
899 const int q[3] = {x, y, z};
900 int qm[3] = {x, y, z};
902 const double xc = geo.cellExtra(q, c, vv, tt, dnn) - geo.cellExtra(qm, c, vv, tt, dnn);
903 int p1[3] = {x, y, z}, p2[3] = {x, y, z};
906 const double y1 = geo.edgeTraction(p1, a1, c, c, tt) - geo.edgeTraction(q, a1, c, c, tt);
907 const double y2 = geo.edgeTraction(p2, a2, c, c, tt) - geo.edgeTraction(q, a2, c, c, tt);
908 const double t = (wc * xc + f1 * y1) + f2 * y2;
909 const long i = geo.idx(q);
914 const int lc = lo[c];
915 Kokkos::parallel_for(
916 "peclet::flow::vof::sharp_viscous_rhs", Kokkos::RangePolicy<CCExec>(
CCExec(), 0, nl),
917 KOKKOS_LAMBDA(
long r) {
918 const long i = list(r);
919 const long z = i / geo.st[2], rr = i - z * geo.st[2], y = rr / geo.st[1];
920 const int q[3] = {(int)(rr - y * geo.st[1]), (int)y, (
int)z};
923 body(q[0], q[1], q[2]);
933 const int nx = geo.e[0] - 2 * g, ny = geo.e[1] - 2 * g, nz = geo.e[2] - 2 * g;
934 if (nx <= 0 || ny <= 0 || nz <= 0)
937 Kokkos::parallel_scan(
938 "peclet::flow::vof::sharp_rhs_compact",
939 Kokkos::RangePolicy<CCExec>(
CCExec(), 0, (
long)nx * ny * nz),
940 KOKKOS_LAMBDA(
const long r,
long& upd,
const bool final) {
941 const int q[3] = {g + (int)(r % nx), g + (int)((r / nx) % ny),
942 g + (int)(r / ((
long)nx * ny))};
944 for (
int dz = -1; dz <= 1 && !hit; ++dz)
945 for (
int dy = -1; dy <= 1 && !hit; ++dy)
946 for (
int dx = -1; dx <= 1 && !hit; ++dx) {
947 const int p[3] = {q[0] + dx, q[1] + dy, q[2] + dz};
948 hit = geo.cellClass(p) !=
kSvNone;
952 list(upd) = geo.idx(q);
963 double wc,
bool skipLoC) {
964 const SvList list(Kokkos::view_alloc(
CCExec(),
"peclet::flow::vof::sharp_rhs_list",
965 Kokkos::WithoutInitializing),
966 (std::size_t)gg.e[0] * gg.e[1] * gg.e[2]);
968 addSharpViscousRhs(c, bb, rs, v, gg, tau, dnn, g, wc, skipLoC, list, nl);
984 double untiedGap = std::numeric_limits<double>::infinity();
991 long cnt[4] = {0, 0, 0, 0};
992 for (
int w = 0; w < 4; ++w) {
994 Kokkos::parallel_reduce(
995 "peclet::flow::vof::sharp_census",
997 KOKKOS_LAMBDA(
int x,
int y,
int z,
long& acc) {
998 const int q[3] = {x, y, z};
999 const int k = g.cellClass(q);
1005 acc +=
fb(g.idx(q)) ? 1 : 0;
1012 const bool one = g.colour(q) >= 1.0 - g.eps;
1013 int lo3[3] = {x, y, z}, hi3[3] = {x, y, z};
1016 bool film = g.inDomain(lo3) && g.inDomain(hi3);
1018 const double cl = g.colour(lo3), ch = g.colour(hi3);
1020 ((cl >= 1.0 - g.eps) != one) && ((ch >= 1.0 - g.eps) != one);
1022 acc += film ? 1 : 0;
1031 out.fallback = cnt[3];
1035 Kokkos::parallel_reduce(
1036 "peclet::flow::vof::sharp_census_tied", rng,
1037 KOKKOS_LAMBDA(
int x,
int y,
int z,
long& acc) {
1038 const int k[3] = {x, y, z};
1039 for (
int ac = 0; ac < 3; ++ac) {
1040 double sp = 0.0, gp = 0.0;
1042 acc += (g.edgeTieKeys(k, ac, sp, gp, bl) >= 2) ? 1 : 0;
1046 double spread = 0.0;
1047 Kokkos::parallel_reduce(
1048 "peclet::flow::vof::sharp_census_spread", rng,
1049 KOKKOS_LAMBDA(
int x,
int y,
int z,
double& acc) {
1050 const int k[3] = {x, y, z};
1051 for (
int ac = 0; ac < 3; ++ac) {
1052 double sp = 0.0, gp = 0.0;
1054 if (g.edgeTieKeys(k, ac, sp, gp, bl) >= 2)
1055 acc = Kokkos::fmax(acc, sp);
1058 Kokkos::Max<double>(spread));
1060 Kokkos::parallel_reduce(
1061 "peclet::flow::vof::sharp_census_gap", rng,
1062 KOKKOS_LAMBDA(
int x,
int y,
int z,
double& acc) {
1063 const int k[3] = {x, y, z};
1064 for (
int ac = 0; ac < 3; ++ac) {
1065 double sp = 0.0, gp = -1.0;
1067 if (g.edgeTieKeys(k, ac, sp, gp, bl) >= 1 && gp >= 0.0)
1068 acc = Kokkos::fmin(acc, gp);
1071 Kokkos::Min<double>(gap));
1073 Kokkos::parallel_reduce(
1074 "peclet::flow::vof::sharp_census_blended", rng,
1075 KOKKOS_LAMBDA(
int x,
int y,
int z,
long& acc) {
1076 const int k[3] = {x, y, z};
1077 for (
int ac = 0; ac < 3; ++ac) {
1078 double sp = 0.0, gp = 0.0;
1080 g.edgeTieKeys(k, ac, sp, gp, bl);
1086 out.blended = blended;
1087 out.tieSpread = Kokkos::fmax(spread, 0.0);
1088 if (gap < std::numeric_limits<double>::max())
1089 out.untiedGap = gap;
flow — VoF rung V3 (WO-O): the view-level driver for the curvature cascade.
flow — face/cell material-property accessors for the variable-coefficient momentum operator.
flow — portable (Kokkos) cut-cell pressure-operator face openness from an SDF.
void sharpFit(const SharpGeom &gg, const CCConst(&v)[3], CCField t0, CCField t1, CCField t2, CCField dnn, SvByte fb, C3 lo, C3 hi, SvList list)
The τ̂/D̂_nn fit (§5.3) over the cells [lo, hi) of the solver block: interfacial cells get their fit ...
constexpr double kSvOwnerTieTol
The owner-set tolerance τ_own (§5.8), index units, absolute: the candidates of an edge whose plane di...
SharpCensus sharpCensus(const SharpGeom &gg, SvByteConst fb, C3 lo, C3 hi)
constexpr int kVofWarp
The team size of a device tier-3 launch: one warp / wavefront.
bool vofIsInterface(double c, double eps)
wyIsMixed with a wisp threshold: the cell carries an interface only while eps < C < 1 - eps.
Kokkos::View< std::uint8_t *, CCMem > SvByte
Per-cell byte fields on the solver block: the band class and the fit-fallback flag.
constexpr std::uint8_t kSvVirtual0
Kokkos::View< int *, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged > SvScrI
Kokkos::View< long *, CCMem > SvList
The compacted interfacial cells of a fit (local linear indices), the device fit's worklist.
void sharpClassify(const SharpGeom &gg, SvByte cls)
The band classes over the WHOLE solver block (§5.2, §5.7 Q-B).
Kokkos::View< const std::uint8_t *, CCMem > SvByteConst
constexpr int svItemRow(int it)
The first row of item it (row order of SharpGeom::fitItem); kSvItems gives kSvRows.
Kokkos::View< double *, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged > SvScrD
Team scratch of the device fit, one team per interfacial cell: per row of the current chunk its 9 coe...
constexpr double kSvOwnerRampTol
The end of the owner-weight ramp τ₁ (§5.9), index units, absolute: a candidate whose distance exceeds...
constexpr int kSvNormalItems
The fit (§5.3) as items and rows (SharpGeom::fitItem): 27 block cells of 3 normal links,...
static double ownerWeight(double g)
The owner weight of a candidate whose plane distance exceeds the closest by g (§5....
constexpr std::uint8_t kSvNone
Band class of a cell.
void addSharpViscousRhs(int c, CCField bb, CCConst rs, const CCConst(&v)[3], const SharpGeom &gg, const CCConst(&tau)[3], CCConst dnn, int g, double wc, bool skipLoC, SvList list, long nl)
The explicit band terms of the u_c rows over the inner cells [g, e−g)³ (§5.4): the τ-terms of the fou...
constexpr int kSvChunkRows
long sharpRhsCompact(const SharpGeom &gg, int g, SvList list)
The cells of the inner box [g, e−g)³ whose band terms (addSharpViscousRhs) can be nonzero for some co...
constexpr std::uint8_t kSvPlane
constexpr int kSvChunkItems
The device fit walks its items in chunks of kSvChunkItems (rows of a chunk: at most 91,...
void sharpFitTeam(const Member &tm, const SvFitScratch &sc, const SharpGeom &g, const int K[3], const CCConst(&v)[3], long i, CCField t0, CCField t1, CCField t2, CCField dnn, SvByte fb)
SharpGeom::fitCell of cell K on a whole team (the shape of curvFallbackTeam), per chunk of items in i...
SvRole
Which half of the time split a SharpFaceProps feeds (§6.1, WO-5b): the implicit band (ibmBuildDiffusi...
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
Kokkos::View< double *, CCMem > CCField
flow — thin shim: the container-free VoF PLIC geometric toolbox (rung V0) now live in core.
flow — the multidimensional iteration policies: iteration order follows storage.
The census of the band (§9, G-SV10) over [lo, hi), LOCAL to this block: interfacial cells,...
The face viscosity under the sharp interface (§5.4 a, §6): a band edge across a (a ≠ c) takes μ̄_c,...
double beta(long i, long j) const
double idiag(long i) const
The band geometry and the closure constants, by value into every kernel.
VofMetric gm
the metric of vofPhysNormal (h = ℓ)
int cellClass(const int q[3]) const
int fitItem(const int K[3], int it, const CCConst(&v)[3], int ra[3], int rc[3], double th[3], double mv[3]) const
The rows of item it of the fit of K (§5.3), in the fit's fixed order: item it < 27 is block cell it =...
long st3[3]
colour block strides
double p1
LinearMix μ(f) = p0 + p1·f (internal units).
double r
μ(1), μ(0), min, μ_lo/μ_hi
bool fitCell(const int K[3], const CCConst(&v)[3], double tau[3], double &dnn) const
The fit of interfacial cell (X, Y, Z) (§5.3): L, the low-μ-side gradient, from the 81 normal links of...
void plane(const int q[3], int k, double m[3], double &al) const
The plane (m, α) of a band cell of class k, in the cell's local index coordinates (m·ξ < α is the C =...
int edgeDistances(const int k[3], int a, int c, double dist[4]) const
Pass 1 of the owner set (§5.8): d_t = |m·ξ_E − α|/|m|₂ for each interfacial cell t of E_ac(k) (t in t...
long st[3]
solver block strides
void fitRow(int a, int c, double thA, double mv, const double n[3], double N[81], double rhs[9]) const
bool edgeFaceFraction(const int k[3], int a, int c, int row, double &f) const
F̄_row(E_ac(k)), row ∈ {a, c} (§5.8 item 4, §5.9): the owner-set weighted mean of the C = 1 fraction ...
void edgeTau(const int k[3], int a, int c, const CCConst(&tau)[3], double t[3]) const
τ̂ at E_ac(k) (§5.2, §5.7 Q-A): the arithmetic mean of τ̂_K over the interfacial cells K of E,...
double eps
interfacial threshold: the wisp guard (set_vof_interface_eps)
SvByteConst cls
band class, solver block
bool edgeInDomain(const int k[3], int a, int c) const
A shear link's sample lies in the closed physical domain: the edge's b-layer is an in-domain cell lay...
double edgePhase(const int k[3], int a, int c) const
The C = 1 fraction of a link at an edge with no owner: its in-domain cells are pure and of one phase ...
static T pick4(const T v[4], int t)
v[t] by selects, so a small array indexed by a runtime offset stays in registers.
double linkFraction(const int k[3], int dd, int cc, const int o[3], const double m[3], double al) const
The C = 1 fraction of the shear link ∂_dd u_cc at its edge E(k) (§5.1 L): the plane x_cc = k_cc,...
static bool fitSolve(double N[81], const double rhs[9], const double n[3], double mulo, double tau[3], double &dnn)
The solve of the fit's normal equations N (upper triangle, row-major 9×9, overwritten) and right-hand...
CCConst pa
reconstructed PLIC offsets α, colour block
double res(double f) const
int dlo[3]
in-domain cells: dlo <= x_a < dhi (solver coordinates)
double rowFaceFraction(const int k[3], int a, int c, int row, const int o[3], const double m[3], double al) const
The C = 1 fraction of the u_row face at E_ac(k), row ∈ {a, c} (§5.1 F_c / F_a): the plane through E n...
bool inDomain(const int q[3]) const
bool lowA
the C = 1 phase is the low-μ side
int d
colour ghost − solver ghost
double colour(const int q[3]) const
long idx(const int q[3]) const
double cellExtra(const int q[3], int c, const CCConst(&v)[3], const CCConst(&tau)[3], CCConst dnn) const
The explicit part of the u_c stress at cell q beyond today's 2μ(C)∂_c u_c (§5.4 b): 2(μ_A − μ_B)(C̄ −...
long idx3(const int q[3]) const
void fitCoef(int a, int c, double thA, const double n[3], double co[9]) const
One least-squares row of the kinked model (§5.3) for link ∂_a u_c with C = 1 kernel fraction thA and ...
void fitNormal(const int K[3], double n[3]) const
The physical unit normal of interfacial cell K's own plane (the fit's n).
int edgeOwnerSet(const int k[3], int a, int c, double dist[4], double &dmin, double w[4]) const
The owner set of E_ac(k) (§5.8 items 1–2, §5.9 item 3): pass 1 (edgeDistances), d_min over K_E,...
bool edgeLinkFractions(const int k[3], int a, int c, double &tac, double &tca) const
θ̄_ac and θ̄_ca at E_ac(k) (§5.8 item 4, §5.9): the owner-set weighted means of the C = 1 fractions o...
double mu(double f) const
int e[3]
solver block extents
int edgeTieKeys(const int k[3], int ac, double &spread, double &gap, bool &blended) const
The census keys of edge E_ac(k), ac = 0, 1, 2 for (a, c) = (0,1), (0,2), (1,2) (§5....
static void edgeCells(int a, int c, int da[4], int dc[4])
The four cells of E_ac(k) in the fixed offset order, as (δa, δc): cell = k − δa e_a − δc e_c.
CCConst pm[3]
reconstructed PLIC normals m (index space), colour block
double ell[3]
ℓ_a = h_a/h_ref
double edgeTraction(const int k[3], int a, int c, int row, const CCConst(&tau)[3]) const
The explicit interface-traction part of the u_row stress at E_ac(k) (§5.4 a, §5.8,...
CCConst col
colour C, colour block (ghosts valid)
double forEachOwner(const int k[3], int a, int c, F &&f) const
The owner set of E_ac(k) (§5.2, §5.8, §5.9 item 4): calls f(o, m, α, w) for each member – the interfa...
SvFitScratch(const Member &tm)
static std::size_t shmem()
static constexpr double F