28int main(
int argc,
char** argv) {
29 Kokkos::initialize(argc, argv);
33 const int ix0 = ghost, iy0 = ghost, iz0 = ghost;
34 const int inx = 16, iny = 12, inz = 10;
35 const int ex = inx + 2 * ghost, ey = iny + 2 * ghost, ez = inz + 2 * ghost;
36 const std::size_t n = (std::size_t)ex * ey * ez;
39 std::uniform_real_distribution<double> uf(-1.0, 1.0);
40 std::vector<double> hU(n), hV(n), hW(n), hP(n);
41 for (std::size_t i = 0; i < n; ++i) {
48 auto up = [&](
const char* nm, std::vector<double>& h) {
50 auto m = Kokkos::create_mirror_view(v);
51 for (std::size_t i = 0; i < n; ++i)
53 Kokkos::deep_copy(v, m);
56 DView U = up(
"U", hU), V = up(
"V", hV), W = up(
"W", hW), P = up(
"P", hP);
58 const long ninner = (long)inx * iny * inz;
59 DView outTVD(
"outTVD", ninner), outFOU(
"outFOU", ninner);
62 "advect", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, ninner),
63 KOKKOS_LAMBDA(
long c) {
64 const int lx = (int)(c % inx), ly = (int)((c / inx) % iny),
65 lz = (
int)(c / ((long)inx * iny));
66 const int x = lx + ix0, y = ly + iy0, z = lz + iz0;
69 outTVD(c) =
advect(comp, x, y, z, Ua, Va, Wa, Pa);
70 outFOU(c) =
advect_fou(comp, x, y, z, Ua, Va, Wa, Pa);
73 auto hT = Kokkos::create_mirror_view(outTVD);
74 Kokkos::deep_copy(hT, outTVD);
75 auto hF = Kokkos::create_mirror_view(outFOU);
76 Kokkos::deep_copy(hF, outFOU);
80 HostAcc Uh{hU.data(), ex, ey}, Vh{hV.data(), ex, ey}, Wh{hW.data(), ex, ey},
81 Ph{hP.data(), ex, ey};
82 auto close = [](
double a,
double b) {
return std::fabs(a - b) <= 1e-9 * (1.0 + std::fabs(b)); };
83 for (
long c = 0; c < ninner; ++c) {
84 const int lx = (int)(c % inx), ly = (int)((c / inx) % iny), lz = (
int)(c / ((long)inx * iny));
85 const int x = lx + ix0, y = ly + iy0, z = lz + iz0;
86 const double rT =
advect(comp, x, y, z, Uh, Vh, Wh, Ph);
87 const double rF =
advect_fou(comp, x, y, z, Uh, Vh, Wh, Ph);
88 if (!close(hT(c), rT) || !close(hF(c), rF))
92 std::fprintf(stderr,
"FAIL: %d/%ld advection cells differ\n", bad, ninner);
95 std::printf(
"[advection] PASS: %ld cells, Koren-TVD + FOU match host (exec: %s)\n", ninner,
96 Kokkos::DefaultExecutionSpace::name());