15#include <Kokkos_Core.hpp>
19#include "peclet/core/common/types.hpp"
20#include "peclet/core/decomp/block_decomposer.hpp"
22using peclet::core::IVec;
23using peclet::core::decomp::BlockDecomposer;
26static constexpr int N = 32,
STEPS = 100;
27static constexpr double RHO = 1.0,
MU = 0.1,
F = 1e-3,
DT = 60.0;
30 const double R =
rfrac *
N;
31 std::vector<double> sdf((std::size_t)
N *
N *
N);
32 const double cs[2] = {0.25 *
N, 0.75 *
N};
33 for (
int z = 0; z <
N; ++z)
34 for (
int y = 0; y <
N; ++y)
35 for (
int x = 0; x <
N; ++x) {
39 for (
double sz : cs) {
40 auto wrap = [](
double d) {
return d -
N * std::round(d /
N); };
41 const double dx = wrap(x -
sx), dy = wrap(y - sy), dz = wrap(z - sz);
42 best = std::min(
best, std::sqrt(dx * dx + dy * dy + dz * dz) - R);
44 sdf[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] =
best;
63 auto b =
dec.block(rank);
64 const int ox = (int)b.origin[0], oy = (
int)b.origin[1], oz = (int)b.origin[2];
65 const int lnx = (int)b.size[0],
lny = (
int)b.size[1],
lnz = (int)b.size[2];
66 std::vector<double> l((std::size_t)
lnx *
lny *
lnz);
67 for (
int z = 0; z <
lnz; ++z)
68 for (
int y = 0; y <
lny; ++y)
69 for (
int x = 0; x <
lnx; ++x)
70 l[(std::size_t)x + (std::size_t)y *
lnx + (std::size_t)z *
lnx *
lny] =
71 g[(std::size_t)(x + ox) + (std::size_t)(y + oy) *
N + (std::size_t)(z + oz) *
N *
N];
77 auto b =
dec.block(rank);
78 IbmSolver s((
int)b.size[0], (
int)b.size[1], (
int)b.size[2]);
82 for (
int it = 0; it <
STEPS; ++it)
94 Kokkos::initialize(
argc, argv);
95 int fail = 0, size = 1, rank = 0;
103 std::vector<peclet::core::Real> w((std::size_t)
N *
N *
N, 1.0);
104 for (
int z = 0; z <
N; ++z)
105 for (
int y = 0; y <
N; ++y)
106 for (
int x = 0; x <
N; ++x)
108 w[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] = 6.0;
118 ref.setSolid(
gsdf,
true);
119 for (
int it = 0; it <
STEPS; ++it)
122 for (
double v : ref.getVelocity(0))
129 const double tol = (size == 1) ? 1e-9 : 2e-4;
131 std::printf(
" GraphAMG on weighted ORB: k=%.8e ref=%.8e rel=%.2e (np=%d, tol %.0e)\n",
145 ref.setSolid(
gsdf,
true);
146 for (
int it = 0; it <
STEPS; ++it)
149 for (
double v : ref.getVelocity(0))
157 " GraphAMG bottom, 3-level hierarchy: k=%.8e ref=%.8e rel=%.2e (np=%d, tol %.0e)\n",
165 std::printf(
tf == 0 ?
"OK (np=%d): decomposition-agnostic GraphAMG pressure solve\n"
166 :
"FAILED (np=%d)\n",
170 return tf == 0 ? 0 : 1;
void setSolid(const std::vector< double > &sdfInner, bool cutcellPressure)
Host entry point: upload the inner SDF once and delegate.
void setPressureGraphAmg(bool on)
void setAdvection(bool on)
void setVelocityIterations(int it)
void setPressureLevels(int levels)
void setBodyForce(double fx, double fy, double fz)
Body force per unit volume, in the caller's units (e.g. a mean pressure gradient, or rho*g).
std::vector< double > getVelocity(int c)
void setPressurePcg(bool on, int maxit, double rtol)
void setMu(double m)
Dynamic viscosity, in the caller's units.
void setRho(double r)
Fluid density, in the caller's units.
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
static void configure(IbmSolver &s, bool amg, int levels)
static double perm(const std::vector< double > &gsdf, const BlockDecomposer< 3 > &dec, int rank, bool amg, int levels, MPI_Comm comm)
static constexpr double RHO
static constexpr double MU
static constexpr int STEPS
static constexpr double DT
static constexpr double F
static std::vector< double > localSdf(const std::vector< double > &g, const BlockDecomposer< 3 > &dec, int rank)
static std::vector< double > packingSdf(double rfrac=0.18)