287int main(
int argc,
char** argv) {
288 MPI_Init(&argc, &argv);
289 Kokkos::initialize(argc, argv);
292 int rank = 0, size = 1;
293 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
294 MPI_Comm_size(MPI_COMM_WORLD, &size);
295 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
296 auto blk = dec.block(rank);
297 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
298 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
299 const int gn[3] = {
NX,
NY,
NZ};
300 bool cut[3] = {
false,
false,
false};
301 for (
const auto& sz : dec.sizes())
302 for (
int a = 0; a < 3; ++a)
303 if ((
int)sz[a] != gn[a])
306 std::printf(
"VOF BC MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
NX,
307 NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"");
308 if (size > 1 && !cut[2]) {
310 std::printf(
" FAIL — the decomposition does NOT cut z (the inflow/outflow axis)\n");
325 const int nSlug = 20, nAfter = 480;
327 sd.initMpi(dec, MPI_COMM_WORLD);
330 for (
int i = 0; i < nSlug + nAfter; ++i) {
335 if (std::getenv(
"PECLET_VOF_BC_TRACE") && rank == 0) {
336 const auto cc = sd.
getVof();
340 std::printf(
" trace step %3d: face %.6g %.6g | C sum %.6g nonfinite %ld\n", i, v[4],
343 for (
int f = 0; f < 6; ++f)
347 double gSum = 0.0, gLedger = 0.0;
348 MPI_Allreduce(&locSum, &gSum, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
349 MPI_Allreduce(&
ledger, &gLedger, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
351 double gIn = 0.0, gOut = 0.0;
352 double lIn = tot[4], lOut = -tot[5];
353 MPI_Allreduce(&lIn, &gIn, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
354 MPI_Allreduce(&lOut, &gOut, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
355 const std::vector<double> gc =
360 double rLedger = 0.0;
361 for (
int i = 0; i < nSlug + nAfter; ++i) {
363 ref.setVofInflow(4, 0.0);
365 const auto v = ref.vofBcVolumes();
366 for (
int f = 0; f < 6; ++f)
369 const double dc =
maxAbsDiff(gc, ref.getVof());
371 const double dl = std::fabs(gLedger - rLedger);
373 std::printf(
" [slug-kin np=%d] FAIL — %ld non-finite colour cells\n", size, nbad);
376 if (!(gLedger == gLedger) || !(gIn == gIn) || !(gOut == gOut)) {
377 std::printf(
" [slug-kin np=%d] FAIL — the boundary ledger is not finite\n", size);
380 const double budget = std::fabs(gSum - gLedger);
381 std::printf(
" [slug-kin np=%d] colour vs single-rank %.3e (BITWISE required)\n", size,
384 " [slug-kin np=%d] ledger vs single-rank %.3e; global budget "
385 "|sum(C) - ledger| %.3e; in %.10g out %.10g\n",
386 size, dl, budget, gIn, gOut);
388 std::printf(
" [slug-kin np=%d] FAIL — colour is not bitwise\n", size);
391 if (!(budget < 1e-8)) {
392 std::printf(
" [slug-kin np=%d] FAIL — the global budget does not close\n", size);
395 if (!(std::fabs(gIn - gOut) < 1e-9 * gIn) || !(gIn > 0.0)) {
396 std::printf(
" [slug-kin np=%d] FAIL — in/out do not balance\n", size);
404 const int steps = 30;
406 sd.initMpi(dec, MPI_COMM_WORLD);
410 for (
int i = 0; i < steps; ++i) {
417 auto hr = Kokkos::create_mirror_view(rv);
418 Kokkos::deep_copy(hr, rv);
419 const int G = 2, ex = lnx + 2 *
G, ey = lny + 2 *
G;
420 const double ghost = hr((std::size_t)(
G + lnx / 2) + (std::size_t)(
G + lny / 2) * ex +
421 (std::size_t)(
G - 1) * ex * ey);
422 const bool owns = (oz == 0);
423 int bad = (owns && std::fabs(ghost - 100.0) > 1e-9) ? 1 : 0;
425 MPI_Allreduce(&bad, &badAll, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
426 const std::vector<double> gc =
429 MPI_Allreduce(&itmax, &gItmax, 1, MPI_LONG, MPI_MAX, MPI_COMM_WORLD);
433 for (
int i = 0; i < steps; ++i)
435 const double dc =
maxAbsDiff(gc, ref.getVof());
437 const double csum =
sumOf(ref.getVof());
439 " [jet-coupl np=%d] colour vs single-rank %.3e (signed sum %.3e); inflow rho ghost "
440 "owners wrong on %d rank(s); pressure %ld/400, max|div| %.3e\n",
441 size, dc, dsum, badAll, gItmax, divmax);
448 const double tol = (size == 1) ? 0.0 : 1e-6;
450 std::printf(
" [jet-coupl np=%d] FAIL — the colour field is wrong (tol %.1e)\n", size,
454 const double tolSum = (size == 1) ? 0.0 : 1e-11 * std::fabs(csum);
455 if (!(std::fabs(dsum) <= tolSum)) {
457 " [jet-coupl np=%d] FAIL — the colour difference does not CANCEL: signed sum %.3e "
463 std::printf(
" [jet-coupl np=%d] FAIL — the inflow rho ghost is not the inlet fluid's\n",
468 std::printf(
" [jet-coupl np=%d] FAIL — the pressure solve CAPPED (run invalid)\n", size);
492 const int steps = 20;
494 sd.initMpi(dec, MPI_COMM_WORLD);
497 double ledger = 0.0, solidSum = 0.0;
499 for (
int i = 0; i < steps; ++i) {
502 for (
int f = 0; f < 6; ++f)
507 double g0 = 0, g1 = 0, gLed = 0, gSolid = 0;
508 MPI_Allreduce(&vol0loc, &g0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
509 MPI_Allreduce(&vol1loc, &g1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
510 MPI_Allreduce(&
ledger, &gLed, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
511 MPI_Allreduce(&solidSum, &gSolid, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
512 const std::vector<double> gc =
518 for (
int i = 0; i < steps; ++i)
520 const double dc =
maxAbsDiff(gc, ref.getVof());
521 const double budget = std::fabs((g1 - g0) - gLed);
531 " [packing-kin np=%d] colour vs single-rank %.3e (BITWISE required); budget "
532 "|d sum(eps_eff C) - ledger| %.3e (rel %.3e, NOT gated — the prescribed field is not "
533 "discretely solenoidal); solid colour %.3e\n",
534 size, dc, budget, budget / g0, gSolid);
536 std::printf(
" [packing-kin np=%d] FAIL — the composed colour is not bitwise\n", size);
540 std::printf(
" [packing-kin np=%d] FAIL — %ld non-finite colour cells\n", size, nbad);
543 if (!(gSolid == 0.0)) {
544 std::printf(
" [packing-kin np=%d] FAIL — colour leaked into solid cells\n", size);
560 const int steps = 40;
562 sd.initMpi(dec, MPI_COMM_WORLD);
565 double ledger = 0.0, solidSum = 0.0;
567 for (
int i = 0; i < steps; ++i) {
571 for (
int f = 0; f < 6; ++f)
576 double g0 = 0, g1 = 0, gLed = 0, gSolid = 0;
578 MPI_Allreduce(&vol0loc, &g0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
579 MPI_Allreduce(&vol1loc, &g1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
580 MPI_Allreduce(&
ledger, &gLed, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
581 MPI_Allreduce(&solidSum, &gSolid, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
582 MPI_Allreduce(&itmax, &gIt, 1, MPI_LONG, MPI_MAX, MPI_COMM_WORLD);
583 const std::vector<double> gc =
588 for (
int i = 0; i < steps; ++i)
590 const double dc =
maxAbsDiff(gc, ref.getVof());
591 const double budget = std::fabs((g1 - g0) - gLed);
593 const double csum =
sumOf(ref.getVof());
595 " [packing np=%d] colour vs single-rank %.3e (signed sum %.3e, rel %.3e); budget "
596 "|d sum(eps_eff C) - ledger| %.3e (rel %.3e); solid colour %.3e; "
597 "pressure %ld/400\n",
598 size, dc, dsum, dsum / csum, budget, budget / g0, gSolid, gIt);
647 const double tol = (size == 1) ? 0.0 : 1e-6;
649 std::printf(
" [packing np=%d] FAIL — the colour field is wrong (tol %.1e)\n", size,
656 const double tolSum = (size == 1) ? 0.0 : 1e-11 * std::fabs(csum);
657 if (!(std::fabs(dsum) <= tolSum)) {
659 " [packing np=%d] FAIL — the colour difference does not CANCEL: signed sum %.3e "
660 "> %.3e (colour created or destroyed, not moved)\n",
664 if (!(budget / g0 < 1e-10)) {
665 std::printf(
" [packing np=%d] FAIL — the composed budget does not close\n", size);
668 if (!(gSolid == 0.0)) {
669 std::printf(
" [packing np=%d] FAIL — colour leaked into solid cells\n", size);
673 std::printf(
" [packing np=%d] FAIL — the pressure solve CAPPED (run invalid)\n", size);
693 const int steps = 30;
694 Colo sd(lnx, lny, lnz);
695 sd.initMpi(dec, MPI_COMM_WORLD);
697 double colLedger = 0.0;
700 for (
int i = 0; i < steps; ++i) {
704 for (
int f = 0; f < 6; ++f)
708 double gC0 = 0, gC1 = 0, gColLed = 0;
710 MPI_Allreduce(&colC0, &gC0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
711 MPI_Allreduce(&colC1, &gC1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
712 MPI_Allreduce(&colLedger, &gColLed, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
713 MPI_Allreduce(&colIt, &gColIt, 1, MPI_LONG, MPI_MAX, MPI_COMM_WORLD);
714 const std::vector<double> gcol =
719 for (
int i = 0; i < steps; ++i)
721 const double dcol =
maxAbsDiff(gcol, ref.getVof());
722 const double budget = std::fabs((gC1 - gC0) - gColLed);
723 const double csum =
sumOf(ref.getVof());
725 " [colo-jet np=%d] colour vs single-rank %.3e; budget |d sum(C) - ledger| %.3e "
726 "(rel %.3e); pressure %ld/400\n",
727 size, dcol, budget, budget / gC0, gColIt);
728 const double tolCol = (size == 1) ? 0.0 : 1e-9 * std::fabs(csum);
729 if (!(dcol <= tolCol)) {
730 std::printf(
" [colo-jet np=%d] FAIL — the colour field is wrong (tol %.1e)\n", size,
734 if (!(budget / gC0 < 1e-10)) {
735 std::printf(
" [colo-jet np=%d] FAIL — the boundary budget does not close\n", size);
739 std::printf(
" [colo-jet np=%d] FAIL — the pressure solve CAPPED (run invalid)\n", size);
745 MPI_Allreduce(&fail, &gfail, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
748 std::printf(fail ?
"FAILED\n" :
"OK\n");