23#include <Kokkos_Core.hpp>
34 std::fprintf(stderr, "CHECK failed: %s\n at %s:%d\n", #cond, __FILE__, __LINE__); \
40constexpr double U = 1.0,
R = 4.3;
45 std::vector<double> sdf((std::size_t)
NX *
NY *
NZ);
46 const double cy = 0.5 * (
NY - 1), cz = 0.5 * (
NZ - 1);
47 for (
int z = 0; z <
NZ; ++z)
48 for (
int y = 0; y <
NY; ++y)
49 for (
int x = 0; x <
NX; ++x) {
50 const double dx = x - cx, dy = y - cy, dz = z - cz;
51 sdf[(std::size_t)x + (std::size_t)y *
NX + (std::size_t)z *
NX *
NY] =
52 std::sqrt(dx * dx + dy * dy + dz * dz) -
R;
62 s.setAdvection(
false);
63 s.setVelocityIterations(200);
64 s.setVelocityResidualTolerance(1e-10);
65 s.setPressureLevels(3);
66 s.setPressurePcg(
true,
PMAXIT, 1e-10);
67 s.setDomainBc(0, 2,
U, 0.0, 0.0);
68 s.setDomainBc(1, 3, 0.0, 0.0, 0.0);
69 for (
int f = 2;
f < 6; ++
f)
70 s.setDomainBc(f, 1, 0.0, 0.0, 0.0);
80Result
run(
double cx,
bool solid,
bool outflowOpCoeff =
true) {
83 s.setOutflowOperatorCoefficient(outflowOpCoeff);
87 s.setPressureGeometry(std::vector<double>((std::size_t)
NX *
NY *
NZ, 1e30));
91 r.iters =
s.lastPressureIterations();
92 r.divp =
s.maxOpenDivergenceProjected();
101bool sealedPocketRejected() {
104 std::vector<double>
sdf((std::size_t)
NX *
NY *
NZ, -1.0);
105 const int py =
NY / 2, pz =
NZ / 2;
106 sdf[(std::size_t)0 + (std::size_t)py *
NX + (std::size_t)pz *
NX *
NY] = 1.0;
107 for (
int x = 4;
x <
NX; ++
x)
108 for (
int z = 0;
z <
NZ; ++
z)
109 for (
int y = 0;
y <
NY; ++
y)
110 sdf[(std::size_t)
x + (std::size_t)y *
NX + (std::size_t)
z *
NX *
NY] = 1.0;
112 s.setSolid(sdf,
true);
113 }
catch (
const std::exception& e) {
114 std::printf(
"[openbc-solid] sealed inlet pocket rejected: %s\n",
e.what());
121int main(
int argc,
char** argv) {
122 Kokkos::initialize(argc, argv);
129 const char*
fmt =
"[openbc-solid] staggered %-26s iters %3ld projected max|div| %.3e\n";
130 std::printf(
fmt,
"all-fluid duct:", empty.iters, empty.divp);
131 std::printf(
fmt,
"sphere clear of the faces:", clear.iters, clear.divp);
132 std::printf(
fmt,
"sphere cutting the OUTLET:", cutOut.iters, cutOut.divp);
133 std::printf(
fmt,
"sphere cutting the INLET:", cutIn.iters, cutIn.divp);
135 const Result all[4] = {empty, clear, cutOut, cutIn};
136 for (
const Result& r : all) {
138 CHECK(r.divp < 1e-7);
146 "[openbc-solid] staggered %-26s iters %3ld projected max|div| %.3e (the defect)\n",
147 "OUTLET, literal-1.0 row:", ablated.iters, ablated.divp);
148 CHECK(ablated.divp > 1e-4);
150 CHECK(sealedPocketRejected<peclet::flow::IbmSolver>());
168 const Result cEmpty =
run<Colo>(0.0,
false);
171 const Result cCutIn =
run<Colo>(-0.5,
true);
172 const char* cfmt =
"[openbc-solid] collocated %-26s iters %3ld max|div| %.3e\n";
173 std::printf(cfmt,
"all-fluid duct:", cEmpty.iters, cEmpty.divp);
174 std::printf(cfmt,
"sphere clear of the faces:", cClear.iters, cClear.divp);
175 std::printf(cfmt,
"sphere cutting the OUTLET:", cCutOut.iters, cCutOut.divp);
176 std::printf(cfmt,
"sphere cutting the INLET:", cCutIn.iters, cCutIn.divp);
177 const Result cAll[4] = {cEmpty, cClear, cCutOut, cCutIn};
178 for (
const Result& r : cAll)
180 CHECK(sealedPocketRejected<Colo>());
183 std::printf(
"[openbc-solid] OK\n");
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
static constexpr int STEPS
static std::vector< double > sphereSdf()
static void configure(IbmSolver &s)
static std::string fmt(const char *f, double a, long b=0)
peclet::flow::Solver< peclet::flow::Colocated > Colo
static constexpr double U
static constexpr double R
static constexpr int PMAXIT