88 s.setAdvection(
false);
89 const bool blocks = (cfg == 1), pc = (cfg == 2);
92 s.setDomainBc(4, 1, 0, 0, 0);
93 s.setDomainBc(5, 1, 0, 0, 0);
94 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
97 s.setPressureLevels(1);
98 s.setPressureChebyshev(
true, 400, 1e-14);
100 std::vector<double> c((std::size_t)lnx * lny * lnz, 0.0), t(c.size(), 0.0);
101 for (
int z = 0; z < lnz; ++z)
102 for (
int y = 0; y < lny; ++y)
103 for (
int x = 0; x < lnx; ++x) {
105 std::fmax(
bubbleAt(0, x + ox, y + oy, z + oz),
bubbleAt(1, x + ox, y + oy, z + oz));
106 const std::size_t i = (std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny;
108 t[i] = 0.5 + 0.25 * std::sin(0.3 * (x + ox)) * std::cos(0.2 * (z + oz));
111 s.setPropertyModel(
"rho", ClosureKind::LinearMix,
"C",
"", {
RHO_L,
RHO_G -
RHO_L});
112 s.setPropertyModel(
"mu", ClosureKind::LinearMix,
"C",
"", {
MU_L,
MU_G -
MU_L});
113 s.setPropertyModel(
"force_z", ClosureKind::LinearMix,
"C",
"",
116 s.setSurfaceTension(
SIGMA);
117 s.addScalar(
"T", 0.02, 1, 30);
121 s.setPhaseChangeThermal(
"T", 0.5, 0.02, 0.02, 0.0);
122 s.setPhaseChangeEnergy(1.0, 2.0);
125 std::vector<std::array<int, 6>> boxes;
126 for (
int b = 0; b < 2; ++b) {
127 std::array<int, 6> q;
128 const double c3[3] = {
CX[b],
CY[b],
CZ[b]};
129 for (
int d = 0; d < 3; ++d) {
130 q[d] = (int)std::floor(c3[d] -
RB) - 1;
131 q[3 + d] = (int)std::ceil(c3[d] +
RB) + 1;
139 s.enableVofBlocksFromField(boxes);
143 s.setDt(pc ? 0.02 : 0.25 * s.capillaryDt());
146static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
147 int lnx,
int lny,
int lnz,
int rank,
int size) {
148 std::vector<double> global;
150 global.assign(
GCELLS, 0.0);
151 for (
int r = 0; r < size; ++r) {
152 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
155 for (
int z = 0; z < lnz; ++z)
156 for (
int y = 0; y < lny; ++y)
157 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
158 (std::size_t)(z + oz) *
NX *
NY],
159 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
160 (std::size_t)lnx *
sizeof(
double));
164 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
165 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
166 }
else if (rank == 0) {
167 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
168 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
169 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
171 for (
int z = 0; z < meta[5]; ++z)
172 for (
int y = 0; y < meta[4]; ++y)
173 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
174 (std::size_t)(z + meta[2]) *
NX *
NY],
175 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
176 (std::size_t)meta[3] *
sizeof(
double));
201int main(
int argc,
char** argv) {
202 MPI_Init(&argc, &argv);
203 Kokkos::initialize(argc, argv);
206 int rank = 0, size = 1;
207 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
208 MPI_Comm_size(MPI_COMM_WORLD, &size);
209 const int STEPS = (argc > 1) ? std::atoi(argv[1]) : 12;
210 const int MOVE_AT =
STEPS / 2;
217 auto D1 = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ, 1);
218 std::vector<peclet::core::Real> w(
GCELLS, 1.0);
219 for (
int z = 0; z <
NZ; ++z)
220 for (
int y = 0; y <
NY; ++y)
221 for (
int x = 0; x <
NX; ++x)
223 w[(std::size_t)x + (std::size_t)y *
NX + (std::size_t)z *
NX *
NY] = 24.0;
224 BlockDecomposer<3> D2((std::size_t)size, IVec<3>{
NX,
NY,
NZ}, w);
226 auto blk = D1.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];
232 for (
int r = 0; r < size; ++r) {
233 const auto a = D1.block(r), b = D2.block(r);
234 for (
int d = 0; d < 3; ++d)
235 if (a.origin[d] != b.origin[d] || a.size[d] != b.size[d])
240 "VOF REDISTRIBUTE MPI np=%d grid %dx%dx%d block %dx%dx%d partition moves: %s\n", size,
241 NX,
NY,
NZ, lnx, lny, lnz, moved ?
"YES" :
"no");
242 for (
int r = 0; r < size && size > 1; ++r) {
243 const auto a = D1.block(r), b = D2.block(r);
244 std::printf(
" rank %d: %ldx%ldx%ld @ (%ld,%ld,%ld) -> %ldx%ldx%ld @ (%ld,%ld,%ld)\n",
245 r, (
long)a.size[0], (
long)a.size[1], (
long)a.size[2], (
long)a.origin[0],
246 (
long)a.origin[1], (
long)a.origin[2], (
long)b.size[0], (
long)b.size[1],
247 (
long)b.size[2], (
long)b.origin[0], (
long)b.origin[1], (
long)b.origin[2]);
250 if (size > 1 && !moved) {
252 std::printf(
" FAIL - the weighted ORB coincides with the default one; nothing is gated\n");
256 static const char* CFGNAME[3] = {
"VoF + closures + scalar",
257 "VoF + closures + scalar + the BLOCK container",
258 "VoF + scalar + PHASE CHANGE (consistent energy)"};
259 for (
int cfg = 0; cfg < 3; ++cfg) {
260 const bool blocks = (cfg == 1);
262 std::printf(
" --- configuration: %s\n", CFGNAME[cfg]);
264 sd.initMpi(D1, MPI_COMM_WORLD);
265 configure(sd, ox, oy, oz, lnx, lny, lnz, cfg);
266 for (
int k = 0; k < MOVE_AT; ++k)
270 const char* fn[6] = {
"C",
"u",
"v",
"w",
"P",
"T"};
271 std::vector<double> pre[6],
post[6];
272 auto snap = [&](std::vector<double>* out,
int px,
int py,
int pz,
int qx,
int qy,
int qz) {
274 for (
int c = 0; c < 3; ++c)
279 snap(pre, ox, oy, oz, lnx, lny, lnz);
280 std::vector<double> volPre;
283 std::vector<double> l(st.size(), 0.0);
284 volPre.assign(st.size(), 0.0);
285 for (std::size_t i = 0; i < st.size(); ++i)
287 MPI_Allreduce(l.data(), volPre.data(), (
int)l.size(), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
290 sd.rebalanceByWeights(w);
292 const auto nb = D2.block(rank);
293 const int nox = (int)nb.origin[0], noy = (
int)nb.origin[1], noz = (int)nb.origin[2];
294 const int nlx = (int)nb.size[0], nly = (
int)nb.size[1], nlz = (int)nb.size[2];
295 snap(
post, nox, noy, noz, nlx, nly, nlz);
297 std::printf(
" R1 across the move (must be bitwise):");
298 for (
int i = 0; i < 6; ++i) {
300 std::printf(
" %s %ld cells / %.2e", fn[i], nd,
maxDiff(pre[i],
post[i]));
308 std::vector<double> l(st.size(), 0.0), volPost(st.size(), 0.0);
309 for (std::size_t i = 0; i < st.size(); ++i)
311 MPI_Allreduce(l.data(), volPost.data(), (
int)l.size(), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
314 for (std::size_t i = 0; i < volPost.size(); ++i)
315 dm = std::fmax(dm, std::fabs(volPost[i] - volPre[i]));
316 std::printf(
" R3 marker volumes across the move: %zu markers, max|dV| = %.3e\n",
318 if (!(dm <= 1e-12 * std::fmax(1.0, volPre.empty() ? 1.0 : volPre[0])))
324 for (
int k = MOVE_AT; k <
STEPS; ++k)
326 std::vector<double> g[6];
327 snap(g, nox, noy, noz, nlx, nly, nlz);
335 sc.initMpi(D1, MPI_COMM_WORLD);
336 configure(sc, ox, oy, oz, lnx, lny, lnz, cfg);
337 for (
int k = 0; k <
STEPS; ++k)
339 std::vector<double> gc[6];
340 gc[0] =
gatherGlobal(sc.getVof(), ox, oy, oz, lnx, lny, lnz, rank, size);
341 for (
int c = 0; c < 3; ++c)
342 gc[1 + c] =
gatherGlobal(sc.getVelocity(c), ox, oy, oz, lnx, lny, lnz, rank, size);
343 gc[4] =
gatherGlobal(sc.getPressure(), ox, oy, oz, lnx, lny, lnz, rank, size);
344 gc[5] =
gatherGlobal(sc.getField(
"T"), ox, oy, oz, lnx, lny, lnz, rank, size);
349 for (
int k = 0; k <
STEPS; ++k)
351 std::vector<double> r[6] = {ref.getVof(), ref.getVelocity(0), ref.getVelocity(1),
352 ref.getVelocity(2), ref.getPressure(), ref.getField(
"T")};
354 " R2 vs the single-rank reference after %d steps"
355 " [rebalanced | never-rebalanced control]:\n ",
357 for (
int i = 0; i < 6; ++i) {
362 const double bound = std::fmax(1e-13, 4.0 * dc);
363 std::printf(
" d%s %.2e|%.2e", fn[i], d, dc);
372 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
374 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
376 MPI_Comm_size(MPI_COMM_WORLD, &size);
378 std::printf(totalFail == 0
379 ?
"OK (np=%d): a VoF (+block) run survives a MOVING rebalance bit-exactly\n"
380 :
"FAILED (np=%d)\n",
384 return totalFail == 0 ? 0 : 1;