12#include <Kokkos_Core.hpp>
16#include "peclet/core/common/types.hpp"
17#include "peclet/core/decomp/block_decomposer.hpp"
19using peclet::core::IVec;
20using peclet::core::decomp::BlockDecomposer;
23static constexpr int N = 32,
STEPS = 120;
24static constexpr double RHO = 1.0,
MU = 0.1,
F = 1e-3,
DT = 60.0;
27 const double R =
rfrac *
N;
28 std::vector<double> sdf((std::size_t)
N *
N *
N);
29 const double cs[2] = {0.25 *
N, 0.75 *
N};
30 for (
int z = 0; z <
N; ++z)
31 for (
int y = 0; y <
N; ++y)
32 for (
int x = 0; x <
N; ++x) {
36 for (
double sz : cs) {
37 auto wrap = [](
double d) {
return d -
N * std::round(d /
N); };
38 const double dx = wrap(x -
sx), dy = wrap(y - sy), dz = wrap(z - sz);
39 best = std::min(
best, std::sqrt(dx * dx + dy * dy + dz * dz) - R);
41 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 gsdf[(std::size_t)(x + ox) + (std::size_t)(y + oy) *
N + (std::size_t)(z + oz) *
N *
N];
85 Kokkos::initialize(
argc, argv);
86 int fail = 0, size = 1, rank = 0;
95 std::vector<peclet::core::Real> w((std::size_t)
N *
N *
N, 1.0);
96 for (
int z = 0; z <
N; ++z)
97 for (
int y = 0; y <
N; ++y)
98 for (
int x = 0; x <
N; ++x)
100 w[(std::size_t)x + (std::size_t)y *
N + (std::size_t)z *
N *
N] = 6.0;
104 auto b1 =
D1.block(rank);
109 for (
int it = 0; it <
STEPS / 2; ++it)
118 std::printf(
" div PRE-redistribute = %.2e\n",
div_pre);
125 std::printf(
" global-u sum pre=%.12e post=%.12e |d|=%.2e (redistribute data movement)\n",
139 ref.setSolid(
gsdf,
true);
140 for (
int it = 0; it <
STEPS; ++it)
143 for (
double v : ref.getVelocity(0))
150 const double tol = (size == 1) ? 1e-12 : 2e-5;
153 " k_dist=%.8e k_ref=%.8e rel=%.2e div=%.2e (np=%d, tol %.0e, redistributed)\n",
161 std::printf(
totalFail == 0 ?
"OK (np=%d): mid-run redistribute preserves the solution\n"
162 :
"FAILED (np=%d)\n",
void setSolid(const std::vector< double > &sdfInner, bool cutcellPressure)
Host entry point: upload the inner SDF once and delegate.
double maxOpenDivergence()
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 std::vector< double > localSdf(const std::vector< double > &gsdf, const BlockDecomposer< 3 > &dec, int rank)
static constexpr double RHO
static constexpr double MU
static double localUSum(IbmSolver &s)
static constexpr int STEPS
static constexpr double DT
static constexpr double F
static void configure(IbmSolver &s)
static std::vector< double > packingSdf(double rfrac=0.18)