96 s.setAdvection(
false);
97 s.setPressurePcg(
true, 200, 1e-10);
98 s.setVelocityIterations(60);
100 s.setDomainBc(2, 1, 0.0, 0.0, 0.0);
101 s.setDomainBc(3, 2,
ULID, 0.0, 0.0);
103 s.setPressureGeometry(std::vector<double>((std::size_t)lnx * lny * lnz, 10.0));
105 s.setField(
"mu",
blockOf([&](
int x,
int y,
int z) {
return muAt(c, x, y, z); }, ox, oy, oz, lnx,
107 s.setPropertyMode(
true,
true);
108 s.exchangeField(
"mu");
111 s.setField(
"src",
blockOf(
srcAt, ox, oy, oz, lnx, lny, lnz));
112 s.exchangeField(
"src");
123static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
124 int lnx,
int lny,
int lnz,
int rank,
int size) {
125 std::vector<double> global;
127 global.assign(
GCELLS, 0.0);
128 for (
int r = 0; r < size; ++r) {
129 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
132 for (
int z = 0; z < lnz; ++z)
133 for (
int y = 0; y < lny; ++y)
134 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
NX +
135 (std::size_t)(z + oz) *
NX *
NY],
136 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
137 (std::size_t)lnx *
sizeof(
double));
141 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
142 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
143 }
else if (rank == 0) {
144 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
145 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
146 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
148 for (
int z = 0; z < meta[5]; ++z)
149 for (
int y = 0; y < meta[4]; ++y)
150 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
NX +
151 (std::size_t)(z + meta[2]) *
NX *
NY],
152 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
153 (std::size_t)meta[3] *
sizeof(
double));
197int main(
int argc,
char** argv) {
198 MPI_Init(&argc, &argv);
199 Kokkos::initialize(argc, argv);
202 int rank = 0, size = 1;
203 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
204 MPI_Comm_size(MPI_COMM_WORLD, &size);
206 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
207 auto blk = dec.block(rank);
208 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
209 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
210 const int gn[3] = {
NX,
NY,
NZ};
211 bool cut[3] = {
false,
false,
false};
212 for (
const auto& sz : dec.sizes())
213 for (
int a = 0; a < 3; ++a)
214 if ((
int)sz[a] != gn[a])
217 std::printf(
"VARMU MPI np=%d grid %dx%dx%d block %dx%dx%d cut axes: %s%s%s\n", size,
NX,
218 NY,
NZ, lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"");
222 for (
const Config& c : configs) {
225 if (size > 1 && !cut[1]) {
228 " [%-9s np=%d] FAIL — the decomposition does NOT cut the walled y axis; "
229 "this test exists to gate the domain-BC / property-ghost rank ownership on "
230 "a CUT walled axis (WO-F)\n",
236 sd.initMpi(dec, MPI_COMM_WORLD);
237 configure(sd, c, ox, oy, oz, lnx, lny, lnz);
238 for (
int it = 0; it < c.steps; ++it)
240 std::vector<double> gu[3];
241 for (
int comp = 0; comp < 3; ++comp)
245 const std::vector<double> gp =
251 for (
int it = 0; it < c.steps; ++it)
253 double du = 0, umag = 0;
254 for (
int comp = 0; comp < 3; ++comp) {
255 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
256 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
258 const double rel = du / (umag + 1e-300);
259 const double dp =
maxAbsDiff(gp, ref.getPressure());
260 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-14, 1e-11 * pmag);
270 bool ok = du <= utol && dp <= ptol;
273 ok = ok && aerr < 5e-3;
277 std::snprintf(extra,
sizeof(extra),
" analytic err=%.4f%%", aerr * 100.0);
279 " [%-9s np=%d] du=%.3e (rel %.2e, tol %.1e) | dp=%.3e (|P|=%.2e, tol %.1e)"
281 c.name, size, du, rel, utol, dp, pmag, ptol, extra, ok ?
"OK" :
"FAIL");
285 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
288 std::printf(
"VARMU 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)
static void configure(IbmSolver &s, const Config &c, int ox, int oy, int oz, int lnx, int lny, int lnz)