17#include <Kokkos_Core.hpp>
23#include "peclet/core/geom/scene_builder.hpp"
25using peclet::core::solver::AndersonRole;
33void check(
bool ok,
const std::string& what) {
34 std::printf(
" [%s] %s\n", ok ?
"ok" :
"FAIL", what.c_str());
41std::vector<double>
sphereSdf(
double radius) {
42 std::vector<double> sdf((std::size_t)
N *
N *
N);
43 const double c = 0.5 *
N;
44 for (
int z = 0; z <
N; ++z)
45 for (
int y = 0; y <
N; ++y)
46 for (
int x = 0; x <
N; ++x) {
47 const double dx = x + 0.5 - c, dy = y + 0.5 - c, dz = z + 0.5 - c;
48 sdf[(std::size_t)x + (std::size_t)
N * (y + (std::size_t)
N * z)] =
49 std::sqrt(dx * dx + dy * dy + dz * dz) - radius;
54std::vector<double> allFluid() {
55 return std::vector<double>((std::size_t)
N *
N *
N, 1.0);
60 s.setAdvection(
false);
64 s.setBodyForce(1e-3, 0.0, 0.0);
65 s.setPressurePcg(
true, 200, 1e-8);
70void checkFields(S& s,
const typename S::MarchState& ms,
const std::vector<std::string>& names,
71 int carriedFrom,
const std::string& tag) {
72 check(ms.fields.size() == names.size() && ms.roles.size() == names.size(),
73 tag +
": " + std::to_string(names.size()) +
" fields and roles");
74 if (ms.fields.size() != names.size() || ms.roles.size() != names.size())
76 const std::size_t nPad = (std::size_t)ms.e.x * ms.e.y * ms.e.z;
77 check(ms.G == 2 && ms.e.x ==
N + 4 && ms.e.y ==
N + 4 && ms.e.z ==
N + 4,
78 tag +
": e = n + 2G, G = 2");
79 for (std::size_t f = 0; f < names.size(); ++f) {
80 const AndersonRole want = (int)f < carriedFrom ? AndersonRole::Velocity : AndersonRole::Carried;
81 const bool same = ms.fields[f].data() == s.fieldView(names[f]).data();
82 check(ms.roles[f] == want && ms.fields[f].extent(0) == nPad &&
same,
83 tag +
": field " + std::to_string(f) +
" is '" + names[f] +
"' (" +
84 (want == AndersonRole::Velocity ?
"Velocity" :
"Carried") +
", padded)");
89 std::printf(
"rows of §3.1\n");
95 const auto ms = s.marchState();
96 checkFields(s, ms, {
"u",
"v",
"w",
"p"}, 3,
"staggered + advection");
97 check(ms.signature[0] == 6.0 && ms.signature[1] == 1.0 && ms.signature[2] == 1.0 &&
98 ms.signature[3] == 1e-3 && ms.signature[4] == 0.0 && ms.signature[5] == 0.0,
99 "staggered: signature (dt, rho, mu, F) in cell units");
100 check(ms.signature[6] == 1.0 && ms.signature[7] == 0.0 && ms.signature[8] == 0.0,
101 "staggered: signature advection (on, scheme SOU, explicit)");
102 s.setAdvectionScheme(1);
103 s.setImplicitAdvection(
true);
104 const auto ms2 = s.marchState();
105 check(ms2.signature[7] == 1.0 && ms2.signature[8] == 1.0,
106 "staggered: signature follows set_advection_scheme / set_implicit_advection");
111 s.setAdvection(
false);
113 checkFields(s, s.marchState(), {
"u",
"v",
"w",
"p"}, 3,
"collocated AUTO ghost, Stokes");
118 s.setCollocatedScheme(
"ghost");
119 s.setAdvection(
true);
120 s.setUfAdvection(
false);
122 checkFields(s, s.marchState(), {
"u",
"v",
"w",
"p"}, 3,
123 "collocated ghost + advection, set_uf_advection(False)");
128 s.setCollocatedScheme(
"ghost");
129 s.setAdvection(
true);
131 const auto ms = s.marchState();
134 first4.fields.resize(std::min<std::size_t>(4, ms.fields.size()));
135 first4.roles.resize(std::min<std::size_t>(4, ms.roles.size()));
136 checkFields(s, first4, {
"u",
"v",
"w",
"p"}, 3,
137 "collocated ghost + projected-face advection (first 4)");
138 bool faces = ms.fields.size() == 7;
139 for (std::size_t f = 4; faces && f < 7; ++f)
140 faces = ms.roles[f] == AndersonRole::Carried &&
141 ms.fields[f].extent(0) == (std::size_t)ms.e.x * ms.e.y * ms.e.z;
143 bool distinct =
true;
144 for (std::size_t f = 4; f < 7; ++f)
145 for (std::size_t g = 0; g < f; ++g)
146 distinct = distinct && ms.fields[f].data() != ms.fields[g].data();
149 check(faces,
"collocated ghost + projected-face advection: + uf, vf, wf (Carried, padded)");
155template <
class S,
class Make>
156void refusal(
const std::string& tag,
const std::string& token, Make make) {
162 (void)s.marchState();
163 }
catch (
const std::runtime_error& e) {
166 const bool own = what.find(token) != std::string::npos;
167 const bool hint = what.find(
"pass accelerate=False") != std::string::npos;
168 check(own && hint,
"refusal " + tag +
": \"" + what +
"\"");
172 namespace g = peclet::core::geom;
173 std::vector<int> ni(g::kNodeIntStride, 0), ii(g::kInstanceIntStride, 0);
174 std::vector<double> nr(g::kNodeRealStride, 0.0), ir(g::kInstanceRealStride, 0.0);
183 ir[0] = ir[1] = ir[2] = 0.5 *
N;
186 s.setScene(ni, nr, ii, ir,
true);
187 s.setSolidFromScene(
true);
191 std::printf(
"refusals (§5.3)\n");
192 refusal<Colo>(
"1 collocated gauge-exact",
"not the fluid-only 'ghost' projection", [](
Colo& s) {
193 s.setCollocatedScheme(
"gauge-exact");
196 refusal<Colo>(
"1 collocated embed",
"not the fluid-only 'ghost' projection", [](
Colo& s) {
197 s.setCollocatedScheme(
"embed");
200 refusal<Stag>(
"2 VoF",
"VoF", [](
Stag& s) {
201 s.setPressureGeometry(allFluid());
204 refusal<Stag>(
"3 phase change",
"phase change", [](
Stag& s) {
205 s.setPressureGeometry(allFluid());
206 s.enablePhaseChange(1.0, 10.0, 1.0);
208 refusal<Stag>(
"4 scalar",
"transported scalar", [](
Stag& s) { s.addScalar(
"T", 0.1, 0, 1); });
209 refusal<Stag>(
"5 porous",
"porous", [](
Stag& s) { s.setPorousContinuity(
true); });
210 refusal<Stag>(
"6 variable rho (closure)",
"variable density or viscosity", [](
Stag& s) {
214 refusal<Stag>(
"6 mu field",
"variable density or viscosity", [](
Stag& s) { s.addField(
"mu"); });
215 refusal<Stag>(
"7 drag",
"drag_beta", [](
Stag& s) { s.enableDrag(); });
216 refusal<Stag>(
"8 cell force",
"cell force", [](
Stag& s) { s.enableCellForce(); });
217 refusal<Stag>(
"9 moving scene",
"moving scene", [](
Stag& s) {
219 s.setInstanceMotion(0, {1e-3, 0.0, 0.0}, {0.0, 0.0, 0.0},
nullptr);
221 refusal<Stag>(
"10 superficial velocity",
"set_superficial_velocity",
222 [](
Stag& s) { s.setSuperficialVelocity(
true, 0, 1e-3); });
223 refusal<Stag>(
"11 pressure warm start",
"warm start",
224 [](
Stag& s) { s.setPressureWarmstart(
true); });
225 refusal<Stag>(
"12 balanced-force projection",
"balanced-force projection",
226 [](
Stag& s) { s.setBalancedForceProjection(
true); });
234 (void)s.marchState();
235 }
catch (
const std::exception&) {
238 check(ok,
"a static scene is allowed");
244int main(
int argc,
char** argv) {
245 Kokkos::initialize(argc, argv);
252 std::fprintf(stderr,
"\n%d CHECK(s) failed\n",
failures);
255 std::printf(
"\nAll march-state checks passed.\n");
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
static std::vector< double > sphereSdf()
static void check(bool ok, const std::string &what)
peclet::flow::Solver< peclet::flow::Staggered > Stag
peclet::flow::Solver< peclet::flow::Colocated > Colo
static void sphereScene(std::vector< int > &ni, std::vector< double > &nr, std::vector< int > &ii, std::vector< double > &ir)
static bool same(double a, double b)