95 s.setMu(c.walls ? 0.0 : 0.05);
97 s.setAdvection(!c.walls);
99 s.setDomainBc(4, 1, 0, 0, 0);
100 s.setDomainBc(5, 1, 0, 0, 0);
102 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
103 s.setVof(
blockOf([&](
int x,
int y,
int z) {
return colourAt(c, x, y, z); }, ox, oy, oz, lnx, lny,
106 {1.0, c.ratio - 1.0});
113 s.setPressureChebyshev(
true, 120, 1e-12);
122static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
123 int lnx,
int lny,
int lnz,
int rank,
int size) {
124 std::vector<double> global;
126 global.assign(
GCELLS, 0.0);
127 for (
int r = 0; r < size; ++r) {
128 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
131 for (
int z = 0; z < lnz; ++z)
132 for (
int y = 0; y < lny; ++y)
133 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
134 (std::size_t)(z + oz) *
NX *
NY],
135 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
136 (std::size_t)lnx *
sizeof(
double));
140 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
141 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
142 }
else if (rank == 0) {
143 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
144 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
145 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
147 for (
int z = 0; z < meta[5]; ++z)
148 for (
int y = 0; y < meta[4]; ++y)
149 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
150 (std::size_t)(z + meta[2]) *
NX *
NY],
151 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
152 (std::size_t)meta[3] *
sizeof(
double));
198int main(
int argc,
char** argv) {
199 MPI_Init(&argc, &argv);
200 Kokkos::initialize(argc, argv);
203 int rank = 0, size = 1;
204 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
205 MPI_Comm_size(MPI_COMM_WORLD, &size);
207 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
208 auto blk = dec.block(rank);
209 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
210 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
211 const int gn[3] = {
NX,
NY,
NZ};
212 bool cut[3] = {
false,
false,
false};
213 for (
const auto& sz : dec.sizes())
214 for (
int a = 0; a < 3; ++a)
215 if ((
int)sz[a] != gn[a])
218 std::printf(
"VOF TWOPHASE MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
219 NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
222 const Config configs[] = {{
"walls-z",
true, 1000.0, 1.0, 20},
223 {
"shear-per",
false, 10.0, 1.0, 40}};
225 for (
const Config& c : configs) {
229 if (size > 1 && !cut[2]) {
231 std::printf(
" [%-9s np=%d] FAIL — the decomposition does NOT cut z\n", c.name, size);
237 sd.initMpi(dec, MPI_COMM_WORLD);
238 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
241 MPI_Allreduce(&v0Loc, &v0, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
242 for (
int it = 0; it < c.steps; ++it)
246 MPI_Allreduce(&v1Loc, &v1, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
248 std::vector<double> gu[3];
249 for (
int comp = 0; comp < 3; ++comp)
251 const std::vector<double> gp =
253 const std::vector<double> gc =
260 const double rv0 =
sumOf(ref.getVof());
261 for (
int it = 0; it < c.steps; ++it)
263 const double refDrift = (
sumOf(ref.getVof()) - rv0) / rv0;
264 double du = 0, umag = 0;
265 for (
int comp = 0; comp < 3; ++comp) {
266 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
267 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
269 const auto refC = ref.getVof();
270 const double dp =
maxAbsDiff(gp, ref.getPressure());
272 const double pmag =
maxAbs(ref.getPressure());
273 const double drift = (v1 - v0) / v0;
278 const double utol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * umag);
279 const double ptol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * pmag);
280 const double ctol = (size == 1) ? 0.0 : 1e-11;
282 " [%-9s np=%d] du %.3e (tol %.1e, |u| %.2e) dp %.3e (tol %.1e, |P| %.2e) "
283 "dC %.3e (tol %.1e) dV/V %+.3e\n",
284 c.name, size, du, utol, umag, dp, ptol, pmag, dc, ctol, drift);
285 if (!(du <= utol) || !(dp <= ptol) || !(dc <= ctol)) {
286 std::printf(
" [%-9s np=%d] FAIL — distributed vs single-rank\n", c.name, size);
297 std::printf(
" [%-9s np=%d] colour drift dist %+.4e ref %+.4e (delta %.2e)\n", c.name,
298 size, drift, refDrift, std::fabs(drift - refDrift));
299 if (!(std::fabs(drift - refDrift) < 1e-13)) {
300 std::printf(
" [%-9s np=%d] FAIL — colour drift is decomposition-dependent\n", c.name,
304 }
else if (!(std::fabs(drift) < 1e-11)) {
305 std::printf(
" [%-9s np=%d] FAIL — colour volume drift %.3e\n", c.name, size, drift);
310 const double umaxD = std::fmax(
maxAbs(gu[0]), std::fmax(
maxAbs(gu[1]),
maxAbs(gu[2])));
311 std::printf(
" [%-9s np=%d] hydrostatic through C: max|u| %.3e dP/dz rel-err %.3e\n",
312 c.name, size, umaxD, perr);
313 if (!(perr < 1e-11) || !(umaxD < 1e-9)) {
314 std::printf(
" [%-9s np=%d] FAIL — hydrostatic balance through C\n", c.name, size);
319 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
322 std::printf(fail ?
"FAILED\n" :
"OK\n");