84 int oy,
int oz,
int lnx,
int lny,
int lnz) {
88 s.setBodyForce(
F, 0, 0);
89 s.setAdvection(
false);
90 s.setVelocityIterations(60);
91 s.setPressureLevels(4);
92 s.setPressurePcg(
true, 200, 1e-9);
93 s.setSolid(lsdf,
true);
95 s.setPropertyMode(
true,
true);
96 s.setField(
"mu",
blockOf(
muAt, ox, oy, oz, lnx, lny, lnz));
97 s.exchangeField(
"mu");
100 s.setDensityMode(
true);
101 s.setField(
"rho",
blockOf(
rhoAt, ox, oy, oz, lnx, lny, lnz));
102 s.exchangeField(
"rho");
105 s.setPorousContinuity(
true);
106 s.setField(
"eps",
blockOf(
epsAt, ox, oy, oz, lnx, lny, lnz));
107 s.exchangeField(
"eps");
110 s.addScalar(
"c", 0.05, 1, 40);
112 s.exchangeField(
"c");
119 s.addScalar(
"c", 0.1, 1, 40);
122 s.setScalarBc(
"c", 0, 2, 1.0);
123 s.setScalarBc(
"c", 1, 2, 0.0);
124 s.exchangeField(
"c");
130static std::vector<double>
gatherGlobal(
const std::vector<double>& local,
int ox,
int oy,
int oz,
131 int lnx,
int lny,
int lnz,
int rank,
int size) {
132 std::vector<double> global;
134 global.assign((std::size_t)
N *
N *
N, 0.0);
135 for (
int r = 0; r < size; ++r) {
136 int meta[6] = {ox, oy, oz, lnx, lny, lnz};
139 for (
int z = 0; z < lnz; ++z)
140 for (
int y = 0; y < lny; ++y)
141 std::memcpy(&global[(std::size_t)ox + (std::size_t)(y + oy) *
N +
142 (std::size_t)(z + oz) *
N *
N],
143 &local[(std::size_t)y * lnx + (std::size_t)z * lnx * lny],
144 (std::size_t)lnx *
sizeof(
double));
148 MPI_Send(meta, 6, MPI_INT, 0, 100 + r, MPI_COMM_WORLD);
149 MPI_Send(local.data(), (
int)local.size(), MPI_DOUBLE, 0, 200 + r, MPI_COMM_WORLD);
150 }
else if (rank == 0) {
151 MPI_Recv(meta, 6, MPI_INT, r, 100 + r, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
152 std::vector<double> buf((std::size_t)meta[3] * meta[4] * meta[5]);
153 MPI_Recv(buf.data(), (
int)buf.size(), MPI_DOUBLE, r, 200 + r, MPI_COMM_WORLD,
155 for (
int z = 0; z < meta[5]; ++z)
156 for (
int y = 0; y < meta[4]; ++y)
157 std::memcpy(&global[(std::size_t)meta[0] + (std::size_t)(y + meta[1]) *
N +
158 (std::size_t)(z + meta[2]) *
N *
N],
159 &buf[(std::size_t)y * meta[3] + (std::size_t)z * meta[3] * meta[4]],
160 (std::size_t)meta[3] *
sizeof(
double));
167static double relErr(
const std::vector<double>& a,
const std::vector<double>& b) {
168 double md = 0, mb = 0;
169 for (std::size_t i = 0; i < b.size(); ++i) {
170 md = std::max(md, std::fabs(a[i] - b[i]));
171 mb = std::max(mb, std::fabs(b[i]));
173 return md / (mb + 1e-300);
176int main(
int argc,
char** argv) {
177 MPI_Init(&argc, &argv);
178 Kokkos::initialize(argc, argv);
181 int rank = 0, size = 1;
182 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
183 MPI_Comm_size(MPI_COMM_WORLD, &size);
184 const std::vector<double> gsdf =
packingSdf();
188 const peclet::core::decomp::BlockDecomposer<3> dec =
189 peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
N,
N,
N);
190 auto blk = dec.block(rank);
191 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
192 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
193 std::vector<double> lsdf((std::size_t)lnx * lny * lnz);
194 for (
int z = 0; z < lnz; ++z)
195 for (
int y = 0; y < lny; ++y)
196 for (
int x = 0; x < lnx; ++x)
197 lsdf[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] =
198 gsdf[(std::size_t)(x + ox) + (std::size_t)(y + oy) *
N +
199 (std::size_t)(z + oz) *
N *
N];
201 const Config configs[] = {{
"varmu",
true,
false,
false,
false,
false},
202 {
"varrho",
false,
true,
false,
false,
false},
203 {
"porous",
false,
false,
true,
false,
false},
204 {
"scalar",
false,
false,
false,
true,
false},
205 {
"scalarbc",
false,
false,
false,
false,
true}};
207 for (
const Config& c : configs) {
210 sd.initMpi(
N,
N,
N, MPI_COMM_WORLD);
211 configure(sd, c, lsdf, ox, oy, oz, lnx, lny, lnz);
212 for (
int it = 0; it <
STEPS; ++it)
215 std::vector<double> gc;
216 if (c.scalar || c.scalarBc)
220 double eu = -1, ec = -1;
224 for (
int it = 0; it <
STEPS; ++it)
226 eu =
relErr(gu, ref.getVelocity(0));
227 const bool hasC = c.scalar || c.scalarBc;
229 ec =
relErr(gc, ref.getField(
"c"));
230 const double tol = (size == 1) ? 1e-12 : 5e-5;
231 const bool ok = eu <= tol && (!hasC || ec <= tol);
232 std::printf(
" [%-8s np=%d] u rel=%.3e%s tol=%.0e %s\n", c.name, size, eu,
233 hasC ? (std::string(
" c rel=") + std::to_string(ec)).c_str() :
"", tol,
238 MPI_Bcast(&fail, 1, MPI_INT, 0, MPI_COMM_WORLD);
241 std::printf(
"MULTIPHYSICS MPI (np=%d): %s\n", size, fail ?
"FAIL" :
"PASS");
static std::vector< double > blockOf(Fn f, int ox, int oy, int oz, int lnx, int lny, int lnz)
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, const std::vector< double > &lsdf, int ox, int oy, int oz, int lnx, int lny, int lnz)