28#include <Kokkos_Core.hpp>
48 std::fprintf(stderr, "CHECK failed: %s\n at %s:%d\n", #cond, __FILE__, __LINE__); \
53std::size_t idx(
int x,
int y,
int z,
int nx,
int ny) {
54 return (std::size_t)x + (std::size_t)y * nx + (std::size_t)z * (std::size_t)nx * ny;
64 double cx[8], cy[8], cz[8], r[8];
66 double sdfAt(
double x,
double y,
double z)
const {
68 for (
int s = 0;
s < n; ++
s)
69 for (
int px = -1; px <= 1; ++px)
70 for (
int py = -1; py <= 1; ++py)
71 for (
int pz = -1; pz <= 1; ++pz) {
72 const double dx =
x - (cx[
s] + px * N), dy = y - (cy[s] + py * N),
73 dz =
z - (cz[
s] + pz * N);
74 const double d = std::sqrt(dx * dx + dy * dy + dz * dz) - r[
s];
75 best =
d < best ?
d : best;
81SphereArray makeArray(
int N) {
85 const double f =
N / 32.0;
86 const double px[4] = {6.0, 20.0, 11.0, 26.0}, py[4] = {7.0, 9.0, 24.0, 22.0},
87 pz[4] = {8.0, 23.0, 19.0, 6.0};
88 for (
int s = 0;
s < 4; ++
s) {
97std::vector<double> arraySdfInner(
const SphereArray& a,
int N) {
98 std::vector<double> sd((std::size_t)
N *
N *
N);
99 for (
int z = 0;
z <
N; ++
z)
100 for (
int y = 0;
y <
N; ++
y)
101 for (
int x = 0;
x <
N; ++
x)
102 sd[idx(x, y, z,
N,
N)] =
a.sdfAt(x + 0.5, y + 0.5, z + 0.5);
107void arraySdfBlock(
const SphereArray& a,
CCField dst,
I3 e,
int g) {
108 auto h = Kokkos::create_mirror_view(dst);
109 for (
int z = 0;
z <
e.z; ++
z)
110 for (
int y = 0;
y <
e.y; ++
y)
111 for (
int x = 0;
x <
e.x; ++
x)
112 h(
L3(x, y, z, e)) =
a.sdfAt(x - g + 0.5, y - g + 0.5, z - g + 0.5);
113 Kokkos::deep_copy(dst, h);
116std::vector<double> hostOf(
SField v) {
117 auto h = Kokkos::create_mirror_view(v);
118 Kokkos::deep_copy(h, v);
119 std::vector<double>
out(
v.extent(0));
120 for (std::size_t i = 0;
i <
out.size(); ++
i)
127 for (
int i = 0;
i <
steps; ++
i)
132void bridgeWithGeometry() {
134 const SphereArray arr = makeArray(
N);
136 s.setAdvection(
false);
140 s.setBodyForce(2e-3, 1e-3, 0.0);
141 s.setSolid(arraySdfInner(arr,
N),
true);
144 CHECK(
s.vofHasGeometry());
149 const long len = (long)
e3.x *
e3.y *
e3.z;
150 CCField sdf3(
"t::sdf3", len), ox3(
"t::ox3", len), oy3(
"t::oy3", len), oz3(
"t::oz3", len),
152 arraySdfBlock(arr, sdf3, e3, g);
153 peclet::flow::buildOpenness(ox3, oy3, oz3,
CCConst(sdf3),
C3{
e3.x,
e3.y,
e3.z}, 1.0, 1.0, 1.0,
156 const std::vector<double> refO[3] = {hostOf(ox3), hostOf(oy3), hostOf(oz3)};
157 const auto refE = hostOf(cs3);
158 const long sd3[3] = {1, (long)
e3.x, (
long)
e3.x *
e3.y};
160 const auto& adv =
s.vofAdvector();
161 double dOpen = 0.0, dEps = 0.0;
162 for (
int d = 0;
d < 3; ++
d) {
163 const auto got = hostOf(adv.faceOpenness(d));
164 for (
int z = g;
z <
g +
N; ++
z)
165 for (
int y = g;
y <
g +
N; ++
y)
166 for (
int x = g;
x <
g +
N; ++
x) {
167 const long i =
L3(x, y, z, e3);
171 dOpen = std::fmax(dOpen, std::fabs(got[i] - refO[d][i + sd3[d]]));
175 const auto got = hostOf(adv.epsFraction());
176 for (
int z = g;
z <
g +
N; ++
z)
177 for (
int y = g;
y <
g +
N; ++
y)
178 for (
int x = g;
x <
g +
N; ++
x) {
179 const long i =
L3(x, y, z, e3);
180 dEps = std::fmax(dEps, std::fabs(got[i] - refE[i]));
184 "G3a geometry embed: max|openness - independent| %.3e max|eps - independent| %.3e\n", dOpen,
191 std::vector<double> c0((std::size_t)
N *
N *
N, 0.0);
192 for (
int z = 0;
z <
N; ++
z)
193 for (
int y = 0;
y <
N; ++
y)
194 for (
int x = 0;
x <
N; ++
x)
195 c0[idx(x, y, z,
N,
N)] = (
z <
N / 2) ? 1.0 : ((
z ==
N / 2) ? 0.37 : 0.0);
199 ref.init(
N,
N,
N, 1.0, g);
203 ref.interfaceLocalCfl =
true;
204 ref.enableGeometry();
207 auto ho = Kokkos::create_mirror_view(
ref.faceOpenness(0));
208 for (
int d = 0;
d < 3; ++
d) {
209 auto hd = Kokkos::create_mirror_view(
ref.faceOpenness(d));
210 for (
long i = 0;
i < len; ++
i)
211 hd(i) = (
i + sd3[
d] < len) ? refO[d][i + sd3[d]] : 0.0;
212 Kokkos::deep_copy(
ref.faceOpenness(d), hd);
214 auto he = Kokkos::create_mirror_view(
ref.epsFraction());
215 for (
long i = 0;
i < len; ++
i)
217 Kokkos::deep_copy(
ref.epsFraction(), he);
222 if (
ref.hasGeometry() &&
f.data() ==
ref.colour().data()) {
231 ref.classifyGeometry();
233 ref.finalizeGeometry();
235 auto hc = Kokkos::create_mirror_view(
ref.colour());
236 auto hk = Kokkos::create_mirror_view(
ref.kindDouble());
237 Kokkos::deep_copy(hk,
ref.kindDouble());
238 for (
long i = 0;
i < len; ++
i)
240 for (
int z = 0;
z <
N; ++
z)
241 for (
int y = 0;
y <
N; ++
y)
242 for (
int x = 0;
x <
N; ++
x) {
243 const long i =
L3(x + g, y + g, z + g, e3);
244 hc(i) = hk(i) > 0.5 ? 0.0 : c0[idx(x, y, z,
N,
N)];
246 Kokkos::deep_copy(
ref.colour(), hc);
250 const auto uu =
s.getVelocity(0), vv =
s.getVelocity(1), ww =
s.getVelocity(2);
252 auto hu = Kokkos::create_mirror_view(
ref.faceU());
253 auto hv = Kokkos::create_mirror_view(
ref.faceV());
254 auto hw = Kokkos::create_mirror_view(
ref.faceW());
255 for (
int z = 0;
z <
e3.z; ++
z)
256 for (
int y = 0;
y <
e3.y; ++
y)
257 for (
int x = 0;
x <
e3.x; ++
x) {
258 const int gx = ((
x -
g) %
N +
N) %
N, gy = ((y - g) %
N +
N) %
N,
259 gz = ((
z -
g) %
N +
N) %
N;
260 const long i =
L3(x, y, z, e3);
261 hu(i) = uu[idx((gx + 1) %
N, gy, gz,
N,
N)];
262 hv(i) = vv[idx(gx, (gy + 1) %
N, gz,
N,
N)];
263 hw(i) = ww[idx(gx, gy, (gz + 1) %
N,
N,
N)];
265 Kokkos::deep_copy(
ref.faceU(), hu);
266 Kokkos::deep_copy(
ref.faceV(), hv);
267 Kokkos::deep_copy(
ref.faceW(), hw);
269 const double dth = 1.0;
270 double cflRef =
ref.maxCourantInterfaceAuto(dth);
271 const double dtA = cflRef > 0 ? 0.2 / cflRef : 1.0;
273 const int steps = 20;
274 for (
int t = 0;
t <
steps; ++
t) {
276 s.advectVofKinematic(dtA);
278 const auto cs =
s.getVof();
279 const auto cr = hostOf(
ref.colour());
280 const auto kr = hostOf(
ref.kindDouble());
283 double dmax = 0.0, fillMax = 0.0;
284 for (
int z = 0;
z <
N; ++
z)
285 for (
int y = 0;
y <
N; ++
y)
286 for (
int x = 0;
x <
N; ++
x) {
287 const long i =
L3(x + g, y + g, z + g, e3);
289 fillMax = std::fmax(fillMax, cr[i]);
292 dmax = std::fmax(dmax, std::fabs(cs[idx(x, y, z,
N,
N)] - cr[i]));
295 "G3b solver vs standalone through the packing (%d steps, cfl 0.2, dt %.4g): max|dC| over "
296 "fluid cells %.3e (standalone band fill reaches %.3f)\n",
297 steps, dtA, dmax, fillMax);
302void conservationThroughPacking(
int N,
int nAdv) {
303 const SphereArray arr = makeArray(
N);
305 s.setAdvection(
false);
309 s.setBodyForce(2e-3, 1e-3, 5e-4);
310 s.setSolid(arraySdfInner(arr,
N),
true);
312 const double div =
s.maxOpenDivergence();
313 const long pit =
s.lastPressureIterations();
315 std::vector<double> c0((std::size_t)
N *
N *
N, 0.0);
316 for (
int z = 0;
z <
N; ++
z)
317 for (
int y = 0;
y <
N; ++
y)
318 for (
int x = 0;
x <
N; ++
x)
319 c0[idx(x, y, z,
N,
N)] = (
z <
N / 2) ? 1.0 : 0.0;
322 const auto d0 =
s.vofDiagnostics();
323 const double cfl =
s.vofMaxCourant();
324 const double dtA = cfl > 0 ? 0.2 / cfl : 1.0;
325 double clip = 0.0, mnF = 1e30, mxF = -1e30, solidSum = 0.0;
326 for (
int t = 0;
t < nAdv; ++
t) {
327 s.advectVofKinematic(dtA);
328 const auto d =
s.vofDiagnostics();
329 clip +=
d.clippedVolume;
330 mnF = std::fmin(mnF,
d.minCFluid);
331 mxF = std::fmax(mxF,
d.maxCFluid);
332 solidSum = std::fmax(solidSum, std::fabs(
d.solidSumC));
334 const auto d1 =
s.vofDiagnostics();
335 const double drift = std::fabs(d1.volume -
d0.volume) /
d0.volume;
336 const double rawDrift = std::fabs(d1.rawVolume -
d0.rawVolume) /
d0.rawVolume;
338 "G2 packing %d^3, %d kinematic steps at cfl 0.2 (dt %.4g):\n"
339 " max|div(open u)| %.3e (pressure iters %ld)\n"
340 " sum eps_eff C: %.15e -> %.15e relative drift %.3e\n"
341 " sum eps C: %.15e -> %.15e relative drift %.3e\n"
342 " solid cells %ld, cut cells %ld, max|sum C over solid| %.3e\n"
343 " min/max C over UNCUT fluid cells %.3e / %.15e\n"
344 " clipped liquid volume, total over the run %.6e (%.3e of the liquid volume)\n",
345 N, nAdv, dtA, div, pit,
d0.volume, d1.volume, drift,
d0.rawVolume, d1.rawVolume, rawDrift,
346 d1.solidCells, d1.cutCells, solidSum, mnF, mxF, clip, clip /
d0.volume);
348 CHECK(drift <= 1e-11);
349 CHECK(solidSum == 0.0);
350 CHECK(mnF >= -1e-12);
351 CHECK(mxF <= 1.0 + 1e-12);
352 CHECK(d1.solidCells > 0);
353 CHECK(d1.cutCells > 0);
361void neutralFillCap(
int steps,
bool zeroSolid =
true) {
362 const int NX = 40,
NY = 40,
NZ = 28;
363 const double zw = 3.5;
364 const double R = 12.0;
365 const double sigma = 1.0;
366 std::vector<double> sd((std::size_t)
NX *
NY *
NZ);
367 for (
int z = 0;
z <
NZ; ++
z)
368 for (
int y = 0;
y <
NY; ++
y)
369 for (
int x = 0;
x <
NX; ++
x)
370 sd[idx(x, y, z,
NX,
NY)] = (
z + 0.5) - zw;
373 const double cx =
NX * 0.5, cy =
NY * 0.5;
374 std::vector<double> c0((std::size_t)
NX *
NY *
NZ, 0.0);
375 for (
int z = 0;
z <
NZ; ++
z)
376 for (
int y = 0;
y <
NY; ++
y)
377 for (
int x = 0;
x <
NX; ++
x) {
379 for (
int a = 0;
a < 4; ++
a)
380 for (
int b = 0;
b < 4; ++
b)
381 for (
int c = 0;
c < 4; ++
c) {
382 const double px =
x + (
a + 0.5) / 4.0, py = y + (b + 0.5) / 4.0,
383 pz =
z + (
c + 0.5) / 4.0;
387 const double dx = px - cx,
dy = py - cy,
dz = pz - zw;
388 if (dx * dx + dy * dy + dz * dz <
R *
R)
391 c0[idx(x, y, z,
NX,
NY)] =
tot ? (double)in / tot : 0.0;
395 s.setAdvection(
false);
398 s.setSolid(sd,
true);
400 s.setVofSolidColourZero(zeroSolid);
402 s.setSurfaceTension(sigma);
403 const double dtSig =
s.capillaryDt();
404 s.setDt(0.5 * dtSig);
405 const double V00 =
s.vofDiagnostics().volume;
407 double uTrace[4] = {0, 0, 0, 0};
408 for (
int i = 0;
i <
steps; ++
i) {
410 maxIt = std::max(maxIt,
s.lastPressureIterations());
411 if ((i + 1) % (steps / 4) == 0) {
412 const int slot = std::min(3, (i + 1) / (steps / 4) - 1);
414 for (
int c = 0;
c < 3; ++
c)
415 for (
double v :
s.getVelocity(c))
416 m = std::fmax(m, std::fabs(v));
422 const auto cens = [&] {
423 s.computeVofCurvature();
424 return s.vofCurvatureStats();
426 const auto kap =
s.getVofCurvature();
427 const auto kbr =
s.getVofCurvatureBranch();
428 double kmaxWall = 0.0;
429 long brWall[7] = {0, 0, 0, 0, 0, 0, 0};
430 for (
int z = (
int)std::ceil(zw);
z < (
int)std::ceil(zw) + 2; ++
z)
431 for (
int y = 0;
y <
NY; ++
y)
432 for (
int x = 0;
x <
NX; ++
x) {
433 const std::size_t
i = idx(x, y, z,
NX,
NY);
434 const int b = (
int)kbr[i];
438 kmaxWall = std::fmax(kmaxWall, std::fabs(kap[i]));
440 const auto d =
s.vofDiagnostics();
441 const auto cc =
s.getVof();
445 const int x0 =
NX / 2, y0 =
NY / 2;
446 for (
int z = 0;
z <
NZ; ++
z)
447 h += cc[idx(x0, y0, z,
NX,
NY)] * ((
z + 1 <= zw) ? 0.0 : std::fmin(1.0, z + 1 - zw));
451 const int z0 = (
int)std::ceil(zw);
453 for (
int y = 0;
y <
NY; ++
y)
454 for (
int x = 0;
x <
NX; ++
x)
455 area += cc[idx(x, y, z0,
NX,
NY)];
456 const double a = std::sqrt(area / M_PI);
457 const double theta = 2.0 * std::atan2(h, a) * 180.0 / M_PI;
458 const double Rc = (
a *
a +
h *
h) / (2.0 * h);
459 const double V =
d.volume;
460 const double V0 = 2.0 * M_PI *
R *
R *
R / 3.0;
462 const auto pf =
s.getField(
"p");
463 double pIn = 0.0, pOut = 0.0;
464 int nIn = 0, nOut = 0;
465 for (
int z = 0;
z <
NZ; ++
z)
466 for (
int y = 0;
y <
NY; ++
y)
467 for (
int x = 0;
x <
NX; ++
x) {
468 const double dx =
x + 0.5 - cx,
dy =
y + 0.5 - cy,
dz =
z + 0.5 - zw;
469 const double r = std::sqrt(dx * dx + dy * dy + dz * dz);
473 pIn +=
pf[idx(x, y, z,
NX,
NY)];
475 }
else if (r > 1.5 *
R && r < 1.8 *
R) {
476 pOut +=
pf[idx(x, y, z,
NX,
NY)];
480 const double dP = (nIn ? pIn / nIn : 0.0) - (nOut ? pOut / nOut : 0.0);
484 double umax = 0.0, umaxAll = 0.0;
485 for (
int c = 0;
c < 3; ++
c) {
486 const auto v =
s.getVelocity(c);
487 for (
int z = 0;
z <
NZ; ++
z)
488 for (
int y = 0;
y <
NY; ++
y)
489 for (
int x = 0;
x <
NX; ++
x) {
490 const double a = std::fabs(v[idx(x, y, z,
NX,
NY)]);
491 umaxAll = std::fmax(umaxAll, a);
492 if (z >= (
int)std::ceil(zw) + 1)
493 umax = std::fmax(umax, a);
496 const double Ca = 0.05 *
umax / sigma;
498 "G5 cap on a cut wall (D/dx %.0f, %d steps at 0.5 dt_sigma = %.4g, solid colour %s), "
499 "pressure iters max %ld:\n"
500 " volume %.6f -> %.6f (drift %.3e); analytic hemisphere %.6f\n"
501 " h %.4f a %.4f -> apparent theta %.3f deg (target 90)\n"
502 " cap sphere radius %.4f (target %.1f); Young-Laplace dP %.6f vs 2 sigma/R %.6f "
504 " max|u| (open fluid) %.3e -> spurious Ca %.3e ; max|u| incl. the wall band %.3e ;\n"
505 " trace of max|u| (all cells) over the run %.2e %.2e %.2e %.2e\n"
506 " wall band: max|kappa| %.4f, branches 0/1/2/3/4/5/6 = %ld/%ld/%ld/%ld/%ld/%ld/%ld "
507 "(global no_estimate %ld)\n"
508 " clipped volume last step %.3e ; clamped faces %ld ; solid sum C %.3e\n",
509 2 *
R, steps, 0.5 * dtSig, zeroSolid ?
"ZERO" :
"band fill", maxIt, V00, V,
510 std::fabs(V - V00) / V00, V0, h, a, theta, Rc,
R, dP, 2.0 * sigma / Rc,
511 std::fabs(dP - 2.0 * sigma / Rc) / (2.0 * sigma / Rc), umax, Ca, umaxAll, uTrace[0],
512 uTrace[1], uTrace[2], uTrace[3], kmaxWall, brWall[0], brWall[1], brWall[2], brWall[3],
513 brWall[4], brWall[5], brWall[6], cens.noEstimate,
d.clippedVolume,
d.clampedFaces,
515 CHECK(std::fabs(theta - 90.0) <= 3.0);
516 CHECK(std::fabs(dP - 2.0 * sigma / Rc) / (2.0 * sigma / Rc) <= 0.01);
518 CHECK(
d.solidSumC == 0.0);
519 CHECK(std::fabs(V - V00) / V00 <= 1e-9);
533void momentumCutCells() {
535 const SphereArray arr = makeArray(
N);
536 const auto sdf = arraySdfInner(arr,
N);
537 const double U[3] = {1.0, 0.6, -0.4};
539 for (
double R : {10.0, 1
e2, 1
e3}) {
547 s.setSolid(sdf,
true);
548 s.setPressureChebyshev(
true, 300, 1e-13);
550 std::vector<double> c0((std::size_t)
N *
N *
N);
551 for (
int z = 0;
z <
N; ++
z)
552 for (
int y = 0;
y <
N; ++
y)
553 for (
int x = 0;
x <
N; ++
x)
554 c0[idx(x, y, z,
N,
N)] = peclet::flow::vof::sphereCellFraction(0.5 *
N, 0.5 *
N, 0.5 *
N,
555 0.28 *
N, x, y, z, 1.0, 4);
558 s.enableVofMomentum(1.0,
R);
559 const std::size_t
nc = (std::size_t)
N *
N *
N;
560 s.uploadVelocity(std::vector<double>(nc,
U[0]), std::vector<double>(nc,
U[1]),
561 std::vector<double>(nc,
U[2]));
562 s.advectVofMomentum();
564 for (
int c = 0;
c < 3; ++
c)
565 for (
double v :
s.getVofAdvectedVelocity(c))
566 dev = std::fmax(dev, std::fabs(v -
U[c]));
567 const auto md =
s.vofMomentumDiagnostics();
569 "G8a packing + uniform U, ratio %-6g: max|u_adv - U| = %.17g%s (rho^e floor hit %ld, "
570 "flux clamps %ld)\n",
571 R, dev, dev == 0.0 ?
" BITWISE" :
"", md.floored, md.clamped);
573 CHECK(md.floored == 0);
576 for (
const char* sch : {
"upwind",
"muscl_mixed",
"muscl_mixed_capped",
"muscl_phase"})
577 for (
double R : {1.0, 1
e2, 1
e3, 1e4}) {
582 s.setSolid(sdf,
true);
583 s.setPressureChebyshev(
true, 300, 1e-13);
585 std::vector<double> c0((std::size_t)
N *
N *
N);
586 for (
int z = 0;
z <
N; ++
z)
587 for (
int y = 0;
y <
N; ++
y)
588 for (
int x = 0;
x <
N; ++
x)
589 c0[idx(x, y, z,
N,
N)] = peclet::flow::vof::sphereCellFraction(
590 0.5 *
N, 0.5 *
N, 0.5 *
N, 0.28 *
N, x, y, z, 1.0, 4);
593 s.enableVofMomentum(1.0,
R);
594 s.setVofMomentumScheme(sch);
595 const std::size_t
nc = (std::size_t)
N *
N *
N;
596 s.uploadVelocity(std::vector<double>(nc,
U[0]), std::vector<double>(nc,
U[1]),
597 std::vector<double>(nc,
U[2]));
599 for (
int k = 0;
k < 3; ++
k) {
600 s.advectVofMomentum();
601 for (
int c = 0;
c < 3; ++
c)
602 for (
double v :
s.getVofAdvectedVelocity(c))
603 dev = std::fmax(dev, std::fabs(v -
U[c]));
605 const auto md =
s.vofMomentumDiagnostics();
607 "G8a %-18s packing + uniform U, ratio %-6g, 3 advections: max|u_adv - U| = "
608 "%.17g%s (floored %ld, clamped %ld, capped %ld)\n",
609 sch,
R, dev, dev == 0.0 ?
" BITWISE" :
"", md.floored, md.clamped, md.capped);
611 CHECK(md.floored == 0);
627 for (
int momentumOn = 1; momentumOn >= 0; --momentumOn) {
628 const double R = 10.0, grav = 2
e-3;
629 const double liq = 0.25, rhoMean = liq *
R + (1.0 - liq);
631 s.setAdvection(
false);
635 s.setSolid(sdf,
true);
637 std::vector<double> c0((std::size_t)
N *
N *
N, 0.0);
638 for (
int z = 0;
z <
N; ++
z)
639 for (
int y = 0;
y <
N; ++
y)
640 for (
int x = 0;
x <
N; ++
x)
641 c0[idx(x, y, z,
N,
N)] = (
z >= 3 *
N / 4) ? 1.0 : 0.0;
645 const bool nonZeroMean = std::getenv(
"PECLET_VOF_CUTCELL_NONZERO_FORCE") !=
nullptr;
647 {nonZeroMean ? 0.0 : grav * rhoMean, -grav});
649 s.enableVofMomentum(1.0,
R);
650 const double v0 =
s.vofDiagnostics().volume;
652 const int steps = 200;
653 double umax = 0.0, clip = 0.0, mn = 1e30,
mx = -1e30;
654 for (
int i = 0;
i <
steps; ++
i) {
656 maxIt = std::max(maxIt,
s.lastPressureIterations());
657 const auto d =
s.vofDiagnostics();
658 clip +=
d.clippedVolume;
659 mn = std::fmin(mn,
d.minCFluid);
660 mx = std::fmax(mx,
d.maxCFluid);
661 if (std::getenv(
"PECLET_VOF_CUTCELL_TRACE") && (i % 5) == 0) {
663 for (
int c = 0;
c < 3; ++
c)
664 for (
double v :
s.getVelocity(c))
665 um =
um > std::fabs(v) ?
um : std::fabs(v);
666 double mnCc = 0, mxCc = 0, mnRho = 0;
669 const auto md =
s.vofMomentumDiagnostics();
670 for (
int c = 0;
c < 3; ++
c) {
671 mnCc = std::fmin(mnCc, md.minCc[c]);
672 mxCc = std::fmax(mxCc, md.maxCc[c]);
675 floored = md.floored;
678 " trace %3d vol %.12e minC %.3e maxC %.6f max|u| %.4e cfl %.4f iters %ld "
679 "C^e [%.3e, %.6f] minRho^e %.4e floored %ld\n",
680 i,
d.volume,
d.minCFluid,
d.maxCFluid, um,
s.vofLastCourant(),
681 s.lastPressureIterations(), mnCc, mxCc, mnRho, floored);
684 for (
int c = 0;
c < 3; ++
c)
685 for (
double v :
s.getVelocity(c))
686 umax = std::fmax(umax, std::fabs(v));
687 const auto d1 =
s.vofDiagnostics();
688 const double drift = (d1.volume -
v0) / v0;
690 "G8b packing draining, ratio %g, %d coupled steps, momentum consistency %s:\n"
691 " colour drift %.3e (%.3e per step), max|div(open u)| %.3e, pressure iters max %ld\n"
692 " min/max C over uncut fluid %.3e / %.15f, clipped volume total %.3e, max|u| %.3e, "
693 "solid sum C %.3e\n",
694 R, steps, momentumOn ?
"ON" :
"off", drift, drift / steps,
s.maxOpenDivergence(), maxIt, mn,
695 mx, clip, umax, d1.solidSumC);
696 CHECK(!std::isnan(umax) && !std::isnan(drift));
697 CHECK(std::fabs(drift) / steps <= 1e-10);
698 CHECK(d1.solidSumC == 0.0);
705int main(
int argc,
char** argv) {
706 std::setvbuf(stdout,
nullptr, _IONBF, 0);
707 Kokkos::initialize(argc, argv);
710 if (
const char* e = std::getenv(
"PECLET_VOF_CUTCELL_LONG"))
711 quick = (e[0] ==
'0');
712 bridgeWithGeometry();
713 conservationThroughPacking(quick ? 24 : 48, quick ? 200 : 500);
714 if (!std::getenv(
"PECLET_VOF_CUTCELL_SKIP_G5")) {
715 neutralFillCap(quick ? 120 : 200);
719 if (std::getenv(
"PECLET_VOF_CUTCELL_FILL_ABLATION"))
720 neutralFillCap(quick ? 120 : 200,
false);
726 std::fprintf(stderr,
"%d check(s) FAILED\n",
failures);
728 std::printf(
"all vof cut-cell checks passed\n");
Weymouth-Yue split advection of a colour field on an extended (inner + ghost) block.
static constexpr int kVofG
static constexpr double defaultVofWispEps()
Weymouth-Yue split advection of a colour field on an extended (inner + ghost) block.
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
Slot slot(const Kokkos::View< double *, CCMem > &ks, int k)
Kokkos::View< double *, SMem > SField
long L3(int x, int y, int z, I3 e)
Kokkos::View< const double *, CCMem > CCConst
void buildCellFraction(CCField cs, CCConst sdf, C3 e, int g)
Kokkos::View< double *, CCMem > CCField
void buildOpenness(CCField ox, CCField oy, CCField oz, CCConst sdf, C3 ext, double dx, double dy, double dz, int order=1)
Solver< Staggered > IbmSolver
void periodicFill(SField f, I3 e, int g, bool px, bool py, bool pz)
Periodic wrap of a single-block extended field (serial reference path; the MPI path uses core's GridH...
flow — thin shim: the container-free VoF PLIC geometric toolbox (rung V0) now live in core.
Kokkos::View< const double *, CCMem > CCConst
Kokkos::View< double *, CCMem > CCField
static double sdfAt(int gx, int gy, int gz, int nx, int ny, int nz, double dref)
static constexpr double U
static constexpr double R
Kokkos::View< double *, SMem > SField
long L3(int x, int y, int z, I3 e)