35#ifndef PECLET_CORE_SCHEME_CUT_CELL_GEOMETRY_HPP
36#define PECLET_CORE_SCHEME_CUT_CELL_GEOMETRY_HPP
75#ifdef KOKKOS_INLINE_FUNCTION
76 return Kokkos::sqrt(x);
83 return x < 0.0 ? -x : x;
99 const double den = (x - y) * (x - z);
101 return (x * x) / den;
107 return (x * x) / ((x - y) * (x - z));
112 const double den = ((a - b1) * (a - b2)) * (a - b3);
114 return (a * a * a) / den;
115 const double s = 1.0 /
ccgMaxAbs4(a, b1, b2, b3);
120 return (a * a * a) / (((a - b1) * (a - b2)) * (a - b3));
126 double den = ((a1 - b1) * (a1 - b2)) * ((a2 - b1) * (a2 - b2));
128 const double s = 1.0 /
ccgMaxAbs4(a1, a2, b1, b2);
133 den = ((a1 - b1) * (a1 - b2)) * ((a2 - b1) * (a2 - b2));
135 const double p = a1 * a2;
136 const double num = p * p - (a1 + a2) * (b1 + b2) * p + b1 * b2 * (a1 * a1 + p + a2 * a2);
146 const bool pa = a > 0.0, pb = b > 0.0, pc = c > 0.0;
147 const int np = (pa ? 1 : 0) + (pb ? 1 : 0) + (pc ? 1 : 0);
171 const double v[4] = {v0, v1, v2, v3};
172 double pos[4], neg[4];
174 for (
int k = 0; k < 4; ++k) {
213 return a == 0 ? h[1] * h[2] : (a == 1 ? h[0] * h[2] : h[0] * h[1]);
220 for (
int a = 0; a < 3; ++a)
228 for (
int a = 0; a < 3; ++a)
229 x[a] = (((c >> a) & 1) ? 0.5 : -0.5) * h[a];
234 t1 = (a == 0) ? 1 : 0;
235 t2 = (a == 2) ? 1 : 2;
240 const int a = f >> 1, side = f & 1;
243 const int u = (k == 1 || k == 2) ? 1 : 0;
244 const int w = (k >= 2) ? 1 : 0;
245 return (side << a) | (u << t1) | (w << t2);
251 double centre,
const double h[3],
double val[4],
260 const int a = f >> 1;
261 for (
int d = 0; d < 3; ++d) {
265 pos[2][a] = ((f & 1) ? 0.5 : -0.5) * h[a];
271 const double t = vp / (vp - vn);
272 for (
int d = 0; d < 3; ++d)
273 x[d] = xp[d] + t * (xn[d] - xp[d]);
277 w[0] = u[1] * v[2] - u[2] * v[1];
278 w[1] = u[2] * v[0] - u[0] * v[2];
279 w[2] = u[0] * v[1] - u[1] * v[0];
283 return ccgSqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
290 double& area,
double cen[3]) {
293 for (
int k = 0; k < 4; ++k) {
299 if (np == 0 || np == 4)
301 const int pRef = ip[0];
305 ccgCross(val[ip[0]], val[in[0]], pos[ip[0]], pos[in[0]], X[0]);
306 ccgCross(val[ip[0]], val[in[1]], pos[ip[0]], pos[in[1]], X[1]);
307 ccgCross(val[ip[1]], val[in[1]], pos[ip[1]], pos[in[1]], X[2]);
308 ccgCross(val[ip[1]], val[in[0]], pos[ip[1]], pos[in[0]], X[3]);
309 double d02[3], d13[3];
310 for (
int d = 0; d < 3; ++d) {
311 d02[d] = X[2][d] - X[0][d];
312 d13[d] = X[3][d] - X[1][d];
315 for (
int d = 0; d < 3; ++d)
318 double d01[3], d03[3], tA[3], tB[3];
319 for (
int d = 0; d < 3; ++d) {
320 d01[d] = X[1][d] - X[0][d];
321 d03[d] = X[3][d] - X[0][d];
326 const double wS = wA + wB;
327 for (
int d = 0; d < 3; ++d) {
328 const double cA = (X[0][d] + X[1][d] + X[2][d]) / 3.0;
329 const double cB = (X[0][d] + X[2][d] + X[3][d]) / 3.0;
330 cen[d] = wS > 0.0 ? (wA * cA + wB * cB) / wS : 0.25 * (X[0][d] + X[1][d] + X[2][d] + X[3][d]);
335 for (
int k = 0; k < 3; ++k) {
336 const int p = (np == 1) ? ip[0] : ip[k];
337 const int n = (np == 1) ? in[k] : in[0];
338 ccgCross(val[p], val[n], pos[p], pos[n], X[k]);
340 double d01[3], d02[3];
341 for (
int d = 0; d < 3; ++d) {
342 d01[d] = X[1][d] - X[0][d];
343 d02[d] = X[2][d] - X[0][d];
346 for (
int d = 0; d < 3; ++d) {
348 cen[d] = (X[0][d] + X[1][d] + X[2][d]) / 3.0;
352 const double dot = vec[0] * (pos[pRef][0] - X[0][0]) + vec[1] * (pos[pRef][1] - X[0][1]) +
353 vec[2] * (pos[pRef][2] - X[0][2]);
355 for (
int d = 0; d < 3; ++d)
374 const double face[6],
double centre,
381 for (
int d = 0; d < 3; ++d) {
389 for (
int f = 0; f < 6; ++f) {
390 const double cc = face[f];
400 bool anyPos = centre > 0.0, anyNonPos = !(centre > 0.0);
401 for (
int c = 0; c < 8; ++c) {
402 anyPos = anyPos || corner[c] > 0.0;
403 anyNonPos = anyNonPos || !(corner[c] > 0.0);
405 for (
int f = 0; f < 6; ++f) {
406 anyPos = anyPos || face[f] > 0.0;
407 anyNonPos = anyNonPos || !(face[f] > 0.0);
409 if (!anyPos || !anyNonPos) {
410 g.
kappa = anyPos ? 1.0 : 0.0;
421 double wc[3] = {0.0, 0.0, 0.0};
422 double refVec[3] = {0.0, 0.0, 0.0};
423 double refArea = -1.0;
424 for (
int f = 0; f < 6; ++f) {
425 for (
int k = 0; k < 4; ++k) {
426 double val[4], pos[4][3];
429 double vec[3], cen[3], area;
432 for (
int d = 0; d < 3; ++d) {
434 wc[d] += area * cen[d];
437 if (area > refArea) {
439 for (
int d = 0; d < 3; ++d)
444 g.
kappa = ksum / 24.0;
451 double vA[3] = {0.0, 0.0, 0.0}, vB[3] = {0.0, 0.0, 0.0};
452 double cA[3] = {0.0, 0.0, 0.0}, cB[3] = {0.0, 0.0, 0.0};
453 double sA = 0.0, sB = 0.0;
454 for (
int f = 0; f < 6; ++f) {
455 for (
int k = 0; k < 4; ++k) {
456 double val[4], pos[4][3];
458 double vec[3], cen[3], area;
461 const double dot = vec[0] * refVec[0] + vec[1] * refVec[1] + vec[2] * refVec[2];
462 double* v =
dot >= 0.0 ? vA : vB;
463 double* c =
dot >= 0.0 ? cA : cB;
464 for (
int d = 0; d < 3; ++d) {
466 c[d] += area * cen[d];
468 (
dot >= 0.0 ? sA : sB) += area;
471 if (sA > 0.0 && sB > 0.0) {
472 for (
int d = 0; d < 3; ++d) {
488 for (
int d = 0; d < 3; ++d) {
core — the shared cut-cell IBM boundary-distance closure polynomials (flow <-> amr).
#define PECLET_CORE_CC_HD
PECLET_CORE_CC_HD double triOnePositive(double x, double y, double z)
PECLET_CORE_CC_HD void ccgFanTet(int f, int k, const double corner[8], const double face[6], double centre, const double h[3], double val[4], double pos[4][3])
PECLET_CORE_CC_HD void ccgCrossProd(const double u[3], const double v[3], double w[3])
PECLET_CORE_CC_HD double ccgSqrt(double x)
PECLET_CORE_CC_HD void ccgTangents(int a, int &t1, int &t2)
PECLET_CORE_CC_HD double ccgMaxAbs4(double a, double b, double c, double d)
PECLET_CORE_CC_HD double ccgAbs(double x)
PECLET_CORE_CC_HD double tetOnePositive(double a, double b1, double b2, double b3)
PECLET_CORE_CC_HD void ccgCornerPos(int c, const double h[3], double x[3])
PECLET_CORE_CC_HD bool ccgTetPiece(const double val[4], const double pos[4][3], double vec[3], double &area, double cen[3])
PECLET_CORE_CC_HD double ccgNorm(const double v[3])
PECLET_CORE_CC_HD void ccgCross(double vp, double vn, const double xp[3], const double xn[3], double x[3])
PECLET_CORE_CC_HD int ccgFanCorner(int f, int k)
PECLET_CORE_CC_HD double ccgMaxAbs3(double a, double b, double c)
PECLET_CORE_CC_HD double tetTwoPositive(double a1, double a2, double b1, double b2)
PECLET_CORE_CC_HD CutCellGeometry cutCellGeometryFanTet(const double corner[8], const double face[6], double centre, const double h[3])
The cut-cell record of one cell from its 15 PL samples (§2.2): corner[8] (index bx+2by+4bz),...
constexpr double kSingleFacetRho
ρ = |areaPL| / areaSum at or above which the cell carries ONE facet (§2.2).
PECLET_CORE_CC_HD double fanFaceAperture(double v00, double v10, double v11, double v01, double cc)
PL aperture of one face from its fan (§2.2): the corner values in loop order c00, c10,...
PECLET_CORE_CC_HD double cutCellFaceArea(int a, const double h[3])
Face area of axis a for cell size h: the product of the two other spacings.
CutCellKind
Facet classification of a cut cell (§2.2).
@ none
no facet (uncut, or every piece below the drop threshold)
@ thinSolid
two facets, solid between two fluids (a counted resolution error)
@ single
one facet (ρ ≥ 0.5, or the two-group split left a group empty)
@ gap
two facets, fluid between two walls
PECLET_CORE_CC_HD double triPositiveFraction(double a, double b, double c)
Fraction of a triangle on which the linear interpolant of its vertex values (a, b,...
constexpr double kApertureSnap
Aperture snap threshold at BOTH ends (§2.3): a < 1e-3 → 0, a > 1 − 1e-3 → 1.
constexpr double kPieceDropRel
A facet piece with area < kPieceDropRel · min_a A_a is dropped (§2.2).
PECLET_CORE_CC_HD double snapAperture(double a)
Snap a face aperture at both ends (§2.3): a < 1e-3 → 0, a > 1 − 1e-3 → 1, else a.
PECLET_CORE_CC_HD void facetAreaVector(const double ap[6], const double h[3], double out[3])
The area vector the apertures imply through the divergence theorem (§2.3): out_a = A_a (ap[2a+1] − ap...
PECLET_CORE_CC_HD double tetPositiveFraction(double v0, double v1, double v2, double v3)
Fraction of a tetrahedron on which the linear interpolant of its vertex values is strictly positive (...
PECLET_HD Real dot(Vec3< Real > a, Vec3< Real > b)
The geometric record of one cell (§2.1). Double, cell-centred frame, internal lengths.
double facetCentroid[2][3]
per facet: centroid relative to the cell centre; unused 0
double areaPL[3]
net PL facet area vector (into the fluid)
double kappa
fluid volume fraction ∈ [0, 1]
double aperture[6]
open fraction of each face, −x,+x,−y,+y,−z,+z, UNSNAPPED
double facetArea[2][3]
per facet: area vector (into the fluid); unused slots 0