flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
test_mg_depth_policy.cpp
Go to the documentation of this file.
1// doc/mg_depth_policy.md WO-1: the AUTO pressure-MG depth (CutcellMG::init with nLevels == 0),
2// single rank, hierarchy only (no operator, no solve). Every row of the note's §4.4 table that fits
3// in memory here: the resolved depth D and the bottom's global dims, plus the natural end of a
4// badly factored grid (400^3), the 'smoother'-forced singular operator (only a <= 4-cell bottom is
5// admitted), an anchored (outflow) operator (depth 4 until WO-5), and the explicit depths, which
6// stay exact. The two largest rows of §4.4 (512x512x256, 1024x1024x512) and predict(levels=0) ==
7// the built hierarchy are in tests/kokkos_mpi/test_mg_depth_policy_mpi.cpp: CutcellMG::predict is
8// compiled with PECLET_FLOW_MPI only, and a 1024x1024x512 level 0 does not fit a test.
9#include <cstdio>
10#include <Kokkos_Core.hpp>
11#include <string>
12#include <vector>
13
14#include "mac_cutcell_mg.hpp"
15
16using namespace peclet::flow;
17
18namespace {
19
20int g_fail = 0;
21
22struct Row {
23 C3 grid;
24 int levels; // 0 = AUTO
25 int mode; // setAgglomerationMode: -1 auto (the Solver default), 0 smoother, 1 agglomerated
26 bool outflow;
27 int wantD;
28 C3 wantBottom;
29 const char* what;
30 std::vector<int> wantLine = {}; // Amendment A2.3: the triggered smoothed levels
31};
32
33void check(const Row& r) {
34 CutcellMG mg;
35 if (r.outflow) {
36 const int bc[6] = {2, 3, 1, 1, 1, 1}; // inflow -x, outflow +x, walls: the anchored operator
38 }
39 mg.setAgglomerationMode(r.mode); // before init, as Solver::setSolidInitPressureMg does
40 mg.init(r.grid.x, r.grid.y, r.grid.z, r.levels);
41 const std::vector<C3> ratio = mg.levelRatios();
42 C3 b = r.grid;
43 for (std::size_t L = 0; L + 1 < ratio.size(); ++L)
44 b = C3{b.x / ratio[L].x, b.y / ratio[L].y, b.z / ratio[L].z};
45 const int D = mg.nLevels();
46 // Amendment A2.3: of the §4.4 rows only 16x16x4 has a triggered smoothed level, its smoothed
47 // bottom L3 (2x2x2, z blocked at L1, A' 4 > theta; coordinator ruling 2026-10-26).
48 const std::vector<int> line = mg.lineSmoothedLevels();
49 const bool lineOk = line == r.wantLine;
50 const bool ok = D == r.wantD && b.x == r.wantBottom.x && b.y == r.wantBottom.y &&
51 b.z == r.wantBottom.z && D == (int)ratio.size() && lineOk;
52 if (!ok)
53 ++g_fail;
54 std::printf(
55 "%s %4dx%4dx%4d levels=%d mode=%2d%s: D %d bottom %dx%dx%d (want %d, %dx%dx%d)%s %s\n",
56 ok ? "PASS" : "FAIL", r.grid.x, r.grid.y, r.grid.z, r.levels, r.mode,
57 r.outflow ? " outflow" : "", D, b.x, b.y, b.z, r.wantD, r.wantBottom.x, r.wantBottom.y,
58 r.wantBottom.z, line.empty() ? "" : " LINE-TRIGGERED", r.what);
59 std::fflush(stdout);
60}
61
62// Amendment A2.3 / WO-A2a: the triggered smoothed levels (T holds and the V-cycle smooths the
63// level, a smoothed bottom included) of a hierarchy whose strong axis stops coarsening.
64struct LineRow {
65 C3 grid;
66 int levels; // 0 = AUTO
67 bool outflow;
68 int wantD;
69 std::vector<int> want; // the triggered smoothed levels
70 const char* what;
71};
72
73void checkLine(const LineRow& r) {
74 CutcellMG mg;
75 if (r.outflow) {
76 const int bc[6] = {2, 3, 1, 1, 1, 1};
78 }
79 mg.setAgglomerationMode(-1); // the Solver default
80 mg.init(r.grid.x, r.grid.y, r.grid.z, r.levels);
81 const int D = mg.nLevels();
82 const std::vector<int> got = mg.lineSmoothedLevels();
83 const std::vector<int> ax = mg.lineAxes();
84 bool axisOk = true; // every triggered level's line axis is the blocked one, z, on these grids
85 for (int L : got)
86 axisOk = axisOk && ax[L] == 2;
87 const bool ok = D == r.wantD && got == r.want && axisOk;
88 if (!ok)
89 ++g_fail;
90 std::string gs = "{", ws = "{", as;
91 for (std::size_t i = 0; i < got.size(); ++i)
92 gs += (i ? "," : "") + std::to_string(got[i]);
93 for (std::size_t i = 0; i < r.want.size(); ++i)
94 ws += (i ? "," : "") + std::to_string(r.want[i]);
95 for (std::size_t L = 0; L < ax.size(); ++L)
96 as += (L ? " " : "") + std::to_string(ax[L]);
97 std::printf(
98 "%s line %4dx%4dx%4d levels=%d%s: D %d triggered smoothed %s} (want %d, %s}) "
99 "lineAxis [%s] %s\n",
100 ok ? "PASS" : "FAIL", r.grid.x, r.grid.y, r.grid.z, r.levels, r.outflow ? " outflow" : "", D,
101 gs.c_str(), r.wantD, ws.c_str(), as.c_str(), r.what);
102 std::fflush(stdout);
103}
104
105} // namespace
106
107int main(int argc, char** argv) {
108 Kokkos::initialize(argc, argv);
109 {
110 // Predicate spot checks (§4.1): the engine's own admission, and the small-bottom clause.
111 const int per[6] = {0, 0, 0, 0, 0, 0};
112 struct P {
113 C3 g;
114 bool anchored;
115 int mode;
116 bool want;
117 };
118 const P ps[] = {
119 {{16, 16, 16}, false, -1, false}, // plane 256 > 192
120 {{12, 12, 12}, false, -1, true}, // 1728 cells, plane 144
121 {{24, 24, 24}, false, -1, false}, // 13824 > 8192 cells
122 {{128, 4, 4}, false, -1, true}, // 2048 cells, plane 16
123 {{16, 12, 8}, false, -1, true}, // the bubble column's bottom
124 {{4, 4, 4}, false, 0, true}, // every axis <= 4: a smoothed bottom suffices
125 {{12, 12, 12}, false, 0, false}, // 'smoother' forced: only small bottoms
126 {{16, 4, 4}, true, -1, true}, // anchored: admitted at depth 4 until WO-5
127 };
128 for (const P& p : ps) {
129 const bool got = CutcellMG::bottomAdmissible(p.g, 4, p.anchored, p.mode, per);
130 if (got != p.want)
131 ++g_fail;
132 std::printf("%s admissible(%dx%dx%d, anchored %d, mode %d) = %d\n",
133 got == p.want ? "PASS" : "FAIL", p.g.x, p.g.y, p.g.z, (int)p.anchored, p.mode,
134 (int)got);
135 }
136 // §4.4, single rank, isotropic metric, the Solver's default mode (-1).
137 const Row rows[] = {
138 {{16, 16, 16}, 0, -1, false, 4, {2, 2, 2}, "state_hash N=16"},
139 {{16, 16, 8}, 0, -1, false, 4, {2, 2, 2}, "state_hash"},
140 {{16, 16, 4}, 0, -1, false, 4, {2, 2, 2}, "state_hash", {3}},
141 {{24, 12, 8}, 0, -1, false, 4, {3, 3, 2}, "state_hash channel"},
142 {{48, 48, 48}, 0, -1, false, 4, {6, 6, 6}, "direct at 4"},
143 {{64, 64, 64}, 0, -1, false, 4, {8, 8, 8}, "direct at 4"},
144 {{96, 96, 96}, 0, -1, false, 4, {12, 12, 12}, "direct at 4"},
145 {{128, 96, 64}, 0, -1, false, 4, {16, 12, 8}, "bubble column: unchanged"},
146 {{64, 48, 32}, 0, -1, false, 4, {8, 6, 4}, "bottom_direct_mpi grid"},
147 {{128, 128, 128}, 0, -1, false, 5, {8, 8, 8}, "16^3 plane 256 -> 5"},
148 {{192, 192, 192}, 0, -1, false, 5, {12, 12, 12}, "swarm 192^3"},
149 {{256, 256, 256}, 0, -1, false, 6, {8, 8, 8}, "swarm 256^3"},
150 {{256, 192, 128}, 0, -1, false, 5, {16, 12, 8}, "bubble column x2"},
151 {{2048, 64, 64}, 0, -1, false, 5, {128, 4, 4}, "long channel"},
152 {{400, 400, 400}, 0, -1, false, 5, {25, 25, 25}, "natural end, inadmissible"},
153 {{128, 32, 32}, 0, -1, true, 4, {16, 4, 4}, "anchored: 4 until WO-5"},
154 {{192, 192, 192}, 0, 0, false, 7, {3, 3, 3}, "'smoother' forced: <= 4 per axis"},
155 {{192, 192, 192}, 0, 1, false, 5, {12, 12, 12}, "'agglomerated' forced"},
156 // explicit depths stay exact
157 {{192, 192, 192}, 4, -1, false, 4, {24, 24, 24}, "explicit 4"},
158 {{192, 192, 192}, 7, -1, false, 7, {3, 3, 3}, "explicit 7"},
159 {{16, 16, 16}, 3, -1, false, 3, {4, 4, 4}, "explicit 3"},
160 {{16, 16, 16}, 1, -1, false, 1, {16, 16, 16}, "explicit 1 (pure RB-GS)"},
161 };
162 for (const Row& r : rows)
163 check(r);
164 // Amendment A2.3: triggered smoothed levels (A' = 2^(L - beta) along the blocked z).
165 const LineRow lines[] = {
166 {{128, 128, 25}, 0, false, 5, {2, 3}, "M10: bottom 8x8x25 direct (A' 16, not smoothed)"},
167 {{128, 128, 25}, 4, false, 4, {2}, "M10 explicit 4: bottom 16x16x25 GraphAMG"},
168 {{512, 512, 100}, 0, false, 7, {4, 5}, "M10b: z stops at 25"},
169 {{512, 64, 25}, 0, false, 5, {2, 3}, "M10v grid: bottom 32x4x25"},
170 {{34, 34, 116}, 0, false, 3, {}, "fluidized bed: no unique strong axis"},
171 {{34, 34, 116}, 0, true, 3, {}, "fluidized bed, anchored"},
172 {{8, 8, 18}, 0, false, 3, {}, "small bed: A' 2 = theta"},
173 {{8, 8, 18}, 0, true, 3, {}, "small bed, anchored"},
174 };
175 for (const LineRow& r : lines)
176 checkLine(r);
177 }
178 Kokkos::finalize();
179 std::printf("mg_depth_policy: %s (%d failures)\n", g_fail ? "FAIL" : "PASS", g_fail);
180 return g_fail ? 1 : 0;
181}
static bool bottomAdmissible(C3 g, int extent, bool anchored, int agglomMode, const int bc[6])
std::vector< C3 > levelRatios() const
The per-level coarsening ratio actually chosen (the level table of §5, gate §8.5).
void setBoundaryConditions(const int bc[6])
std::vector< int > lineAxes() const
std::vector< int > lineSmoothedLevels() const
void setAgglomerationMode(int mode)
void init(int nx, int ny, int nz, int nLevels)
flow — portable (Kokkos) geometric multigrid for the cut-cell (variable-openness) pressure Poisson.
tuple line
Definition summarize.py:78
static void check(bool ok, const std::string &what)