103static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
104 int lnx,
int lny,
int lnz,
int rank,
int size) {
105 std::vector<double> global;
107 global.assign(
GCELLS, 0.0);
108 for (
int r = 0; r < size; ++r) {
109 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
112 for (
int z = 0; z < lnz; ++z)
113 for (
int y = 0; y < lny; ++y)
114 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
115 (std::size_t)(z + oz) *
NX *
NY],
116 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
117 (std::size_t)lnx *
sizeof(
double));
121 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
122 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
123 }
else if (rank == 0) {
124 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
125 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
126 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
128 for (
int z = 0; z < meta[5]; ++z)
129 for (
int y = 0; y < meta[4]; ++y)
130 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
131 (std::size_t)(z + meta[2]) *
NX *
NY],
132 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
133 (std::size_t)meta[3] *
sizeof(
double));
216int main(
int argc,
char** argv) {
217 MPI_Init(&argc, &argv);
218 Kokkos::initialize(argc, argv);
221 int rank = 0, size = 1;
222 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
223 MPI_Comm_size(MPI_COMM_WORLD, &size);
225 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
226 auto blk = dec.block(rank);
227 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
228 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
229 const int gn[3] = {
NX,
NY,
NZ};
230 bool cut[3] = {
false,
false,
false};
231 for (
const auto& sz : dec.sizes())
232 for (
int a = 0; a < 3; ++a)
233 if ((
int)sz[a] != gn[a])
236 std::printf(
"VOF MOMENTUM MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
237 NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
240 const Config configs[] = {{
"walls-z",
true, 1000.0, 0.2, 10},
241 {
"shear-per",
false, 10.0, 0.2, 40}};
243 for (
const Config& c : configs) {
244 if (size > 1 && !cut[2]) {
246 std::printf(
" [%-9s np=%d] FAIL — the decomposition does NOT cut z\n", c.name, size);
251 sd.initMpi(dec, MPI_COMM_WORLD);
252 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
259 double identLoc = 0.0;
261 for (
int comp = 0; comp < 3; ++comp)
264 MPI_Allreduce(&identLoc, &ident, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
268 MPI_Allreduce(&v0Loc, &v0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
269 for (
int it = 1; it < c.steps; ++it)
273 MPI_Allreduce(&v1Loc, &v1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
275 std::vector<double> gu[3], gua[3];
276 for (
int comp = 0; comp < 3; ++comp) {
281 const std::vector<double> gp =
283 const std::vector<double> gc =
288 std::printf(
" [%-9s np=%d] uniform-velocity identity on the advection: %.17g%s\n",
289 c.name, size, ident, ident == 0.0 ?
" (BITWISE, all ranks)" :
"");
290 if (!(ident == 0.0)) {
291 std::printf(
" [%-9s np=%d] FAIL — the identity is not exact under decomposition\n",
297 for (
int it = 0; it < c.steps; ++it)
299 double du = 0, umag = 0, dua = 0;
300 for (
int comp = 0; comp < 3; ++comp) {
301 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
302 dua = std::fmax(dua,
maxAbsDiff(gua[comp], ref.getVofAdvectedVelocity(comp)));
303 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
305 const double dp = c.walls ?
maxAbsDiff(gp, ref.getPressure())
307 const double dc =
maxAbsDiff(gc, ref.getVof());
308 const double pmag =
maxAbs(ref.getPressure());
309 const double drift = (v1 - v0) / v0;
310 const double utol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * umag);
311 const double ptol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * pmag);
312 const double ctol = (size == 1) ? 0.0 : 1e-11;
314 " [%-9s np=%d] du %.3e du_adv %.3e (tol %.1e, |u| %.2e) dp %.3e (tol %.1e, "
315 "|P| %.2e) dC %.3e (tol %.1e) dV/V %+.3e\n",
316 c.name, size, du, dua, utol, umag, dp, ptol, pmag, dc, ctol, drift);
317 if (!(du <= utol) || !(dua <= utol) || !(dp <= ptol) || !(dc <= ctol)) {
318 std::printf(
" [%-9s np=%d] FAIL — distributed vs single-rank\n", c.name, size);
321 if (!c.walls && !(std::fabs(drift) < 1e-11)) {
322 std::printf(
" [%-9s np=%d] FAIL — colour volume drift %.3e\n", c.name, size, drift);
326 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
328 for (
const char* scheme : {
"muscl_phase",
"muscl_mixed_capped"}) {
331 sd.initMpi(dec, MPI_COMM_WORLD);
334 for (
int k = 0; k < nAdv; ++k) {
339 MPI_Allreduce(&capLoc, &cap, 1, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
340 std::vector<double> gua[3];
341 for (
int comp = 0; comp < 3; ++comp)
344 const std::vector<double> gc =
349 for (
int k = 0; k < nAdv; ++k)
350 ref.advectVofMomentum();
351 double dua = 0.0, umag = 0.0;
352 for (
int comp = 0; comp < 3; ++comp) {
353 dua = std::fmax(dua,
maxAbsDiff(gua[comp], ref.getVofAdvectedVelocity(comp)));
354 umag = std::fmax(umag,
maxAbs(ref.getVofAdvectedVelocity(comp)));
356 const double dc =
maxAbsDiff(gc, ref.getVof());
358 " [phase-adv np=%d] G-M2-8 %s, %d advections, ratio 1e3: du_adv %.3e "
359 "(|u| %.2e) dC %.3e (== 0 required; capped faces, all ranks %ld)\n",
360 size, scheme, nAdv, dua, umag, dc, cap);
361 if (!(dua == 0.0) || !(dc == 0.0)) {
363 " [phase-adv np=%d] FAIL — the %s advection is not bitwise "
369 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
372 std::printf(fail ?
"FAILED\n" :
"OK\n");