7#include <Kokkos_Core.hpp>
19 const double dx = 1.0,
dy = 1.0,
dz = 1.0;
20 const std::size_t n = (std::size_t)ext.x * ext.y * ext.z;
21 auto IDX = [&](
int x,
int y,
int z) {
22 return (std::size_t)x + (std::size_t)y * ext.x + (std::size_t)z * (std::size_t)ext.x * ext.y;
26 std::vector<double>
hsdf(n);
27 const double cx = 8,
cy = 8,
cz = 8, R = 5;
28 for (
int z = 0; z < ext.z; ++z)
29 for (
int y = 0; y < ext.y; ++y)
30 for (
int x = 0; x < ext.x; ++x)
32 std::sqrt((x -
cx) * (x -
cx) + (y -
cy) * (y -
cy) + (z -
cz) * (z -
cz)) - R;
34 auto upC = [&](
const char*
nm, std::vector<double>&
h) {
36 auto m = Kokkos::create_mirror_view(v);
37 for (std::size_t
i = 0;
i < n; ++
i)
39 Kokkos::deep_copy(v, m);
43 std::vector<double> o(n);
44 auto m = Kokkos::create_mirror_view(v);
45 Kokkos::deep_copy(m, v);
46 for (std::size_t
i = 0;
i < n; ++
i)
51 CCField sdf =
upC(
"sdf",
hsdf), ox(
"ox", n), oy(
"oy", n), oz(
"oz", n);
56 auto close = [](
double a,
double b) {
57 return std::fabs(a - b) <= 1e-10 * (1.0 + std::fabs(b));
61 auto sampleH = [&](
double X,
double Y,
double Z) {
62 double fx = std::floor(
X),
fy = std::floor(
Y),
fz = std::floor(
Z);
65 auto cl = [&](
int v,
int nn) {
return v < 0 ? 0 : (v >=
nn ?
nn - 1 : v); };
76 return c0 * (1 -
wz) + c1 *
wz;
78 auto faceH = [&](
double X,
double Y,
double Z,
int type) {
83 return ccFractionCore(
sd,
sampleH(
X + e,
Y,
Z),
sampleH(
X - e,
Y,
Z),
sampleH(
X,
Y + e,
Z),
84 sampleH(
X,
Y - e,
Z),
sampleH(
X,
Y,
Z + e),
sampleH(
X,
Y,
Z - e), type,
87 for (
int z = 0; z < ext.z; ++z)
88 for (
int y = 0; y < ext.y; ++y)
89 for (
int x = 0; x < ext.x; ++x) {
90 std::size_t
i =
IDX(x, y, z);
99 std::fprintf(
stderr,
"FAIL: %d openness faces differ\n",
bad);
105 for (std::size_t
i = 0;
i < n; ++
i) {
107 if (v > 1e-9 && v < 1 - 1e-9)
109 else if (v > 1 - 1e-9)
116 std::vector<double>
allf(n, 100.0),
alls(n, -100.0);
120 for (std::size_t
i = 0;
i < n; ++
i)
125 for (std::size_t
i = 0;
i < n; ++
i)
129 std::fprintf(
stderr,
"FAIL: all-fluid/all-solid property\n");
135 "[mac_cutcell] PASS: openness matches host (%d cut / %d open / %d closed x-faces) + "
136 "properties (exec: %s)\n",
flow — portable (Kokkos) cut-cell pressure-operator face openness from an SDF.
double ccFractionCore(double sd, double sxp, double sxm, double syp, double sym, double szp, double szm, int type, double dx, double dy, double dz)
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 *, CCMem > CCField
void buildOpenness(CCField ox, CCField oy, CCField oz, CCConst sdf, C3 ext, double dx, double dy, double dz, int order=1)
int main(int argc, char **argv)
static constexpr double F