88 s.setAdvection(
false);
93 s.setDomainBc(4, 1, 0, 0, 0);
94 s.setDomainBc(5, 1, 0, 0, 0);
96 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
97 s.setVof(
blockOf([&](
int x,
int y,
int z) {
return colourAt(c, x, y, z); }, ox, oy, oz, lnx, lny,
102static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
103 int lnx,
int lny,
int lnz,
int rank,
int size) {
104 std::vector<double> global;
106 global.assign(
GCELLS, 0.0);
107 for (
int r = 0; r < size; ++r) {
108 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
111 for (
int z = 0; z < lnz; ++z)
112 for (
int y = 0; y < lny; ++y)
113 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
114 (std::size_t)(z + oz) *
NX *
NY],
115 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
116 (std::size_t)lnx *
sizeof(
double));
120 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
121 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
122 }
else if (rank == 0) {
123 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
124 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
125 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
127 for (
int z = 0; z < meta[5]; ++z)
128 for (
int y = 0; y < meta[4]; ++y)
129 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
130 (std::size_t)(z + meta[2]) *
NX *
NY],
131 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
132 (std::size_t)meta[3] *
sizeof(
double));
149int main(
int argc,
char** argv) {
150 MPI_Init(&argc, &argv);
151 Kokkos::initialize(argc, argv);
154 int rank = 0, size = 1;
155 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
156 MPI_Comm_size(MPI_COMM_WORLD, &size);
158 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
159 auto blk = dec.block(rank);
160 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
161 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
162 const int gn[3] = {
NX,
NY,
NZ};
163 bool cut[3] = {
false,
false,
false};
164 for (
const auto& sz : dec.sizes())
165 for (
int a = 0; a < 3; ++a)
166 if ((
int)sz[a] != gn[a])
169 std::printf(
"VOF CURVATURE MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n",
170 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
173 const Config configs[] = {{
"sphere-per",
false}, {
"sphere-walls-z",
true}};
175 for (
const Config& c : configs) {
177 if (size > 1 && !cut[2]) {
179 std::printf(
" [%-14s np=%d] FAIL — the decomposition does NOT cut z\n", c.name, size);
186 sd.initMpi(dec, MPI_COMM_WORLD);
187 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
190 long locCounts[7] = {stLoc.interfacial, stLoc.hf, stLoc.hfMixed, stLoc.hfFit,
191 stLoc.pv, stLoc.pvReduced, stLoc.noEstimate};
192 long sumCounts[7] = {0, 0, 0, 0, 0, 0, 0};
193 MPI_Allreduce(locCounts, sumCounts, 7, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
195 const std::vector<double> gk =
197 const std::vector<double> gb =
204 ref.computeVofCurvature();
205 const auto st = ref.vofCurvatureStats();
206 const long refCounts[7] = {st.interfacial, st.hf, st.hfMixed, st.hfFit,
207 st.pv, st.pvReduced, st.noEstimate};
208 double dk = 0.0, db = 0.0;
209 const long nk =
countBitDiff(gk, ref.getVofCurvature(), dk);
210 const long nb =
countBitDiff(gb, ref.getVofCurvatureBranch(), db);
212 bool countsOk =
true;
213 for (
int i = 0; i < 7; ++i)
214 countsOk = countsOk && (sumCounts[i] == refCounts[i]);
217 " [%-14s np=%d] interfacial %ld | HF %ld HFdir %ld HFfit %ld PV %ld PVred %ld"
219 c.name, size, refCounts[0], refCounts[1], refCounts[2], refCounts[3], refCounts[4],
220 refCounts[5], refCounts[6]);
222 " kappa: %ld/%ld cells differ (max |d| %.3e) branch: %ld differ"
224 nk, (
long)
GCELLS, dk, nb, countsOk ?
"MATCHES" :
"DIFFERS");
227 if (nk != 0 || nb != 0 || !countsOk) {
228 std::printf(
" FAIL — the curvature cascade is decomposition-DEPENDENT\n");
232 if (refCounts[4] + refCounts[5] == 0) {
234 " FAIL — the PLIC-volumetric fallback never fired; this configuration "
235 "no longer gates its stencil reach\n");
238 if (refCounts[6] != 0) {
239 std::printf(
" FAIL — %ld interfacial cells got NO curvature estimate\n",
244 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
247 std::printf(
"%s\n", fail ?
"FAILED" :
"PASSED");