flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
sharp_viscous.hpp
Go to the documentation of this file.
1
38#ifndef PECLET_FLOW_VOF_SHARP_VISCOUS_HPP
39#define PECLET_FLOW_VOF_SHARP_VISCOUS_HPP
40
41#include <cstdint>
42#include <Kokkos_Core.hpp>
43#include <limits>
44
45#include "face_props.hpp"
46#include "mac_cutcell.hpp"
47#include "peclet/core/vof/plic_regions.hpp"
48#include "policy.hpp"
49#include "vof/curvature_field.hpp" // vofIsInterface: THE interfacial predicate of the planes
50#include "vof/plic.hpp"
51
52namespace peclet::flow::vof {
53
55using SvByte = Kokkos::View<std::uint8_t*, CCMem>;
56using SvByteConst = Kokkos::View<const std::uint8_t*, CCMem>;
57
60constexpr std::uint8_t kSvNone = 0, kSvPlane = 1, kSvVirtual0 = 2;
61
64constexpr int kSvNormalItems = 27, kSvItems = 27 + 144, kSvRows = 81 + 288, kSvEntries = 45 + 9;
65
69constexpr double kSvOwnerTieTol = 1e-6;
70
74constexpr double kSvOwnerRampTol = 1e-5;
75
80KOKKOS_INLINE_FUNCTION static double ownerWeight(double g) {
81 if (g <= kSvOwnerTieTol)
82 return 1.0;
83 if (!(g < kSvOwnerRampTol))
84 return 0.0;
85 const double s = (kSvOwnerRampTol - g) / (kSvOwnerRampTol - kSvOwnerTieTol);
86 return s * s * (3.0 - 2.0 * s);
87}
88
90using SvList = Kokkos::View<long*, CCMem>;
91
93struct SharpGeom {
94 int e[3] = {0, 0, 0};
95 long st[3] = {1, 0, 0};
96 long st3[3] = {1, 0, 0};
97 int d = 1;
102 int dlo[3] = {0, 0, 0};
103 int dhi[3] = {0, 0, 0};
104 double eps = 0.0;
105 double p0 = 0.0, p1 = 0.0;
106 double muA = 0.0, muB = 0.0, mulo = 0.0, r = 1.0;
107 bool lowA = false;
108 double ell[3] = {1.0, 1.0, 1.0};
109 VofMetric gm;
110
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];
113 }
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];
116 }
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] &&
119 q[2] < dhi[2];
120 }
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; }
125
129 KOKKOS_INLINE_FUNCTION void plane(const int q[3], int k, double m[3], double& al) const {
130 if (k == kSvPlane) {
131 const long j = idx3(q);
132 m[0] = pm[0](j);
133 m[1] = pm[1](j);
134 m[2] = pm[2](j);
135 al = pa(j);
136 return;
137 }
138 const int v = k - kSvVirtual0, ax = v >> 1, side = v & 1;
139 const bool one = colour(q) >= 1.0 - eps; // the cell is pure; its phase
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;
142 m[ax] = s;
143 al = (side == 0) ? 0.0 : s;
144 }
145
147 KOKKOS_INLINE_FUNCTION static void edgeCells(int a, int c, int da[4], int dc[4]) {
148 da[0] = 1;
149 dc[0] = 1;
150 if (a > c) { // s_a > s_c: −s_a < −s_c
151 da[1] = 1;
152 dc[1] = 0;
153 da[2] = 0;
154 dc[2] = 1;
155 } else {
156 da[1] = 0;
157 dc[1] = 1;
158 da[2] = 1;
159 dc[2] = 0;
160 }
161 da[3] = 0;
162 dc[3] = 0;
163 }
164
168 KOKKOS_INLINE_FUNCTION int edgeDistances(const int k[3], int a, int c, double dist[4]) const {
169 int da[4], dc[4];
170 edgeCells(a, c, da, dc);
171 const int b = 3 - a - c;
172 int mask = 0;
173 for (int t = 0; t < 4; ++t) {
174 int q[3] = {k[0], k[1], k[2]};
175 q[a] -= da[t];
176 q[c] -= dc[t];
177 const int kc = cellClass(q);
178 if (kc == kSvNone)
179 continue;
180 double mm[3], aa;
181 plane(q, kc, mm, aa);
182 double xi[3];
183 xi[a] = (double)da[t];
184 xi[c] = (double)dc[t];
185 xi[b] = 0.5;
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;
188 mask |= 1 << t;
189 }
190 return mask;
191 }
192
200 KOKKOS_INLINE_FUNCTION int edgeOwnerSet(const int k[3], int a, int c, double dist[4],
201 double& dmin, double w[4]) const {
202 const int kmask = edgeDistances(k, a, c, dist);
203 dmin = 0.0;
204 int best = -1; // the closest, first in offset order: always a member (item 3, n_E >= 1 iff
205 // K_E ≠ ∅, also when a distance is NaN -- the fit's NaN-plane fallback)
206 for (int t = 0; t < 4; ++t)
207 if (((kmask >> t) & 1) && (best < 0 || dist[t] < dmin)) {
208 dmin = dist[t];
209 best = t;
210 }
211 int tmask = 0;
212 for (int t = 0; t < 4; ++t) {
213 w[t] = 0.0;
214 if (!((kmask >> t) & 1))
215 continue;
216 const double g = dist[t] - dmin;
217 if (t == best || g <= kSvOwnerTieTol)
218 tmask |= 1 << t;
219 w[t] = (t == best) ? 1.0 : ownerWeight(g);
220 }
221 return kmask | (tmask << 4);
222 }
223
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;
232 if (!edgeInDomain(k, a, c))
233 return 0;
234 double dist[4], dmin, w[4];
235 const int m = edgeOwnerSet(k, a, c, dist, dmin, w);
236 int nE = 0;
237 for (int t = 0; t < 4; ++t) {
238 if (!((m >> t) & 1))
239 continue;
240 const double g = dist[t] - dmin;
241 if ((m >> (4 + t)) & 1) {
242 ++nE;
243 spread = Kokkos::fmax(spread, g);
244 } else {
245 gap = (gap < 0.0) ? g : Kokkos::fmin(gap, g);
246 if (g > kSvOwnerTieTol && g < kSvOwnerRampTol)
247 blended = true;
248 }
249 }
250 return nE;
251 }
252
265 template <class F>
266 KOKKOS_INLINE_FUNCTION double forEachOwner(const int k[3], int a, int c, F&& f) const {
267 double dist[4], dmin, w[4];
268 edgeOwnerSet(k, a, c, dist, dmin, w);
269 int da[4], dc[4];
270 edgeCells(a, c, da, dc);
271 int ts = 0, n = 0;
272 for (int t = 0; t < 4; ++t)
273 if (w[t] > 0.0) {
274 ts |= t << (2 * n);
275 ++n;
276 }
277 double W = 0.0;
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);
284 double m[3], al;
285 plane(q, cellClass(q), m, al);
286 f(q, m, al, wt);
287 W += wt;
288 }
289 return W;
290 }
291
293 template <class 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];
296 }
297
300 KOKKOS_INLINE_FUNCTION bool edgeFaceFraction(const int k[3], int a, int c, int row,
301 double& f) const {
302 double acc = 0.0;
303 const double W =
304 forEachOwner(k, a, c, [&](const int o[3], const double m[3], double al, double w) {
305 acc += w * rowFaceFraction(k, a, c, row, o, m, al);
306 });
307 if (W == 0.0)
308 return false;
309 f = acc / W;
310 return true;
311 }
312
316 KOKKOS_INLINE_FUNCTION bool edgeLinkFractions(const int k[3], int a, int c, double& tac,
317 double& tca) const {
318 double sac = 0.0, sca = 0.0;
319 const double W =
320 forEachOwner(k, a, c, [&](const int o[3], const double m[3], double al, double w) {
321 sac += w * linkFraction(k, a, c, o, m, al);
322 sca += w * linkFraction(k, c, a, o, m, al);
323 });
324 if (W == 0.0)
325 return false;
326 tac = sac / W;
327 tca = sca / W;
328 return true;
329 }
330
334 KOKKOS_INLINE_FUNCTION double rowFaceFraction(const int k[3], int a, int c, int row,
335 const int o[3], const double m[3],
336 double al) const {
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; // the lower of the two in-plane axes
342 return plicFaceFraction(m, al, p, xiP, (q == row) ? lr : lb, (q == row) ? lb : lr);
343 }
344
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]));
352 }
353
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] &&
359 k[c] <= dhi[c];
360 }
361
364 KOKKOS_INLINE_FUNCTION double edgePhase(const int k[3], int a, int c) const {
365 int da[4], dc[4];
366 edgeCells(a, c, da, dc);
367 for (int t = 0; t < 4; ++t) {
368 int q[3] = {k[0], k[1], k[2]};
369 q[a] -= da[t];
370 q[c] -= dc[t];
371 if (inDomain(q))
372 return colour(q) >= 1.0 - eps ? 1.0 : 0.0;
373 }
374 return 0.0; // unreachable for an in-domain edge
375 }
376
379 KOKKOS_INLINE_FUNCTION void edgeTau(const int k[3], int a, int c, const CCConst (&tau)[3],
380 double t[3]) const {
381 int da[4], dc[4];
382 edgeCells(a, c, da, dc);
383 long js[4];
384 int nI = 0;
385 for (int s = 0; s < 4; ++s) {
386 int q[3] = {k[0], k[1], k[2]};
387 q[a] -= da[s];
388 q[c] -= dc[s];
389 if (cellClass(q) != kSvNone)
390 js[nI++] = idx(q);
391 }
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;
398 }
399 }
400
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;
410 const double W =
411 forEachOwner(k, a, c, [&](const int o[3], const double m[3], double al, double w) {
412 if (!haveTau) {
413 edgeTau(k, a, c, tau, t);
414 haveTau = true;
415 }
416 double n[3] = {0.0, 0.0, 0.0};
417 vofPhysNormal(m, gm, n);
418 const double mub = mu(rowFaceFraction(k, a, c, row, o, m, al));
419 const double rac = res(linkFraction(k, a, c, o, m, al));
420 const double rca = res(linkFraction(k, c, a, o, m, al));
421 acc += w * (n[a] * t[c] * (1.0 - mub * rac) + n[c] * t[a] * (1.0 - mub * rca));
422 });
423 if (W == 0.0)
424 return 0.0;
425 return acc / W;
426 }
427
431 KOKKOS_INLINE_FUNCTION double cellExtra(const int q[3], int c, const CCConst (&v)[3],
432 const CCConst (&tau)[3], CCConst dnn) const {
433 const int kc = cellClass(q);
434 if (kc == kSvNone)
435 return 0.0;
436 double m[3], al;
437 plane(q, kc, m, al);
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));
445 }
446
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];
455 double pc[3];
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]);
461 }
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 {
464 double co[9];
465 fitCoef(a, c, thA, n, co);
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];
470 }
471 }
472
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 {
481 if (it < kSvNormalItems) {
482 const int q[3] = {K[0] + it % 3 - 1, K[1] + (it / 3) % 3 - 1, K[2] + it / 9 - 1};
483 if (!inDomain(q))
484 return 0;
485 const double tq = colour(q);
486 const long j = idx(q);
487 for (int c = 0; c < 3; ++c) {
488 ra[c] = rc[c] = c;
489 th[c] = tq;
490 mv[c] = v[c](j + st[c]) - v[c](j);
491 }
492 return 3;
493 }
494 const int u = it - kSvNormalItems, pr = u / 48, l = u % 48;
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; // the b extent is 3, the others 4
497 const int k[3] = {K[0] - 1 + l % ex, K[1] - 1 + (l / ex) % ey, K[2] - 1 + l / (ex * ey)};
498 if (!edgeInDomain(k, a, c))
499 return 0;
500 double tac = 0.0, tca = 0.0;
501 if (!edgeLinkFractions(k, a, c, tac, tca))
502 tac = tca = edgePhase(k, a, c);
503 const long j = idx(k);
504 ra[0] = a;
505 rc[0] = c;
506 th[0] = tac;
507 mv[0] = (ell[c] / ell[a]) * (v[c](j) - v[c](j - st[a]));
508 ra[1] = c;
509 rc[1] = a;
510 th[1] = tca;
511 mv[1] = (ell[a] / ell[c]) * (v[a](j) - v[a](j - st[c]));
512 return 2;
513 }
514
520 KOKKOS_INLINE_FUNCTION bool fitCell(const int K[3], const CCConst (&v)[3], double tau[3],
521 double& dnn) const {
522 double n[3] = {0.0, 0.0, 0.0};
523 fitNormal(K, n);
524 double N[81], rhs[9];
525 for (int s = 0; s < 81; ++s)
526 N[s] = 0.0;
527 for (int s = 0; s < 9; ++s)
528 rhs[s] = 0.0;
529 for (int it = 0; it < kSvItems; ++it) {
530 int ra[3], rc[3];
531 double th[3], mv[3];
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);
535 }
536 return fitSolve(N, rhs, n, mulo, tau, dnn);
537 }
538
540 KOKKOS_INLINE_FUNCTION void fitNormal(const int K[3], double n[3]) const {
541 double m[3], al;
542 plane(K, cellClass(K), m, al);
543 vofPhysNormal(m, gm, n);
544 }
545
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) {
550 // Cholesky N = R^T R (upper R in place), pivot test against the trace.
551 double tr = 0.0;
552 for (int s = 0; s < 9; ++s)
553 tr += N[9 * s + s];
554 const double pmin = 1e-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))
560 return false;
561 const double rd = Kokkos::sqrt(dpiv);
562 N[9 * s + s] = rd;
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;
568 }
569 }
570 double y[9], L[9];
571 for (int s = 0; s < 9; ++s) { // R^T y = rhs
572 double x = rhs[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];
576 }
577 for (int s = 8; s >= 0; --s) { // R L = y
578 double x = y[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];
582 }
583 // S = L + L^T; (S n)_p = sum_q (L_pq + L_qp) n_q; tau = mu_lo P(S n); D_nn = n.L n.
584 double sn[3], nsn = 0.0;
585 dnn = 0.0;
586 for (int p = 0; p < 3; ++p) {
587 double x = 0.0;
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];
591 }
592 sn[p] = x;
593 nsn += n[p] * x;
594 }
595 for (int p = 0; p < 3; ++p)
596 tau[p] = mulo * (sn[p] - n[p] * nsn);
597 return true;
598 }
599};
600
603enum class SvRole : int { kImplicit = 0, kExplicit = 1 };
604
615 int c = 0;
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; // the cell between the two u_c faces (VarFaceProps: mu(q))
622 if (geo.cls(q) == kSvNone)
623 return base.beta(i, j);
624 return (role == SvRole::kImplicit) ? 2.0 * base.beta(i, j) : 0.0;
625 }
626 const int a = (ad == 1) ? 0 : ((ad == geo.st[1]) ? 1 : 2);
627 const long kk = (dd > 0) ? j : i;
628 // Not a band edge (none of its four cells k, k - s_a, k - s_c, k - s_a - s_c interfacial):
629 // forEachOwner's W = 0, read without decoding k.
630 const long sa = geo.st[a], sc = geo.st[c];
631 if (geo.cls(kk) == kSvNone && geo.cls(kk - sa) == kSvNone && geo.cls(kk - sc) == kSvNone &&
632 geo.cls(kk - sa - sc) == kSvNone)
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};
636 double f = 0.0;
637 if (!geo.edgeFaceFraction(k, a, c, c, f))
638 return base.beta(i, j);
639 return geo.mu(f);
640 }
641};
642
645inline void sharpClassify(const SharpGeom& gg, SvByte cls) {
646 const SharpGeom g = gg;
647 CCExec space;
648 Kokkos::parallel_for(
649 "peclet::flow::vof::sharp_classify",
650 MDRange3<CCExec>(space, {0, 0, 0}, {g.e[0], g.e[1], g.e[2]}),
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)) {
655 cls(i) = kSvNone;
656 return;
657 }
658 const double cq = g.colour(q);
659 if (vofIsInterface(cq, g.eps)) {
660 cls(i) = kSvPlane;
661 return;
662 }
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;
668 if (!g.inDomain(nb))
669 continue; // a non-periodic physical-domain face never qualifies
670 const double cn = g.colour(nb);
671 if (vofIsInterface(cn, g.eps))
672 continue; // the neighbour must be pure
673 if ((cn >= 1.0 - g.eps) != one) {
674 cls(i) = (std::uint8_t)(kSvVirtual0 + 2 * a + side);
675 return;
676 }
677 }
678 cls(i) = kSvNone;
679 });
680}
681
684constexpr int kSvChunkItems = 32, kSvChunkRows = 3 * kSvNormalItems + 2 * (kSvChunkItems - 27);
685
687KOKKOS_INLINE_FUNCTION constexpr int svItemRow(int it) {
688 return (it < kSvNormalItems) ? 3 * it : 3 * kSvNormalItems + 2 * (it - kSvNormalItems);
689}
690
693using SvScrD = Kokkos::View<double*, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged>;
694using SvScrI = Kokkos::View<int*, CCExec::scratch_memory_space, Kokkos::MemoryUnmanaged>;
698 static std::size_t shmem() {
699 return SvScrD::shmem_size(9 * kSvChunkRows) + SvScrD::shmem_size(kSvChunkRows) +
700 SvScrD::shmem_size(kSvEntries) + SvScrI::shmem_size(kSvChunkRows);
701 }
702 template <class Member>
703 KOKKOS_INLINE_FUNCTION explicit SvFitScratch(const Member& tm)
704 : co(tm.team_scratch(0), 9 * kSvChunkRows)
705 , mv(tm.team_scratch(0), kSvChunkRows)
706 , ent(tm.team_scratch(0), kSvEntries)
707 , ok(tm.team_scratch(0), kSvChunkRows) {}
708};
709
720template <class Member>
721KOKKOS_INLINE_FUNCTION void sharpFitTeam(const Member& tm, const SvFitScratch& sc,
722 const SharpGeom& g, const int K[3], const CCConst (&v)[3],
723 long i, CCField t0, CCField t1, CCField t2, CCField dnn,
724 SvByte fb) {
725 double n[3] = {0.0, 0.0, 0.0};
726 g.fitNormal(K, n); // every lane: deterministic, no broadcast
727 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm, kSvEntries),
728 [&](const int e) { sc.ent(e) = 0.0; });
729 for (int i0 = 0; i0 < kSvItems; i0 += kSvChunkItems) {
730 const int i1 = (i0 + kSvChunkItems < kSvItems) ? i0 + kSvChunkItems : kSvItems;
731 const int rb = svItemRow(i0), nrow = svItemRow(i1) - rb;
732 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm, i0, i1), [&](const int it) {
733 int ra[3], rc[3];
734 double th[3], mv[3];
735 const int nr = g.fitItem(K, it, v, ra, rc, th, mv);
736 const int r0 = svItemRow(it) - rb, nmax = svItemRow(it + 1) - svItemRow(it);
737 for (int q = 0; q < nmax; ++q) {
738 sc.ok(r0 + q) = (q < nr) ? 1 : 0;
739 if (q < nr) {
740 double co[9];
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];
745 }
746 }
747 });
748 tm.team_barrier();
749 Kokkos::parallel_for(Kokkos::TeamThreadRange(tm, kSvEntries), [&](const int e) {
750 double acc = sc.ent(e);
751 if (e >= 45) { // rhs[s] += co[s] * mv
752 const int s = e - 45;
753 for (int r = 0; r < nrow; ++r)
754 if (sc.ok(r))
755 acc += sc.co(9 * r + s) * sc.mv(r);
756 } else { // N[9 s + t] += co[s] * co[t], t >= s, e row-major over the upper triangle
757 int s = 0, t = e;
758 while (t >= 9 - s) {
759 t -= 9 - s;
760 ++s;
761 }
762 t += s;
763 for (int r = 0; r < nrow; ++r)
764 if (sc.ok(r))
765 acc += sc.co(9 * r + s) * sc.co(9 * r + t);
766 }
767 sc.ent(e) = acc;
768 });
769 tm.team_barrier(); // the chunk's rows are consumed before the next chunk overwrites them
770 }
771 Kokkos::single(Kokkos::PerTeam(tm), [&]() {
772 double N[81], rhs[9];
773 for (int s = 0; s < 81; ++s)
774 N[s] = 0.0;
775 int e = 0;
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;
782 std::uint8_t f = 0;
783 if (!SharpGeom::fitSolve(N, rhs, n, g.mulo, t, dn)) {
784 t[0] = t[1] = t[2] = 0.0;
785 dn = 0.0;
786 f = 1;
787 }
788 t0(i) = t[0];
789 t1(i) = t[1];
790 t2(i) = t[2];
791 dnn(i) = dn;
792 fb(i) = f;
793 });
794}
795
803inline void sharpFit(const SharpGeom& gg, const CCConst (&v)[3], CCField t0, CCField t1, CCField t2,
804 CCField dnn, SvByte fb, C3 lo, C3 hi, SvList list) {
805 const SharpGeom g = gg;
806 const CCConst v0 = v[0], v1 = v[1], v2 = v[2];
807 CCExec space;
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)
810 return;
811 const long region = (long)nx * ny * nz;
812 long nb = 0;
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);
819 if (final) {
820 t0(i) = 0.0;
821 t1(i) = 0.0;
822 t2(i) = 0.0;
823 dnn(i) = 0.0;
824 fb(i) = 0;
825 }
826 if (g.cellClass(q) != kSvNone) {
827 if (final)
828 list(upd) = i;
829 ++upd;
830 }
831 },
832 nb);
833 if (nb == 0)
834 return;
835 // Keyed on the EXECUTION space (review F9): on a unified-memory device build HostSpace may
836 // reach CCMem, but the one-thread-per-cell host body must still not run on the GPU.
837 if constexpr (!Kokkos::SpaceAccessibility<CCExec, Kokkos::HostSpace>::accessible) {
838 using Policy = Kokkos::TeamPolicy<CCExec>;
839 Policy pol(space, (int)nb, kVofWarp);
840 pol.set_scratch_size(0, Kokkos::PerTeam(SvFitScratch::shmem()));
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};
847 const SvFitScratch sc(tm);
848 sharpFitTeam(tm, sc, g, K, vv, i, t0, t1, t2, dnn, fb);
849 });
850 } else {
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)) {
860 fb(i) = 1; // the scan left tau_hat = D_nn = 0
861 return;
862 }
863 t0(i) = t[0];
864 t1(i) = t[1];
865 t2(i) = t[2];
866 dnn(i) = dn;
867 });
868 }
869}
870
872inline void sharpFit(const SharpGeom& gg, const CCConst (&v)[3], CCField t0, CCField t1, CCField t2,
873 CCField dnn, SvByte fb, C3 lo, C3 hi) {
874 const long cells = (long)(hi.x - lo.x) * (hi.y - lo.y) * (hi.z - lo.z);
875 SvList list(
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);
879}
880
888inline void addSharpViscousRhs(int c, CCField bb, CCConst rs, const CCConst (&v)[3],
889 const SharpGeom& gg, const CCConst (&tau)[3], CCConst dnn, int g,
890 double wc, bool skipLoC, SvList list, long nl) {
891 const SharpGeom geo = gg;
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};
901 qm[c] -= 1;
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};
904 p1[a1] += 1;
905 p2[a2] += 1;
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);
910 bb(i) += rs(i) * t;
911 };
912 if (nl <= 0)
913 return;
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};
921 if (q[c] < lc)
922 return; // skipLoC: the BC-imposed low-face node
923 body(q[0], q[1], q[2]);
924 });
925}
926
931inline long sharpRhsCompact(const SharpGeom& gg, int g, SvList list) {
932 const SharpGeom geo = gg;
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)
935 return 0;
936 long nl = 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))};
943 bool hit = false;
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;
949 }
950 if (hit) {
951 if (final)
952 list(upd) = geo.idx(q);
953 ++upd;
954 }
955 },
956 nl);
957 return nl;
958}
959
961inline void addSharpViscousRhs(int c, CCField bb, CCConst rs, const CCConst (&v)[3],
962 const SharpGeom& gg, const CCConst (&tau)[3], CCConst dnn, int g,
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]);
967 const long nl = sharpRhsCompact(gg, g, list);
968 addSharpViscousRhs(c, bb, rs, v, gg, tau, dnn, g, wc, skipLoC, list, nl);
969}
970
981 long band = 0, virt = 0, film = 0, fallback = 0;
982 long tied = 0, blended = 0;
983 double tieSpread = 0.0;
984 double untiedGap = std::numeric_limits<double>::infinity();
985};
986
987inline SharpCensus sharpCensus(const SharpGeom& gg, SvByteConst fb, C3 lo, C3 hi) {
988 const SharpGeom g = gg;
989 CCExec space;
990 SharpCensus out;
991 long cnt[4] = {0, 0, 0, 0};
992 for (int w = 0; w < 4; ++w) {
993 long s = 0;
994 Kokkos::parallel_reduce(
995 "peclet::flow::vof::sharp_census",
996 MDRange3<CCExec>(space, {lo.x, lo.y, lo.z}, {hi.x, hi.y, hi.z}),
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);
1000 if (k == kSvNone)
1001 return;
1002 if (w == 0)
1003 acc += 1;
1004 else if (w == 3)
1005 acc += fb(g.idx(q)) ? 1 : 0;
1006 else if (k >= kSvVirtual0) {
1007 if (w == 1) {
1008 acc += 1;
1009 return;
1010 }
1011 const int ax = (k - kSvVirtual0) >> 1;
1012 const bool one = g.colour(q) >= 1.0 - g.eps;
1013 int lo3[3] = {x, y, z}, hi3[3] = {x, y, z};
1014 lo3[ax] -= 1;
1015 hi3[ax] += 1;
1016 bool film = g.inDomain(lo3) && g.inDomain(hi3);
1017 if (film) {
1018 const double cl = g.colour(lo3), ch = g.colour(hi3);
1019 film = !vofIsInterface(cl, g.eps) && !vofIsInterface(ch, g.eps) &&
1020 ((cl >= 1.0 - g.eps) != one) && ((ch >= 1.0 - g.eps) != one);
1021 }
1022 acc += film ? 1 : 0;
1023 }
1024 },
1025 s);
1026 cnt[w] = s;
1027 }
1028 out.band = cnt[0];
1029 out.virt = cnt[1];
1030 out.film = cnt[2];
1031 out.fallback = cnt[3];
1032 // The owner-tie keys (§5.8): the owner set of every edge, exactly as the rule forms it.
1033 const MDRange3<CCExec> rng(space, {lo.x, lo.y, lo.z}, {hi.x, hi.y, hi.z});
1034 long tied = 0;
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;
1041 bool bl = false;
1042 acc += (g.edgeTieKeys(k, ac, sp, gp, bl) >= 2) ? 1 : 0;
1043 }
1044 },
1045 tied);
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;
1053 bool bl = false;
1054 if (g.edgeTieKeys(k, ac, sp, gp, bl) >= 2)
1055 acc = Kokkos::fmax(acc, sp);
1056 }
1057 },
1058 Kokkos::Max<double>(spread));
1059 double gap = 0.0;
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;
1066 bool bl = false;
1067 if (g.edgeTieKeys(k, ac, sp, gp, bl) >= 1 && gp >= 0.0)
1068 acc = Kokkos::fmin(acc, gp);
1069 }
1070 },
1071 Kokkos::Min<double>(gap));
1072 long blended = 0;
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;
1079 bool bl = false;
1080 g.edgeTieKeys(k, ac, sp, gp, bl);
1081 acc += bl ? 1 : 0;
1082 }
1083 },
1084 blended);
1085 out.tied = tied;
1086 out.blended = blended;
1087 out.tieSpread = Kokkos::fmax(spread, 0.0); // 0 when no edge is tied
1088 if (gap < std::numeric_limits<double>::max())
1089 out.untiedGap = gap; // else none: +inf
1090 return out;
1091}
1092
1093} // namespace peclet::flow::vof
1094
1095#endif // PECLET_FLOW_VOF_SHARP_VISCOUS_HPP
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 kSvItems
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 int kSvRows
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...
constexpr int kSvEntries
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).
Definition policy.hpp:36
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
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...
static constexpr int N
static constexpr double F