69static std::vector<double>
evalT(
IbmSolver& s,
const int o[3],
const int ln[3],
bool withReg) {
70 const int e[3] = {ln[0] + 2 *
G, ln[1] + 2 *
G, ln[2] + 2 *
G};
71 const long n = (long)e[0] * e[1] * e[2];
72 const long st[3] = {1L, (long)e[0], (
long)e[0] * e[1]};
73 auto fill = [&](
CCField f,
int id) {
74 auto h = Kokkos::create_mirror_view(f);
75 for (
int z = 0; z < e[2]; ++z)
76 for (
int y = 0; y < e[1]; ++y)
77 for (
int x = 0; x < e[0]; ++x) {
79 x >=
G && x < e[0] -
G && y >=
G && y < e[1] -
G && z >=
G && z < e[2] -
G;
80 h((
long)x + (
long)y * e[0] + (
long)z * e[0] * e[1]) =
81 inner ?
fieldValue(
id, o[0] + x -
G, o[1] + y -
G, o[2] + z -
G)
82 : std::numeric_limits<double>::quiet_NaN();
84 Kokkos::deep_copy(f, h);
89 s.fillPropGhosts(mu,
true);
90 for (
int c = 0; c < 3; ++c) {
92 s.fillVelGhostsTo(v[c], c, 0,
false);
96 CCField tmp(
"fs_mpi_regtmp", n);
97 for (
int c = 0; c < 3; ++c) {
99 s.fillPropGhosts(tmp,
true);
100 reg[c] =
RegMask(
"fs_mpi_reg", n);
103 Kokkos::parallel_for(
104 "fs_mpi_reg_pack", Kokkos::RangePolicy<peclet::flow::CCExec>(0, n),
105 KOKKOS_LAMBDA(
long i) { r(i) = (t(i) != 0.0) ? 1 : 0; });
111 Kokkos::deep_copy(rs, 1.0);
112 std::vector<double> out;
113 out.reserve(3L * ln[0] * ln[1] * ln[2]);
114 for (
int c = 0; c < 3; ++c) {
124 const RegConst rr[3] = {reg[0], reg[1], reg[2]};
126 C3{e[0], e[1], e[2]},
G, 1.0,
false, rr);
129 C3{e[0], e[1], e[2]},
G, 1.0,
false);
132 auto h = Kokkos::create_mirror_view(bb);
133 Kokkos::deep_copy(h, bb);
134 for (
int z =
G; z < e[2] -
G; ++z)
135 for (
int y =
G; y < e[1] -
G; ++y)
136 for (
int x =
G; x < e[0] -
G; ++x)
137 out.push_back(h((
long)x + (
long)y * e[0] + (
long)z * e[0] * e[1]));
142int main(
int argc,
char** argv) {
143 MPI_Init(&argc, &argv);
144 Kokkos::initialize(argc, argv);
147 int rank = 0, size = 1;
148 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
149 MPI_Comm_size(MPI_COMM_WORLD, &size);
150 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
NX,
NY,
NZ);
151 const int gn[3] = {
NX,
NY,
NZ};
153 for (
int a = 0; a < 3; ++a) {
155 for (
const auto& sz : dec.sizes())
156 cut = cut || ((int)sz[a] != gn[a]);
159 const int needCut = (size >= 4) ? 2 : (size >= 2 ? 1 : 0);
161 std::printf(
"FULL_STRESS_MPI np=%d grid %dx%dx%d, %d cut axes (need >= %d)\n", size,
NX,
NY,
166 auto blk = dec.block(rank);
167 const int o[3] = {(int)blk.origin[0], (
int)blk.origin[1], (int)blk.origin[2]};
168 const int ln[3] = {(int)blk.size[0], (
int)blk.size[1], (int)blk.size[2]};
170 s.initMpi(dec, MPI_COMM_WORLD);
172 for (
int pass = 0; pass < 2; ++pass) {
173 const bool withReg = (pass == 1);
174 const std::vector<double> mine =
evalT(s, o, ln, withReg);
176 std::vector<int> counts(size), displs(size);
178 for (
int r = 0; r < size; ++r) {
179 const auto b = dec.block(r);
180 counts[r] = 3 * (int)(b.size[0] * b.size[1] * b.size[2]);
181 displs[r] = (int)total;
184 std::vector<double> all(rank == 0 ? total : 0);
185 MPI_Gatherv(mine.data(), (
int)mine.size(), MPI_DOUBLE, all.data(), counts.data(),
186 displs.data(), MPI_DOUBLE, 0, MPI_COMM_WORLD);
188 const int zo[3] = {0, 0, 0}, gl[3] = {
NX,
NY,
NZ};
190 const std::vector<double> want =
evalT(ref, zo, gl, withReg);
191 long bad = 0, nonzero = 0, nonfinite = 0;
193 for (
int r = 0; r < size; ++r) {
194 const auto b = dec.block(r);
195 const int bs[3] = {(int)b.size[0], (
int)b.size[1], (int)b.size[2]};
196 const long bn = (long)bs[0] * bs[1] * bs[2];
197 for (
int c = 0; c < 3; ++c)
198 for (
int z = 0; z < bs[2]; ++z)
199 for (
int y = 0; y < bs[1]; ++y)
200 for (
int x = 0; x < bs[0]; ++x) {
202 all[displs[r] + c * bn + x + (long)bs[0] * (y + (
long)bs[1] * z)];
203 const int gx = (int)b.origin[0] + x, gy = (
int)b.origin[1] + y,
204 gz = (int)b.origin[2] + z;
206 want[(long)c *
NX *
NY *
NZ + gx + (
long)
NX * (gy + (long)
NY * gz)];
207 if (std::memcmp(&got, &ref1,
sizeof(
double)) != 0)
209 if (!std::isfinite(got))
216 const bool ok = (bad == 0) && (nonfinite == 0) && (nonzero > total / 2);
218 " %-12s T_c vs np 1: %ld/%ld bitwise mismatches, %ld non-finite, %ld nonzero, "
220 withReg ?
"reg mask" :
"no solid", bad, total, nonfinite, nonzero,
maxAbs,
221 ok ?
"PASS" :
"FAIL");
228 MPI_Allreduce(&fail, &gfail, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
void addFullStressRhs(int c, CCField bb, CCConst rs, const CCConst(&v)[3], FaceProps fp, C3 e, int g, double wc, bool skipLoC, const RegConst(®)[3]={RegConst(), RegConst(), RegConst()})
Add rs_c · T_c(uⁿ) to the momentum RHS bb of component c over the inner cells [g, e−g)³.