89 s.setMu(c.walls ? 0.0 : 0.1);
91 s.setAdvection(
false);
93 s.setDomainBc(2 * c.axis + 0, 1, 0, 0, 0);
94 s.setDomainBc(2 * c.axis + 1, 1, 0, 0, 0);
96 s.setBodyForce(
FX, 0, 0);
98 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
99 s.setDensityMode(
true);
100 s.setField(
"rho",
blockOf([&](
int x,
int y,
int z) {
return rhoAt(c, x, y, z); }, ox, oy, oz, lnx,
102 s.exchangeField(
"rho");
121static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
122 int lnx,
int lny,
int lnz,
int rank,
int size) {
123 std::vector<double> global;
125 global.assign(
GCELLS, 0.0);
126 for (
int r = 0; r < size; ++r) {
127 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
130 for (
int z = 0; z < lnz; ++z)
131 for (
int y = 0; y < lny; ++y)
132 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
133 (std::size_t)(z + oz) *
NX *
NY],
134 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
135 (std::size_t)lnx *
sizeof(
double));
139 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
140 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
141 }
else if (rank == 0) {
142 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
143 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
144 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
146 for (
int z = 0; z < meta[5]; ++z)
147 for (
int y = 0; y < meta[4]; ++y)
148 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
149 (std::size_t)(z + meta[2]) *
NX *
NY],
150 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
151 (std::size_t)meta[3] *
sizeof(
double));
190int main(
int argc,
char** argv) {
191 MPI_Init(&argc, &argv);
192 Kokkos::initialize(argc, argv);
195 int rank = 0, size = 1;
196 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
197 MPI_Comm_size(MPI_COMM_WORLD, &size);
199 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
200 auto blk = dec.block(rank);
201 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
202 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
203 const int gn[3] = {
NX,
NY,
NZ};
204 bool cut[3] = {
false,
false,
false};
205 for (
const auto& sz : dec.sizes())
206 for (
int a = 0; a < 3; ++a)
207 if ((
int)sz[a] != gn[a])
210 std::printf(
"VARDENSITY MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
211 NX,
NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"",
214 const Config configs[] = {{
"walls-z", 2,
true}, {
"jump-z", 2,
false}};
216 for (
const Config& c : configs) {
220 if (size > 1 && !cut[c.axis]) {
223 " [%-7s np=%d] FAIL — the decomposition does NOT cut axis %d; this test "
224 "exists to gate the domain-BC / property-ghost rank ownership on a CUT "
225 "walled axis (WO-F)\n",
226 c.name, size, c.axis);
232 sd.initMpi(dec, MPI_COMM_WORLD);
233 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
234 std::vector<long> itd;
235 for (
int it = 0; it <
STEPS; ++it) {
240 std::vector<double> gu[3];
241 for (
int comp = 0; comp < 3; ++comp)
243 const std::vector<double> gp =
250 std::vector<long> itr;
251 std::vector<double> refUmax;
252 for (
int it = 0; it <
STEPS; ++it) {
254 itr.push_back(ref.lastPressureIterations());
256 std::fmax(
maxAbs(ref.getVelocity(0)),
257 std::fmax(
maxAbs(ref.getVelocity(1)),
maxAbs(ref.getVelocity(2)))));
259 double du = 0, umag = 0;
260 for (
int comp = 0; comp < 3; ++comp) {
261 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
262 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
264 const double dp =
maxAbsDiff(gp, ref.getPressure());
265 const double pmag =
maxAbs(ref.getPressure());
267 const double utol = (size == 1) ? 0.0 : std::fmax(1e-15, 1e-11 * umag);
268 const double ptol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * pmag);
278 for (std::size_t k = 0; k < itr.size(); ++k) {
279 if (k > 0 && refUmax[k - 1] <= 1e-12)
282 dits = std::max(dits, std::labs(itd[k] - itr[k]));
299 const long itTol = (size == 1) ? 0 : 1;
300 bool ok = du <= utol && dp <= ptol && dits <= itTol;
301 double umax = -1, perr = -1;
305 ok = ok && umax < 1e-14 && perr < 1e-11;
309 std::snprintf(extra,
sizeof(extra),
" | max|u|=%.2e dP/dz err=%.2e", umax, perr);
311 " [%-7s np=%d] du=%.3e dp=%.3e (tol %.1e/%.1e) | cheb its %ld..%ld "
312 "max-delta=%ld over %d/%d non-degenerate steps%s %s\n",
313 c.name, size, du, dp, utol, ptol, itr.front(), itr.back(), dits, nWin,
STEPS, extra,
315 std::printf(
" dist its:");
317 std::printf(
" %ld", v);
318 std::printf(
"\n ref its:");
320 std::printf(
" %ld", v);
325 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
328 std::printf(
"VARDENSITY MPI (np=%d): %s\n", size, fail ?
"FAIL" :
"PASS");
static std::vector< double > gatherGlobal(const std::vector< double > &local, int ox, int oy, int oz, int lnx, int lny, int lnz, int rank, int size)