71static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
72 int lnx,
int lny,
int lnz,
int rank,
int size) {
73 std::vector<double> global;
75 global.assign(
GCELLS, 0.0);
76 for (
int r = 0; r < size; ++r) {
77 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
80 for (
int z = 0; z < lnz; ++z)
81 for (
int y = 0; y < lny; ++y)
82 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
83 (std::size_t)(z + oz) *
NX *
NY],
84 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
85 (std::size_t)lnx *
sizeof(
double));
89 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
90 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
91 }
else if (rank == 0) {
92 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
93 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
94 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
96 for (
int z = 0; z < meta[5]; ++z)
97 for (
int y = 0; y < meta[4]; ++y)
98 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
99 (std::size_t)(z + meta[2]) *
NX *
NY],
100 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
101 (std::size_t)meta[3] *
sizeof(
double));
117int main(
int argc,
char** argv) {
118 std::setvbuf(stdout,
nullptr, _IONBF, 0);
119 MPI_Init(&argc, &argv);
120 Kokkos::initialize(argc, argv);
123 int rank = 0, size = 1;
124 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
125 MPI_Comm_size(MPI_COMM_WORLD, &size);
126 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
127 auto blk = dec.block(rank);
128 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
129 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
130 const int gn[3] = {
NX,
NY,
NZ};
131 bool cut[3] = {
false,
false,
false};
132 for (
const auto& sz : dec.sizes())
133 for (
int a = 0; a < 3; ++a)
134 if ((
int)sz[a] != gn[a])
138 "VOF DYNAMIC WETTING MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s "
139 "theta_e = %.0f deg, lambda = %.2f cells, u = %.3g\n",
140 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"",
142 if (size > 1 && !cut[2]) {
144 std::printf(
" FAIL — the decomposition does not cut z, so no contact line is cut\n");
147 const std::vector<double> gSdf =
blockOf(
148 [](
int x,
int y,
int z) {
return sdfAt(x + 0.5, y + 0.5, z + 0.5); }, 0, 0, 0,
NX,
NY,
NZ);
150 auto setup = [&](
IbmSolver& s,
int aox,
int aoy,
int aoz,
int anx,
int any,
int anz,
152 s.setAdvection(
false);
155 s.setSolid(
sliceOf(gSdf, aox, aoy, aoz, anx, any, anz),
true);
158 s.setSurfaceTension(
SIGMA);
161 s.setVelocity(2, std::vector<double>((std::size_t)anx * any * anz,
UVEL));
164 s.setContactAngleHysteresis(100.0, 80.0);
165 s.setDt(0.15 * s.capillaryDt());
169 for (
int hyst = 0; hyst < 2; ++hyst) {
171 sd.initMpi(dec, MPI_COMM_WORLD);
172 setup(sd, ox, oy, oz, lnx, lny, lnz, hyst != 0);
174 long loc[4] = {cdLoc.dynamicCells, cdLoc.pinnedCells, cdLoc.advancingCells,
175 cdLoc.recedingCells};
176 long tot[4] = {0, 0, 0, 0};
177 MPI_Allreduce(loc, tot, 4, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
178 std::vector<double> g[5];
179 for (
int q = 0; q < 5; ++q)
184 setup(ref, 0, 0, 0,
NX,
NY,
NZ, hyst != 0);
185 const auto rd = ref.contactAngleDiagnostics();
187 for (
int q = 0; q < 5; ++q)
188 d[q] =
maxAbsDiff(g[q], ref.getVofDynamicField(q));
189 const double df =
maxAbsDiff(gf, ref.getVofFilledColour());
191 " [%s np=%d] imposed %.3e apparent %.3e U_cl %.3e Ca_cl %.3e state %.3e "
192 "band fill %.3e (all bitwise required)\n"
193 " census dynamic/pinned/advancing/receding %ld/%ld/%ld/%ld "
194 "(ref %ld/%ld/%ld/%ld) mean imposed %.6f mean apparent %.6f max|Ca_cl| %.6e\n",
195 hyst ?
"hyst " :
"dyn ", size, d[0], d[1], d[2], d[3], d[4], df, tot[0], tot[1],
196 tot[2], tot[3], rd.dynamicCells, rd.pinnedCells, rd.advancingCells, rd.recedingCells,
197 rd.meanImposedTheta, rd.meanApparentTheta, rd.maxCaCl);
198 for (
int q = 0; q < 5; ++q)
199 if (!(d[q] == 0.0)) {
200 std::printf(
" [np=%d] FAIL — dynamic field %d is not bitwise (%.3e)\n", size, q, d[q]);
204 std::printf(
" [np=%d] FAIL — the theta band fill is not bitwise (%.3e)\n", size, df);
207 if (tot[0] != rd.dynamicCells || tot[1] != rd.pinnedCells || tot[2] != rd.advancingCells ||
208 tot[3] != rd.recedingCells) {
209 std::printf(
" [np=%d] FAIL — the state census differs from the reference\n", size);
217 const int steps = 20;
219 sd.initMpi(dec, MPI_COMM_WORLD);
220 setup(sd, ox, oy, oz, lnx, lny, lnz,
false);
223 MPI_Allreduce(&lv0, &v0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
225 for (
int i = 0; i < steps; ++i) {
230 double v1 = 0.0, solid = 0.0;
231 MPI_Allreduce(&lv1, &v1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
232 MPI_Allreduce(&ls, &solid, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
235 std::vector<double> gu[3];
236 for (
int c = 0; c < 3; ++c)
240 setup(ref, 0, 0, 0,
NX,
NY,
NZ,
false);
241 for (
int i = 0; i < steps; ++i)
244 for (
int c = 0; c < 3; ++c)
245 du = std::fmax(du,
maxAbsDiff(gu[c], ref.getVelocity(c)));
246 const double dc =
maxAbsDiff(gc, ref.getVof());
247 const double di =
maxAbsDiff(gi, ref.getVofDynamicField(0));
248 const double drift = (v1 - v0) / v0;
249 const double tol = size == 1 ? 0.0 : 1e-9;
251 " [coupled np=%d] colour %.3e velocity %.3e imposed theta %.3e drift %.3e "
252 "solid sum C %.3e pressure iters max %ld\n",
253 size, dc, du, di, drift, solid, maxIt);
254 if (!(dc <= tol) || !(du <= tol) || !(di <= 1e-9)) {
255 std::printf(
" [coupled np=%d] FAIL — above tol %.1e\n", size, tol);
258 if (!(solid == 0.0) || !(std::fabs(drift) <= 1e-9)) {
259 std::printf(
" [coupled np=%d] FAIL — solid sum %.3e drift %.3e\n", size, solid, drift);
266 MPI_Allreduce(&fail, &g, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
269 std::printf(fail ?
"VOF DYNAMIC WETTING MPI: FAILED\n"
270 :
"VOF DYNAMIC WETTING MPI: all checks passed\n");