8#include <Kokkos_Core.hpp>
16static long l3(
int x,
int y,
int z,
I3 e) {
17 return (
long)x + (
long)y * e.x + (
long)z * (
long)e.x * e.y;
26 I3 e{inner.x + 2 * g, inner.y + 2 * g, inner.z + 2 * g};
28 const std::size_t n = (std::size_t)e.x * e.y * e.z;
31 std::uniform_real_distribution<double>
uf(-1.0, 1.0);
33 for (std::size_t
i = 0;
i < n; ++
i) {
41 auto up = [&](
const char*
nm, std::vector<double>&
h) {
43 auto m = Kokkos::create_mirror_view(v);
44 for (std::size_t
i = 0;
i < n; ++
i)
46 Kokkos::deep_copy(v, m);
56 auto hp = Kokkos::create_mirror_view(phi);
57 Kokkos::deep_copy(
hp, phi);
58 auto hdo = Kokkos::create_mirror_view(
dout);
64 for (
int z = g; z < e.z - g; ++z)
65 for (
int y = g; y < e.y - g; ++y)
66 for (
int x = g; x < e.x - g; ++x) {
67 if ((((x + og.x) + (y + og.y) + (z + og.z)) & 1) !=
color)
69 long i =
l3(x, y, z, e),
sx = 1,
sy = e.x,
sz = (
long)e.x * e.y;
74 auto close = [](
double a,
double b) {
75 return std::fabs(a - b) <= 1e-10 * (1.0 + std::fabs(b));
78 for (std::size_t
i = 0;
i < n; ++
i)
81 for (
int z = g; z < e.z - g; ++z)
82 for (
int y = g; y < e.y - g; ++y)
83 for (
int x = g; x < e.x - g; ++x) {
84 long i =
l3(x, y, z, e),
sx = 1,
sy = e.x,
sz = (
long)e.x * e.y;
90 std::fprintf(
stderr,
"FAIL: %d cells differ (sweep/divergence)\n",
bad);
98 auto m = Kokkos::create_mirror_view(
phi2);
99 Kokkos::deep_copy(m,
phi2);
101 for (
int z = g; z < e.z - g; ++z)
102 for (
int y = g; y < e.y - g; ++y)
103 for (
int x = g; x < e.x - g; ++x) {
104 long i =
l3(x, y, z, e),
sx = 1,
sy = e.x,
sz = (
long)e.x * e.y;
106 double res = (s - 6.0 * m(
i)) -
hd[
i];
112 for (
int it = 0;
it < 100; ++
it)
115 if (!(r1 < 0.2 *
r0)) {
116 std::fprintf(
stderr,
"FAIL: smoother did not reduce residual (%.3e -> %.3e)\n",
r0, r1);
122 "[mac_stencils] PASS: RB-GS sweep + divergence match host; residual %.2e -> %.2e (exec: "
124 r0, r1, SExec::name());
flow — portable (Kokkos) MAC stencil operators: Red-Black Gauss-Seidel smoothers + divergence.
void divergence(SConst u, SConst v, SConst w, SField d, I3 e, int g)
void ibmFillEntry(const OV &o, int list_idx, int c_idx, float sdf_c, const float sdf_n[6], int bc_type, const float *thEx)
Kokkos::View< double *, SMem > SField
void poisSweep(SField phi, SConst d, I3 e, I3 og, int g)
static long l3(int x, int y, int z, I3 e)
int main(int argc, char **argv)