205static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
206 int lnx,
int lny,
int lnz,
int rank,
int size) {
207 std::vector<double> global;
209 global.assign(
GCELLS, 0.0);
210 for (
int r = 0; r < size; ++r) {
211 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
214 for (
int z = 0; z < lnz; ++z)
215 for (
int y = 0; y < lny; ++y)
216 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
217 (std::size_t)(z + oz) *
NX *
NY],
218 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
219 (std::size_t)lnx *
sizeof(
double));
223 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
224 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
225 }
else if (rank == 0) {
226 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
227 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
228 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
230 for (
int z = 0; z < meta[5]; ++z)
231 for (
int y = 0; y < meta[4]; ++y)
232 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
233 (std::size_t)(z + meta[2]) *
NX *
NY],
234 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
235 (std::size_t)meta[3] *
sizeof(
double));
258int main(
int argc,
char** argv) {
259 MPI_Init(&argc, &argv);
260 Kokkos::initialize(argc, argv);
263 int rank = 0, size = 1;
264 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
265 MPI_Comm_size(MPI_COMM_WORLD, &size);
266 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
267 auto blk = dec.block(rank);
268 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
269 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
271 for (
const auto& sz : dec.sizes())
272 if ((
int)sz[0] !=
NX)
276 "VOF BLOCK DEBRIS MPI (vof_overlap_design G5) np=%d grid %dx%dx%d block "
277 "%dx%dx%d x cut: %s\n",
278 size,
NX,
NY,
NZ, lnx, lny, lnz, cutX ?
"yes" :
"no");
279 if (size > 1 && !cutX) {
281 std::printf(
" FAIL - the decomposition does not cut x, so the markers share a rank\n");
284 const int STEPS = (argc > 1) ? std::atoi(argv[1]) : 20;
286 sd.initMpi(dec, MPI_COMM_WORLD);
287 configure(sd, ox, oy, oz, lnx, lny, lnz);
288 for (
int k = 0; k <
STEPS; ++k)
292 std::vector<double> lLoc =
ledger(sd), lAll(lLoc.size(), 0.0);
293 MPI_Allreduce(lLoc.data(), lAll.data(), (
int)lLoc.size(), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
294 const std::vector<double> gC =
gatherGlobal(sd.
getVof(), ox, oy, oz, lnx, lny, lnz, rank, size);
298 const std::vector<double> r0 =
ledger(ref);
299 for (
int k = 0; k <
STEPS; ++k)
300 ref.advectVofBlocks(
DT,
false);
301 const std::vector<double> rl =
ledger(ref), rC = ref.getVof();
303 for (std::size_t i = 0; i <
GCELLS; ++i)
304 nC += (gC[i] == rC[i]) ? 0 : 1;
306 for (std::size_t i = 0; i < rl.size(); ++i)
307 nL += (lAll[i] == rl[i]) ? 0 : 1;
308 const char* fn[
NF] = {
"volume",
"cells",
"vol",
"returned",
"lost",
"unresolved",
"residue"};
309 for (std::size_t m = 0; m < rl.size() /
NF; ++m) {
310 std::printf(
" marker %zu:", m);
311 for (
int f = 0; f <
NF; ++f)
312 std::printf(
" %s %.17g%s", fn[f], lAll[m *
NF + f],
313 lAll[m *
NF + f] == rl[m *
NF + f] ?
"" :
" (!= np1)");
318 " after %d steps: union colour cells differing from np=1: %ld; ledger fields "
319 "differing: %ld; B returned %.17g (painted %.17g)\n",
320 STEPS, nC, nL, rl[
NF + 3], painted);
322 for (std::size_t m = 0; m < rl.size() /
NF; ++m)
323 dv = std::fmax(dv, std::fabs(rl[m *
NF] - r0[m *
NF]) / r0[m *
NF]);
324 std::printf(
" max marker volume rel change over the run (np=1): %.3e\n", dv);
325 if (!(dv <= 1e-12)) {
326 std::printf(
" FAIL: marker volume not conserved\n");
329 if (nC != 0 || nL != 0) {
330 std::printf(
" FAIL: not bitwise decomposition-independent\n");
333 if (!(rl[
NF + 3] > 0.9 * painted)) {
334 std::printf(
" FAIL: the debris removal did not fire (returned %.3e)\n", rl[
NF + 3]);
337 if (!(rl[3] == 0.0 && rl[
NF + 4] == 0.0)) {
338 std::printf(
" FAIL: marker A removed debris, or the return lost volume\n");
342 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
346 IbmSolver pb(lnx, lny, lnz), pn(lnx, lny, lnz);
347 pb.initMpi(dec, MPI_COMM_WORLD);
348 pn.initMpi(dec, MPI_COMM_WORLD);
352 const double dtB = pb.capillaryDt(), dtN = pn.
capillaryDt();
357 const auto cr = ref.vofBlockOverlapCensus();
358 const double dtR = ref.capillaryDt();
360 " phantom bound, overlapping pair: max S %.17g, excess %.17g, cells %ld, "
361 "active %d (off-switch run: active %d); capillary dt ratio %.17g (want "
362 "%.17g); np=1: max S %.17g cells %ld active %d dt %.17g\n",
363 cb.maxSum, cb.excess, cb.cells, (
int)cb.active, (
int)cn.active, dtB / dtN, want,
364 cr.maxSum, cr.cells, (
int)cr.active, dtR);
365 if (!(cb.active && !cn.active)) {
366 std::printf(
" FAIL: the phantom bound did not activate (or the off switch failed)\n");
369 if (!(std::fabs(dtB / dtN / want - 1.0) <= 1e-14)) {
370 std::printf(
" FAIL: capillary dt ratio is not sqrt(2 rho_min / (rho_min + rho_max))\n");
375 if (!(cb.maxSum == cr.maxSum && cb.cells == cr.cells && cb.active == cr.active &&
376 dtB == dtR && std::fabs(cb.excess - cr.excess) <= 1e-12 * cr.excess)) {
377 std::printf(
" FAIL: the overlap census / bound differs from np = 1\n");
381 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
386 for (
const auto& sz : dec.sizes())
387 if ((
int)sz[1] !=
NY)
390 sw.initMpi(dec, MPI_COMM_WORLD);
392 std::vector<double> v0Loc, v0All;
394 v0Loc.push_back(q.volume);
395 v0All.assign(v0Loc.size(), 0.0);
396 MPI_Allreduce(v0Loc.data(), v0All.data(), (
int)v0Loc.size(), MPI_DOUBLE, MPI_SUM,
400 std::vector<double> vLoc(v0Loc.size()), vAll(v0Loc.size());
401 for (
int k = 0; k <
WSTEPS; ++k) {
404 for (std::size_t m = 0; m < st.size(); ++m)
405 vLoc[m] = st[m].volume;
406 MPI_Allreduce(vLoc.data(), vAll.data(), (
int)vLoc.size(), MPI_DOUBLE, MPI_SUM,
408 for (std::size_t m = 0; m < vAll.size(); ++m)
409 worst = std::fmax(worst, std::fabs(vAll[m] / v0All[m] - 1.0));
411 const std::vector<double> gC =
416 for (
int k = 0; k <
WSTEPS; ++k)
417 ref.advectVofBlocks(
WDT,
false);
418 const std::vector<double> rC = ref.getVof();
419 const auto rs = ref.vofBlockStats();
421 for (std::size_t i = 0; i <
GCELLS; ++i)
422 nC += (gC[i] == rC[i]) ? 0 : 1;
423 for (std::size_t m = 0; m < rs.size(); ++m)
424 nV += (vAll[m] == rs[m].volume) ? 0 : 1;
429 for (
int z = 0; z < wb[5] - wb[2]; ++z)
430 for (
int x = 0; x < wb[3] - wb[0]; ++x)
431 layer += wc[(std::size_t)x + (std::size_t)z * (wb[3] - wb[0]) * (wb[4] - wb[1])];
434 " low-wall marker: box y [%d, %d), wall-layer colour %.3f cells, |v| one face in "
435 "%.3e; master rank %d; y cut %s\n",
436 wb[1], wb[4], layer, vIn, wMaster, cutY ?
"yes" :
"no");
438 " after %d steps: max marker |V/V0-1| %.3e (volumes %.17g, %.17g); union cells "
439 "differing from np=1: %ld; volumes differing: %ld\n",
440 WSTEPS, worst, vAll[0], vAll[1], nC, nV);
441 if (!(layer > 1.0 && wb[1] == 0 && vIn > 1e-3)) {
442 std::printf(
" FAIL: the low-wall scene does not put colour on the wall layer\n");
445 if (size > 1 && wMaster == 0) {
446 std::printf(
" FAIL: the wall marker's master is rank 0 (no MPI gather exercised)\n");
449 if (!(worst <= 1e-12)) {
450 std::printf(
" FAIL: a marker at the low wall does not conserve its volume\n");
453 if (nC != 0 || nV != 0) {
454 std::printf(
" FAIL: the low-wall scene is not bitwise decomposition-independent\n");
458 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
461 std::printf(
"%s\n", fail ?
"FAILED" :
"PASSED");