18int main(
int argc,
char** argv) {
19 Kokkos::initialize(argc, argv);
22 const int g = 2, inx = 14, iny = 12, inz = 10;
23 const int ex = inx + 2 * g, ey = iny + 2 * g, ez = inz + 2 * g;
24 const std::size_t n = (std::size_t)ex * ey * ez;
25 const double dt = 0.3;
28 std::uniform_real_distribution<double> uf(-1.0, 1.0);
29 std::vector<double> hU(n), hV(n), hW(n), hP(n);
30 for (std::size_t i = 0; i < n; ++i) {
36 auto up = [&](
const char* nm, std::vector<double>& h) {
38 auto m = Kokkos::create_mirror_view(v);
39 for (std::size_t i = 0; i < n; ++i)
41 Kokkos::deep_copy(v, m);
44 DView U = up(
"U", hU), V = up(
"V", hV), W = up(
"W", hW), P = up(
"P", hP);
46 const long ninner = (long)inx * iny * inz;
47 DView resid(
"resid", ninner);
50 "fou_op", Kokkos::RangePolicy<Kokkos::DefaultExecutionSpace>(0, ninner),
51 KOKKOS_LAMBDA(
long c) {
52 const int lx = (int)(c % inx), ly = (int)((c / inx) % iny),
53 lz = (
int)(c / ((long)inx * iny));
54 const int x = lx + g, y = ly + g, z = lz + g;
57 double cC = 0, cxm = 0, cxp = 0, cym = 0, cyp = 0, czm = 0, czp = 0;
58 fou_operator(comp, x, y, z, Ua, Va, Wa, dt, cC, cxm, cxp, cym, cyp, czm, czp);
60 double aC = 0, axm = 0, axp = 0, aym = 0, ayp = 0, azm = 0, azp = 0;
61 fou_operator_aniso(comp, x, y, z, Ua, Va, Wa, dt, 1.0, 1.0, 1.0, aC, axm, axp, aym, ayp,
63 long sx = 1, sy = ex, sz = (long)ex * ey, i = (
long)x + (long)y * ex + (
long)z * sz;
64 double lhs = cC * Pa(x, y, z) + cxm * P(i - sx) + cxp * P(i + sx) + cym * P(i - sy) +
65 cyp * P(i + sy) + czm * P(i - sz) + czp * P(i + sz);
66 double rhs = dt *
advect_fou(comp, x, y, z, Ua, Va, Wa, Pa);
67 double anisoDiff = Kokkos::fabs(aC - cC) + Kokkos::fabs(axm - cxm) +
68 Kokkos::fabs(axp - cxp) + Kokkos::fabs(aym - cym) +
69 Kokkos::fabs(ayp - cyp) + Kokkos::fabs(azm - czm) +
70 Kokkos::fabs(azp - czp);
74 resid(c) = Kokkos::fabs(lhs - rhs) + anisoDiff;
76 auto hr = Kokkos::create_mirror_view(resid);
77 Kokkos::deep_copy(hr, resid);
80 for (
long c = 0; c < ninner; ++c) {
81 if (hr(c) > 1e-12 * (1 + std::fabs(hr(c))))
87 std::fprintf(stderr,
"FAIL: %ld/%ld cells operator != dt*advect_fou (max %.2e)\n", (
long)bad,
93 "[fou_operator] PASS: operator == dt*advect_fou and aniso(s=1)==fou_operator (%ld cells, "
95 ninner, Kokkos::DefaultExecutionSpace::name());
void fou_operator_aniso(int comp, int x, int y, int z, A U, A V, A W, double dt, double sx, double sy, double sz, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp)
void fou_operator(int comp, int x, int y, int z, A U, A V, A W, double dt, double &cC, double &cxm, double &cxp, double &cym, double &cyp, double &czm, double &czp)