64 int lnz,
bool trilinear =
false) {
65 const double muRatio = ratio / 10.0;
66 s.setDt(1e4 * (ratio > 1.0 ? ratio / muRatio : 1.0));
67 for (
int f = 2; f < 4; ++f)
68 s.setDomainBc(f, 1, 0.0, 0.0, 0.0);
71 const std::size_t n = (std::size_t)lnx * lny * lnz;
72 s.setPressureGeometry(std::vector<double>(n, 1.0));
73 std::vector<double> c(n);
74 for (
int z = 0; z < lnz; ++z)
75 for (
int y = 0; y < lny; ++y)
76 for (
int x = 0; x < lnx; ++x)
77 c[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] =
83 s.setAdvection(
false);
85 s.setPressureVcycleSymmetric(
false);
91 s.setPressureChebyshev(
true,
MAXIT,
RTOL);
92 for (
int k = 0; k < 3; ++k) {
93 std::vector<double> v(n);
94 for (
int z = 0; z < lnz; ++z)
95 for (
int y = 0; y < lny; ++y)
96 for (
int x = 0; x < lnx; ++x)
97 v[(std::size_t)x + (std::size_t)y * lnx + (std::size_t)z * lnx * lny] =
98 1e-12 *
noiseAt(k, x + ox, y + oy, z + oz);
102 for (
int k = 0; k <
STEPS; ++k) {
105 r.lastTrue = s.lastPressureTrueResidual();
106 r.maxTrue = std::fmax(r.maxTrue, r.lastTrue);
108 r.count = s.numPressureUnconvergedSolves();
120int main(
int argc,
char** argv) {
121 MPI_Init(&argc, &argv);
122 Kokkos::initialize(argc, argv);
125 int rank = 0, size = 1;
126 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
127 MPI_Comm_size(MPI_COMM_WORLD, &size);
128 auto dec = peclet::flow::CutcellMG::decomposition(
static_cast<std::size_t
>(size),
N,
N,
N);
129 auto blk = dec.block(rank);
130 const int ox = (int)blk.origin[0], oy = (
int)blk.origin[1], oz = (int)blk.origin[2];
131 const int lnx = (int)blk.size[0], lny = (
int)blk.size[1], lnz = (int)blk.size[2];
133 std::printf(
"CG GUARD MPI np=%d grid %d^3 block %dx%dx%d rtol %.0e cap %d\n", size,
N,
135 auto check = [&](
bool ok,
const char* what,
const Result& r) {
136 int all = 0, mine = ok ? 1 : 0;
137 MPI_Allreduce(&mine, &all, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD);
139 std::printf(
" %-44s count %ld last true %.3e max true %.3e %s\n", what, r.count,
140 r.lastTrue, r.maxTrue, all ?
"OK" :
"FAIL");
141 fails += all ? 0 : 1;
145 s.initMpi(dec, MPI_COMM_WORLD);
146 const Result r =
run(s,
kFcg, 1e5, ox, oy, oz, lnx, lny, lnz,
true);
149 check(r.count >= 1 &&
same,
"G1 FCG ratio 1e5 trilinear: flagged, same", r);
153 s.initMpi(dec, MPI_COMM_WORLD);
154 const Result r =
run(s,
kCheb, 1e4, ox, oy, oz, lnx, lny, lnz);
156 "G2 Chebyshev ratio 1e4: silent", r);
160 s.initMpi(dec, MPI_COMM_WORLD);
161 const Result r =
run(s,
kPcg, 1.0, ox, oy, oz, lnx, lny, lnz);
162 check(r.count == 0 && r.maxTrue <= 1.0 &&
sameOnAll(r.maxTrue, MPI_COMM_WORLD),
163 "G3 PCG uniform rho: silent, true <= tol", r);
167 s.initMpi(dec, MPI_COMM_WORLD);
168 const Result r =
run(s,
kFcg, 1e4, ox, oy, oz, lnx, lny, lnz);
170 "G5 FCG ratio 1e4 SPD V-cycle: silent", r);
174 for (
int k = 0; k < 2; ++k) {
176 const Result r = k == 0 ?
run(s,
kFcg, 1e5, 0, 0, 0,
N,
N,
N,
true)
178 const bool ok = k == 0 ? r.count >= 1 : (r.count == 0 && r.maxTrue <= 1.0);
179 std::printf(
" %-44s count %ld last true %.3e max true %.3e %s\n",
180 k == 0 ?
"G4 single-rank FCG ratio 1e5 trilinear: flagged"
181 :
"G4 single-rank PCG uniform rho: silent",
182 r.count, r.lastTrue, r.maxTrue, ok ?
"OK" :
"FAIL");
187 MPI_Bcast(&
fails, 1, MPI_INT, 0, MPI_COMM_WORLD);
189 std::printf(
fails ?
"FAILED (%d)\n" :
"OK\n",
fails);
193 return fails ? 1 : 0;
static Result run(IbmSolver &s, Driver d, double ratio, int ox, int oy, int oz, int lnx, int lny, int lnz, bool trilinear=false)