64static std::vector<double>
blobs(
int line) {
65 std::vector<double> f(
GCELLS, 0.0);
66 const double pl[3] = {10.0, 16.0, 22.0};
67 for (
int z = 0; z <
N; ++z)
68 for (
int y = 0; y <
N; ++y)
69 for (
int x = 0; x <
N; ++x) {
70 const double c[3] = {x + 0.5, y + 0.5, z + 0.5};
71 const int a = (line + 1) % 3, b = (line + 2) % 3;
73 for (
int i = 0; i < 6; ++i)
75 for (
double pb : pl) {
76 const double dl = c[line] - (i + 0.5) *
N / 6.0, da = c[a] - pa, db = c[b] - pb;
77 s += -12.0 * std::exp(-(dl * dl + da * da + db * db));
79 f[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] = s;
109static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
110 int lnx,
int lny,
int lnz,
int rank,
int size) {
111 std::vector<double> global;
113 global.assign(
GCELLS, 0.0);
114 for (
int r = 0; r < size; ++r) {
115 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
118 for (
int z = 0; z < lnz; ++z)
119 for (
int y = 0; y < lny; ++y)
120 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
N +
121 (std::size_t)(z + oz) *
N *
N],
122 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
123 (std::size_t)lnx *
sizeof(
double));
127 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
128 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
129 }
else if (rank == 0) {
130 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
131 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
132 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
134 for (
int z = 0; z < meta[5]; ++z)
135 for (
int y = 0; y < meta[4]; ++y)
136 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
N +
137 (std::size_t)(z + meta[2]) *
N *
N],
138 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
139 (std::size_t)meta[3] *
sizeof(
double));
164int main(
int argc,
char** argv) {
165 MPI_Init(&argc, &argv);
166 Kokkos::initialize(argc, argv);
169 int rank = 0, size = 1;
170 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
171 MPI_Comm_size(MPI_COMM_WORLD, &size);
173 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
N,
N,
N);
174 auto blk = dec.block(rank);
175 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
176 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
177 bool cut[3] = {
false,
false,
false};
178 for (
const auto& sz : dec.sizes())
179 for (
int a = 0; a < 3; ++a)
183 std::printf(
"CELLFORCE MPI np=%d grid %d^3 block %dx%dx%d cut axes: %s%s%s\n", size,
N,
184 lnx, lny, lnz, cut[0] ?
"x" :
"", cut[1] ?
"y" :
"", cut[2] ?
"z" :
"");
185 const std::vector<double> allFluid((std::size_t)lnx * lny * lnz, 10.0);
190 s.setAdvection(
false);
191 s.setPressureGeometry(allFluid);
195 s.initMpi(dec, MPI_COMM_WORLD);
196 }
catch (
const std::runtime_error& e) {
202 int t = threw ? 1 : 0, all = 0;
203 MPI_Allreduce(&t, &all, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
204 const bool ok = all == 1 && what.find(
"init_mpi") != std::string::npos;
206 std::printf(
" [order np=%d] set_pressure_geometry -> init_mpi %s %s\n", size,
207 threw ?
"raised" :
"was ACCEPTED (the rank-local pressure solve)",
214 const Config configs[] = {{
"forced-x", 0,
false}, {
"var-y", 1,
true}};
215 for (
const Config& c : configs) {
216 const std::vector<double> fg =
blobs(c.comp);
220 sd.initMpi(dec, MPI_COMM_WORLD);
223 for (
int it = 0; it <
STEPS; ++it)
225 std::vector<double> gu[3];
226 for (
int comp = 0; comp < 3; ++comp)
228 const std::vector<double> gp =
234 ref.setAdvection(
false);
235 ref.setPressureGeometry(std::vector<double>(
GCELLS, 10.0));
237 for (
int it = 0; it <
STEPS; ++it)
239 double du = 0, umag = 0;
240 for (
int comp = 0; comp < 3; ++comp) {
241 du = std::fmax(du,
maxAbsDiff(gu[comp], ref.getVelocity(comp)));
242 umag = std::fmax(umag,
maxAbs(ref.getVelocity(comp)));
244 const double dp =
maxAbsDiff(gp, ref.getPressure());
245 const double pmag =
maxAbs(ref.getPressure());
246 const double utol = (size == 1) ? 0.0 : std::fmax(1e-15, 1e-11 * umag);
247 const double ptol = (size == 1) ? 0.0 : std::fmax(1e-12, 1e-11 * pmag);
249 const bool ok = du <= utol && dp <= ptol && umag > 0.1;
250 std::printf(
" [%-8s np=%d] du=%.3e dp=%.3e (tol %.1e/%.1e) max|u|=%.3e max|p|=%.3e %s\n",
251 c.name, size, du, dp, utol, ptol, umag, pmag, ok ?
"OK" :
"FAIL");
255 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
258 std::printf(
"CELLFORCE 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)