8#include <Kokkos_Core.hpp>
18 std::fprintf(stderr, "CHECK failed: %s\n at %s:%d\n", #cond, __FILE__, __LINE__); \
23double maxAbs(
const std::vector<double>& v) {
26 m = std::fmax(m, std::fabs(x));
31 const int N = 8,
NZ = 24;
34 s.setAdvection(
false);
38 s.setDomainBc(4, 1, 0, 0, 0);
39 s.setDomainBc(5, 1, 0, 0, 0);
40 s.setPressureGeometry(std::vector<double>((std::size_t)
N *
N *
NZ, 10.0));
41 std::vector<double>
rho((std::size_t)
N *
N *
NZ);
42 for (
int z = 0;
z <
NZ; ++
z)
43 for (
int y = 0;
y <
N; ++
y)
44 for (
int x = 0;
x <
N; ++
x)
45 rho[(std::size_t)
x + (std::size_t)y *
N + (std::size_t)
z *
N *
N] =
46 (
z <
NZ / 2) ? ratio : 1.0;
48 s.setField(
"rho", rho);
49 s.setDensityMode(
true);
52 for (
int it = 0;
it < 100; ++
it) {
54 last = std::fmax(
maxAbs(
s.getVelocity(0)),
56 CHECK(!std::isnan(last));
61 auto p =
s.getPressure();
63 const int xc =
N / 2, yc =
N / 2;
64 for (
int z = 1;
z <
NZ; ++
z) {
65 const double dp =
p[(std::size_t)xc + (std::size_t)yc *
N + (std::size_t)z *
N *
N] -
66 p[(std::size_t)
xc + (std::size_t)yc *
N + (std::size_t)(
z - 1) *
N *
N];
67 const double rf = 0.5 * (((
z <
NZ / 2) ?
ratio : 1.0) + ((
z - 1 <
NZ / 2) ?
ratio : 1.0));
68 perr = std::fmax(perr, std::fabs(dp + g * rf) / (g * ratio));
70 std::printf(
"hydrostatic ratio %g: final max|u| %.2e P-grad rel-err %.2e\n", ratio, last, perr);
75void uniformReduction() {
77 const int N = 12,
NZ = 6;
78 std::vector<std::vector<double>> uu, pp;
79 for (
int var = 0; var < 2; ++var) {
81 s.setAdvection(
false);
85 s.setBodyForce(1e-3, 0, 0);
86 std::vector<double>
sdf((std::size_t)
N *
N *
NZ);
87 for (
int z = 0;
z <
NZ; ++
z)
88 for (
int y = 0;
y <
N; ++
y)
89 for (
int x = 0;
x <
N; ++
x)
90 sdf[(std::size_t)
x + (std::size_t)y *
N + (std::size_t)
z *
N *
N] =
91 std::sqrt(std::pow(x -
N / 2.0, 2) + std::pow(y -
N / 2.0, 2)) -
N / 5.0;
92 s.setSolid(sdf,
true);
94 s.setDensityMode(
true);
95 for (
int it = 0;
it < 40; ++
it)
97 uu.push_back(
s.getVelocity(0));
98 pp.push_back(
s.getPressure());
100 double du = 0, dp = 0,
us = 0;
101 for (std::size_t i = 0;
i < uu[0].size(); ++
i) {
102 du = std::fmax(du, std::fabs(uu[0][i] - uu[1][i]));
103 dp = std::fmax(dp, std::fabs(pp[0][i] - pp[1][i]));
104 us = std::fmax(us, std::fabs(uu[0][i]));
106 std::printf(
"uniform-rho reduction: rel du %.2e dp %.2e\n", du / us, dp);
107 CHECK(du / us < 1e-6);
111int main(
int argc,
char** argv) {
112 Kokkos::initialize(argc, argv);
121 std::fprintf(stderr,
"%d failure(s)\n",
failures);
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
Solver< Staggered > IbmSolver
hydrostatic(ratio, mu=0.0, steps=100, g=0.1, dt=1.0, N=8, NZ=24)
static double maxAbs(const std::vector< double > &a)