6#include <Kokkos_Core.hpp>
16 std::fprintf(stderr, "CHECK failed: %s\n at %s:%d\n", #cond, __FILE__, __LINE__); \
21std::vector<double> allFluid(
int nx,
int ny,
int nz) {
22 return std::vector<double>((std::size_t)nx * ny * nz, 10.0);
26double measureEigen(
int N) {
27 const double D = 1.0,
dt = 0.5;
29 s.setAdvection(
false);
31 s.setPressureGeometry(allFluid(
N, 4, 4));
32 s.addScalar(
"c", D, 0, 600);
33 const double k = 2.0 * M_PI /
N;
34 std::vector<double> c0((std::size_t)
N * 4 * 4);
35 for (
int z = 0;
z < 4; ++
z)
36 for (
int y = 0;
y < 4; ++
y)
37 for (
int x = 0;
x <
N; ++
x)
38 c0[(std::size_t)
x + (std::size_t)y *
N + (std::size_t)
z *
N * 4] = std::cos(k * x);
41 auto c1 =
s.getField(
"c");
42 const double peak0 = c0[0], peak1 =
c1[0];
43 return (peak0 / peak1 - 1.0) / (
dt *
D);
49 std::fabs(measureEigen(16) - std::pow(2 * M_PI / 16, 2)) / std::pow(2 * M_PI / 16, 2);
51 std::fabs(measureEigen(32) - std::pow(2 * M_PI / 32, 2)) / std::pow(2 * M_PI / 32, 2);
52 const double order = std::log(e16 / e32) / std::log(2.0);
53 std::printf(
"diffusion rel-errs %.3e %.3e order %.2f\n", e16, e32, order);
58 const double U = 0.4,
dt = 0.5;
60 s.setAdvection(
false);
62 s.setPressureGeometry(allFluid(
N, 4, 4));
63 s.addScalar(
"c", 0.0, 1, 1);
64 std::vector<double>
u((std::size_t)
N * 4 * 4,
U),
zero((std::size_t)
N * 4 * 4, 0.0);
65 s.uploadVelocity(u, zero, zero);
66 std::vector<double> c0((std::size_t)
N * 4 * 4);
68 for (
int z = 0;
z < 4; ++
z)
69 for (
int y = 0;
y < 4; ++
y)
70 for (
int x = 0;
x <
N; ++
x) {
71 const double b = std::exp(-std::pow(x -
N / 2.0, 2) / (2 * std::pow(
N / 12.0, 2)));
72 c0[(std::size_t)x + (std::size_t)
y *
N + (std::size_t)z *
N * 4] = b;
76 for (
int it = 0;
it < 20; ++
it)
78 auto c =
s.getField(
"c");
79 double tot = 0.0,
mx = -1e30;
82 mx = std::fmax(mx, v);
84 const double cons = std::fabs(tot - tot0) / tot0;
85 std::printf(
"advection conservation rel %.2e max %.4f (init 1.0)\n", cons, mx);
87 CHECK(mx < 1.0 + 1e-7);
91int main(
int argc,
char** argv) {
92 Kokkos::initialize(argc, argv);
99 std::fprintf(stderr,
"%d failure(s)\n",
failures);
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
void zero(const ScalarVec &y)
Solver< Staggered > IbmSolver
static constexpr double U