20 Kokkos::initialize(
argc, argv);
24 C3 inner{18, 14, 10}, e{inner.x + 2 * g, inner.y + 2 * g, inner.z + 2 * g}, og{0, 0, 0};
25 const std::size_t n = (std::size_t)e.x * e.y * e.z;
28 std::uniform_real_distribution<double>
uf(-1.0, 1.0);
29 std::uniform_real_distribution<float>
uac(3.0f, 7.0f),
uoff(-1.0f, 1.0f),
u01(0.0f, 1.0f);
30 std::vector<double>
hx(n), hb(n),
hmask(n);
32 for (std::size_t i = 0; i < n; ++i) {
35 hmask[i] = (
u01(rng) < 0.2f) ? 1.0 : 0.0;
44 auto upd = [&](
const char*
nm, std::vector<double>& h) {
46 auto m = Kokkos::create_mirror_view(v);
47 for (std::size_t i = 0; i < n; ++i)
49 Kokkos::deep_copy(v, m);
52 auto upf = [&](
const char*
nm, std::vector<float>& h) {
53 Kokkos::View<float*, CCMem> v(
nm, n);
54 auto m = Kokkos::create_mirror_view(v);
55 for (std::size_t i = 0; i < n; ++i)
57 Kokkos::deep_copy(v, m);
61 std::vector<double> o(n);
62 auto m = Kokkos::create_mirror_view(v);
63 Kokkos::deep_copy(m, v);
64 for (std::size_t i = 0; i < n; ++i)
73 ibmRbgsSweep(x, b,
AC, AW, AE, AS, AN, AB, AT, mask, e, og, g);
77 std::vector<double>
rx =
hx;
79 for (
int z = g; z < e.z - g; ++z)
80 for (
int y = g; y < e.y - g; ++y)
81 for (
int xx = g;
xx < e.x - g; ++
xx) {
82 if (((og.x +
xx + og.y + y + og.z + z) & 1) !=
color)
84 long i =
l3(
xx, y, z, e),
sx = 1, sy = e.x, sz = (
long)e.x * e.y;
90 if (std::fabs(
ac) < 1e-30)
95 rx[i] = (hb[i] - s) /
ac;
97 auto close = [](
double a,
double b2) {
98 return std::fabs(a -
b2) <= 1e-9 * (1.0 + std::fabs(
b2));
101 for (std::size_t i = 0; i < n; ++i)
105 std::fprintf(
stderr,
"FAIL: %d RB-GS cells differ\n",
bad);
110 std::vector<float>
lc(n, 6.f), lo(n, -1.f);
118 for (
int z = g; z < e.z - g; ++z)
119 for (
int y = g; y < e.y - g; ++y)
120 for (
int xx = g;
xx < e.x - g; ++
xx) {
121 long i =
l3(
xx, y, z, e),
sx = 1, sy = e.x, sz = (
long)e.x * e.y;
122 double s = m[i +
sx] + m[i -
sx] + m[i + sy] + m[i - sy] + m[i + sz] + m[i - sz];
123 double res = (6.0 * m[i] - s) - hb[i];
129 for (
int it = 0; it < 100; ++it)
130 ibmRbgsSweep(px, b,
LC,
LW,
LE,
LS,
LN,
LB,
LT,
noMask, e, og, g);
132 if (!(r1 < 0.2 * r0)) {
133 std::fprintf(
stderr,
"FAIL: IBM smoother residual %.3e -> %.3e\n", r0, r1);
138 std::vector<double>
allf(n, 10.0),
alls(n, -10.0);
143 for (std::size_t i = 0; i < n; ++i)
148 for (std::size_t i = 0; i < n; ++i)
153 for (std::size_t i = 0; i < n; ++i)
158 for (std::size_t i = 0; i < n; ++i)
161 if (
bad && !status) {
162 std::fprintf(
stderr,
"FAIL: volfrac/mask property\n");
168 "[mac_ibm] PASS: variable-coeff RB-GS matches host; Laplacian resid %.2e -> %.2e; "
169 "volfrac/mask ok (exec: %s)\n",
170 r0, r1, CCExec::name());
void ibmVolfrac(CCField theta, CCConst sdf, C3 ext, Off3 off, bool aniso=false, double hpx=1.0, double hpy=1.0, double hpz=1.0, double wx=1.0, double wy=1.0, double wz=1.0)
void ibmRbgsSweep(CCField x, CCConst b, MConst AC, MConst AW, MConst AE, MConst AS, MConst AN, MConst AB, MConst AT, CCConst solidmask, C3 ext, C3 og, int g)