flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
dbg_scene.cpp
Go to the documentation of this file.
1#include <cmath>
2#include <cstdio>
3#include <random>
4
5#include "peclet/core/geom/scene_builder.hpp"
6#include "peclet/core/geom/scene_query.hpp"
7using namespace peclet::core;
8using namespace peclet::core::geom;
9struct Rng {
10 std::mt19937_64 g{20260829ull};
11 double u(double lo, double hi) { return std::uniform_real_distribution<double>(lo, hi)(g); }
12};
13int main() {
14 Rng rng;
15 // fast-forward the rng exactly as the test does? The test consumed lots before this section.
16 // Instead: rebuild the same scene with a FRESH rng — positions differ from the test but the
17 // failure mode should reproduce statistically.
18 SceneBuilder<double> b;
19 const int sph = b.addLeaf(kSphere, {0.06});
20 const int shaft = b.addLeaf(kHollowCylinder, {0.03, 0.4, 0.03});
21 const int blade =
22 b.addLeaf(kBox, {0.12, 0.02, 0.03}, Transform<double>{Vec3<double>{0.13, 0, 0}});
23 const int stir = b.addUnion(shaft, blade);
24 const int ell = b.addLeaf(kEllipsoid, {0.09, 0.05, 0.04});
25 for (int i = 0; i < 40; ++i)
26 b.addInstance(sph, Transform<double>{Vec3<double>{rng.u(0, 1), rng.u(0, 1), rng.u(0, 1)}});
27 const double a45 = 0.7853981633974483;
28 b.addInstance(stir, Transform<double>{Vec3<double>{0.5, 0.5, 0.5},
29 Quat<double>{0, std::sin(a45), 0, std::cos(a45)}, 1.2});
30 b.addInstance(ell, Transform<double>{Vec3<double>{0.2, 0.7, 0.3}});
31 const SceneView<double> sv = b.view();
32 for (bool periodic : {true, false}) {
33 const PeriodicBox<double> box{1.0, 1.0, 1.0, periodic};
34 CandidateGrid<double> g = buildSceneCandidateGrid(sv, {0, 0, 0}, {1, 1, 1}, box);
35 const auto gv = g.view();
36 const double* br = g.instBoundR.data();
37 int bad = 0;
38 for (int t = 0; t < 60000; ++t) {
39 const Vec3<double> p{rng.u(-0.2, 1.2), rng.u(-0.2, 1.2), rng.u(-0.2, 1.2)};
40 const double ref = evalScenePeriodic(sv, p, box, br);
41 const double got = evalSceneGrid(sv, p, box, gv, br);
42 if (got != ref) {
43 if (bad < 4) {
44 const long bin = gv.binOf(p);
45 std::printf("[%s] p=(%.6f,%.6f,%.6f) ref=%.12g got=%.12g bin=%ld list=[",
46 periodic ? "per" : "open", p.x, p.y, p.z, ref, got, bin);
47 if (bin >= 0)
48 for (int k = gv.offsets[bin]; k < gv.offsets[bin + 1]; ++k)
49 std::printf("%d ", gv.items[k]);
50 std::printf("]\n");
51 // which instance is the true argmin?
52 int win = -1;
53 double best = 1e300;
54 for (int i = 0; i < sv.instanceCount; ++i) {
55 const double d = evalInstancePeriodic(sv, i, p, box, br[i]);
56 if (d < best) {
57 best = d;
58 win = i;
59 }
60 }
61 std::printf(" argmin=%d dist=%.12g boundR[argmin]=%.4f\n", win, best, br[win]);
62 }
63 ++bad;
64 }
65 }
66 std::printf("%s: %d/60000 mismatches\n", periodic ? "periodic" : "open", bad);
67 }
68 return 0;
69}
int main()
Definition dbg_scene.cpp:13
x
Definition cmp.py:24
y
Definition cmp.py:24
double u(double lo, double hi)
Definition dbg_scene.cpp:11
std::mt19937_64 g
Definition dbg_scene.cpp:10