85 s.setAdvection(
false);
86 const double rl = c.constKappa ?
RHO_G :
RHO_L;
93 s.setVelocityResidualTolerance(0.0);
95 s.setDomainBc(4, 1, 0, 0, 0);
96 s.setDomainBc(5, 1, 0, 0, 0);
98 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
99 s.setPressureChebyshev(
true, 400, 1e-14);
101 s.setVof(
blockOf([&](
int x,
int y,
int z) {
return colourAt(c, x, y, z); }, ox, oy, oz, lnx, lny,
103 s.setPropertyModel(
"rho", ClosureKind::LinearMix,
"C",
"", {
RHO_G, rl -
RHO_G});
104 s.setSurfaceTension(
SIGMA);
106 s.setVofKappaConstant(2.0 /
RDROP);
107 s.setDt(0.5 * s.capillaryDt());
110static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
111 int lnx,
int lny,
int lnz,
int rank,
int size) {
112 std::vector<double> global;
114 global.assign(
GCELLS, 0.0);
115 for (
int r = 0; r < size; ++r) {
116 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
119 for (
int z = 0; z < lnz; ++z)
120 for (
int y = 0; y < lny; ++y)
121 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
122 (std::size_t)(z + oz) *
NX *
NY],
123 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
124 (std::size_t)lnx *
sizeof(
double));
128 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
129 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
130 }
else if (rank == 0) {
131 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
132 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
133 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
135 for (
int z = 0; z < meta[5]; ++z)
136 for (
int y = 0; y < meta[4]; ++y)
137 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
138 (std::size_t)(z + meta[2]) *
NX *
NY],
139 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
140 (std::size_t)meta[3] *
sizeof(
double));
169int main(
int argc,
char** argv) {
170 MPI_Init(&argc, &argv);
171 Kokkos::initialize(argc, argv);
174 int rank = 0, size = 1;
175 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
176 MPI_Comm_size(MPI_COMM_WORLD, &size);
178 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
179 auto blk = dec.block(rank);
180 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
181 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
182 const int gn[3] = {
NX,
NY,
NZ};
183 bool cut[3] = {
false,
false,
false};
184 for (
const auto& sz : dec.sizes())
185 for (
int a = 0; a < 3; ++a)
186 if ((
int)sz[a] != gn[a])
190 "VOF SURFACE TENSION MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
191 NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"");
193 const Config configs[] = {{
"exact-per",
false,
true},
194 {
"exact-walls-z",
true,
true},
195 {
"drop-per",
false,
false},
196 {
"drop-walls-z",
true,
false}};
198 for (
const Config& c : configs) {
199 if (size > 1 && !cut[2]) {
201 std::printf(
" [%-14s np=%d] FAIL — the decomposition does NOT cut z\n", c.name, size);
207 sd.initMpi(dec, MPI_COMM_WORLD);
208 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
209 for (
int k = 0; k < 10; ++k)
216 MPI_Allreduce(&loc, &gmax, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
218 std::vector<double> g[6];
219 const char* fn[6] = {
"u",
"v",
"w",
"P",
"C",
"kappa"};
226 const std::vector<double> gb =
232 for (
int k = 0; k < 10; ++k)
234 std::vector<double> r[6] = {ref.getVelocity(0), ref.getVelocity(1), ref.getVelocity(2),
235 ref.getPressure(), ref.getVof(), ref.getVofCurvature()};
237 for (
int i = 0; i < 6; ++i)
239 double dkb = 0.0, dkk = 0.0;
240 const long nkb =
countBitDiff(gb, ref.getVofCurvatureBranch(), dkb);
244 " [%-14s np=%d] max|u| = %.4e du %.2e dv %.2e dw %.2e dP %.2e"
245 " dC %.2e dkappa %.2e\n",
246 c.name, size, gmax, d[0], d[1], d[2], d[3], d[4], d[5]);
256 std::printf(
" FAIL — the curvature BRANCH is decomposition-dependent (%ld cells)\n",
260 if (size == 1 && nkk != 0) {
261 std::printf(
" FAIL — kappa is not bitwise at np = 1 (%ld cells, max |d| %.3e)\n",
274 const double tol = c.walls ? 1e-8 : 1e-13;
276 std::printf(
" FAIL — the exactness gate is above %.0e (%.3e)\n", tol, gmax);
281 const double tolU = (size == 1) ? 0.0 : 1e-12;
282 const double tolP = (size == 1) ? 0.0 : 1e-9;
283 const double tolC = (size == 1) ? 0.0 : 1e-12;
284 const double tolK = (size == 1) ? 0.0 : 1e-12;
286 std::printf(
" FAIL — kappa differs by more than the colour's own floor (%.2e)\n",
290 if (d[0] > tolU || d[1] > tolU || d[2] > tolU || d[3] > tolP || d[4] > tolC) {
292 " FAIL — the distributed step does not match the single-rank reference"
293 " (tolerances u %.0e P %.0e C %.0e)\n",
298 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
301 std::printf(
"%s\n", fail ?
"FAILED" :
"PASSED");