117#ifndef PECLET_CORE_VOF_CURVATURE_HPP
118#define PECLET_CORE_VOF_CURVATURE_HPP
120#include <Kokkos_Core.hpp>
121#include <Kokkos_MathematicalFunctions.hpp>
185KOKKOS_INLINE_FUNCTION
bool hfIsFull(
double c,
double eps) {
188KOKKOS_INLINE_FUNCTION
bool hfIsEmpty(
double c,
double eps) {
233KOKKOS_INLINE_FUNCTION
bool hfColumnHeight(
const double* col,
int nh,
double& h,
int& orient,
234 double monoTol,
double pureEps =
kHfPureEps) {
237 const int R = nh / 2;
238 double lo = 0.0, hi = 0.0;
239 for (
int k = 0; k < R; ++k) {
241 hi += col[nh - 1 - k];
252 for (
int k = R; k >= 0; --k)
257 for (
int k = R; k < nh; ++k)
263 for (
int k = R; k >= 0; --k)
268 for (
int k = R; k < nh; ++k)
278 for (
int k = a; k <= b; ++k) {
281 if (k < b && (col[k + 1] - col[k]) * orient > monoTol)
284 h = (orient == 1) ? (s +
static_cast<double>(a - R) - 0.5)
285 : (s -
static_cast<double>(b - R) - 0.5);
297 const double hx = 0.5 * (h[2 + 3 * 1] - h[0 + 3 * 1]);
298 const double hy = 0.5 * (h[1 + 3 * 2] - h[1 + 3 * 0]);
299 const double hxx = h[2 + 3 * 1] - 2.0 * h[1 + 3 * 1] + h[0 + 3 * 1];
300 const double hyy = h[1 + 3 * 2] - 2.0 * h[1 + 3 * 1] + h[1 + 3 * 0];
301 const double hxy = 0.25 * (h[2 + 3 * 2] - h[0 + 3 * 2] - h[2 + 3 * 0] + h[0 + 3 * 0]);
302 const double q = 1.0 + hx * hx + hy * hy;
303 const double num = hxx + hyy + hxx * hy * hy + hyy * hx * hx - 2.0 * hxy * hx * hy;
305 return -num / (q * Kokkos::sqrt(q));
328 const int d1 = (d + 1) % 3, d2 = (d + 2) % 3;
329 const double r1 = g.
h[d] / g.
h[d1], r2 = g.
h[d] / g.
h[d2];
330 const double hx = 0.5 * (h[2 + 3 * 1] - h[0 + 3 * 1]) * r1;
331 const double hy = 0.5 * (h[1 + 3 * 2] - h[1 + 3 * 0]) * r2;
332 const double hxx = (h[2 + 3 * 1] - 2.0 * h[1 + 3 * 1] + h[0 + 3 * 1]) * r1 / g.
h[d1];
333 const double hyy = (h[1 + 3 * 2] - 2.0 * h[1 + 3 * 1] + h[1 + 3 * 0]) * r2 / g.
h[d2];
335 0.25 * (h[2 + 3 * 2] - h[0 + 3 * 2] - h[2 + 3 * 0] + h[0 + 3 * 0]) * r1 / g.
h[d2];
336 const double q = 1.0 + hx * hx + hy * hy;
337 const double num = hxx + hyy + hxx * hy * hy + hyy * hx * hx - 2.0 * hxy * hx * hy;
338 return -num / (q * Kokkos::sqrt(q));
348KOKKOS_INLINE_FUNCTION
void curvFrame(
const double n[3],
double t1[3],
double t2[3]) {
350 double m = Kokkos::fabs(n[0]);
351 if (Kokkos::fabs(n[1]) < m) {
352 m = Kokkos::fabs(n[1]);
355 if (Kokkos::fabs(n[2]) < m)
357 double e[3] = {0.0, 0.0, 0.0};
360 t1[0] = e[1] * n[2] - e[2] * n[1];
361 t1[1] = e[2] * n[0] - e[0] * n[2];
362 t1[2] = e[0] * n[1] - e[1] * n[0];
363 const double s = Kokkos::sqrt(t1[0] * t1[0] + t1[1] * t1[1] + t1[2] * t1[2]);
364 const double inv = (s > 0.0) ? 1.0 / s : 0.0;
369 t2[0] = n[1] * t1[2] - n[2] * t1[1];
370 t2[1] = n[2] * t1[0] - n[0] * t1[2];
371 t2[2] = n[0] * t1[1] - n[1] * t1[0];
379 const double q = r / d;
382 const double t = 1.0 - q;
383 const double t2 = t * t;
384 return (1.0 + 4.0 * q) * t2 * t2;
391 const double q = 1.0 + a[1] * a[1] + a[2] * a[2];
392 const double num = a[5] * a[1] * a[1] - a[4] * a[1] * a[2] + a[3] * a[2] * a[2] + a[3] + a[5];
393 return -2.0 * num / (q * Kokkos::sqrt(q));
402KOKKOS_INLINE_FUNCTION
bool curvSolveSym(
const double Ain[6][6],
const double bin[6],
int n,
403 double x[6],
double pivTol) {
405 for (
int i = 0; i < n; ++i) {
406 if (!(Ain[i][i] > 0.0))
408 d[i] = 1.0 / Kokkos::sqrt(Ain[i][i]);
410 double A[6][6], b[6];
411 for (
int i = 0; i < n; ++i) {
412 b[i] = bin[i] * d[i];
413 for (
int j = 0; j < n; ++j)
414 A[i][j] = Ain[i][j] * d[i] * d[j];
417 for (
int i = 0; i < n; ++i) {
419 for (
int k = 0; k < i; ++k)
420 s -= A[i][k] * A[i][k] * A[k][k];
424 for (
int j = i + 1; j < n; ++j) {
426 for (
int k = 0; k < i; ++k)
427 t -= A[j][k] * A[i][k] * A[k][k];
433 for (
int i = 0; i < n; ++i) {
435 for (
int k = 0; k < i; ++k)
439 for (
int i = 0; i < n; ++i)
441 for (
int i = n - 1; i >= 0; --i) {
443 for (
int k = i + 1; k < n; ++k)
447 for (
int i = 0; i < n; ++i)
465KOKKOS_INLINE_FUNCTION
int plicPolygon(
double mx,
double my,
double mz,
double alpha,
467 const double m[3] = {mx, my, mz};
468 const double nrm2 = m[0] * m[0] + m[1] * m[1] + m[2] * m[2];
473 for (
int q = 0; q < 8 && nv < 8; ++q) {
474 const double A[3] = {
static_cast<double>(q & 1),
static_cast<double>((q >> 1) & 1),
475 static_cast<double>((q >> 2) & 1)};
476 const double fA = m[0] * A[0] + m[1] * A[1] + m[2] * A[2] - alpha;
477 for (
int a = 0; a < 3 && nv < 8; ++a) {
480 double B[3] = {A[0], A[1], A[2]};
482 const double fB = fA + m[a];
485 const bool cross = (fA <= 0.0 && fB > 0.0) || (fB <= 0.0 && fA > 0.0);
488 const double den = fA - fB;
489 const double t = (den != 0.0) ? fA / den : 0.0;
490 double p[3] = {A[0], A[1], A[2]};
491 p[a] = A[a] + t * (B[a] - A[a]);
494 for (
int k = 0; k < nv; ++k) {
495 const double dx = p[0] - v[k][0], dy = p[1] - v[k][1], dz = p[2] - v[k][2];
496 if (dx * dx + dy * dy + dz * dz < 1e-24) {
513 const double invn = 1.0 / Kokkos::sqrt(nrm2);
514 const double nh[3] = {m[0] * invn, m[1] * invn, m[2] * invn};
517 double cx = 0.0, cy = 0.0, cz = 0.0;
518 for (
int k = 0; k < nv; ++k) {
523 const double inv = 1.0 /
static_cast<double>(nv);
528 for (
int k = 0; k < nv; ++k) {
529 const double dx = v[k][0] - cx, dy = v[k][1] - cy, dz = v[k][2] - cz;
531 Kokkos::atan2(dx * e2[0] + dy * e2[1] + dz * e2[2], dx * e1[0] + dy * e1[1] + dz * e1[2]);
533 for (
int i = 1; i < nv; ++i) {
534 const double a0 = ang[i];
535 const double p0 = v[i][0], p1 = v[i][1], p2 = v[i][2];
537 while (j >= 0 && ang[j] > a0) {
539 v[j + 1][0] = v[j][0];
540 v[j + 1][1] = v[j][1];
541 v[j + 1][2] = v[j][2];
555 ctr[0] = ctr[1] = ctr[2] = 0.0;
559 for (
int k = 1; k + 1 < nv; ++k) {
560 const double a1[3] = {v[k][0] - v[0][0], v[k][1] - v[0][1], v[k][2] - v[0][2]};
561 const double a2[3] = {v[k + 1][0] - v[0][0], v[k + 1][1] - v[0][1], v[k + 1][2] - v[0][2]};
562 const double cx = a1[1] * a2[2] - a1[2] * a2[1];
563 const double cy = a1[2] * a2[0] - a1[0] * a2[2];
564 const double cz = a1[0] * a2[1] - a1[1] * a2[0];
565 const double t = 0.5 * Kokkos::sqrt(cx * cx + cy * cy + cz * cz);
567 ctr[0] += t * (v[0][0] + v[k][0] + v[k + 1][0]) / 3.0;
568 ctr[1] += t * (v[0][1] + v[k][1] + v[k + 1][1]) / 3.0;
569 ctr[2] += t * (v[0][2] + v[k][2] + v[k + 1][2]) / 3.0;
572 const double inv = 1.0 / area;
594 for (
int i = 0; i < 6; ++i)
598 for (
int k = 0; k < nv; ++k) {
599 const int k1 = (k + 1 == nv) ? 0 : k + 1;
600 const double x0 = xy[k][0], y0 = xy[k][1];
601 const double x1 = xy[k1][0], y1 = xy[k1][1];
602 const double dx = x1 - x0, dy = y1 - y0;
605 s[0] += dy * 0.5 * (x0 + x1);
606 s[1] += dy * (x0 * x0 + x0 * x1 + x1 * x1) / 6.0;
607 s[2] += dy * (2.0 * x0 * y0 + x0 * y1 + x1 * y0 + 2.0 * x1 * y1) / 6.0;
608 s[3] += dy * (x0 + x1) * (x0 * x0 + x1 * x1) / 12.0;
611 (x0 * x0 * y0 + 0.5 * x0 * x0 * dy + x0 * dx * y0 + (2.0 / 3.0) * x0 * dx * dy +
612 dx * dx * y0 / 3.0 + 0.25 * dx * dx * dy);
614 s[5] += dy * (x0 * y0 * y0 + x0 * y0 * dy + x0 * dy * dy / 3.0 + 0.5 * dx * y0 * y0 +
615 (2.0 / 3.0) * dx * y0 * dy + 0.25 * dx * dy * dy);
644 for (
int i = 0; i < 6; ++i) {
646 for (
int j = 0; j < 6; ++j)
656KOKKOS_INLINE_FUNCTION
void ptFitAdd(
PtFit& f,
const double X[3],
const double org[3],
657 const double t1[3],
const double t2[3],
const double nn[3],
659 const double di[3] = {X[0] - org[0], X[1] - org[1], X[2] - org[2]};
664 const double x = d[0] * t1[0] + d[1] * t1[1] + d[2] * t1[2];
665 const double y = d[0] * t2[0] + d[1] * t2[1] + d[2] * t2[2];
666 const double z = d[0] * nn[0] + d[1] * nn[1] + d[2] * nn[2];
667 const double w =
wendlandWeight(Kokkos::sqrt(x * x + y * y + z * z), dW);
670 const double phi[6] = {1.0, x, y, x * x, x * y, y * y};
671 for (
int i = 0; i < 6; ++i) {
672 f.
b[i] += w * phi[i] * z;
673 for (
int j = 0; j < 6; ++j)
674 f.
A[i][j] += w * phi[i] * phi[j];
680KOKKOS_INLINE_FUNCTION
void ptFitAdd(
PtFit& f,
const double X[3],
const double org[3],
681 const double t1[3],
const double t2[3],
const double nn[3],
689 for (
int i = 0; i < 6; ++i)
695 const int id[3] = {0, 3, 5};
696 double Ar[6][6], br[6], ar[6];
697 for (
int i = 0; i < 3; ++i) {
699 for (
int j = 0; j < 3; ++j)
700 Ar[i][j] = f.
A[
id[i]][
id[j]];
724 for (
int i = 0; i < 6; ++i) {
726 for (
int j = 0; j < 6; ++j)
762KOKKOS_INLINE_FUNCTION
bool pvTermNormal(
double mx,
double my,
double mz,
const double t1[3],
763 const double t2[3],
const double nn[3],
double cosMin,
765 const double n2 = mx * mx + my * my + mz * mz;
771 const double mi[3] = {mx / g.
h[0], my / g.
h[1], mz / g.
h[2]};
772 const double invn = 1.0 / Kokkos::sqrt(mi[0] * mi[0] + mi[1] * mi[1] + mi[2] * mi[2]);
773 np[0] = (mi[0] * t1[0] + mi[1] * t1[1] + mi[2] * t1[2]) * invn;
774 np[1] = (mi[0] * t2[0] + mi[1] * t2[1] + mi[2] * t2[2]) * invn;
775 np[2] = (mi[0] * nn[0] + mi[1] * nn[1] + mi[2] * nn[2]) * invn;
776 if (!(np[2] > cosMin))
792 int nv,
const double off[3],
const double org[3],
793 const double t1[3],
const double t2[3],
794 const double nn[3],
double dW,
const VofMetric& g) {
799 double px = 0.0, py = 0.0;
800 for (
int k = 0; k < nv; ++k) {
801 const double Xi[3] = {off[0] + v[k][0] - 0.5 - org[0], off[1] + v[k][1] - 0.5 - org[1],
802 off[2] + v[k][2] - 0.5 - org[2]};
805 xy[k][0] = X[0] * t1[0] + X[1] * t1[1] + X[2] * t1[2];
806 xy[k][1] = X[0] * t2[0] + X[1] * t2[1] + X[2] * t2[2];
807 const double z = X[0] * nn[0] + X[1] * nn[1] + X[2] * nn[2];
812 const double invv = 1.0 /
static_cast<double>(nv);
819 if (!(Kokkos::fabs(s[0]) > 1e-14))
823 const double b1 = -np[0] / np[2], b2 = -np[1] / np[2];
824 const double b0 = zc - b1 * px - b2 * py;
826 const double r = Kokkos::sqrt(px * px + py * py + zc * zc);
831 const double B = b0 * s[0] + b1 * s[1] + b2 * s[2];
834 for (
int i = 0; i < 6; ++i)
847KOKKOS_INLINE_FUNCTION
bool pvFitTerm(
PvTerm& t,
double mx,
double my,
double mz,
double alpha,
848 const double off[3],
const double org[3],
const double t1[3],
849 const double t2[3],
const double nn[3],
double dW,
853 if (!
pvTermNormal(mx, my, mz, t1, t2, nn, cosMin, g, np))
859 return pvTermPolygon(t, np, v, nv, off, org, t1, t2, nn, dW, g);
865 const double w = t.
w, B = t.
B;
866 const double* s = t.
s;
867 for (
int i = 0; i < 6; ++i) {
868 f.
b[i] += w * s[i] * B;
869 for (
int j = 0; j < 6; ++j)
870 f.
A[i][j] += w * s[i] * s[j];
878KOKKOS_INLINE_FUNCTION
bool pvFitAdd(
PvFit& f,
double mx,
double my,
double mz,
double alpha,
879 const double off[3],
const double org[3],
const double t1[3],
880 const double t2[3],
const double nn[3],
double dW,
883 if (!
pvFitTerm(t, mx, my, mz, alpha, off, org, t1, t2, nn, dW, cosMin, g))
890KOKKOS_INLINE_FUNCTION
bool pvFitAdd(
PvFit& f,
double mx,
double my,
double mz,
double alpha,
891 const double off[3],
const double org[3],
const double t1[3],
892 const double t2[3],
const double nn[3],
double dW,
894 return pvFitAdd(f, mx, my, mz, alpha, off, org, t1, t2, nn, dW, cosMin,
VofMetric{});
910 for (
int i = 0; i < 6; ++i)
917 const int id[3] = {0, 3, 5};
918 double Ar[6][6], br[6], ar[6];
919 for (
int i = 0; i < 3; ++i) {
921 for (
int j = 0; j < 3; ++j)
922 Ar[i][j] = f.
A[
id[i]][
id[j]];
951 const double w = t.
w, B = t.
B;
952 const double* s = t.
s;
953 for (
int i = 0; i < 6; ++i) {
954 f.
b[i] += w * s[i] * B;
955 for (
int j = 0; j <= i; ++j)
956 f.
A[i][j] += w * s[i] * s[j];
971 const double w = t.
w;
973 const int i = e - 21;
974 a += w * t.
s[i] * t.
B;
978 while ((i + 1) * (i + 2) / 2 <= e)
980 const int j = e - i * (i + 1) / 2;
981 a += w * t.
s[i] * t.
s[j];
986 for (
int i = 0; i < 6; ++i) {
987 f.
b[i] = ent[21 + i];
988 for (
int j = 0; j < 6; ++j)
989 f.
A[i][j] = (j <= i) ? ent[i * (i + 1) / 2 + j] : 0.0;
1004KOKKOS_INLINE_FUNCTION
void pvPolygonBuild(
double mx,
double my,
double mz,
double alpha,
1010 double sx = 0.0, sy = 0.0, sz = 0.0;
1011 for (
int k = 0; k < P.
nv; ++k) {
1016 const double inv = 1.0 /
static_cast<double>(P.
nv);
1017 P.
vbar[0] = sx * inv - 0.5;
1018 P.
vbar[1] = sy * inv - 0.5;
1019 P.
vbar[2] = sz * inv - 0.5;
1034 const double org[3],
double dW,
const VofMetric& g) {
1039 const double Xi[3] = {P.
vbar[0] + off[0] - org[0], P.
vbar[1] + off[1] - org[1],
1040 P.
vbar[2] + off[2] - org[2]};
1043 return X[0] * X[0] + X[1] * X[1] + X[2] * X[2] > dW * dW * (1.0 + 1e-9);
1063KOKKOS_INLINE_FUNCTION
void pvMomentsBuild(
double mx,
double my,
double mz,
double alpha,
1065 for (
int a = 0; a < 3; ++a) {
1071 for (
int q = 0; q < 6; ++q)
1073 const double m[3] = {mx, my, mz};
1081 double sc[3] = {0.0, 0.0, 0.0};
1082 for (
int k = 0; k < nv; ++k) {
1083 const double Xi[3] = {v[k][0] - 0.5, v[k][1] - 0.5, v[k][2] - 0.5};
1089 const double inv = 1.0 /
static_cast<double>(nv);
1090 P.
c[0] = sc[0] * inv;
1091 P.
c[1] = sc[1] * inv;
1092 P.
c[2] = sc[2] * inv;
1093 constexpr int ip[6] = {0, 1, 2, 0, 0, 1}, iq[6] = {0, 1, 2, 1, 2, 2};
1094 for (
int k = 1; k + 1 < nv; ++k) {
1095 const double* A = Y[0];
1096 const double* B = Y[k];
1097 const double* C = Y[k + 1];
1098 const double u[3] = {B[0] - A[0], B[1] - A[1], B[2] - A[2]};
1099 const double w[3] = {C[0] - A[0], C[1] - A[1], C[2] - A[2]};
1100 const double cx = u[1] * w[2] - u[2] * w[1];
1101 const double cy = u[2] * w[0] - u[0] * w[2];
1102 const double cz = u[0] * w[1] - u[1] * w[0];
1103 const double At = 0.5 * Kokkos::sqrt(cx * cx + cy * cy + cz * cz);
1104 const double S[3] = {A[0] + B[0] + C[0], A[1] + B[1] + C[1], A[2] + B[2] + C[2]};
1106 for (
int a = 0; a < 3; ++a)
1107 P.
m1[a] += At * S[a] / 3.0;
1108 for (
int q = 0; q < 6; ++q) {
1109 const int p0 = ip[q], q0 = iq[q];
1110 P.
m2[q] += At / 12.0 * (A[p0] * A[q0] + B[p0] * B[q0] + C[p0] * C[q0] + S[p0] * S[q0]);
1122 double t1[3],
double t2[3],
double org[3]) {
1123 if (!(P.
n[0] * P.
n[0] + P.
n[1] * P.
n[1] + P.
n[2] * P.
n[2] > 0.0))
1130 org[0] = P.
m1[0] / P.
a;
1131 org[1] = P.
m1[1] / P.
a;
1132 org[2] = P.
m1[2] / P.
a;
1134 const double h[3] = {-0.5, -0.5, -0.5};
1155 const double org[3],
const double t1[3],
1156 const double t2[3],
const double nn[3],
double dW,
1159 const double cj = P.
n[0] * nn[0] + P.
n[1] * nn[1] + P.
n[2] * nn[2];
1169 const double rc[3] = {P.
c[0] + d[0], P.
c[1] + d[1], P.
c[2] + d[2]};
1170 const double r = Kokkos::sqrt(rc[0] * rc[0] + rc[1] * rc[1] + rc[2] * rc[2]);
1174 const double a = P.
a;
1175 const double* m1 = P.
m1;
1176 const double* m2 = P.
m2;
1177 const double Q1[3] = {m1[0] + d[0] * a, m1[1] + d[1] * a, m1[2] + d[2] * a};
1179 const double Qxx = m2[0] + 2.0 * d[0] * m1[0] + d[0] * d[0] * a;
1180 const double Qyy = m2[1] + 2.0 * d[1] * m1[1] + d[1] * d[1] * a;
1181 const double Qzz = m2[2] + 2.0 * d[2] * m1[2] + d[2] * d[2] * a;
1182 const double Qxy = m2[3] + d[0] * m1[1] + m1[0] * d[1] + d[0] * d[1] * a;
1183 const double Qxz = m2[4] + d[0] * m1[2] + m1[0] * d[2] + d[0] * d[2] * a;
1184 const double Qyz = m2[5] + d[1] * m1[2] + m1[1] * d[2] + d[1] * d[2] * a;
1185 const double u[3] = {Qxx * t1[0] + Qxy * t1[1] + Qxz * t1[2],
1186 Qxy * t1[0] + Qyy * t1[1] + Qyz * t1[2],
1187 Qxz * t1[0] + Qyz * t1[1] + Qzz * t1[2]};
1188 const double v[3] = {Qxx * t2[0] + Qxy * t2[1] + Qxz * t2[2],
1189 Qxy * t2[0] + Qyy * t2[1] + Qyz * t2[2],
1190 Qxz * t2[0] + Qyz * t2[1] + Qzz * t2[2]};
1193 s[1] = cj * (t1[0] * Q1[0] + t1[1] * Q1[1] + t1[2] * Q1[2]);
1194 s[2] = cj * (t2[0] * Q1[0] + t2[1] * Q1[1] + t2[2] * Q1[2]);
1195 s[3] = cj * (t1[0] * u[0] + t1[1] * u[1] + t1[2] * u[2]);
1196 s[4] = cj * (t2[0] * u[0] + t2[1] * u[1] + t2[2] * u[2]);
1197 s[5] = cj * (t2[0] * v[0] + t2[1] * v[1] + t2[2] * v[2]);
1198 if (!(Kokkos::fabs(s[0]) > 1e-14))
1201 t.
B = cj * (nn[0] * Q1[0] + nn[1] * Q1[1] + nn[2] * Q1[2]);
1202 for (
int i = 0; i < 6; ++i)
bool hfIsFull(double c, double eps)
Colour thresholds for "this cell is pure", at a caller-supplied tolerance.
constexpr int kPvEntries
Number of independent entries of the PV normal equations: the 21 of the lower triangle (with the diag...
void pvFitAccumLower(PvFit &f, const PvTerm &t)
Lower-triangle accumulation: pvFitAccum restricted to j <= i (design G §5.1c).
void pvPolygonBuild(double mx, double my, double mz, double alpha, PvPolygon &P)
Build a PvPolygon from a cell's PLIC plane: nv = plicPolygon(m, alpha, v), then vbar.
constexpr int kHfColumn
Column length of the height function, NH in Han et al.
bool pvOutsideSupport(const PvPolygon &P, const double off[3], const double org[3], double dW, const VofMetric &g)
true iff the cached polygon is CERTAINLY outside the Wendland support of a target with origin org (in...
void curvFrame(const double n[3], double t1[3], double t2[3])
Right-handed orthonormal frame (t1, t2, n) from a unit vector n.
bool pvFitTerm(PvTerm &t, double mx, double my, double mz, double alpha, const double off[3], const double org[3], const double t1[3], const double t2[3], const double nn[3], double dW, double cosMin, const VofMetric &g)
One stencil polygon's contribution to the PV fit: everything pvFitAdd computes before the accumulatio...
bool pvFrameMoments(const PvMoments &P, const VofMetric &g, double nn[3], double t1[3], double t2[3], double org[3])
Tier 3's fit frame from the TARGET's cached moments: nn = P.n, curvFrame(nn, t1, t2),...
bool ptFitSolve(const PtFit &f, double a[6], bool &red)
Solve the point fit, with the same rank cascade as pvFitSolve.
bool pvTermPolygon(PvTerm &t, const double np[3], const double v[8][3], int nv, const double off[3], const double org[3], const double t1[3], const double t2[3], const double nn[3], double dW, const VofMetric &g)
The POLYGON half of pvFitTerm (design G §5.1a): everything pvFitTerm does after if (nv < 3) return fa...
void pvMomentsBuild(double mx, double my, double mz, double alpha, const VofMetric &g, PvMoments &P)
Build a PvMoments from a cell's PLIC plane (index-space m, alpha) and the cell metric: the physical u...
constexpr double kHfPureEps
The FLOOR of the "this cell is pure" thresholds.
double paraboloidKappa(const double a[6])
Mean curvature (times two) of the paraboloid z = a0 + a1 x + a2 y + a3 x^2 + a4 x y + a5 y^2 at the o...
bool pvTermMoments(PvTerm &t, const PvMoments &P, const double off[3], const double org[3], const double t1[3], const double t2[3], const double nn[3], double dW, double cosMin, const VofMetric &g)
One stencil polygon's PV term from its cached moments (design G §5.1d, "V6"): the same integrals as p...
void pvFitAccum(PvFit &f, const PvTerm &t)
Fold one accepted term (t.ok) into the fit — the accumulation half of pvFitAdd, with its expressions ...
constexpr int kPvHalf
Half-width of the PV fit stencil: S = 2*kPvHalf + 1 = 5, Han et al.'s recommended S.
constexpr double kPtWeightWidth
Wendland support width for the tier-2b height-position fit.
CurvatureBranch
Which branch of the cascade produced a cell's curvature.
@ kCurvHfMixed
tier 2a: standard HF in one of the two remaining directions
@ kCurvNoEstimate
NO estimate: fewer than 3 usable PLIC polygons in the stencil.
@ kCurvPvReduced
tier 3 with the rank-deficient 3-parameter model (a1 = a2 = a4 = 0)
@ kCurvNone
not an interfacial cell — kappa is 0 because there is no interface
@ kCurvHfFit
tier 2b: paraboloid fit to the interface positions of whichever columns ARE consistent,...
@ kCurvPv
tier 3: PLIC-volumetric paraboloid fit, 5^3 Wendland-weighted
@ kCurvHf
tier 1: standard HF in the preferred (largest |n_d|) direction
int plicPolygon(double mx, double my, double mz, double alpha, double v[8][3])
Vertices of the polygon {x in [0,1]^3 : m .
bool pvTermNormal(double mx, double my, double mz, const double t1[3], const double t2[3], const double nn[3], double cosMin, const VofMetric &g, double np[3])
The NORMAL half of pvFitTerm (design G, flow doc/vof_curvature_cost_design.md §5.1a): the n2 > 0 chec...
bool pvFitSolve(const PvFit &f, double a[6], bool &red)
Solve the accumulated PV system.
double hfPatchKappa(const double h[9])
Mean-curvature-times-two from a 3x3 patch of heights, Han et al.
bool hfIsEmpty(double c, double eps)
void pvFitAccumEntry(double &a, const PvTerm &t, int e)
ONE entry e in [0, 27) of the accumulation, for an entry-parallel fold (design G §5....
constexpr double kPvWeightWidth
Wendland support width d in cell units.
void ptFitAdd(PtFit &f, const double X[3], const double org[3], const double t1[3], const double t2[3], const double nn[3], double dW, const VofMetric &g)
Fold one interface point into the fit.
double vofPhysNormalInv(const double m[3], const VofMetric &g, double n[3])
vofPhysNormal in the RECIPROCAL-MULTIPLY form — n = (H^-1 m) * (1/|H^-1 m|), which is what the curvat...
void polygonMoments2d(const double xy[8][2], int nv, double s[6])
The six monomial integrals s = ( |G|, int x, int y, int x^2, int xy, int y^2 ) over the planar polygo...
bool curvSolveSym(const double Ain[6][6], const double bin[6], int n, double x[6], double pivTol)
Solve the symmetric positive-semidefinite n x n system A x = b (n <= 6) by LDL^T with Jacobi (diagona...
bool pvFitAdd(PvFit &f, double mx, double my, double mz, double alpha, const double off[3], const double org[3], const double t1[3], const double t2[3], const double nn[3], double dW, double cosMin, const VofMetric &g)
Fold one stencil cell's PLIC polygon into the fit: pvFitTerm, then pvFitAccum if the polygon is accep...
bool hfColumnHeight(const double *col, int nh, double &h, int &orient, double monoTol, double pureEps=kHfPureEps)
One height from one column of colour values.
void polygonAreaCentroid(const double v[8][3], int nv, double ctr[3], double &area)
Area and centroid of a planar polygon in 3-D (fan triangulation from v[0]).
double wendlandWeight(double r, double d)
Wendland C2 radial basis function, Han et al.
void pvFitFromEntries(PvFit &f, const double ent[kPvEntries], int npoly)
A PvFit from the 27 entries of pvFitAccumEntry (+ npoly); the upper triangle is zero.
PECLET_HD Vec3< Real > cross(Vec3< Real > a, Vec3< Real > b)
core — PLIC (piecewise-linear interface construction) geometric toolbox: the analytic plane<->volume ...
Accumulator for an ordinary weighted linear least-squares paraboloid through points.
Accumulator for the PV normal equations, Han et al.
The per-cell MOMENT cache entry (design G §5.1d, "V6"): the 3-D area moments of a cell's PLIC polygon...
double m2[6]
int_P Y Y^T dA, in the order xx, yy, zz, xy, xz, yz
double n[3]
unit PHYSICAL normal (vofPhysNormalInv); (0,0,0) if degenerate
double c[3]
physical vertex average (1/nv) sum_k Y_k — the Wendland point
double a
area (physical); 0 when nv < 3 or the normal is degenerate
The per-cell POLYGON cache entry (design G §5.1b, "V5"): plicPolygon's output for one cell's PLIC pla...
double v[8][3]
cell-local [0,1]^3 vertices; slots >= nv unused
int nv
plicPolygon's return value (0 if the normal is degenerate)
double vbar[3]
(sum_k v[k]) * (1/nv) - 0.5; 0 when nv == 0
One stencil cell's PLIC polygon in the PV fit: the parameters of pvFitTerm and pvFitAdd.
The per-axis cell size, in the solver's reference length (hRef), of the cell these kernels map to the...
void toPhys(const double X[3], double out[3]) const
Index displacement -> physical displacement (in hRef): X'_a = h[a] X_a.