peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
repair.hpp
Go to the documentation of this file.
1
44#ifndef PECLET_VORO_REPAIR_HPP
45#define PECLET_VORO_REPAIR_HPP
46
47#include <cmath>
48#include <Kokkos_Core.hpp>
49#include <string>
50
51#include "peclet/core/common/view.hpp"
57
58namespace peclet::voro {
59
63 enum Route { kTwoPass = 0, kDilated = 1, kRebuildGate = 2 };
64 int pass1 = 0;
65 int pass1Raw = 0;
66 int pass2 = 0;
67 int extra = 0;
68 int surgical = 0;
69 int verifyPasses = 0;
70 int wallFlagged = 0;
71 int nearFlagged = 0;
73 bool fellBack = false;
74};
75
78 long buried = 0;
79 long reachExceeded = 0;
80 long empty = 0;
81 long overflow = 0;
82 long incomplete = 0;
83 long degenerate = 0;
85};
86
89template <class Real, int MAXP = kMaxPlanes, int MAXT = kMaxTriangles, bool Weighted = false,
90 class Sdf = NoSdf>
92 using Mem = peclet::core::MemSpace;
93 using Exec = peclet::core::ExecSpace;
94 using PlanePolicy = std::conditional_t<Weighted, Power, Voronoi>; // radical vs bisector planes
95 static constexpr bool kHasSdf = !std::is_same_v<Sdf, NoSdf>;
96 // The certificate/load/re-eval path reads the resident `poke4` plane set by pointer and never
97 // touches the edge adjacency, so it uses a LEAN cell with NO `adj` member (TrackAdj=false) —
98 // ~MAXT*3*4 bytes smaller per thread, which lifts occupancy on the full-N certify (the GPU
99 // repair's hot kernel). Only the cell-BUILDING paths (the gather's CellBuilder, rebuildAdjAll,
100 // surgicalRepair) need `adj` to derive poke4, so they use the TrackAdj=true BuildCell.
104
105 int N = 0;
106 int nProc =
107 0;
110 Real L[3] = {1, 1, 1};
111 Real tol =
112 0;
113 Real skin = 0;
114 int verifyCap = 2;
115
116 // ---- Phase 3: adaptive three-way gate (decided after the free certificate, before any gather)
117 // ----
118 bool useGate = true;
119 bool profile = false;
122 false;
126 double churnThresh =
127 0.55;
130 0.15;
132 int clusterNbhd = 18;
134 // ---- Phase 4: single-face surgical repair (no grid gather; gated, default OFF — see note) ----
135 // NEGATIVE RESULT (measured): on this engine surgical re-clip is BOTH slower and not robustly
136 // exact, so it stays off. (1) Slower: the cold gather clips closest-first with the
137 // security-radius early-out (the cell tightens fast, few live triangles per clip), whereas
138 // re-clipping the stored+partner candidates unsorted keeps the cell large and costs more O(#tri)
139 // horizon scans — the gather wins. (2) Not exact: a surgically-rebuilt cell that GAINS a
140 // neighbour absent from its candidate set stays convex, so the certificate can't see the gain
141 // (§1c) and the verify loop can't catch it; the small per-step error then COMPOUNDS in the
142 // resident store (maxRelV grew to ~0.5 over a sweep). Making it exact needs the maintained
143 // 1-/2-ring candidate set (the ConnectivityArena the plan parks). Kept as the implemented
144 // experiment behind this flag; the production path is the Phase-3 gated two-pass gather.
145 bool surgical =
146 false;
147 static constexpr int kExtraCap = 8;
148 // ---- Lawson local convexity certificate (the cheap O(nt) convexity test) ----
150 true;
157 bool adjFresh =
158 false;
162 bool useLocalNow = false;
163
164 Kokkos::View<int*, Mem> lastStatus;
167 BuildReport r;
168 if (lastStatus.extent(0) == 0)
169 return r;
170 auto h = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, lastStatus);
171 for (int i = 0; i < nProc; ++i) {
172 const int s = h(i);
173 r.buried += (s & kBuried) ? 1 : 0;
174 r.reachExceeded += (s & kReachExceeded) ? 1 : 0;
175 r.empty += (s & kEmpty) ? 1 : 0;
176 r.overflow += (s & kOverflow) ? 1 : 0;
177 r.incomplete += (s & kIncomplete) ? 1 : 0;
178 r.degenerate += (s & kDegenerate) ? 1 : 0;
179 }
181 return r;
182 }
183
185 Kokkos::View<Real*, Mem> vol; // N : cell volumes (the published geometry scalar)
186 Kokkos::View<Real*, Mem> xRef; // 3N : positions at the last (re)build (Verlet reference)
187 Kokkos::View<Real*, Mem> weight; // N : per-seed power weights (empty for Voronoi); DOFs
188 // alongside positions. Set via setWeights before rebuild/step.
189
191 void setWeights(const Kokkos::View<Real*, Mem>& w) { weight = w; }
192
193 // ---- near-miss (face-gain) completeness ----
194 // The seed-local certificate cannot see a face GAINED from a seed that is not in the stored
195 // topology (its bisector drifts into the cell without either seed moving past the Verlet
196 // skin): measured ~0.1 % of neighbour relations missed per step, ~1e-3 volume error over long
197 // runs. Every (re)build records the candidates whose plane missed the cell by less than
198 // `nearMargin` (a multiple of the skin); the certificate re-tests those planes on the current
199 // positions and flags both cells when one now cuts. Set useNearMiss=false for the old (cheaper,
200 // incomplete) certificate.
201 bool useNearMiss = true;
202 int kNearCap = 32;
203 Real nearMarginFrac = Real(0.5);
204 bool nearFresh = false;
208 Kokkos::View<int*, Mem> near, nearCnt;
209 Kokkos::View<int, Mem> nearCounter;
210
211 // ---- SDF solid (rung A0) ----
212 Sdf sdf;
214 bool wallExact = true;
215 Real wallSkin = 0;
216 Kokkos::View<int, Mem> wallCounter;
217 // scratch
218 Kokkos::View<int*, Mem> mask, mask2, mover, rebuilt, wl1, wl2, wlM;
219 Kokkos::View<int*, Mem> cellFlag; // per linear grid-cell flagged-seed count (dilation)
220 Kokkos::View<int*, Mem> extraNbr, extraCnt; // Phase-4 partner-discovered candidate neighbours
221 Kokkos::View<int, Mem> counter;
222 int gridNcell = 0;
223
228 void alloc(int n, const Real Lbox[3], Real tol_, Real skin_, int sw_ = kSearchWindow,
229 int densityCount_ = -1, int nProc_ = -1) {
230 N = n;
231 nProc = (nProc_ < 0) ? n : nProc_;
232 sw = sw_;
233 densityCount = densityCount_ < 0 ? n : densityCount_;
234 tol = tol_;
235 skin = skin_;
236 for (int k = 0; k < 3; ++k)
237 L[k] = Lbox[k];
238 store.alloc(n);
239 store.allocPoke4(); // resident local-cert plane set (computed by the gather, read each step by
240 // the cert)
241 using Kokkos::view_alloc;
242 using Kokkos::WithoutInitializing;
243 vol = Kokkos::View<Real*, Mem>("mt.vol", n);
244 xRef = Kokkos::View<Real*, Mem>(view_alloc(std::string("mt.xRef"), WithoutInitializing),
245 (size_t)n * 3);
246 mask = Kokkos::View<int*, Mem>("mt.mask", n);
247 mask2 = Kokkos::View<int*, Mem>("mt.mask2", n);
248 mover = Kokkos::View<int*, Mem>("mt.mover", n);
249 rebuilt = Kokkos::View<int*, Mem>("mt.rebuilt", n);
250 wl1 = Kokkos::View<int*, Mem>(view_alloc(std::string("mt.wl1"), WithoutInitializing), n);
251 wl2 = Kokkos::View<int*, Mem>(view_alloc(std::string("mt.wl2"), WithoutInitializing), n);
252 wlM = Kokkos::View<int*, Mem>(view_alloc(std::string("mt.wlM"), WithoutInitializing), n);
253 extraNbr = Kokkos::View<int*, Mem>(view_alloc(std::string("mt.extraNbr"), WithoutInitializing),
254 (size_t)n * kExtraCap);
255 extraCnt = Kokkos::View<int*, Mem>("mt.extraCnt", n);
256 counter = Kokkos::View<int, Mem>("mt.counter");
257 // Per-backend gate threshold: rebuild is cheap + clip-bound on GPU (repair loses past ~50%
258 // flagged), expensive on the CPU paths (repair pays out to ~85%). Hand-set from the
259 // cross-device sweep; the plan's Phase-3 tuning would fit these from logged (signals vs
260 // verify-clean) per backend.
261 constexpr bool host = Kokkos::SpaceAccessibility<Kokkos::HostSpace, Mem>::accessible;
262 churnThresh = host ? 0.70 : 0.50;
263 if (useNearMiss) {
264 near = Kokkos::View<int*, Mem>(view_alloc(std::string("mt.near"), WithoutInitializing),
265 (size_t)n * kNearCap);
266 nearCnt = Kokkos::View<int*, Mem>("mt.nearCnt", n);
267 nearCounter = Kokkos::View<int, Mem>("mt.nearCounter");
268 }
269 if constexpr (kHasSdf) {
270 wall.alloc(n);
271 wallCounter = Kokkos::View<int, Mem>("mt.wallCounter");
272 surgical = false; // the surgical re-clip knows nothing of walls; the gather does
273 }
274 }
275
278 KOKKOS_INLINE_FUNCTION static void dispFromRef(const Kokkos::View<Real*, Mem>& P,
279 const Kokkos::View<Real*, Mem>& XR, int i, Real Lx,
280 Real Ly, Real Lz, Real& dx, Real& dy, Real& dz) {
281 dx = P(3 * i) - XR(3 * i);
282 dy = P(3 * i + 1) - XR(3 * i + 1);
283 dz = P(3 * i + 2) - XR(3 * i + 2);
284 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
285 dx = dx > Lxh ? dx - Lx : (dx < -Lxh ? dx + Lx : dx);
286 dy = dy > Lyh ? dy - Ly : (dy < -Lyh ? dy + Ly : dy);
287 dz = dz > Lzh ? dz - Lz : (dz < -Lzh ? dz + Lz : dz);
288 }
289
298 void rebuild(const Kokkos::View<Real*, Mem>& pos, bool eagerAdj = true) {
299 Kokkos::View<long*, Mem> gd;
300 const int nBuild =
301 (nProc == N) ? -1 : nProc; // build only the owned cells; ghosts are candidates
302 // A gate-rebuild (eagerAdj=false) stays in the high-churn regime and skips the near-miss
303 // emission like it skips the adjacency; the lists are rebuilt once churn drops (step()).
304 const bool emitNear = useNearMiss && eagerAdj;
305 auto res = buildTessellation<Real, Weighted, Sdf>(
306 pos, weight, N, L, sw, densityCount, gd, sdf, /*withForceGeom=*/false, nBuild, store.np,
307 store.nt, store.pnbr, store.tri, /*outCand=*/{}, /*outCandCnt=*/{}, /*candCap=*/0,
308 /*wlc=*/nullptr, wall, /*withAreaGrad=*/false, emitNear ? near : Kokkos::View<int*, Mem>{},
309 emitNear ? nearCnt : Kokkos::View<int*, Mem>{}, emitNear ? kNearCap : 0,
310 nearMarginFrac * skin, /*withWallFD=*/false, /*withMoments=*/false, profile);
311 nearFresh = emitNear;
312 lastStatus = res.status;
313 lastOverBufferRebuilds = res.overBufferRebuilds;
314 Kokkos::deep_copy(vol, res.view.cellVolume);
315 Kokkos::deep_copy(xRef, pos);
316 adjFresh = false; // the cold build does not emit adjacency
317 if (eagerAdj)
318 maybeBuildAdj(pos); // the whole topology changed -> repopulate store.poke4 (unless gating)
319 }
320
322 int compact(const Kokkos::View<int*, Mem>& m, const Kokkos::View<int*, Mem>& wl) {
323 Kokkos::deep_copy(counter, 0);
324 auto M = m;
325 auto W = wl;
326 auto c = counter;
327 Kokkos::parallel_for(
328 "mt.compact", Kokkos::RangePolicy<Exec>(0, nProc), KOKKOS_LAMBDA(int i) {
329 if (M(i))
330 W(Kokkos::atomic_fetch_add(&c(), 1)) = i;
331 });
332 int h = 0;
333 Kokkos::deep_copy(h, counter);
334 return h;
335 }
336
348 template <bool Local>
349 void certify(const Kokkos::View<Real*, Mem>& pos, const Kokkos::View<int*, Mem>& outMask,
350 const Kokkos::View<int*, Mem>& outMover, bool useSkin) {
351 Kokkos::deep_copy(outMask, 0);
352 if (useSkin)
353 Kokkos::deep_copy(outMover, 0);
354 // Phase-4: in the Pass-1 certify, also record partner-discovered new neighbours for the
355 // surgical path. The gaining cells of a flip are the violated-plane partners; each pair gains
356 // the other, so scatter every other partner of a flagging cell onto each partner's
357 // extra-candidate list (no dedup — duplicates are harmless no-op clips; overflow past kExtraCap
358 // just truncates and the cell falls back to a full gather at verify). Only in Pass 1 (useSkin),
359 // and only when surgical is enabled.
360 const bool doExtra = surgical && useSkin;
361 if (doExtra)
362 Kokkos::deep_copy(extraCnt, 0);
363 auto EN = extraNbr;
364 auto EC = extraCnt;
365 constexpr int kCap = kExtraCap;
366 auto P = pos;
367 auto XR = xRef;
368 auto Vv = vol;
369 auto M = outMask;
370 auto Mv = outMover;
371 Store st = store;
372 auto Pk4 = store.poke4;
373 const Real Lx = L[0], Ly = L[1], Lz = L[2];
374 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
375 const Real tolL = tol, half2 = Real(0.25) * skin * skin;
376 const bool skinOn = useSkin;
377 const int nP_ = nProc;
378 auto Wt =
379 weight; // power weights (empty for Voronoi; captured for reevalGeometry<PlanePolicy>)
380 // near-miss (face-gain) check captures
381 auto NR = near;
382 auto NC = nearCnt;
383 auto NCtr = nearCounter;
384 const int nearCapL = kNearCap; // a local: a member read inside the lambda would capture `this`
385 const bool nearOn = useNearMiss && useSkin && nearFresh; // once per step (Pass-1 certify)
386 if (nearOn)
387 Kokkos::deep_copy(nearCounter, 0);
388 // SDF boundary watch captures (force-captured outside the constexpr-if, nvcc rule)
390 Sdf Sd = sdf;
391 auto WC = wallCounter;
392 const bool wallExactL = wallExact;
393 const Real wallSkin2 = wallSkin * wallSkin;
394 if constexpr (kHasSdf)
395 Kokkos::deep_copy(wallCounter, 0);
396 Kokkos::parallel_for(
397 "mt.certify", Kokkos::RangePolicy<Exec>(0, nProc), KOKKOS_LAMBDA(int i) {
398 CertCell c;
399 st.load(i, c, Lx, Ly, Lz);
400 Real dx, dy, dz;
401 dispFromRef(P, XR, i, Lx, Ly, Lz, dx, dy, dz);
402 const bool wallOk = Wl.load(i, c, dx, dy, dz); // no-op (true) without a wall store
403 // force-capture everything the constexpr boundary watch reads OUTSIDE it (nvcc rule)
404 const Sdf SdC = Sd;
405 int* wcPtr = WC.data();
406 const bool wallExactC = wallExactL;
407 const Real wallSkin2C = wallSkin2;
408 const Real* wPtr = Wt.data(); // force-capture Wt OUTSIDE the constexpr-if (nvcc rule)
409 Real wSelfI = Real(0);
410 if constexpr (Weighted)
411 wSelfI = Wt(i);
412 c.template reevalGeometry<PlanePolicy>(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx,
413 wSelfI, wPtr);
414 Vv(i) = c.volumePerVertex();
415 int partners[32];
416 int nP = 0;
417 bool ok;
418 // Force-capture every lambda capture used in the branches OUTSIDE the constexpr-if (nvcc:
419 // an extended __host__ __device__ lambda cannot FIRST-capture a variable inside a
420 // constexpr-if).
421 const unsigned char* pk4 = &Pk4((size_t)i * MAXT * 4); // poke4 is always allocated
422 const Real tl = tolL;
423 if constexpr (Local) {
424 // Outside-seed cells (a live plane with nn < 0) take the full test (WO-3b). Only a
425 // power cell can have one: Voronoi keeps the local test with no scan.
426 bool fullTest = false;
427 if constexpr (Weighted)
428 fullTest = c.anyLiveNegOffset();
429 if (fullTest)
430 ok = c.isSelfConsistentPartners(tl, partners, 32, nP);
431 else
432 ok = c.isLocallyConvexPartners(pk4, tl, partners, 32, nP);
433 } else {
434 (void)pk4;
435 ok = c.isSelfConsistentPartners(tl, partners, 32, nP);
436 }
437 bool mover = false;
438 if (skinOn) {
439 mover = (dx * dx + dy * dy + dz * dz) > half2;
440 if (mover)
441 Mv(i) = 1;
442 }
443 // ---- vanishing power cells (outside-seed §10, R-a/R-b): Pass-1 certify only ----
444 // force-capture what the constexpr branch reads OUTSIDE it (nvcc rule)
445 int* const mskPtr = M.data();
446 const int nOwned = nP_;
447 if constexpr (Weighted) {
448 if (skinOn) {
449 bool vanish = false;
450 if (c.nt == 0) { // R-a: empty power cell (an overflowed cell is stored the same way)
451 vanish = true;
452 if constexpr (kHasSdf) // a seed in the solid is empty by the wall, not by power
453 vanish = SdC.eval(P(3 * i), P(3 * i + 1), P(3 * i + 2)) > Real(0);
454 } else if (!(Vv(i) > Real(0))) { // R-b: folded stale topology (NaN included)
455 vanish = true;
456 for (int t = 0; t < c.nt; ++t) { // flag every owned live-plane partner
457 if (!c.alive[t])
458 continue;
459 const int ks[3] = {c.t0[t], c.t1[t], c.t2[t]};
460 for (int k : ks) {
461 const int j = c.pnbr[k];
462 if (k >= 6 && j >= 0 && j < nOwned)
463 Kokkos::atomic_exchange(&mskPtr[j], 1);
464 }
465 }
466 }
467 if (vanish) { // full gather + Pass 2; the flag line below sets M(i)
468 mover = true;
469 Mv(i) = 1;
470 }
471 }
472 } else {
473 (void)mskPtr;
474 (void)nOwned;
475 }
476 // ---- SDF boundary watch (rung A0): what the seed-seed certificate cannot see ----
477 bool wflag = false;
478 if constexpr (kHasSdf) {
479 const Real seed[3] = {P(3 * i), P(3 * i + 1), P(3 * i + 2)};
480 if (!wallOk) {
481 wflag = true; // crossed one of its own wall planes
482 } else if (Wl.cnt(i) > 0) {
483 if (wallExactC || (dx * dx + dy * dy + dz * dz) > wallSkin2C) {
484 wflag = true; // a moved wall cell: only a fresh clip reproduces the cold build
485 } else { // skin mode: keep the planes unless the seed or a vertex entered the
486 // solid (a sagitta-placed plane sits beyond the surface, so the seed can
487 // enter the solid without crossing its own plane)
488 if (SdC.eval(seed[0], seed[1], seed[2]) <= Real(0))
489 wflag = true;
490 for (int t = 0; t < c.nt && !wflag; ++t)
491 if (c.alive[t] && SdC.eval(seed[0] + c.vx[t], seed[1] + c.vy[t],
492 seed[2] + c.vz[t]) < Real(-1e-8))
493 wflag = true;
494 }
495 } else if (c.nt == 0) {
496 wflag = SdC.eval(seed[0], seed[1], seed[2]) > Real(0); // seed back in the fluid
497 } else {
498 wflag = sdfWouldClip(c, seed, SdC); // the cold build would cut this cell
499 }
500 if (wflag)
501 Kokkos::atomic_inc(wcPtr);
502 }
503 // near-miss check: does any recorded non-neighbour plane now cut the cell?
504 bool nflag = false;
505 if (nearOn) {
506 const int nc = NC(i);
507 if (nc > nearCapL) {
508 nflag = true; // list overflowed at build: re-gather conservatively
509 } else {
510 const Real sx = P(3 * i), sy = P(3 * i + 1), sz = P(3 * i + 2);
511 for (int q = 0; q < nc; ++q) {
512 const int j = NR((size_t)i * nearCapL + q);
513 if (j < 0)
514 continue;
515 Real rx = P(3 * j) - sx, ry = P(3 * j + 1) - sy, rz = P(3 * j + 2) - sz;
516 rx = rx > Lxh ? rx - Lx : (rx < -Lxh ? rx + Lx : rx);
517 ry = ry > Lyh ? ry - Ly : (ry < -Lyh ? ry + Ly : ry);
518 rz = rz > Lzh ? rz - Lz : (rz < -Lzh ? rz + Lz : rz);
519 const Real pv[3] = {rx, ry, rz};
520 Real wN = Real(0);
521 if constexpr (Weighted)
522 wN = Wt(j);
523 const Real off = PlanePolicy::template offsetFromRel<Real>(pv, wSelfI, wN);
524 if (c.planeGap(pv, off) > Real(0)) {
525 nflag = true;
526 if (j < nP_)
527 Kokkos::atomic_exchange(&M(j), 1); // the gain is mutual
528 }
529 }
530 }
531 if (nflag)
532 Kokkos::atomic_inc(&NCtr());
533 }
534 if (!ok || mover || wflag || nflag)
535 M(i) = 1;
536 // only mark partners we MAINTAIN (owned); a ghost partner is the owning rank's
537 // responsibility.
538 for (int q = 0; q < nP; ++q)
539 if (partners[q] < nP_)
540 Kokkos::atomic_exchange(&M(partners[q]), 1);
541 if (doExtra) { // each pair of gaining cells gains the other -> seed the surgical
542 // candidate lists
543 for (int q = 0; q < nP; ++q) {
544 const int cell = partners[q];
545 if (cell < 0 || cell >= nP_)
546 continue;
547 for (int r = 0; r < nP; ++r) {
548 if (r == q)
549 continue;
550 const int nb = partners[r];
551 if (nb < 0)
552 continue;
553 const int slot = Kokkos::atomic_fetch_add(&EC(cell), 1);
554 if (slot < kCap)
555 EN((size_t)cell * kCap + slot) = nb;
556 }
557 }
558 }
559 });
560 }
561
570 template <bool Local>
571 void certifyList(const Kokkos::View<Real*, Mem>& pos, const Kokkos::View<int*, Mem>& list, int n,
572 const Kokkos::View<int*, Mem>& outMask) {
573 Kokkos::deep_copy(outMask, 0);
574 if (n <= 0)
575 return;
576 auto P = pos;
577 auto Vv = vol;
578 auto M = outMask;
579 Store st = store;
580 auto Pk4 = store.poke4;
581 const Real Lx = L[0], Ly = L[1], Lz = L[2];
582 const Real tolL = tol;
583 const int nP_ = nProc;
584 auto Wt = weight;
586 auto XR = xRef;
587 Kokkos::parallel_for(
588 "mt.certifyList", Kokkos::RangePolicy<Exec>(0, n), KOKKOS_LAMBDA(int s) {
589 const int i = list(s);
590 CertCell c;
591 st.load(i, c, Lx, Ly, Lz);
592 {
593 Real dx, dy, dz;
594 dispFromRef(P, XR, i, Lx, Ly, Lz, dx, dy, dz);
595 Wl.load(i, c, dx, dy, dz); // no-op without a wall store
596 }
597 const Real* wPtr = Wt.data(); // force-capture Wt OUTSIDE the constexpr-if (nvcc rule)
598 Real wSelfI = Real(0);
599 if constexpr (Weighted)
600 wSelfI = Wt(i);
601 c.template reevalGeometry<PlanePolicy>(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx,
602 wSelfI, wPtr);
603 Vv(i) = c.volumePerVertex();
604 int partners[32];
605 int nP = 0;
606 bool ok;
607 const unsigned char* pk4 =
608 &Pk4((size_t)i * MAXT * 4); // force-capture poke4 + tol OUTSIDE the
609 const Real tl = tolL; // constexpr-if (nvcc extended-lambda rule)
610 if constexpr (Local) {
611 // Outside-seed cells (a live plane with nn < 0) take the full test (WO-3b). Only a
612 // power cell can have one: Voronoi keeps the local test with no scan.
613 bool fullTest = false;
614 if constexpr (Weighted)
615 fullTest = c.anyLiveNegOffset();
616 if (fullTest)
617 ok = c.isSelfConsistentPartners(tl, partners, 32, nP);
618 else
619 ok = c.isLocallyConvexPartners(pk4, tl, partners, 32, nP);
620 } else {
621 (void)pk4;
622 ok = c.isSelfConsistentPartners(tl, partners, 32, nP);
623 }
624 if (!ok)
625 M(i) = 1;
626 for (int q = 0; q < nP; ++q)
627 if (partners[q] < nP_)
628 Kokkos::atomic_exchange(&M(partners[q]), 1);
629 });
630 }
631
637 void rebuildAdjAll(const Kokkos::View<Real*, Mem>& pos) {
638 if (!localCert)
639 return;
640 Store st = store;
641 auto P = pos;
642 auto Pk4 = store.poke4;
643 const Real Lx = L[0], Ly = L[1], Lz = L[2];
644 auto Wt = weight;
646 auto XR = xRef;
647 Kokkos::parallel_for(
648 "mt.rebuildAdjAll", Kokkos::RangePolicy<Exec>(0, nProc), KOKKOS_LAMBDA(int i) {
649 BuildCell c;
650 st.load(i, c, Lx, Ly,
651 Lz); // load brings topology; adj is rebuilt to derive the cert planes
652 {
653 Real dx, dy, dz;
654 dispFromRef(P, XR, i, Lx, Ly, Lz, dx, dy, dz);
655 Wl.load(i, c, dx, dy, dz); // no-op without a wall store
656 }
657 const Real* wPtr = Wt.data(); // force-capture Wt OUTSIDE the constexpr-if (nvcc rule)
658 Real wSelfI = Real(0);
659 if constexpr (Weighted)
660 wSelfI = Wt(i);
661 c.template reevalGeometry<PlanePolicy>(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx,
662 wSelfI, wPtr); // computePoke4 needs vertices
664 c.computePoke4(&Pk4((size_t)i * MAXT *
665 4)); // the only thing this pass produces (topology unchanged)
666 });
667 }
673 void maybeBuildAdj(const Kokkos::View<Real*, Mem>& pos) {
674 if (localCert && !adjFresh) {
675 rebuildAdjAll(pos);
676 adjFresh = true;
677 useLocalNow = true;
678 }
679 }
680
685 void gatherSet(const TessGrid<Real>& grid, const Kokkos::View<int*, Mem>& wl, int n,
686 const Kokkos::View<Real*, Mem>& pos) {
687 if (n <= 0)
688 return;
689 // TrackAdj gather: clip stitches the edge adjacency incrementally; the builder derives the cert
690 // plane set from it (computePoke4, no findSharing) into store.poke4, so the local cert stays
691 // valid for the gathered cells with no separate maintenance pass.
692 subsetGather<Real, Weighted, true, Sdf>(grid, wl, n, store.np, store.nt, store.pnbr, store.tri,
693 vol, store.poke4, sdf, /*withForceGeom=*/false, wall,
696 auto W = wl;
697 auto rb = rebuilt;
698 auto P = pos;
699 auto XR = xRef;
700 Kokkos::parallel_for(
701 "mt.markRebuilt", Kokkos::RangePolicy<Exec>(0, n), KOKKOS_LAMBDA(int s) {
702 const int i = W(s);
703 rb(i) = 1;
704 XR(3 * i) = P(3 * i);
705 XR(3 * i + 1) = P(3 * i + 1);
706 XR(3 * i + 2) = P(3 * i + 2);
707 });
708 }
709
712 void collectNewNbrs(const Kokkos::View<int*, Mem>& wl, int n,
713 const Kokkos::View<int*, Mem>& outMask) {
714 Kokkos::deep_copy(outMask, 0);
715 if (n <= 0)
716 return;
717 Store st = store;
718 auto rb = rebuilt;
719 auto M = outMask;
720 const int nP_ = nProc;
721 Kokkos::parallel_for(
722 "mt.collectNbrs", Kokkos::RangePolicy<Exec>(0, n), KOKKOS_LAMBDA(int s) {
723 const int i = wl(s);
724 const int np = st.np(i), nt = st.nt(i);
725 for (int k = 6; k < np; ++k) {
726 const int j = st.pnbr((size_t)i * MAXP + k);
727 if (j < 0 || j >= nP_ || rb(j))
728 continue; // only expand neighbours we MAINTAIN (owned)
729 int cnt = 0; // face = ≥3 incident live triangles
730 for (int t = 0; t < nt; ++t) {
731 const unsigned w = st.tri((size_t)i * MAXT + t);
732 if (!((w >> 24) & 1u))
733 continue;
734 const int a = (int)(w & 0xffu), b = (int)((w >> 8) & 0xffu),
735 cc = (int)((w >> 16) & 0xffu);
736 if (a == k || b == k || cc == k)
737 ++cnt;
738 }
739 if (cnt >= 3)
740 Kokkos::atomic_exchange(&M(j), 1);
741 }
742 });
743 }
744
753 void surgicalRepair(const Kokkos::View<int*, Mem>& wl, int n,
754 const Kokkos::View<Real*, Mem>& pos) {
755 if (n <= 0)
756 return;
757 auto W = wl;
758 auto P = pos;
759 auto rb = rebuilt;
760 auto XR = xRef;
761 auto Vv = vol;
762 auto EN = extraNbr;
763 auto EC = extraCnt;
764 constexpr int kCap = kExtraCap;
765 Store st = store;
766 auto Pk4 = store.poke4;
767 const Real Lx = L[0], Ly = L[1], Lz = L[2];
768 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
769 Kokkos::parallel_for(
770 "mt.surgical", Kokkos::RangePolicy<Exec>(0, n), KOKKOS_LAMBDA(int s) {
771 const int i = W(s);
772 BuildCell c;
773 c.initBox(Lx, Ly, Lz);
774 const Real sx = P(3 * i), sy = P(3 * i + 1), sz = P(3 * i + 2);
775 const int npi = st.np(i);
776 for (int k = 6; k < npi && !c.overflow; ++k) { // stored neighbours, current positions
777 const int j = st.pnbr((size_t)i * MAXP + k);
778 if (j < 0)
779 continue;
780 Real rx = P(3 * j) - sx, ry = P(3 * j + 1) - sy, rz = P(3 * j + 2) - sz;
781 rx = rx > Lxh ? rx - Lx : (rx < -Lxh ? rx + Lx : rx);
782 ry = ry > Lyh ? ry - Ly : (ry < -Lyh ? ry + Ly : ry);
783 rz = rz > Lzh ? rz - Lz : (rz < -Lzh ? rz + Lz : rz);
784 const Real nrm[3] = {rx, ry, rz};
785 c.clip(nrm, Real(0.5) * (rx * rx + ry * ry + rz * rz), j);
786 }
787 const int ne = EC(i) < kCap ? EC(i) : kCap;
788 for (int e = 0; e < ne && !c.overflow; ++e) { // partner-discovered new neighbours
789 const int j = EN((size_t)i * kCap + e);
790 if (j < 0 || j == i)
791 continue;
792 Real rx = P(3 * j) - sx, ry = P(3 * j + 1) - sy, rz = P(3 * j + 2) - sz;
793 rx = rx > Lxh ? rx - Lx : (rx < -Lxh ? rx + Lx : rx);
794 ry = ry > Lyh ? ry - Ly : (ry < -Lyh ? ry + Ly : ry);
795 rz = rz > Lzh ? rz - Lz : (rz < -Lzh ? rz + Lz : rz);
796 const Real nrm[3] = {rx, ry, rz};
797 c.clip(nrm, Real(0.5) * (rx * rx + ry * ry + rz * rz), j);
798 }
799 if (!c.overflow) {
800 st.save(i, c);
801 Vv(i) = c.volumePerVertex();
802 c.computePoke4(
803 &Pk4((size_t)i * MAXT * 4)); // refresh the cert plane set for this re-clipped cell
804 }
805 rb(i) = 1;
806 XR(3 * i) = sx;
807 XR(3 * i + 1) = sy;
808 XR(3 * i + 2) = sz;
809 });
810 }
811
818 bool dilate(const TessGrid<Real>& grid, const Kokkos::View<Real*, Mem>& pos) {
819 const int dimx = grid.dimx, dimy = grid.dimy, dimz = grid.dimz;
820 const int ncell = dimx * dimy * dimz;
821 if ((int)cellFlag.extent(0) < ncell)
822 cellFlag = Kokkos::View<int*, Mem>(
823 Kokkos::view_alloc(std::string("mt.cellFlag"), Kokkos::WithoutInitializing), ncell);
824 Kokkos::deep_copy(cellFlag, 0);
825 const Real icx = grid.icx, icy = grid.icy, icz = grid.icz;
826 auto P = pos;
827 auto M = mask;
828 auto CF = cellFlag;
829 Kokkos::parallel_for(
830 "mt.dilate.count", Kokkos::RangePolicy<Exec>(0, nProc), KOKKOS_LAMBDA(int i) {
831 if (!M(i))
832 return;
833 const int gx = ((int)Kokkos::floor(P(3 * i) * icx) % dimx + dimx) % dimx;
834 const int gy = ((int)Kokkos::floor(P(3 * i + 1) * icy) % dimy + dimy) % dimy;
835 const int gz = ((int)Kokkos::floor(P(3 * i + 2) * icz) % dimz + dimz) % dimz;
836 Kokkos::atomic_inc(&CF(gx + gy * dimx + gz * dimx * dimy));
837 });
838 const int thr = clusterNbhd;
839 long added = 0;
840 Kokkos::parallel_reduce(
841 "mt.dilate.mark", Kokkos::RangePolicy<Exec>(0, nProc),
842 KOKKOS_LAMBDA(int i, long& a) {
843 if (M(i))
844 return;
845 const int gx = ((int)Kokkos::floor(P(3 * i) * icx) % dimx + dimx) % dimx;
846 const int gy = ((int)Kokkos::floor(P(3 * i + 1) * icy) % dimy + dimy) % dimy;
847 const int gz = ((int)Kokkos::floor(P(3 * i + 2) * icz) % dimz + dimz) % dimz;
848 int sum = 0;
849 for (int dz = -1; dz <= 1; ++dz)
850 for (int dy = -1; dy <= 1; ++dy)
851 for (int dx = -1; dx <= 1; ++dx) {
852 const int nx = (gx + dx + dimx) % dimx, ny = (gy + dy + dimy) % dimy,
853 nz = (gz + dz + dimz) % dimz;
854 sum += CF(nx + ny * dimx + nz * dimx * dimy);
855 }
856 if (sum > thr) {
857 M(i) = 1;
858 ++a;
859 }
860 },
861 added);
862 return added > 0;
863 }
864
868 void certifyDispatch(const Kokkos::View<Real*, Mem>& pos, const Kokkos::View<int*, Mem>& outMask,
869 const Kokkos::View<int*, Mem>& outMover, bool useSkin) {
870 if (useLocalNow)
871 certify<true>(pos, outMask, outMover, useSkin);
872 else
873 certify<false>(pos, outMask, outMover, useSkin);
874 }
875 void certifyListDispatch(const Kokkos::View<Real*, Mem>& pos, const Kokkos::View<int*, Mem>& list,
876 int n, const Kokkos::View<int*, Mem>& outMask) {
877 if (useLocalNow)
878 certifyList<true>(pos, list, n, outMask);
879 else
880 certifyList<false>(pos, list, n, outMask);
881 }
882
884 RepairStats step(const Kokkos::View<Real*, Mem>& pos) {
885 RepairStats s;
886 auto grid = buildTessGrid<Real, Weighted>(pos, weight, N, L, sw, densityCount,
887 Kokkos::View<long*, Mem>());
888 Kokkos::deep_copy(rebuilt, 0);
889 // Use the cheap local certificate whenever store.poke4 is valid for the current topology. With
890 // the 4th-face plane included the local cert matches the brute flag set (it is complete, not a
891 // subset), so no per-step displacement gate or brute fallback is needed — large moves and
892 // teleports are handled by the same detect→gather→verify path. (adj/face4 are invalidated only
893 // by a cold rebuild.)
895
896 // Pass 1: detect (flagged ∪ partners ∪ skin-movers). flagged-commons + their violated-plane
897 // partners (the gaining cells) fully cover an isolated flip — no Pass 2 for flips.
898 certifyDispatch(pos, mask, mover, /*useSkin=*/true);
899 int n1 = compact(mask, wl1);
900 s.pass1Raw = n1;
901 if constexpr (kHasSdf)
902 Kokkos::deep_copy(s.wallFlagged, wallCounter);
903 if (useNearMiss)
904 Kokkos::deep_copy(s.nearFlagged, nearCounter);
905
906 // Small-displacement fast path: the certificate found every cell consistent and no skin-mover
907 // (n1 counts flagged ∪ partners ∪ movers). By the §1 completeness argument a stale topology
908 // always flags some cell, so n1==0 ⇒ the stored topology is still Voronoi on the new positions
909 // — the re-eval already refreshed every volume, so publish with NO gather and NO verify pass.
910 // This is the "almost no cells invalidated" regime: the per-step cost collapses to one re-eval
911 // + the grid.
912 if (n1 == 0) {
913 maybeBuildAdj(pos);
914 return s;
915 }
916
917 // Phase-3 adaptive gate (decided here, after the FREE certificate, before any gather):
918 // high global churn -> a full rebuild is cheaper than repairing this many cells;
919 // dense local cluster -> dilate the Pass-1 set by a grid-cell buffer (one regional gather);
920 // else (sparse) -> the two-pass repair below.
921 if (useGate && (double)n1 / (nProc > 0 ? nProc : 1) > churnThresh) {
922 rebuild(pos,
923 /*eagerAdj=*/false); // high-churn regime: stay on brute, don't pay adj maintenance
925 return s;
926 }
927 if (useNearMiss && !nearFresh) {
928 // First low-churn step after gate-rebuilds: the certificate above ran WITHOUT the near-miss
929 // lists (incomplete for face gains), so do not repair on it — pay one emitting rebuild
930 // (exact) and repair from the next step on with fresh lists.
931 rebuild(pos, /*eagerAdj=*/true);
933 return s;
934 }
935 if (useGate && useDilation && n1 > 0 && (double)n1 / nProc < dilateMaxChurn &&
936 dilate(grid, pos)) {
937 n1 = compact(mask, wl1);
939 }
940 s.pass1 = n1;
941 int nM = compact(mover, wlM);
942 // Pass 1 gather. Phase 4: FLIP cells (flagged non-movers) are repaired SURGICALLY (re-clip
943 // known candidates, no grid gather); far-mover insertions keep the full gather (their new
944 // neighbours are in no candidate list). Default (surgical off): the whole Pass-1 set goes
945 // through the full gather.
946 if (surgical && !kHasSdf) {
947 auto Msk = mask;
948 auto Mv = mover;
949 auto M2 = mask2;
950 Kokkos::parallel_for(
951 "mt.surgMask", Kokkos::RangePolicy<Exec>(0, nProc),
952 KOKKOS_LAMBDA(int i) { M2(i) = (Msk(i) && !Mv(i)) ? 1 : 0; });
953 int nS =
954 compact(mask2, wl1); // wl1's Pass-1 list no longer needed -> reuse for the flip list
955 s.surgical = nS;
956 surgicalRepair(wl1, nS, pos); // flips: no gather
957 gatherSet(grid, wlM, nM, pos); // movers: full gather
958 } else {
959 gatherSet(grid, wl1, n1, pos);
960 }
961
962 // Pass 2: ONLY the new face-neighbours of the skin-MOVERS (the insertion side §1c — those
963 // neighbours never flag and are never partners). Expanding every Pass-1 cell would re-clip ~all
964 // neighbours of every flip cluster for nothing; movers are the only cells whose rebuild reveals
965 // an unflagged gainer.
967 int n2 = compact(mask2, wl2);
968 s.pass2 = n2;
969 gatherSet(grid, wl2, n2, pos);
971 pos); // first low-churn step after a rebuild: populate adj so verify + next steps go local
972
973 // Verify (scoped): re-certify only the GATHERED cells (every non-gathered cell is provably
974 // unchanged — see certifyList). Clean ⇒ publish; else gather the still-flagged ∪ partners
975 // (residual coupled flips / tol-degenerate cells) and re-verify, bounded.
976 for (int vp = 0; vp < verifyCap + 1; ++vp) {
977 const int ng = compact(rebuilt, wl1); // all cells gathered so far this step
978 // Verify with the step's certificate: a far/teleport step already forced useLocalNow=false,
979 // so its verify is the COMPLETE brute form (catches far-pokes the gather left on a gathered
980 // cell). A small- displacement local step uses the cheap local verify over the
981 // freshly-gathered (locally convex) set.
982 certifyListDispatch(pos, wl1, ng, mask);
983 int nv = compact(mask, wl2);
984 s.verifyPasses = vp + 1;
985 if (nv == 0)
986 return s; // clean — done
987 if (vp == verifyCap)
988 break; // out of budget — fall back
989 s.extra += nv;
990 gatherSet(grid, wl2, nv, pos);
991 }
992
993 // Still dirty after the verify budget: cold rebuild (always exact). Rare; the data point that
994 // says "for this step, rebuild was cheaper" — the adaptive gate (Phase 3) will pre-empt it up
995 // front.
996 rebuild(pos);
997 s.fellBack = true;
998 return s;
999 }
1000};
1001
1002} // namespace peclet::voro
1003
1004#endif // PECLET_VORO_REPAIR_HPP
Device-native Voronoi tessellation, geometry and finite-volume physics.
Definition convex_cell.hpp:41
@ kOverflow
Definition tessellator.hpp:50
@ kBuried
Definition tessellator.hpp:62
@ kReachExceeded
Definition tessellator.hpp:63
@ kDegenerate
Definition tessellator.hpp:67
@ kIncomplete
Definition tessellator.hpp:52
@ kEmpty
Definition tessellator.hpp:51
KOKKOS_INLINE_FUNCTION bool sdfWouldClip(const ConvexCell< Real, MAXP, MAXT, TrackAdj > &c, const Real seed[3], const Sdf &sdf)
Definition sdf.hpp:552
constexpr int kMaxPlanes
Definition params.hpp:18
constexpr int kMaxTriangles
Definition params.hpp:19
constexpr int kSearchWindow
Definition params.hpp:28
A2a validity diagnostics of a cold (re)build (counts over the maintained cells).
Definition repair.hpp:77
long buried
power cells that are empty (exact — see kBuried)
Definition repair.hpp:78
long empty
cells with no volume (in-solid seeds + empty power cells)
Definition repair.hpp:80
long reachExceeded
cells whose search reach passed half the box (min-image invalid)
Definition repair.hpp:79
long incomplete
cells whose coverage did not close
Definition repair.hpp:82
long degenerate
cells cut through a (near-)cospherical vertex (kDegenerate; valid)
Definition repair.hpp:83
int overBufferRebuilds
over-buffer misses of the build (TessellatorResult)
Definition repair.hpp:84
long overflow
cells that hit a capacity (planes / triangles / facets)
Definition repair.hpp:81
Definition convex_cell.hpp:140
KOKKOS_INLINE_FUNCTION Real volumePerVertex() const
Definition convex_cell.hpp:1585
KOKKOS_INLINE_FUNCTION Real planeGap(const Real pdir[3], Real d) const
Definition convex_cell.hpp:611
KOKKOS_INLINE_FUNCTION bool isLocallyConvexPartners(const unsigned char *poke4, Real tol, int *outPartners, int maxPartners, int &nPartners) const
Definition convex_cell.hpp:537
unsigned char t1[MAXT]
Definition convex_cell.hpp:156
KOKKOS_INLINE_FUNCTION void initBox(Real L0, Real L1, Real L2)
Definition convex_cell.hpp:182
bool overflow
set if MAXP/MAXT exceeded -> cell invalid, caller falls back
Definition convex_cell.hpp:160
int nt
triangle high-water mark
Definition convex_cell.hpp:159
KOKKOS_INLINE_FUNCTION void rebuildAdjacency()
Definition convex_cell.hpp:709
Real vy[MAXT]
Definition convex_cell.hpp:157
KOKKOS_INLINE_FUNCTION bool isSelfConsistentPartners(Real tol, int *outPartners, int maxPartners, int &nPartners) const
Definition convex_cell.hpp:424
int pnbr[MAXP]
neighbour seed id per plane (<0 => bounding box)
Definition convex_cell.hpp:154
Real vx[MAXT]
Definition convex_cell.hpp:157
unsigned char t2[MAXT]
triangle = triple of plane indices
Definition convex_cell.hpp:156
KOKKOS_INLINE_FUNCTION bool clip(const Real pdir[3], Real d, int nbr, Real *gapOut=nullptr)
Definition convex_cell.hpp:895
unsigned char t0[MAXT]
Definition convex_cell.hpp:156
KOKKOS_INLINE_FUNCTION bool anyLiveNegOffset() const
Definition convex_cell.hpp:268
KOKKOS_INLINE_FUNCTION void computePoke4(unsigned char *out) const
Definition convex_cell.hpp:474
bool alive[MAXT]
triangle live flag
Definition convex_cell.hpp:158
Real vz[MAXT]
cached dual-vertex position per triangle
Definition convex_cell.hpp:157
Definition repair.hpp:91
Kokkos::View< int, Mem > nearCounter
Definition repair.hpp:209
void gatherSet(const TessGrid< Real > &grid, const Kokkos::View< int *, Mem > &wl, int n, const Kokkos::View< Real *, Mem > &pos)
Definition repair.hpp:685
bool surgical
repair flip cells by re-clipping known candidates instead of gathering
Definition repair.hpp:145
bool wallExact
re-gather every wall-clipped cell that moved (== cold build)
Definition repair.hpp:214
Kokkos::View< int *, Mem > rebuilt
Definition repair.hpp:218
peclet::core::MemSpace Mem
Definition repair.hpp:92
Kokkos::View< int, Mem > counter
Definition repair.hpp:221
double dilateMaxChurn
Definition repair.hpp:129
void certify(const Kokkos::View< Real *, Mem > &pos, const Kokkos::View< int *, Mem > &outMask, const Kokkos::View< int *, Mem > &outMover, bool useSkin)
Definition repair.hpp:349
Kokkos::View< Real *, Mem > vol
Definition repair.hpp:185
bool useNearMiss
Definition repair.hpp:201
WallStore< Real > wall
persisted wall planes (allocated by alloc() when kHasSdf)
Definition repair.hpp:213
int nProc
Definition repair.hpp:106
Kokkos::View< int *, Mem > mask
Definition repair.hpp:218
void certifyDispatch(const Kokkos::View< Real *, Mem > &pos, const Kokkos::View< int *, Mem > &outMask, const Kokkos::View< int *, Mem > &outMover, bool useSkin)
Definition repair.hpp:868
Kokkos::View< int *, Mem > mask2
Definition repair.hpp:218
int densityCount
Definition repair.hpp:109
bool localCert
Definition repair.hpp:149
peclet::core::ExecSpace Exec
Definition repair.hpp:93
Kokkos::View< int *, Mem > cellFlag
Definition repair.hpp:219
int lastOverBufferRebuilds
of the last cold (re)build (BuildReport)
Definition repair.hpp:120
void surgicalRepair(const Kokkos::View< int *, Mem > &wl, int n, const Kokkos::View< Real *, Mem > &pos)
Definition repair.hpp:753
int N
total cells in the resident arrays (single-domain: all; MPI: owned+ghost)
Definition repair.hpp:105
Kokkos::View< int, Mem > wallCounter
Definition repair.hpp:216
void rebuild(const Kokkos::View< Real *, Mem > &pos, bool eagerAdj=true)
Definition repair.hpp:298
RepairStats step(const Kokkos::View< Real *, Mem > &pos)
One moving-point update step. Updates store + vol in place from pos.
Definition repair.hpp:884
Kokkos::View< Real *, Mem > xRef
Definition repair.hpp:186
bool profile
the cold build's timing / over-buffer report on stderr
Definition repair.hpp:119
Real L[3]
Definition repair.hpp:110
void certifyList(const Kokkos::View< Real *, Mem > &pos, const Kokkos::View< int *, Mem > &list, int n, const Kokkos::View< int *, Mem > &outMask)
Definition repair.hpp:571
int gridNcell
Definition repair.hpp:222
void alloc(int n, const Real Lbox[3], Real tol_, Real skin_, int sw_=kSearchWindow, int densityCount_=-1, int nProc_=-1)
Definition repair.hpp:228
bool adjFresh
Definition repair.hpp:157
int clusterNbhd
Definition repair.hpp:132
bool dilate(const TessGrid< Real > &grid, const Kokkos::View< Real *, Mem > &pos)
Definition repair.hpp:818
Kokkos::View< int *, Mem > extraCnt
Definition repair.hpp:220
bool useDilation
Definition repair.hpp:121
Real nearMarginFrac
margin = nearMarginFrac · skin
Definition repair.hpp:203
bool nearFresh
Definition repair.hpp:204
Kokkos::View< Real *, Mem > weight
Definition repair.hpp:187
static KOKKOS_INLINE_FUNCTION void dispFromRef(const Kokkos::View< Real *, Mem > &P, const Kokkos::View< Real *, Mem > &XR, int i, Real Lx, Real Ly, Real Lz, Real &dx, Real &dy, Real &dz)
Definition repair.hpp:278
Kokkos::View< int *, Mem > wl1
Definition repair.hpp:218
int verifyCap
max verify extra-passes before falling back to a full rebuild
Definition repair.hpp:114
static constexpr bool kHasSdf
Definition repair.hpp:95
Real skin
Verlet skin width (absolute); a particle moving > skin/2 is a Pass-1 mover.
Definition repair.hpp:113
void maybeBuildAdj(const Kokkos::View< Real *, Mem > &pos)
Definition repair.hpp:673
Kokkos::View< int *, Mem > extraNbr
Definition repair.hpp:220
Kokkos::View< int *, Mem > mover
Definition repair.hpp:218
bool useGate
high-churn → rebuild routing (the "never slower than rebuild" guard)
Definition repair.hpp:118
Kokkos::View< int *, Mem > wlM
Definition repair.hpp:218
Kokkos::View< int *, Mem > lastStatus
Definition repair.hpp:164
int compact(const Kokkos::View< int *, Mem > &m, const Kokkos::View< int *, Mem > &wl)
Compact the nonzero entries of m[0..nProc) into wl, returning the count.
Definition repair.hpp:322
bool useLocalNow
this step's certify uses the local cert (= localCert && adjFresh)
Definition repair.hpp:162
int sw
Definition repair.hpp:109
BuildReport report() const
A2a validity diagnostics of the last cold (re)build (counts over the maintained cells).
Definition repair.hpp:166
Sdf sdf
the geometry provider (replicated on every rank under MPI)
Definition repair.hpp:212
void rebuildAdjAll(const Kokkos::View< Real *, Mem > &pos)
Definition repair.hpp:637
void setWeights(const Kokkos::View< Real *, Mem > &w)
Set the per-seed power weights (Weighted only). Held by reference; the caller keeps it alive.
Definition repair.hpp:191
Kokkos::View< int *, Mem > near
Definition repair.hpp:208
Kokkos::View< int *, Mem > wl2
Definition repair.hpp:218
std::conditional_t< Weighted, Power, Voronoi > PlanePolicy
Definition repair.hpp:94
Kokkos::View< int *, Mem > nearCnt
Definition repair.hpp:208
Real tol
certificate tolerance (absolute distance); ~1e-4·spacing FP64, ~2e-3·spacing FP32
Definition repair.hpp:111
static constexpr int kExtraCap
per-cell capacity for partner-discovered new neighbours
Definition repair.hpp:147
int kNearCap
per-cell list capacity (overflow ⇒ re-gather every step)
Definition repair.hpp:202
double churnThresh
Definition repair.hpp:126
void certifyListDispatch(const Kokkos::View< Real *, Mem > &pos, const Kokkos::View< int *, Mem > &list, int n, const Kokkos::View< int *, Mem > &outMask)
Definition repair.hpp:875
Store store
Definition repair.hpp:184
Real wallSkin
skin mode (wallExact=false): re-gather a wall cell only past this
Definition repair.hpp:215
void collectNewNbrs(const Kokkos::View< int *, Mem > &wl, int n, const Kokkos::View< int *, Mem > &outMask)
Definition repair.hpp:712
Sentinel "no geometry" provider — the default; the clip stage is skipped.
Definition sdf.hpp:39
Per-step repair telemetry.
Definition repair.hpp:61
int wallFlagged
cells flagged by the SDF boundary watch (0 without an SDF)
Definition repair.hpp:70
int extra
cells gathered across the verify extra-passes
Definition repair.hpp:67
int pass1
cells gathered in Pass 1 (flagged ∪ partners ∪ skin-movers, after dilation)
Definition repair.hpp:64
int surgical
Pass-1 cells repaired surgically (Phase 4, no grid gather)
Definition repair.hpp:68
int pass2
cells gathered in Pass 2 (new face-neighbours of the movers)
Definition repair.hpp:66
bool fellBack
true if the cold-build fallback was triggered (repair did not close)
Definition repair.hpp:73
Route route
Definition repair.hpp:72
int pass1Raw
flagged count BEFORE dilation (the gate signal: pass1Raw/nProc = churn)
Definition repair.hpp:65
Route
Which path the Phase-3 adaptive gate took this step.
Definition repair.hpp:63
@ kDilated
Definition repair.hpp:63
@ kTwoPass
Definition repair.hpp:63
@ kRebuildGate
Definition repair.hpp:63
int nearFlagged
cells flagged by the near-miss (face-gain) check
Definition repair.hpp:71
int verifyPasses
number of verify iterations run
Definition repair.hpp:69
Definition tess_grid.hpp:56
int dimz
Definition tess_grid.hpp:71
int dimy
Definition tess_grid.hpp:71
int dimx
Definition tess_grid.hpp:71
Real icz
Definition tess_grid.hpp:70
Real icx
Definition tess_grid.hpp:70
Real icy
Definition tess_grid.hpp:70
Definition topology_store.hpp:39
void alloc(int n)
Definition topology_store.hpp:53
Kokkos::View< int *, MemSpace > np
Definition topology_store.hpp:42
Kokkos::View< unsigned char *, MemSpace > poke4
Definition topology_store.hpp:47
KOKKOS_INLINE_FUNCTION void load(int i, Cell &c, Real L0, Real L1, Real L2) const
Definition topology_store.hpp:93
Kokkos::View< unsigned *, MemSpace > tri
Definition topology_store.hpp:45
KOKKOS_INLINE_FUNCTION void save(int i, const Cell &c) const
Persist cell c at slot i (call after the cell is finalised — clipped + complete).
Definition topology_store.hpp:75
Kokkos::View< int *, MemSpace > nt
Definition topology_store.hpp:43
Kokkos::View< int *, MemSpace > pnbr
Definition topology_store.hpp:44
void allocPoke4()
Definition topology_store.hpp:67
Definition sdf.hpp:352
Kokkos::View< int *, MemSpace > cnt
Definition sdf.hpp:356
KOKKOS_INLINE_FUNCTION bool load(int i, Cell &c, Real dx, Real dy, Real dz) const
Definition sdf.hpp:393