90static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
91 int lnx,
int lny,
int lnz,
int rank,
int size) {
92 std::vector<double> global;
94 global.assign(
GCELLS, 0.0);
95 for (
int r = 0; r < size; ++r) {
96 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
99 for (
int z = 0; z < lnz; ++z)
100 for (
int y = 0; y < lny; ++y)
101 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
102 (std::size_t)(z + oz) *
NX *
NY],
103 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
104 (std::size_t)lnx *
sizeof(
double));
108 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
109 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
110 }
else if (rank == 0) {
111 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
112 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
113 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
115 for (
int z = 0; z < meta[5]; ++z)
116 for (
int y = 0; y < meta[4]; ++y)
117 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
118 (std::size_t)(z + meta[2]) *
NX *
NY],
119 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
120 (std::size_t)meta[3] *
sizeof(
double));
139int main(
int argc,
char** argv) {
140 std::setvbuf(stdout,
nullptr, _IONBF, 0);
141 MPI_Init(&argc, &argv);
142 Kokkos::initialize(argc, argv);
145 int rank = 0, size = 1;
146 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
147 MPI_Comm_size(MPI_COMM_WORLD, &size);
148 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
149 auto blk = dec.block(rank);
150 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
151 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
152 const int gn[3] = {
NX,
NY,
NZ};
153 bool cut[3] = {
false,
false,
false};
154 for (
const auto& sz : dec.sizes())
155 for (
int a = 0; a < 3; ++a)
156 if ((
int)sz[a] != gn[a])
160 "VOF WETTING MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s "
161 "theta = %.0f deg\n",
162 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"",
164 if (size > 1 && !cut[2]) {
166 std::printf(
" FAIL — the decomposition does not cut z, so the contact line is not cut\n");
169 const std::vector<double> gSdf =
blockOf(
170 [](
int x,
int y,
int z) {
return sdfAt(x + 0.5, y + 0.5, z + 0.5); }, 0, 0, 0,
NX,
NY,
NZ);
172 auto setup = [&](
IbmSolver& s,
int aox,
int aoy,
int aoz,
int anx,
int any,
int anz,
174 s.setAdvection(
false);
177 s.setSolid(
sliceOf(gSdf, aox, aoy, aoz, anx, any, anz),
true);
180 s.setSurfaceTension(1.0);
182 s.setContactAngle(
THETA);
183 s.setDt(0.15 * s.capillaryDt());
189 sd.initMpi(dec, MPI_COMM_WORLD);
190 setup(sd, ox, oy, oz, lnx, lny, lnz,
true);
192 long loc[5] = {cdLoc.contactCells, cdLoc.neighbourCells, cdLoc.pureCells, cdLoc.parallelCells,
194 long tot[5] = {0, 0, 0, 0, 0};
195 MPI_Allreduce(loc, tot, 5, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
198 const auto gn0 = [&] {
200 s2.initMpi(dec, MPI_COMM_WORLD);
201 setup(s2, ox, oy, oz, lnx, lny, lnz,
false);
202 return gatherGlobal(s2.getVofFilledColour(), ox, oy, oz, lnx, lny, lnz, rank, size);
206 setup(ref, 0, 0, 0,
NX,
NY,
NZ,
true);
207 const auto rd = ref.contactAngleDiagnostics();
208 const double d =
maxAbsDiff(g, ref.getVofFilledColour());
211 " [fill np=%d] theta band fill %.3e (bitwise required) | band census "
212 "theta/neighbour/pure/parallel/neutral %ld/%ld/%ld/%ld/%ld "
213 "(ref %ld/%ld/%ld/%ld/%ld) mean apparent %.3f deg | "
214 "max |theta-fill - neutral-fill| %.3e\n",
215 size, d, tot[0], tot[1], tot[2], tot[3], tot[4], rd.contactCells, rd.neighbourCells,
216 rd.pureCells, rd.parallelCells, rd.neutralCells, rd.meanApparentAngle, dn);
218 std::printf(
" [fill np=%d] FAIL — the theta band fill is not bitwise\n", size);
221 if (tot[0] != rd.contactCells || tot[1] != rd.neighbourCells || tot[2] != rd.pureCells ||
222 tot[3] != rd.parallelCells || tot[4] != rd.neutralCells) {
223 std::printf(
" [fill np=%d] FAIL — the band census differs from the reference\n", size);
231 const int steps = 25;
233 sd.initMpi(dec, MPI_COMM_WORLD);
234 setup(sd, ox, oy, oz, lnx, lny, lnz,
true);
237 MPI_Allreduce(&lv0, &v0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
239 for (
int i = 0; i < steps; ++i) {
244 double v1 = 0.0, solid = 0.0;
245 MPI_Allreduce(&lv1, &v1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
246 MPI_Allreduce(&ls, &solid, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
248 std::vector<double> gu[3];
249 for (
int c = 0; c < 3; ++c)
253 setup(ref, 0, 0, 0,
NX,
NY,
NZ,
true);
254 for (
int i = 0; i < steps; ++i)
257 for (
int c = 0; c < 3; ++c)
258 du = std::fmax(du,
maxAbsDiff(gu[c], ref.getVelocity(c)));
259 const double dc =
maxAbsDiff(gc, ref.getVof());
260 const double drift = (v1 - v0) / v0;
261 const double tol = size == 1 ? 0.0 : 1e-9;
263 " [coupled np=%d] colour %.3e velocity %.3e drift %.3e solid sum C %.3e "
264 "pressure iters max %ld\n",
265 size, dc, du, drift, solid, maxIt);
266 if (!(dc <= tol) || !(du <= tol)) {
267 std::printf(
" [coupled np=%d] FAIL — colour %.3e velocity %.3e above tol %.1e\n", size,
271 if (!(solid == 0.0) || !(std::fabs(drift) <= 1e-9)) {
272 std::printf(
" [coupled np=%d] FAIL — solid sum %.3e drift %.3e\n", size, solid, drift);
283 const int steps = 25;
285 sd.initMpi(dec, MPI_COMM_WORLD);
286 setup(sd, ox, oy, oz, lnx, lny, lnz,
true);
290 for (
int i = 0; i < steps; ++i) {
297 std::vector<double> gu[3];
298 for (
int c = 0; c < 3; ++c)
302 MPI_Allreduce(&ran32, &ran32All, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
305 setup(ref, 0, 0, 0,
NX,
NY,
NZ,
true);
308 for (
int i = 0; i < steps; ++i) {
310 refIt = std::max(refIt, ref.lastPressureIterations());
313 for (
int c = 0; c < 3; ++c)
314 du = std::fmax(du,
maxAbsDiff(gu[c], ref.getVelocity(c)));
315 const double dc =
maxAbsDiff(gc, ref.getVof());
316 const double dp =
maxAbsDiff(gp, ref.getPressure());
317 const double tol = size == 1 ? 0.0 : 1e-9;
319 " [fp32 np=%d] colour %.3e velocity %.3e pressure %.3e pressure iters max %ld "
320 "(single rank %ld)%s\n",
321 size, dc, du, dp, maxIt, refIt, ran32All ?
"" :
" -- the FP32 V-cycle did NOT run");
322 if (!ran32All || !(dc <= tol) || !(du <= tol) || (size == 1 && !(dp == 0.0)) ||
323 (size == 1 && maxIt != refIt)) {
325 " [fp32 np=%d] FAIL — colour %.3e velocity %.3e pressure %.3e above tol %.1e\n",
326 size, dc, du, dp, tol);
334 MPI_Allreduce(&fail, &g, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
337 std::printf(fail ?
"VOF WETTING MPI: FAILED\n" :
"VOF WETTING MPI: all checks passed\n");