70 s.setAdvection(
false);
73 s.setDomainBc(4, 1, 0, 0, 0);
74 s.setDomainBc(5, 1, 0, 0, 0);
75 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
76 s.setPressureChebyshev(
true, 400, 1e-14);
79 std::vector<double> c((std::size_t)lnx * lny * lnz, 0.0);
80 for (
int z = 0; z < lnz; ++z)
81 for (
int y = 0; y < lny; ++y)
82 for (
int x = 0; x < lnx; ++x) {
83 const double v = std::fmax(
bubbleAt(0, x + ox, y + oy, z + oz),
84 bubbleAt(1, x + ox, y + oy, z + oz));
85 c[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] = v;
88 s.setPropertyModel(
"rho", ClosureKind::LinearMix,
"C",
"", {
RHO_L,
RHO_G -
RHO_L});
89 s.setPropertyModel(
"mu", ClosureKind::LinearMix,
"C",
"", {
MU_L,
MU_G -
MU_L});
90 s.setPropertyModel(
"force_z", ClosureKind::LinearMix,
"C",
"",
93 s.setSurfaceTension(
SIGMA);
94 std::vector<std::array<int, 6>> boxes;
95 for (
int b = 0; b < 2; ++b) {
97 const double c3[3] = {
CX[b],
CY[b],
CZ[b]};
98 for (
int d = 0; d < 3; ++d) {
99 q[d] = (int)std::floor(c3[d] -
RB) - 1;
100 q[3 + d] = (int)std::ceil(c3[d] +
RB) + 1;
108 s.enableVofBlocksFromField(boxes);
110 s.enableVofBlockCsf();
111 s.setDt(0.25 * s.capillaryDt());
117static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
118 int lnx,
int lny,
int lnz,
int rank,
int size) {
119 std::vector<double> global;
121 global.assign(
GCELLS, 0.0);
122 for (
int r = 0; r < size; ++r) {
123 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
126 for (
int z = 0; z < lnz; ++z)
127 for (
int y = 0; y < lny; ++y)
128 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
129 (std::size_t)(z + oz) *
NX *
NY],
130 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
131 (std::size_t)lnx *
sizeof(
double));
135 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
136 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
137 }
else if (rank == 0) {
138 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
139 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
140 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
142 for (
int z = 0; z < meta[5]; ++z)
143 for (
int y = 0; y < meta[4]; ++y)
144 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
145 (std::size_t)(z + meta[2]) *
NX *
NY],
146 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
147 (std::size_t)meta[3] *
sizeof(
double));
170int main(
int argc,
char** argv) {
171 MPI_Init(&argc, &argv);
172 Kokkos::initialize(argc, argv);
175 int rank = 0, size = 1;
176 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
177 MPI_Comm_size(MPI_COMM_WORLD, &size);
179 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
180 auto blk = dec.block(rank);
181 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
182 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
183 const int gn[3] = {
NX,
NY,
NZ};
184 bool cut[3] = {
false,
false,
false};
185 for (
const auto& sz : dec.sizes())
186 for (
int a = 0; a < 3; ++a)
187 if ((
int)sz[a] != gn[a])
191 "VOF BLOCK NS MPI (rung W2, WO-W12) np=%d grid %dx%dx%d block %dx%dx%d cut axes: "
193 size,
NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"");
194 if (size > 1 && !cut[2]) {
196 std::printf(
" FAIL - the decomposition does NOT cut z, so no marker is cut\n");
200 const int STEPS = (argc > 1) ? std::atoi(argv[1]) : 12;
205 constexpr bool hostBackend =
206 std::is_same_v<peclet::flow::CCExec::memory_space, Kokkos::HostSpace>;
207 for (
int cfg = 0; cfg < (hostBackend ? 3 : 2); ++cfg) {
208 const bool csf = (cfg == 1);
210 std::printf(
" --- configuration: block advection + varRho%s%s\n",
211 csf ?
" + the BLOCK CSF" :
" (surface tension OFF)",
212 cfg == 2 ?
", bottom 'algebraic' on both sides" :
"");
214 sd.initMpi(dec, MPI_COMM_WORLD);
215 configure(sd, ox, oy, oz, lnx, lny, lnz, csf);
221 long nClip = 0, nDebris = 0, nOverlap = 0;
222 for (
int k = 0; k <
STEPS; ++k) {
227 nDebris += q.debrisCells + q.debrisUnresolved + (q.debrisReturned != 0.0 ? 1 : 0);
232 long loc[3] = {nClip, nDebris, nOverlap}, glb[3];
233 MPI_Allreduce(loc, glb, 3, MPI_LONG, MPI_SUM, MPI_COMM_WORLD);
235 std::printf(
" overlap-design counters over %d steps: clipped %ld, debris cells %ld, "
236 "overlap cells %ld\n",
STEPS, glb[0], glb[1], glb[2]);
237 if (glb[0] != 0 || glb[1] != 0 || glb[2] != 0) {
239 std::printf(
" FAIL: an overlap-design rule fired on a non-colliding pair\n");
247 for (
const auto& q : stats)
248 std::printf(
" dist block %ld master %d box [%d,%d)x[%d,%d)x[%d,%d)\n", q.id, q.master,
249 q.lo[0], q.hi[0], q.lo[1], q.hi[1], q.lo[2], q.hi[2]);
250 std::vector<double> vLoc(stats.size(), 0.0), vAll(stats.size(), 0.0);
251 std::vector<double> aLoc(stats.size(), 0.0), aAll(stats.size(), 0.0);
252 for (std::size_t i = 0; i < stats.size(); ++i) {
253 vLoc[i] = stats[i].volume;
254 aLoc[i] = stats[i].area;
256 MPI_Allreduce(vLoc.data(), vAll.data(), (
int)vLoc.size(), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
257 MPI_Allreduce(aLoc.data(), aAll.data(), (
int)aLoc.size(), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
259 std::vector<double> gf[3];
261 for (
int c = 0; c < 3; ++c)
263 std::vector<double> g[5];
278 ref.setPressureBottomSolver(hostBackend && cfg != 2 ? 0 : 2);
279 for (
int k = 0; k <
STEPS; ++k)
281 std::vector<double> r[5] = {ref.getVelocity(0), ref.getVelocity(1), ref.getVelocity(2),
282 ref.getPressure(), ref.getVof()};
283 const char* fn[5] = {
"u",
"v",
"w",
"P",
"C"};
287 for (
int i = 0; i < 5; ++i) {
291 std::printf(
" np=%d after %d steps:", size,
STEPS);
292 for (
int i = 0; i < 5; ++i)
293 std::printf(
" d%s %.2e", fn[i], d[i]);
295 std::printf(
" bitwise-differing cells:");
296 for (
int i = 0; i < 5; ++i)
297 std::printf(
" %s %ld", fn[i], nb[i]);
302 for (
int c = 0; c < 3; ++c) {
303 const std::vector<double> rf = ref.getVofBlockForce(c);
306 df = std::fmax(df,
maxDiff(gf[c], rf));
308 std::printf(
" scattered CSF face force vs np=1: max|d| %.3e over %ld bit-differing "
311 for (
const auto& q : ref.vofBlockStats())
312 std::printf(
" ref block %ld box [%d,%d)x[%d,%d)x[%d,%d)\n", q.id, q.lo[0], q.hi[0],
313 q.lo[1], q.hi[1], q.lo[2], q.hi[2]);
314 const auto rs = ref.vofBlockStats();
315 double dv = 0.0, da = 0.0, sumMark = 0.0, sumUnion = 0.0;
316 for (std::size_t i = 0; i < rs.size(); ++i) {
317 dv = std::fmax(dv, std::fabs(vAll[i] - rs[i].volume));
318 da = std::fmax(da, std::fabs(aAll[i] - rs[i].area));
319 sumMark += rs[i].volume;
321 for (
double q : r[4])
323 std::printf(
" markers: V %.6f / %.6f, area %.2f / %.2f; |dV| vs np=1 %.2e, |dA| %.2e\n",
324 rs[0].volume, rs[1].volume, rs[0].area, rs[1].area, dv, da);
325 std::printf(
" UNION deficit sum(V_marker) - sum(C_union) = %.4f cells (the shared liquid; "
326 "> 0 means the two markers OVERLAP, which a single field cannot do)\n",
330 const double tolU = (size == 1) ? 0.0 : 1e-12;
331 const double tolP = (size == 1) ? 0.0 : 1e-9;
332 const double tolC = (size == 1) ? 0.0 : 1e-12;
333 const double tol[5] = {tolU, tolU, tolU, tolP, tolC};
334 for (
int i = 0; i < 5; ++i)
335 if (!(d[i] <= tol[i])) {
336 std::printf(
" FAIL: d%s = %.3e exceeds %.1e\n", fn[i], d[i], tol[i]);
339 if (!(dv <= (size == 1 ? 0.0 : 1e-11))) {
340 std::printf(
" FAIL: marker volume drift %.3e\n", dv);
344 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
347 std::printf(
"%s\n", fail ?
"FAILED" :
"PASSED");