11#ifndef PECLET_FLOW_MAC_IBM_HPP
12#define PECLET_FLOW_MAC_IBM_HPP
14#include <Kokkos_Core.hpp>
22using MConst = Kokkos::View<const float*, CCMem>;
29KOKKOS_INLINE_FUNCTION
bool ibmIsCut(
float sc,
const float sn[6]) {
32 for (
int k = 0; k < 6; ++k)
45 Kokkos::View<int*, CCMem> idMap, Kokkos::View<int, CCMem> counter) {
47 Kokkos::deep_copy(space, counter, 0);
48 Kokkos::deep_copy(space, idMap, -1);
49 using MD = Kokkos::MDRangePolicy<CCExec, Kokkos::Rank<3>>;
51 "peclet::flow::ibm_build_overlay", MD(space, {g, g, g}, {ext.
x - g, ext.
y - g, ext.
z - g}),
52 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
53 const long idx = (long)lx + (
long)ly * ext.
x + (long)lz * (
long)ext.
x * ext.
y;
54 const float sc = (float)
ccSampleExt(sdf, ext, lx + off.
x, ly + off.
y, lz + off.
z);
55 const int d[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
57 for (
int k = 0; k < 6; ++k)
58 sn[k] = (
float)
ccSampleExt(sdf, ext, lx + d[k][0] + off.
x, ly + d[k][1] + off.
y,
59 lz + d[k][2] + off.
z);
62 const int slot = Kokkos::atomic_fetch_add(&counter(), 1);
64 ibmFillEntry<SCHEME>(ov, slot, (
int)idx, sc, sn, bc_type);
68 Kokkos::deep_copy(cnt, counter);
75 using MD = Kokkos::MDRangePolicy<CCExec, Kokkos::Rank<3>>;
77 "peclet::flow::ibm_volfrac", MD(space, {0, 0, 0}, {ext.
x, ext.
y, ext.
z}),
78 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
79 const long i = (long)lx + (
long)ly * ext.
x + (long)lz * (
long)ext.
x * ext.
y;
80 const double sd =
ccSampleExt(sdf, ext, lx + off.
x, ly + off.
y, lz + off.
z);
81 const double t = 0.5 + sd;
82 theta(i) = t < 0.0 ? 0.0 : (t > 1.0 ? 1.0 : t);
89 using MD = Kokkos::MDRangePolicy<CCExec, Kokkos::Rank<3>>;
91 "peclet::flow::ibm_solid", MD(space, {0, 0, 0}, {ext.
x, ext.
y, ext.
z}),
92 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
93 const long i = (long)lx + (
long)ly * ext.
x + (long)lz * (
long)ext.
x * ext.
y;
94 const double sd =
ccSampleExt(sdf, ext, lx + off.
x, ly + off.
y, lz + off.
z);
95 mask(i) = (sd < 0.0) ? 1.0 : 0.0;
102 using MD = Kokkos::MDRangePolicy<CCExec, Kokkos::Rank<3>>;
103 Kokkos::parallel_for(
104 "peclet::flow::ibm_clean", MD(space, {0, 0, 0}, {ext.
x, ext.
y, ext.
z}),
105 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
106 const long i = (long)lx + (
long)ly * ext.
x + (long)lz * (
long)ext.
x * ext.
y;
107 const float sc = (float)
ccSampleExt(sdf, ext, lx + off.
x, ly + off.
y, lz + off.
z);
108 const int d[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
110 for (
int k = 0; k < 6; ++k)
111 sn[k] = (
float)
ccSampleExt(sdf, ext, lx + d[k][0] + off.
x, ly + d[k][1] + off.
y,
112 lz + d[k][2] + off.
z);
113 const bool solid = (sc <= 0.0f);
114 m(i) = (solid ||
ibmIsCut(sc, sn)) ? 0.0 : 1.0;
124 const bool hasMask = (solidmask.extent(0) != 0);
125 using MD = Kokkos::MDRangePolicy<CCExec, Kokkos::Rank<3>>;
126 Kokkos::parallel_for(
127 "peclet::flow::ibm_rbgs", MD(space, {g, g, g}, {ext.
x - g, ext.
y - g, ext.
z - g}),
128 KOKKOS_LAMBDA(
int lx,
int ly,
int lz) {
129 if (((og.
x + lx + og.
y + ly + og.
z + lz) & 1) != color)
131 const long sx = 1, sy = ext.
x, sz = (long)ext.
x * ext.
y;
132 const long i = (long)lx + (
long)ly * ext.
x + (long)lz * sz;
133 if (hasMask && solidmask(i) > 0.5) {
137 const double ac =
AC(i);
138 if (Kokkos::fabs(ac) < 1e-30)
140 const double s = (double)AE(i) * x(i + sx) + (double)AW(i) * x(i - sx) +
141 (double)AN(i) * x(i + sy) + (double)AS(i) * x(i - sy) +
142 (double)AT(i) * x(i + sz) + (double)AB(i) * x(i - sz);
143 x(i) = (b(i) - s) / ac;
149 ibmRbgsStencilColor(x, b,
AC, AW, AE, AS, AN, AB, AT, solidmask, ext, og, g, 0);
150 ibmRbgsStencilColor(x, b,
AC, AW, AE, AS, AN, AB, AT, solidmask, ext, og, g, 1);
flow — portable (Kokkos) Robust-Scaled cut-cell IBM primitives + per-cut-cell overlay build.
flow — portable (Kokkos) cut-cell pressure-operator face openness from an SDF.
int buildIbmOverlay(CCConst sdf, C3 ext, int g, Off3 off, int bc_type, const IbmOverlay &ov, Kokkos::View< int *, CCMem > idMap, Kokkos::View< int, CCMem > counter)
void ibmSolidMask(CCField mask, CCConst sdf, C3 ext, Off3 off)
void ibmCleanFluidMask(CCField m, CCConst sdf, C3 ext, Off3 off)
void ibmRbgsStencilColor(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, int color)
bool ibmIsCut(float sc, const float sn[6])
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)
Kokkos::View< double *, CCMem > CCField
Kokkos::DefaultExecutionSpace CCExec
Kokkos::View< const float *, CCMem > MConst
double ccSampleExt(CCConst sdf, C3 ext, double x, double y, double z)
Kokkos::View< const double *, CCMem > CCConst
void ibmVolfrac(CCField theta, CCConst sdf, C3 ext, Off3 off)
static constexpr double AC