38 const double R = std::cbrt(3.0 * 0.125 / (4.0 *
M_PI)) *
N, c = 0.5 *
N;
39 std::vector<double> sdf((std::size_t)
N *
N *
N);
40 for (
int z = 0; z <
N; ++z)
41 for (
int y = 0; y <
N; ++y)
42 for (
int x = 0; x <
N; ++x) {
43 const double dx = x + 0.5 - c, dy = y + 0.5 - c, dz = z + 0.5 - c;
44 sdf[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] =
45 std::sqrt(dx * dx + dy * dy + dz * dz) - R;
64 Kokkos::initialize(
argc, argv);
65 int fail = 0, size = 1, rank = 0;
73 peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
N,
N,
N, 0, 1.05);
74 auto blk =
dec.block(rank);
75 const int org[3] = {(int)blk.origin[0], (
int)blk.origin[1], (int)blk.origin[2]};
76 const int ln[3] = {(int)blk.size[0], (
int)blk.size[1], (int)blk.size[2]};
77 std::vector<double>
lsdf((std::size_t)
ln[0] *
ln[1] *
ln[2]);
78 for (
int z = 0; z <
ln[2]; ++z)
79 for (
int y = 0; y <
ln[1]; ++y)
80 for (
int x = 0; x <
ln[0]; ++x)
81 lsdf[(std::size_t)x + (std::size_t)y *
ln[0] + (std::size_t)z *
ln[0] *
ln[1]] =
82 gsdf[(std::size_t)(x + org[0]) + (std::size_t)(y + org[1]) *
N +
83 (std::size_t)(z + org[2]) *
N *
N];
92 for (
int k = 0; k <
STEPS; ++k) {
94 std::vector<double> g = acc.core().gamma();
95 int head[2] = {(int)g.size(), (int)acc.core().status()};
98 std::vector<double> g0 = g;
99 g0.resize((std::size_t)
head0[0]);
102 std::memcmp(g.data(), g0.data(),
sizeof(
double) * g.size()) != 0)
107 std::printf(
" distributed: status %s, residual %.6e, %d columns, %d restarts\n",
108 acc.statusName(), acc.residual(), acc.numColumns(), acc.numRestarts());
114 std::vector<std::vector<double>>
ug(3);
115 for (
int c = 0; c < 3; ++c) {
117 std::vector<int>
meta(6 * size);
118 int mine[6] = {org[0], org[1], org[2],
ln[0],
ln[1],
ln[2]};
121 int nloc = (int)loc.size();
123 std::vector<double> all;
126 for (
int r = 0; r < size; ++r) {
130 all.resize((std::size_t)off);
135 ug[c].assign((std::size_t)
N *
N *
N, 0.0);
136 for (
int r = 0; r < size; ++r) {
137 const int* m = &
meta[6 * r];
138 for (
int z = 0; z < m[5]; ++z)
139 for (
int y = 0; y < m[4]; ++y)
140 for (
int x = 0; x < m[3]; ++x)
141 ug[c][(std::size_t)(x + m[0]) + (std::size_t)(y + m[1]) *
N +
142 (std::size_t)(z + m[2]) *
N *
N] =
143 all[(std::size_t)
displs[r] + (std::size_t)x + (std::size_t)y * m[3] +
144 (std::size_t)z * m[3] * m[4]];
153 ref.setSolid(
gsdf,
true);
155 for (
int k = 0; k <
STEPS; ++k)
157 std::printf(
" single-rank: status %s, residual %.6e (distributed %.6e)\n", acc.statusName(),
160 for (
int c = 0; c < 3; ++c) {
161 const std::vector<double> u1 = ref.getVelocity(c);
162 double du = 0.0, umax = 0.0;
163 for (std::size_t i = 0; i < u1.size(); ++i) {
164 du = std::max(du, std::fabs(
ug[c][i] - u1[i]));
165 umax = std::max(umax, std::fabs(u1[i]));
167 const double rel = umax > 0.0 ? du / umax : du;
168 worst = std::max(worst, rel);
169 std::printf(
" component %d: max|u_np - u_1| / max|u_1| = %.3e (max|u_1| = %.6e)\n", c, rel,
172 std::printf(
" gamma / window / status mismatches across ranks: %ld\n", gm);
173 if (worst > 1e-8 || gm != 0)
181 std::printf(
"OK (np=%d): distributed Anderson march == single-rank, gamma identical\n", size);
183 std::fprintf(
stderr,
"FAILED (np=%d)\n", size);
void setBodyForce(double fx, double fy, double fz)
Body force per unit volume, in the caller's units (e.g. a mean pressure gradient, or rho*g).