15#include <Kokkos_Core.hpp>
18#include "peclet/core/common/types.hpp"
19#include "peclet/core/decomp/block_decomposer.hpp"
20#include "peclet/core/halo/grid_halo_topology.hpp"
22using peclet::core::IVec;
32static double source(
int gx,
int gy,
int gz, IVec<3> gs) {
33 return std::sin(2.0 * M_PI * gx / gs[0]) +
34 std::cos(4.0 * M_PI * gy / gs[1]) * std::sin(2.0 * M_PI * gz / gs[2]);
38 auto hb = Kokkos::create_mirror_view(b);
39 for (std::size_t c = 0; c < b.extent(0); ++c)
41 for (
int z =
G; z < ext.
z -
G; ++z)
42 for (
int y =
G; y < ext.
y -
G; ++y)
43 for (
int x =
G; x < ext.
x -
G; ++x)
44 hb((
long)x + (
long)y * ext.
x + (
long)z * (
long)ext.
x * ext.
y) =
45 source(x -
G + og.x, y -
G + og.y, z -
G + og.z, gs);
46 Kokkos::deep_copy(b, hb);
49int main(
int argc,
char** argv) {
50 MPI_Init(&argc, &argv);
51 Kokkos::initialize(argc, argv);
52 int fail = 0, size = 1, rank = 0;
54 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
55 MPI_Comm_size(MPI_COMM_WORLD, &size);
56 IVec<3> gs{32, 32, 32};
59 const std::size_t n = (std::size_t)ext.x * ext.y * ext.z;
61 FPV AC(
"AC", n), AW(
"AW", n), AE(
"AE", n), AS(
"AS", n), AN(
"AN", n), AB(
"AB", n), AT(
"AT", n);
63 for (
FPV* p : {&AW, &AE, &AS, &AN, &AB, &AT})
64 Kokkos::deep_copy(*p, (
float)(-
BETA));
67 CCField th(
"th", n), solid(
"solid", n), clean(
"clean", n);
68 Kokkos::deep_copy(th, 1.0);
69 Kokkos::deep_copy(solid, 0.0);
70 Kokkos::deep_copy(clean, 1.0);
74 Kokkos::deep_copy(x, 0.0);
76 auto hx = Kokkos::create_mirror_view(x);
77 Kokkos::deep_copy(hx, x);
82 vmg.initMpi(gs[0], gs[1], gs[2],
NLEV, MPI_COMM_WORLD);
87 ref.init(gs[0], gs[1], gs[2],
NLEV);
88 const C3 re{(int)gs[0] + 2 *
G, (
int)gs[1] + 2 *
G, (int)gs[2] + 2 *
G}, ro{0, 0, 0};
92 for (
int z =
G; z < l0.
ext.
z -
G; ++z)
93 for (
int y =
G; y < l0.
ext.
y -
G; ++y)
94 for (
int x =
G; x < l0.
ext.
x -
G; ++x) {
95 const int gx = x -
G + l0.
og.
x, gy = y -
G + l0.
og.
y, gz = z -
G + l0.
og.
z;
96 const double a = hx((
long)x + (
long)y * l0.
ext.
x + (
long)z * (
long)l0.
ext.
x * l0.
ext.
y);
98 hr((
long)(gx +
G) + (
long)(gy +
G) * re.x + (
long)(gz +
G) * (
long)re.x * re.y);
99 const double d = std::fabs(a - rr);
103 if (maxdiff > 1e-11) {
105 std::fprintf(stderr,
"[rank %d] max|distributed - single-rank VelocityMG| = %.3e\n", rank,
107 }
else if (rank == 0)
108 std::printf(
" max|distributed - single-rank| = %.3e (np=%d)\n", maxdiff, size);
111 MPI_Allreduce(&fail, &totalFail, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
114 std::printf(
"OK (np=%d): production VelocityMG V-cycle distributed == single-rank\n", size);
116 std::fprintf(stderr,
"FAILED (np=%d): %d ranks differ\n", size, totalFail);
120 return totalFail == 0 ? 0 : 1;
void setFineStencil(FPC AC, FPC AW, FPC AE, FPC AS, FPC AN, FPC AB, FPC AT)
int solve(CCConst b, CCField x, int nvc, int pre, int post, int bottom, double tol=0.0, Comm comm=nullComm(), double resTol=0.0)
void setStaircase(CCConst theta0, CCConst solid0, CCConst resmask0, double nu_dt, double idiag, double thresh)
flow — portable (Kokkos) velocity (momentum) multigrid for the IBM diffusion solve: the STAIRCASE coa...
Kokkos::View< const double *, CCMem > CCConst
Kokkos::View< const MReal *, CCMem > FPC
Kokkos::View< double *, CCMem > CCField
Kokkos::View< MReal *, CCMem > FPV
static HostVec setupAndSolve(CutcellMG &mg, C3 ext, C3 og, int nx, int ny, int nz, bool collective, int *iters)
static constexpr int NLEV
static constexpr double IDIAG
static constexpr double AC
static constexpr double BETA
static constexpr int NVCYC
static void fillSource(CCField b, C3 ext, C3 og, IVec< 3 > gs)
static double source(int gx, int gy, int gz, IVec< 3 > gs)