peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
tessellator.hpp
Go to the documentation of this file.
1
26#ifndef PECLET_VORO_TESSELLATOR_HPP
27#define PECLET_VORO_TESSELLATOR_HPP
28
29#include <array>
30#include <cmath>
31#include <cstdint>
32#include <cstdio>
33#include <Kokkos_Core.hpp>
34#include <string>
35#include <type_traits>
36#include <vector>
37
38#include "morton/morton.hpp" // suite spatial-index primitive (after Kokkos_Core: MORTON_HD->KOKKOS_FUNCTION)
39#include "peclet/core/common/view.hpp"
41#include "peclet/voro/sdf.hpp"
42#include "peclet/voro/tess_grid.hpp" // counting-sort grid + worklist (kWlOffBias, morton3, TessGrid)
44
45namespace peclet::voro {
46
49 kOk = 0,
51 kEmpty = 2, // zero-volume cell: an SDF seed in the solid, or an empty power cell (kBuried)
53 // Power only, informational (NOT a defect): the seed lies outside its own NON-empty cell (some
54 // facet plane has radical offset d = ½(|r|²+w_i−w_j) < 0, stored sign-safe with nn < 0). The
55 // geometry is exact.
57 // kBuried — Power only, exact (NOT a defect): the power cell is EMPTY (every point is dominated
58 // in power distance); published with zero volume and no facets, always together with kEmpty.
59 // Rung A2a validity diagnostic kReachExceeded: the cell's converged search reach exceeded half
60 // the smallest box edge, so the min-image gather may have missed a non-nearest periodic image
61 // and the partition is not guaranteed exact.
62 kBuried = 16,
64 // Informational, NOT a defect: a cut of this cell met (near-)cospherical input — a vertex ON the
65 // cutting plane to round-off — and the clip's topology rule decided it (ConvexCell::degenerate,
66 // see inconsistentFan / growDisk). The cell is a valid convex cell, exact up to round-off.
67 kDegenerate = 64
68};
69
70template <class Real>
73 Kokkos::View<int*, peclet::core::MemSpace> status; // per-cell StatusBit mask
78};
79
98template <class Cell, int MAXF>
99KOKKOS_INLINE_FUNCTION int areaGradEnumerate(const Cell& c, const int* faces, int nf,
100 unsigned char* part, unsigned char* pcnt, bool& full) {
101 constexpr int kMaxFV = Cell::MAXFV;
102 signed char faceOf[256];
103 for (int k = 0; k < c.np; ++k)
104 faceOf[k] = -1;
105 for (int idx = 0; idx < nf; ++idx)
106 faceOf[faces[idx]] = (signed char)idx;
107 for (int idx = 0; idx < nf; ++idx)
108 pcnt[idx] = 0;
109 full = false;
110 for (int t = 0; t < c.nt; ++t) {
111 if (!c.alive[t])
112 continue;
113 const int tp[3] = {c.t0[t], c.t1[t], c.t2[t]};
114 for (int a = 0; a < 3; ++a) {
115 const int fa = faceOf[tp[a]];
116 if (fa < 0)
117 continue;
118 for (int b = 0; b < 3; ++b) {
119 if (b == a)
120 continue;
121 const int fb = faceOf[tp[b]];
122 if (fb < 0)
123 continue;
124 bool seen = false;
125 for (int q = 0; q < pcnt[fa]; ++q)
126 if (part[fa * kMaxFV + q] == (unsigned char)fb) {
127 seen = true;
128 break;
129 }
130 if (seen)
131 continue;
132 if (pcnt[fa] >= kMaxFV) {
133 full = true;
134 continue;
135 }
136 part[fa * kMaxFV + pcnt[fa]] = (unsigned char)fb;
137 ++pcnt[fa];
138 }
139 }
140 }
141 int total = 0;
142 for (int idx = 0; idx < nf; ++idx)
143 total += 1 + pcnt[idx];
144 return total;
145}
146
149template <class Cell, int MAXF, class IView, class RView>
150KOKKOS_INLINE_FUNCTION void areaGradFill(const Cell& c, const int* faces, int nf,
151 const unsigned char* part, const unsigned char* pcnt,
152 int base, int ebase, const IView& oEdgeOff,
153 const IView& oEdgeCnt, const IView& oEdgeFacet,
154 const RView& oEdgeGrad, const RView& oEdgeLen) {
155 using Real = typename RView::non_const_value_type;
156 constexpr int kMaxFV = Cell::MAXFV;
157 // Edge lengths (track C2a′, opt-in when oEdgeLen is sized): each facet-edge slot is visited by
158 // exactly the two dual triangles (cell vertices) it joins; accumulate S = v1 + v2 and
159 // Q = |v1|² + |v2|² in a 4-stride scratch, then |v1 − v2|² = 2Q − |S|² (no per-edge state).
160 const bool wl = oEdgeLen.extent(0) > 0;
161 signed char faceOf[256];
162 for (int k = 0; k < c.np; ++k)
163 faceOf[k] = -1;
164 for (int idx = 0; idx < nf; ++idx)
165 faceOf[faces[idx]] = (signed char)idx;
166 int run = ebase;
167 for (int idx = 0; idx < nf; ++idx) {
168 oEdgeOff(base + idx) = run;
169 oEdgeCnt(base + idx) = 1 + pcnt[idx];
170 oEdgeFacet(run) = base + idx;
171 for (int q = 0; q < pcnt[idx]; ++q)
172 oEdgeFacet(run + 1 + q) = base + part[idx * kMaxFV + q];
173 for (int e = 0; e < 1 + pcnt[idx]; ++e) {
174 for (int cc = 0; cc < 3; ++cc)
175 oEdgeGrad((size_t)(run + e) * 3 + cc) = Real(0);
176 if (wl)
177 for (int cc = 0; cc < 4; ++cc)
178 oEdgeLen((size_t)(run + e) * 4 + cc) = Real(0);
179 }
180 run += 1 + pcnt[idx];
181 }
182 for (int t = 0; t < c.nt; ++t) {
183 if (!c.alive[t])
184 continue;
185 int pl[3];
186 Real contrib[3], grad[3][3][3];
187 c.geomVolumeAreaGrad(t, pl, contrib, grad);
188 for (int a = 0; a < 3; ++a) {
189 const int fa = faceOf[pl[a]];
190 if (fa < 0)
191 continue;
192 const int eoff = oEdgeOff(base + fa);
193 for (int b = 0; b < 3; ++b) {
194 const int fb = faceOf[pl[b]];
195 if (fb < 0)
196 continue;
197 int slot = 0;
198 if (b != a) {
199 slot = -1;
200 for (int q = 0; q < pcnt[fa]; ++q)
201 if (part[fa * kMaxFV + q] == (unsigned char)fb) {
202 slot = 1 + q;
203 break;
204 }
205 if (slot < 0)
206 continue;
207 }
208 const size_t o = (size_t)(eoff + slot) * 3;
209 oEdgeGrad(o + 0) += grad[a][b][0];
210 oEdgeGrad(o + 1) += grad[a][b][1];
211 oEdgeGrad(o + 2) += grad[a][b][2];
212 if (wl && slot > 0) {
213 const size_t l = (size_t)(eoff + slot) * 4;
214 oEdgeLen(l + 0) += c.vx[t];
215 oEdgeLen(l + 1) += c.vy[t];
216 oEdgeLen(l + 2) += c.vz[t];
217 oEdgeLen(l + 3) += c.vx[t] * c.vx[t] + c.vy[t] * c.vy[t] + c.vz[t] * c.vz[t];
218 }
219 }
220 }
221 }
222 if (wl) { // finalize: slot 0 (the facet itself) = 0, partners = |v1 − v2|
223 for (int e = ebase; e < run; ++e) {
224 const size_t l = (size_t)e * 4;
225 const Real S2 = oEdgeLen(l) * oEdgeLen(l) + oEdgeLen(l + 1) * oEdgeLen(l + 1) +
226 oEdgeLen(l + 2) * oEdgeLen(l + 2);
227 const Real d2 = Real(2) * oEdgeLen(l + 3) - S2;
228 oEdgeLen(l) = d2 > Real(0) ? Kokkos::sqrt(d2) : Real(0);
229 }
230 }
231}
232
233template <class Real, bool Weighted, class Sdf, bool TrackAdj = false, int MAXP = kMaxPlanes,
234 int MAXT = kMaxTriangles>
236 using MemSpace = peclet::core::MemSpace;
237 // Cell capacities: 64 planes / 112 dual triangles is the production layout (the topology
238 // store's strides). A static build may ask for more (wall-adapted seed shells around curved
239 // walls need ~100 planes per wall cell — rung C4/B follow-up): buildTessellation<…, MAXP, MAXT>.
240 static constexpr int kMaxP = MAXP; // plane cap (overflow -> kOverflow)
241 static constexpr int kMaxT = MAXT; // dual-triangle (vertex) cap
242 static constexpr int MAXF_TMP = MAXP; // max facets one cell may publish
244 using PlanePolicy = std::conditional_t<Weighted, Power, Voronoi>; // radical vs bisector planes
245
246 // Grid-sorted inputs (read).
247 Kokkos::View<int*, MemSpace> binned;
248 Kokkos::View<Real*, MemSpace> posSorted;
249 Kokkos::View<Real*, MemSpace> wSorted;
250 Kokkos::View<gid_t*, MemSpace> gidSorted;
251 Kokkos::View<int*, MemSpace> cellStart;
252 // Per-sub-position worklist (both backends): for the wlS^3 sub-region a seed lands in, the
253 // block offsets (packed (dx,dy,dz), kWlOffBias) sorted by nearest-corner dist^2 (wlRmin,
254 // absolute). The Voronoi gather walks the presorted list and breaks once wlRmin exceeds the
255 // security radius — a table lookup, no per-block geometry. ConvexCell is lean enough that
256 // the worklist runs on the GPU too (its geometry pass is cheap, so no occupancy penalty).
257 Kokkos::View<int*, MemSpace> wlOff;
258 Kokkos::View<Real*, MemSpace> wlRmin;
259 // Published outputs (write).
260 Kokkos::View<int*, MemSpace> status;
261 Kokkos::View<Real*, MemSpace> cellVol;
262 Kokkos::View<int*, MemSpace> facetCount;
263 Kokkos::View<int*, MemSpace> cellFacetBase;
264 Kokkos::View<int*, MemSpace> oNbr;
265 Kokkos::View<Real*, MemSpace> oArea, oDV, oConn;
266 Kokkos::View<int*, MemSpace> facetCursor;
267 // Grid scalars.
268 Real icx, icy, icz, Lx, Ly, Lz, minCsz;
269 Real wMaxAll; // global max weight (Power only) — bounds the weight-aware worklist reach
272 size_t facetCap;
273 Sdf sdf;
274 // Optional Part-II (moving-points) outputs — emitted only when the views are sized (else left
275 // empty so existing callers are unaffected): the compact resident TOPOLOGY store (np/nt +
276 // pnbr/packed-triangles at kMaxP/kMaxT strides, written from the final clipped cell) and the
277 // per-cell CANDIDATE (skin) list = the neighbour ids this cell examined (within the worklist's
278 // security reach), capped at candCap. Together they let a later step re-evaluate geometry
279 // (ConvexCell::reevalGeometry) and locally repair off the skin list without re-gathering. See
280 // peclet/voro/docs/voronoi_dynamic_update_study.md.
281 Kokkos::View<int*, MemSpace> oNp, oNt, oTopoPnbr;
282 Kokkos::View<unsigned*, MemSpace> oTri;
283 Kokkos::View<unsigned char*, MemSpace>
284 oPoke4; // N*kMaxT*4 local-cert plane set (3 edge-opposite +
285 // 4th-face), emitted only when TrackAdj && emitTopo
286 Kokkos::View<int*, MemSpace> oCand, oCandCnt;
289 // Optional (rung A0): the resident SDF WALL planes of each finalised cell, persisted alongside
290 // the topology so the moving-point path can re-evaluate a wall-clipped cell (a wall plane has no
291 // partner seed to rebuild it from). No-op when the store is unallocated.
293 // Optional (rung A3): the facet-edge AREA-JACOBIAN CSR (TessellationView::edge*). Written only
294 // when `withAreaGrad` (the views are sized); one atomic reservation per cell on `edgeCursor`.
295 static constexpr int kMaxFV = Cell::MAXFV; // edge partners one face may have
296 Kokkos::View<int*, MemSpace> oEdgeOff, oEdgeCnt, oEdgeFacet;
297 Kokkos::View<Real*, MemSpace> oEdgeGrad;
298 Kokkos::View<Real*, MemSpace> oEdgeLen; // 4-stride scratch → edge lengths (C2a′)
299 Kokkos::View<int*, MemSpace> edgeCursor;
300 size_t edgeCap = 0;
301 bool withAreaGrad = false;
302 // Optional (moving-point certificate completeness): per-cell NEAR-MISS list — the examined
303 // candidates whose plane did NOT cut but came within `nearMargin` of a vertex, plus the search
304 // reach extended by the margin so no such candidate hides just beyond the security radius. The
305 // repair's certificate re-tests these planes each step (ConvexCell::planeGap), which closes
306 // the face-gain blind spot of the seed-local certificate. A count of nearCap+1 marks overflow
307 // (the cell is then re-gathered every step). Emitted only when oNear is sized.
308 Kokkos::View<int*, MemSpace> oNear, oNearCnt;
309 int nearCap = 0;
310 Real nearMargin = Real(0);
311 // Optional (rung A1, force half): per-cell wall part of dV/dx and dA_wall/dx by in-kernel
312 // central differences of the SDF clip (sdfWallFD). Emitted only when oWallDV is sized.
313 Kokkos::View<Real*, MemSpace> oWallDV, oWallDA;
314 // Optional (track B, rung B1): per-facet second moment ∫|s|² dA about the foot point (over-buffer
315 // like oArea; packed with the facet CSR). Emitted only when oMoment2 is sized.
316 Kokkos::View<Real*, MemSpace> oMoment2;
317 // Original seed index -> grid-sorted slot (TessGrid::slotOf). Read only by a Power build's
318 // publish: a radical plane's connector is the generator connector relVec(slotOf(pnbr)), not
319 // 2·foot. Unused (may be empty) for Voronoi.
320 Kokkos::View<int*, MemSpace> slotOf;
321
326 KOKKOS_INLINE_FUNCTION void publishAreaGrad(const Cell& c, int i, int base, const int* faces,
327 int nf) const {
328 unsigned char part[MAXF_TMP * kMaxFV];
329 unsigned char pcnt[MAXF_TMP];
330 bool full = false;
331 const int total = areaGradEnumerate<Cell, MAXF_TMP>(c, faces, nf, part, pcnt, full);
332 const int ebase = Kokkos::atomic_fetch_add(&edgeCursor(0), total);
333 if (full || (size_t)ebase + (size_t)total > edgeCap) {
334 status(i) |= kOverflow;
335 for (int idx = 0; idx < nf; ++idx) {
336 oEdgeOff(base + idx) = 0;
337 oEdgeCnt(base + idx) = 0;
338 }
339 return;
340 }
341 areaGradFill<Cell, MAXF_TMP>(c, faces, nf, part, pcnt, base, ebase, oEdgeOff, oEdgeCnt,
343 }
344
346 KOKKOS_INLINE_FUNCTION void relVec(int q, Real pix, Real piy, Real piz, Real pv[3]) const {
347 Real rx = posSorted(3 * q + 0) - pix, ry = posSorted(3 * q + 1) - piy,
348 rz = posSorted(3 * q + 2) - piz;
349 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
350 pv[0] = rx > Lxh ? rx - Lx : (rx < -Lxh ? rx + Lx : rx);
351 pv[1] = ry > Lyh ? ry - Ly : (ry < -Lyh ? ry + Ly : ry);
352 pv[2] = rz > Lzh ? rz - Lz : (rz < -Lzh ? rz + Lz : rz);
353 }
354
356 KOKKOS_INLINE_FUNCTION int gridCell(int rgx, int rgy, int rgz) const {
357 int gx = rgx < 0 ? rgx + dimx : (rgx >= dimx ? rgx - dimx : rgx);
358 int gy = rgy < 0 ? rgy + dimy : (rgy >= dimy ? rgy - dimy : rgy);
359 int gz = rgz < 0 ? rgz + dimz : (rgz >= dimz ? rgz - dimz : rgz);
360 return useMorton ? morton3(gx, gy, gz) : (gx + gy * dimx + gz * dimx * dimy);
361 }
362
364 KOKKOS_INLINE_FUNCTION void homeCell(Real pix, Real piy, Real piz, int& cx, int& cy,
365 int& cz) const {
366 cx = ((((int)Kokkos::floor(pix * icx)) % dimx) + dimx) % dimx;
367 cy = ((((int)Kokkos::floor(piy * icy)) % dimy) + dimy) % dimy;
368 cz = ((((int)Kokkos::floor(piz * icz)) % dimz) + dimz) % dimz;
369 }
370
372 KOKKOS_INLINE_FUNCTION int subBase(Real pix, Real piy, Real piz) const {
373 const Real fxi = pix * icx, fyi = piy * icy, fzi = piz * icz;
374 int sx = (int)((fxi - Kokkos::floor(fxi)) * Real(wlS));
375 int sy = (int)((fyi - Kokkos::floor(fyi)) * Real(wlS));
376 int sz = (int)((fzi - Kokkos::floor(fzi)) * Real(wlS));
377 sx = sx < 0 ? 0 : (sx >= wlS ? wlS - 1 : sx);
378 sy = sy < 0 ? 0 : (sy >= wlS ? wlS - 1 : sy);
379 sz = sz < 0 ? 0 : (sz >= wlS ? wlS - 1 : sz);
380 return (sx + wlS * (sy + wlS * sz)) * nOff;
381 }
382
384 KOKKOS_INLINE_FUNCTION int worklistCell(int base, int g, int cx, int cy, int cz) const {
385 const int packed = wlOff(base + g);
386 const int rgx = cx + ((packed & 0xFF) - kWlOffBias);
387 const int rgy = cy + (((packed >> 8) & 0xFF) - kWlOffBias);
388 const int rgz = cz + (((packed >> 16) & 0xFF) - kWlOffBias);
389 return gridCell(rgx, rgy, rgz);
390 }
391
395 KOKKOS_INLINE_FUNCTION void emitEmptyTopo(int i) const {
396 oNp(i) = 6;
397 oNt(i) = 0;
398 for (int k = 0; k < 6; ++k) // the box slots too, so an empty cell's store is fully defined
399 oTopoPnbr[(size_t)i * kMaxP + k] = -1;
400 if (oWall.active())
401 oWall.cnt(i) = 0;
402 }
403
407 KOKKOS_INLINE_FUNCTION void finishCell(Cell& c, int i, Real pix, Real piy, Real piz, Real covSq,
408 Real wSelf = Real(0)) const {
409 if (c.overflow) {
410 status(i) = kOverflow;
411 facetCount(i) = 0;
412 cellFacetBase(i) = 0;
413 cellVol(i) = Real(0);
414 if (emitTopo)
415 emitEmptyTopo(i); // an overflowed cell reads as empty, never as its stale predecessor
416 return;
417 }
418 // Complete iff the gathered coverage inscribes past the reachability radius. Voronoi:
419 // blockReachSq = 4·rSqMax (unchanged). Power: the larger weight-aware reach, so a cell whose
420 // heavy far neighbour lies beyond the coverage is correctly flagged kIncomplete.
421 const bool incomplete =
422 !(covSq > PlanePolicy::template blockReachSq<Real>(c.maxVertexRsq(), wSelf, wMaxAll));
423 (void)sdf;
424 if constexpr (!std::is_same_v<Sdf, NoSdf>) {
425 const Real seedW[3] = {pix, piy, piz};
426 const bool wallFD = oWallDV.extent(0) > 0;
427 Real dV[3] = {Real(0), Real(0), Real(0)}, dA[3] = {Real(0), Real(0), Real(0)};
428 if (wallFD) {
429 // the un-clipped cell is only needed when the clip will act (seed within the circumradius)
430 const Real phiC = sdf.eval(pix, piy, piz);
431 const Real rad = Kokkos::sqrt(c.maxVertexRsq());
432 if (phiC > Real(0) && phiC <= rad + Real(1e-8)) {
433 const Cell unclipped = c;
434 clipCellAgainstSdf<Real, kMaxP, kMaxT>(c, seedW, sdf);
435 bool hasWall = false;
436 for (int k = 0; k < c.np && !hasWall; ++k)
437 hasWall = (c.pnbr[k] == kBoundaryFacet);
438 if (hasWall && !c.empty() && !c.overflow)
439 sdfWallFD<Real, kMaxP, kMaxT>(unclipped, seedW, sdf, Real(1e-4) * rad, dV, dA);
440 } else {
441 clipCellAgainstSdf<Real, kMaxP, kMaxT>(c, seedW, sdf);
442 }
443 for (int d = 0; d < 3; ++d) {
444 oWallDV(3 * (size_t)i + d) = dV[d];
445 oWallDA(3 * (size_t)i + d) = dA[d];
446 }
447 } else {
448 clipCellAgainstSdf<Real, kMaxP, kMaxT>(c, seedW, sdf);
449 }
450 }
451 int st = kOk;
452 if (c.overflow)
453 st |= kOverflow;
454 if (c.degenerate)
455 st |= kDegenerate;
456 // A2a: the converged search reach must stay within the min-image half box.
457 {
458 const Real reachR =
459 Kokkos::sqrt(PlanePolicy::template blockReachSq<Real>(c.maxVertexRsq(), wSelf, wMaxAll));
460 Real Lmin = Lx < Ly ? Lx : Ly;
461 Lmin = Lmin < Lz ? Lmin : Lz;
462 if (reachR > Real(0.5) * Lmin)
463 st |= kReachExceeded;
464 }
465 const bool empty = c.empty();
466 if (empty)
467 st |= kEmpty;
468 if (incomplete)
469 st |= kIncomplete;
470 if constexpr (Weighted) {
471 // The seed lies outside its own non-empty cell iff some facet plane excludes it (nn < 0):
472 // informational, the geometry is exact (independent of the gather order).
473 if (!empty && !c.overflow) {
474 bool neg = false;
475 for (int t = 0; t < c.nt && !neg; ++t)
476 if (c.alive[t])
477 neg = c.nn[c.t0[t]] < Real(0) || c.nn[c.t1[t]] < Real(0) || c.nn[c.t2[t]] < Real(0);
478 if (neg)
479 st |= kNegOffset;
480 }
481 }
482 cellVol(i) = (empty || c.overflow) ? Real(0) : c.volumePerVertex();
483
484 // Part-II: persist the final (post-SDF-clip) topology so a later step can re-eval/repair
485 // without a rebuild.
486 if (emitTopo && !empty && !c.overflow) {
487 oNp(i) = c.np;
488 oNt(i) = c.nt;
489 for (int k = 0; k < c.np; ++k)
490 oTopoPnbr[(size_t)i * kMaxP + k] = c.pnbr[k];
491 for (int t = 0; t < c.nt; ++t)
492 oTri[(size_t)i * kMaxT + t] = (unsigned)c.t0[t] | ((unsigned)c.t1[t] << 8) |
493 ((unsigned)c.t2[t] << 16) | ((c.alive[t] ? 1u : 0u) << 24);
494 if constexpr (TrackAdj) // derive the local-cert plane set from the clip-maintained adj (no
495 // findSharing)
496 c.computePoke4(&oPoke4[(size_t)i * kMaxT * 4]);
497 oWall.save(i, c); // wall planes (no-op unless the store is allocated)
498 } else if (emitTopo && empty) {
499 emitEmptyTopo(i);
500 }
501
502 // Collect this cell's live faces (a plane with >=3 incident live triangles), then reserve
503 // a contiguous CSR range with one atomic and write the per-facet geometry straight in.
504 int faces[MAXF_TMP];
505 int nf = 0;
506 if (!empty && !c.overflow) {
507 for (int k = 0; k < c.np; ++k) {
508 int cnt = 0;
509 for (int t = 0; t < c.nt; ++t)
510 if (c.alive[t] && (c.t0[t] == k || c.t1[t] == k || c.t2[t] == k))
511 ++cnt;
512 if (cnt < 3)
513 continue; // not a polygon face
514 if (nf >= MAXF_TMP) {
515 st |= kOverflow;
516 break;
517 }
518 faces[nf++] = k;
519 }
520 }
521 status(i) = st;
522 const int base = Kokkos::atomic_fetch_add(&facetCursor(0), nf);
523 if ((size_t)base + (size_t)nf > facetCap) {
524 status(i) |= kOverflow;
525 facetCount(i) = 0;
526 cellFacetBase(i) = 0;
527 return;
528 }
529 facetCount(i) = nf;
530 cellFacetBase(i) = base;
531 if (withAreaGrad && nf > 0)
532 publishAreaGrad(c, i, base, faces, nf);
533 for (int idx = 0; idx < nf; ++idx) {
534 const int k = faces[idx];
535 Real area[3] = {0, 0, 0}, dv[3] = {0, 0, 0}, conn[3];
536 conn[0] = Real(2) * c.n[k][0];
537 conn[1] = Real(2) * c.n[k][1];
538 conn[2] = Real(2) * c.n[k][2];
539 if constexpr (Weighted) {
540 // Power: the connector is the generator connector the radical plane was clipped with
541 // (the same relVec), not 2·foot: the plane is shifted by the weight difference (and a
542 // re-evaluated cell whose seed lies outside it has its foot pointing AWAY from the
543 // neighbour, see reevalPublish). Box and wall planes (pnbr < 0) keep 2·foot.
544 if (c.pnbr[k] >= 0)
545 relVec(slotOf(c.pnbr[k]), pix, piy, piz, conn);
546 if (withForceGeom)
547 c.facetGeometryFrom(k, conn, area, dv); // area vector (along conn) + dV
548 } else {
549 if (withForceGeom)
550 c.facetGeometry(k, area, dv, conn); // area vector + dV + connector
551 }
552 if (oMoment2.extent(0) > 0)
553 oMoment2((size_t)base + idx) = c.faceMoment2(k);
554 oNbr((size_t)base + idx) = c.pnbr[k];
555 const size_t o = ((size_t)base + idx) * 3;
556 for (int cc = 0; cc < 3; ++cc) {
557 oArea(o + cc) = area[cc];
558 oDV(o + cc) = dv[cc];
559 oConn(o + cc) = conn[cc];
560 }
561 }
562 }
563
570 KOKKOS_INLINE_FUNCTION bool gatherCell(int pi, Cell& c, Real& pix, Real& piy, Real& piz,
571 Real& wSelf, int& ncRec, int& nnRec) const {
572 // Voronoi (Weighted=false) uses the bisector plane + security-radius early-out. Power
573 // (Weighted=true) uses the radical plane offset ½(|r|²+w_self−w_nbr) — which can be negative
574 // (the seed can lie OUTSIDE its own cell; the clip stores such a plane sign-safe) so the
575 // bisector security certificate is invalid; Power walks the weight-aware reach instead.
576 const int i = binned(pi);
577 pix = posSorted(3 * pi + 0);
578 piy = posSorted(3 * pi + 1);
579 piz = posSorted(3 * pi + 2);
580 int cx, cy, cz;
581 homeCell(pix, piy, piz, cx, cy, cz);
582 const int base = subBase(pix, piy, piz);
583 c.initBox(Lx, Ly, Lz);
584 wSelf = Real(0);
585 if constexpr (Weighted)
586 wSelf = wSorted(pi);
587 bool emptied = false; // Power: a clip took every vertex — the power cell is empty
588 // Early wall clip (rung C4/B follow-up): the tangent plane at the SEED'S OWN FOOT on the wall
589 // bounds the cell toward the solid before any neighbour is gathered. Without it a cell next
590 // to a curved wall extends through the solid to the far side until the SDF clip runs after
591 // the gather — for nearly cospherical seeds (a wall-adapted shell around a sphere) every
592 // shell seed then neighbours every other through the sphere's centre and the plane cap
593 // overflows at any capacity. The plane is the first wall facet; the full clip refines it.
594 if constexpr (!std::is_same_v<Sdf, NoSdf>) {
595 const Real phi0 = sdf.eval(pix, piy, piz);
596 if (phi0 > Real(0)) {
597 Real g[3];
598 sdfGradient(sdf, pix, piy, piz, g);
599 const Real gl = Kokkos::sqrt(g[0] * g[0] + g[1] * g[1] + g[2] * g[2]);
600 if (gl > Real(0)) {
601 // RETREATED by φ₀ into the solid (plane at 2φ₀): the tangent plane itself would cut the
602 // fluid sliver between it and a convex wall (w²/2R deep at lateral distance w — measured
603 // 1 % of the fluid volume on the sphere array); at 2φ₀ it only bounds the reach, the
604 // vertex-foot clip (A0/A1) then places the exact wall facets.
605 const Real pdir[3] = {-g[0] / gl, -g[1] / gl, -g[2] / gl};
606 c.clip(pdir, Real(2) * phi0, kBoundaryFacet);
607 }
608 }
609 }
610
611 // The worklist is sorted by nearest-corner dist², so once wlRmin exceeds the reachability
612 // radius every remaining block is too far to cut — break. Voronoi keeps the exact bisector
613 // certificate (secR2 = 2·rSqMax, break at wlRmin > 2·secR2 = 4·rSqMax) so the unweighted path
614 // stays byte-identical. Power uses the weight-aware reach (blockReachSq) with the global max
615 // weight.
616 Real secR2 = Real(2) * c.maxVertexRsq(); // Voronoi
617 Real reachSq =
618 PlanePolicy::template blockReachSq<Real>(c.maxVertexRsq(), wSelf, wMaxAll); // Pow
619 ncRec = 0; // Part-II: count of recorded candidate (skin) ids for this cell
620 const bool emitNear = oNear.extent(0) > 0 && nearCap > 0;
621 nnRec = 0; // near-miss candidates recorded for this cell
622 // With near-miss emission the worklist reach grows by the margin: a plane can miss the cell
623 // by less than the margin while its seed sits beyond the security radius.
624 const Real nm = emitNear ? nearMargin : Real(0);
625 for (int g = 0; g < nOff && !c.overflow && !emptied; ++g) {
626 if constexpr (Weighted) {
627 const Real rr = Kokkos::sqrt(reachSq) + Real(2) * nm;
628 if (wlRmin(base + g) > rr * rr)
629 break;
630 } else {
631 // sorted ⇒ rest are farther; cell closed. Break radius² = 4·rSqMax = 2·secR2, extended to
632 // (2·rmax + 2·margin)² when near-misses are recorded.
633 const Real rr = Kokkos::sqrt(Real(2) * secR2) + Real(2) * nm;
634 if (wlRmin(base + g) > rr * rr)
635 break;
636 }
637 const int gc = worklistCell(base, g, cx, cy, cz);
638 for (int q = cellStart(gc); q < cellStart(gc + 1) && !c.overflow && !emptied; ++q) {
639 if (q == pi)
640 continue;
641 if (haveGid && gidSorted(q) == gidSorted(pi))
642 continue;
643 // A seed already clipped is a SECOND PERIODIC IMAGE reaching the worklist (a large cell
644 // whose search radius, block-rounded and extended by the near-miss margin, passes half
645 // the box): keep the first, nearest image — the min-image the re-evaluation rebuilds —
646 // and skip the rest, or the resident topology carries two planes for one neighbour and
647 // re-evaluates to a different cell (measured on a wall-hugging cell: 1.24e-3 vs 2.3e-4).
648 {
649 const int id = binned(q);
650 bool dup = false;
651 for (int k = 6; k < c.np && !dup; ++k)
652 dup = (c.pnbr[k] == id);
653 if (dup)
654 continue;
655 }
656 // record the examined neighbour as a skin candidate (within the worklist's security reach),
657 // capped.
658 if (emitCand && ncRec < candCap)
659 oCand[(size_t)i * candCap + ncRec++] = binned(q);
660 Real pv[3];
661 relVec(q, pix, piy, piz, pv);
662 Real wNbr = Real(0);
663 if constexpr (Weighted)
664 wNbr = wSorted(q);
665 const Real off = PlanePolicy::template offsetFromRel<Real>(pv, wSelf, wNbr);
666 if constexpr (Weighted) {
667 // Power: d = ½(|r|²+w_i−w_j) may be ≤ 0 (the seed lies outside this half-space); the
668 // clip stores the plane sign-safe, and a plane that takes every vertex empties the cell.
669 // Conservative cull, d > 0 only: r·v ≤ |r|·√rSqMax, so |r|²·rSqMax ≤ d² ⇒ no cut.
670 const Real rho = pv[0] * pv[0] + pv[1] * pv[1] + pv[2] * pv[2];
671 if (!emitNear && off > Real(0) && rho * c.maxVertexRsq() <= off * off)
672 continue; // provably beyond reach
673 Real gap;
674 if (c.clip(pv, off, binned(q), emitNear ? &gap : nullptr)) {
675 if (c.nt == 0) { // the power cell is empty: stop the gather
676 emptied = true;
677 break;
678 }
679 reachSq = PlanePolicy::template blockReachSq<Real>(c.maxVertexRsq(), wSelf, wMaxAll);
680 } else if (emitNear && gap > -nm) {
681 if (nnRec < nearCap)
682 oNear[(size_t)i * nearCap + nnRec] = binned(q);
683 ++nnRec;
684 }
685 } else {
686 if (!emitNear && off >= secR2)
687 continue; // beyond the radius: cannot cut (bisector certificate)
688 Real gap;
689 if (c.clip(pv, off, binned(q), emitNear ? &gap : nullptr)) {
690 secR2 = Real(2) * c.maxVertexRsq();
691 } else if (emitNear && gap > -nm) {
692 if (nnRec < nearCap)
693 oNear[(size_t)i * nearCap + nnRec] = binned(q);
694 ++nnRec;
695 }
696 }
697 }
698 }
699 return !emptied;
700 }
701
705 KOKKOS_INLINE_FUNCTION void buildCell(int pi) const {
706 const int i = binned(pi);
707 Cell c;
708 Real pix, piy, piz, wSelf;
709 int ncRec, nnRec;
710 const bool nonEmpty = gatherCell(pi, c, pix, piy, piz, wSelf, ncRec, nnRec);
711 (void)nonEmpty; // only a power cell can be emptied by its neighbours
712 const bool emitNear = oNear.extent(0) > 0 && nearCap > 0;
713 if constexpr (Weighted) {
714 // Empty power cell: exact, published with zero volume and no facets (kEmpty | kBuried). No
715 // SDF clip and no completeness test: a subset of the constraints that is already empty
716 // certifies emptiness.
717 if (!nonEmpty) {
718 status(i) = kEmpty | kBuried;
719 facetCount(i) = 0;
720 cellFacetBase(i) = 0;
721 cellVol(i) = Real(0);
722 if (emitTopo)
723 emitEmptyTopo(i);
724 if (emitCand)
725 oCandCnt(i) = ncRec;
726 if (emitNear)
727 oNearCnt(i) = 0;
728 return;
729 }
730 }
731 if (emitCand)
732 oCandCnt(i) = ncRec;
733 if (emitNear)
734 oNearCnt(i) = nnRec > nearCap ? nearCap + 1 : nnRec; // nearCap+1 = overflow marker
735 // Completeness uses the conservative inscribed-sphere coverage (sw·minCsz)², the same
736 // criterion the legacy gather used: complete iff (sw·minCsz)² > 4·rSqMax.
737 const Real covSq = Real(sw) * minCsz * Real(sw) * minCsz;
738 finishCell(c, i, pix, piy, piz, covSq, wSelf);
739 }
740};
741
745template <class D, class S>
746void packFacetsByCell(const char* label, const Kokkos::View<D*, peclet::core::MemSpace>& dst,
747 const Kokkos::View<S*, peclet::core::MemSpace>& src, int stride,
748 const Kokkos::View<int*, peclet::core::MemSpace>& from,
749 const Kokkos::View<int*, peclet::core::MemSpace>& to,
750 const Kokkos::View<int*, peclet::core::MemSpace>& count) {
751 using Exec = peclet::core::ExecSpace;
752 const int N = static_cast<int>(count.extent(0));
753 Kokkos::parallel_for(
754 label, Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int i) {
755 const size_t o = (size_t)from(i) * stride, p = (size_t)to(i) * stride;
756 const size_t n = (size_t)count(i) * stride;
757 for (size_t k = 0; k < n; ++k)
758 dst(p + k) = static_cast<D>(src(o + k));
759 });
760}
761
762namespace detail {
765template <class Real>
767 using MemSpace = peclet::core::MemSpace;
768 size_t facetCap = 0, edgeCap = 0;
769 bool withAreaGrad = false, withMoments = false;
770 Kokkos::View<int*, MemSpace> oNbr;
771 Kokkos::View<Real*, MemSpace> oArea, oDV, oConn;
772 Kokkos::View<int*, MemSpace> facetCursor;
773 Kokkos::View<int*, MemSpace> oEdgeOff, oEdgeCnt, oEdgeFacet, edgeCursor;
774 Kokkos::View<Real*, MemSpace> oEdgeGrad, oEdgeLen;
775 Kokkos::View<Real*, MemSpace> oMoment2; // Track B (B1): per-facet second moments (opt-in)
776
777 void init(size_t facetCap_, bool withAreaGrad_, bool withMoments_) {
781 facetCursor = Kokkos::View<int*, MemSpace>("facetCursor", 1); // zero-initialised
782 // Rung A3: facet-edge area-Jacobian over-buffer (opt-in). A face has ~5.2 edges on average
783 // (Poisson–Voronoi), so ~6.2 entries per facet incl. the self slot; cap at 8 per facet — the
784 // same estimate-then-exact rule as the facet cap (its cursor is the exact edge demand too).
785 edgeCap = withAreaGrad ? facetCap * 8 : 0;
786 if (withAreaGrad)
787 edgeCursor = Kokkos::View<int*, MemSpace>("edgeCursor", 1);
788 alloc();
789 }
790
791 // (Re)allocate every over-buffer at the current caps and rewind the cursors.
792 void alloc() {
793 using Kokkos::view_alloc;
794 using Kokkos::WithoutInitializing;
795 oNbr = Kokkos::View<int*, MemSpace>(view_alloc(std::string("oNbr"), WithoutInitializing),
796 facetCap);
797 oArea = Kokkos::View<Real*, MemSpace>(view_alloc(std::string("oArea"), WithoutInitializing),
798 facetCap * 3);
799 oDV = Kokkos::View<Real*, MemSpace>(view_alloc(std::string("oDV"), WithoutInitializing),
800 facetCap * 3);
801 oConn = Kokkos::View<Real*, MemSpace>(view_alloc(std::string("oConn"), WithoutInitializing),
802 facetCap * 3);
803 Kokkos::deep_copy(facetCursor, 0);
804 if (withAreaGrad) {
805 oEdgeOff = Kokkos::View<int*, MemSpace>(
806 view_alloc(std::string("oEdgeOff"), WithoutInitializing), facetCap);
807 oEdgeCnt = Kokkos::View<int*, MemSpace>(
808 view_alloc(std::string("oEdgeCnt"), WithoutInitializing), facetCap);
809 oEdgeFacet = Kokkos::View<int*, MemSpace>(
810 view_alloc(std::string("oEdgeFacet"), WithoutInitializing), edgeCap);
811 oEdgeGrad = Kokkos::View<Real*, MemSpace>(
812 view_alloc(std::string("oEdgeGrad"), WithoutInitializing), edgeCap * 3);
813 oEdgeLen = Kokkos::View<Real*, MemSpace>(
814 view_alloc(std::string("oEdgeLen"), WithoutInitializing), edgeCap * 4);
815 Kokkos::deep_copy(edgeCursor, 0);
816 }
817 if (withMoments)
818 oMoment2 = Kokkos::View<Real*, MemSpace>(
819 view_alloc(std::string("oMoment2"), WithoutInitializing), facetCap);
820 }
821};
822
826template <class Real, class Builder, class BinnedView>
828 bool prof) {
829 using MemSpace = peclet::core::MemSpace;
830 using Exec = peclet::core::ExecSpace;
831 int nFacetsRaw = 0, nEdgesRaw = 0;
832 int overBufferRebuilds = 0;
833 for (int attempt = 0;; ++attempt) {
834 Kokkos::parallel_for(
835 "tess.build", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int pi) {
836 if (binnedV0(pi) >= nBuildL)
837 return; // candidate-only seed: skip its cell
838 op.buildCell(pi);
839 });
840 Kokkos::deep_copy(nFacetsRaw, Kokkos::subview(bufs.facetCursor, 0));
841 if (bufs.withAreaGrad)
842 Kokkos::deep_copy(nEdgesRaw, Kokkos::subview(bufs.edgeCursor, 0));
843 const bool facetOver = (size_t)nFacetsRaw > bufs.facetCap;
844 const bool edgeOver = bufs.withAreaGrad && (size_t)nEdgesRaw > bufs.edgeCap;
845 if (!(facetOver || edgeOver) || attempt >= 2)
846 break;
847 // The estimate was too small: the cursors hold the exact demand. Re-allocate at that size
848 // and rebuild; every per-cell output is rewritten by the second pass (the cell builder
849 // assigns, never accumulates, and the cursors are rewound), so nothing stale survives.
850 if (facetOver)
851 bufs.facetCap = (size_t)nFacetsRaw;
852 if (edgeOver)
853 bufs.edgeCap = (size_t)nEdgesRaw;
854 ++overBufferRebuilds;
855 if (prof)
856 std::fprintf(stderr, "[tess.build] over-buffer exceeded (facets %d, edges %d): rebuilding\n",
858 // Release the first attempt's buffers (both the locals and the builder's copies) BEFORE
859 // allocating the larger ones, so the peak stays at one over-buffer set, not two.
860 Kokkos::fence();
861 op.oNbr = bufs.oNbr = Kokkos::View<int*, MemSpace>();
862 op.oArea = bufs.oArea = Kokkos::View<Real*, MemSpace>();
863 op.oDV = bufs.oDV = Kokkos::View<Real*, MemSpace>();
864 op.oConn = bufs.oConn = Kokkos::View<Real*, MemSpace>();
865 op.oEdgeOff = bufs.oEdgeOff = Kokkos::View<int*, MemSpace>();
866 op.oEdgeCnt = bufs.oEdgeCnt = Kokkos::View<int*, MemSpace>();
867 op.oEdgeFacet = bufs.oEdgeFacet = Kokkos::View<int*, MemSpace>();
868 op.oEdgeGrad = bufs.oEdgeGrad = Kokkos::View<Real*, MemSpace>();
869 op.oEdgeLen = bufs.oEdgeLen = Kokkos::View<Real*, MemSpace>();
870 op.oMoment2 = bufs.oMoment2 = Kokkos::View<Real*, MemSpace>();
871 bufs.alloc();
872 op.oNbr = bufs.oNbr;
873 op.oArea = bufs.oArea;
874 op.oDV = bufs.oDV;
875 op.oConn = bufs.oConn;
876 op.facetCap = bufs.facetCap;
877 op.oEdgeOff = bufs.oEdgeOff;
878 op.oEdgeCnt = bufs.oEdgeCnt;
879 op.oEdgeFacet = bufs.oEdgeFacet;
880 op.oEdgeGrad = bufs.oEdgeGrad;
881 op.oEdgeLen = bufs.oEdgeLen;
882 op.edgeCap = bufs.edgeCap;
883 op.oMoment2 = bufs.oMoment2;
884 }
885 return overBufferRebuilds;
886}
887
891template <class Real>
893 const Kokkos::View<int*, peclet::core::MemSpace>& cellFacetBase,
894 const Kokkos::View<int*, peclet::core::MemSpace>& facetCount,
895 const Kokkos::View<Real*, peclet::core::MemSpace>& cellVol,
896 const Kokkos::View<Real*, peclet::core::MemSpace>& oWallDV,
897 const Kokkos::View<Real*, peclet::core::MemSpace>& oWallDA, int N) {
898 using MemSpace = peclet::core::MemSpace;
899 using Exec = peclet::core::ExecSpace;
900 using Kokkos::view_alloc;
901 using Kokkos::WithoutInitializing;
902 Kokkos::View<int*, MemSpace> pubBase(
903 view_alloc(std::string("cellFacetOffset"), WithoutInitializing), N);
904 int nFacets = 0;
905 {
906 auto fc = facetCount;
907 auto pb = pubBase;
908 Kokkos::parallel_scan(
909 "tess.facetScan", Kokkos::RangePolicy<Exec>(0, N),
910 KOKKOS_LAMBDA(const int i, int& upd, const bool fin) {
911 if (fin)
912 pb(i) = upd;
913 upd += fc(i);
914 },
915 nFacets);
916 }
918 view.cellFacetCount = facetCount;
919 view.cellVolume = cellVol;
920 view.cellSeedId =
921 Kokkos::View<gid_t*, MemSpace>(view_alloc(std::string("cellSeedId"), WithoutInitializing), N);
922 {
923 auto vSeed = view.cellSeedId;
924 Kokkos::parallel_for(
925 "tess.seedId", Kokkos::RangePolicy<Exec>(0, N),
926 KOKKOS_LAMBDA(const int i) { vSeed(i) = (gid_t)i; });
927 }
928
929 // Pack each over-buffer component into a right-sized published view, then free the
930 // source immediately. Copying-and-freeing one array at a time holds peak memory at
931 // ~(over-buffer + one compact array) instead of (over-buffer + full compact CSR) —
932 // the latter OOM'd the GPU at large N. numFacets() == nFacets, so the CSR contract is
933 // intact (consumers see correctly sized views). The fence before each free ensures the
934 // copy completed before the source is released.
935 view.facetNeighbor = Kokkos::View<gid_t*, MemSpace>(
936 view_alloc(std::string("facetNeighbor"), WithoutInitializing), nFacets);
937 packFacetsByCell("tess.packNbr", view.facetNeighbor, bufs.oNbr, 1, cellFacetBase, pubBase,
938 facetCount);
939 Kokkos::fence();
940 bufs.oNbr = Kokkos::View<int*, MemSpace>();
941
942 view.facetArea = Kokkos::View<Real*, MemSpace>(
943 view_alloc(std::string("facetArea"), WithoutInitializing), (size_t)nFacets * 3);
944 packFacetsByCell("tess.packArea", view.facetArea, bufs.oArea, 3, cellFacetBase, pubBase,
945 facetCount);
946 Kokkos::fence();
947 bufs.oArea = Kokkos::View<Real*, MemSpace>();
948
949 view.facetConnect = Kokkos::View<Real*, MemSpace>(
950 view_alloc(std::string("facetConnect"), WithoutInitializing), (size_t)nFacets * 3);
951 packFacetsByCell("tess.packDV", view.facetConnect, bufs.oDV, 3, cellFacetBase, pubBase,
952 facetCount);
953 Kokkos::fence();
954 bufs.oDV = Kokkos::View<Real*, MemSpace>();
955
956 view.facetConnVec = Kokkos::View<Real*, MemSpace>(
957 view_alloc(std::string("facetConnVec"), WithoutInitializing), (size_t)nFacets * 3);
958 packFacetsByCell("tess.packConn", view.facetConnVec, bufs.oConn, 3, cellFacetBase, pubBase,
959 facetCount);
960 if (oWallDV.extent(0) > 0) {
961 view.cellWallDV = oWallDV;
962 view.cellWallDA = oWallDA;
963 }
964 if (bufs.withMoments) {
965 view.facetMoment2 = Kokkos::View<Real*, MemSpace>(
966 view_alloc(std::string("facetMoment2"), WithoutInitializing), nFacets);
967 packFacetsByCell("tess.packMoment2", view.facetMoment2, bufs.oMoment2, 1, cellFacetBase,
968 pubBase, facetCount);
969 }
970 return nFacets;
971}
972
976template <class Real>
978 const Kokkos::View<int*, peclet::core::MemSpace>& cellFacetBase,
979 const Kokkos::View<int*, peclet::core::MemSpace>& facetCount, int N,
980 int nFacets) {
981 using MemSpace = peclet::core::MemSpace;
982 using Exec = peclet::core::ExecSpace;
983 using Kokkos::view_alloc;
984 using Kokkos::WithoutInitializing;
985 Kokkos::View<int*, MemSpace> pubEBase(
986 view_alloc(std::string("tess.edgeBase"), WithoutInitializing), N);
987 int nEdges = 0;
988 {
989 auto ob = cellFacetBase;
990 auto fc = facetCount;
991 auto ec = bufs.oEdgeCnt;
992 auto pe = pubEBase;
993 Kokkos::parallel_scan(
994 "tess.edgeScan", Kokkos::RangePolicy<Exec>(0, N),
995 KOKKOS_LAMBDA(const int i, int& upd, const bool fin) {
996 int ne = 0;
997 for (int k = 0; k < fc(i); ++k)
998 ne += ec(ob(i) + k);
999 if (fin)
1000 pe(i) = upd;
1001 upd += ne;
1002 },
1003 nEdges);
1004 }
1005 view.facetEdgeOffset = Kokkos::View<int*, MemSpace>(
1006 view_alloc(std::string("facetEdgeOffset"), WithoutInitializing), nFacets);
1007 view.facetEdgeCount = Kokkos::View<int*, MemSpace>(
1008 view_alloc(std::string("facetEdgeCount"), WithoutInitializing), nFacets);
1009 view.edgeFacet = Kokkos::View<int*, MemSpace>(
1010 view_alloc(std::string("edgeFacet"), WithoutInitializing), nEdges);
1011 view.edgeAreaGrad = Kokkos::View<Real*, MemSpace>(
1012 view_alloc(std::string("edgeAreaGrad"), WithoutInitializing), (size_t)nEdges * 3);
1013 view.edgeLength = Kokkos::View<Real*, MemSpace>(
1014 view_alloc(std::string("edgeLength"), WithoutInitializing), nEdges);
1015 auto ob = cellFacetBase;
1016 auto pb = view.cellFacetOffset;
1017 auto fc = facetCount;
1018 auto pe = pubEBase;
1019 auto sOff = bufs.oEdgeOff, sCnt = bufs.oEdgeCnt, sFacet = bufs.oEdgeFacet;
1020 auto sGrad = bufs.oEdgeGrad, sLen = bufs.oEdgeLen;
1021 auto dOff = view.facetEdgeOffset, dCnt = view.facetEdgeCount, dFacet = view.edgeFacet;
1022 auto dGrad = view.edgeAreaGrad, dLen = view.edgeLength;
1023 Kokkos::parallel_for(
1024 "tess.packEdges", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int i) {
1025 const int n = fc(i);
1026 if (n == 0)
1027 return;
1028 const int o = ob(i), p = pb(i), shift = p - o;
1029 const int e0 = sOff(o), pe0 = pe(i);
1030 int ne = 0;
1031 for (int k = 0; k < n; ++k) {
1032 dOff(p + k) = sOff(o + k) - e0 + pe0;
1033 dCnt(p + k) = sCnt(o + k);
1034 ne += sCnt(o + k);
1035 }
1036 for (int e = 0; e < ne; ++e) {
1037 dFacet(pe0 + e) = sFacet(e0 + e) + shift;
1038 for (int cc = 0; cc < 3; ++cc)
1039 dGrad((size_t)(pe0 + e) * 3 + cc) = sGrad((size_t)(e0 + e) * 3 + cc);
1040 dLen(pe0 + e) = sLen((size_t)(e0 + e) * 4);
1041 }
1042 });
1043}
1044
1046template <int kMaxT>
1047void printMaxFacets(const Kokkos::View<int*, peclet::core::MemSpace>& facetCount, int N) {
1048 using Exec = peclet::core::ExecSpace;
1049 // Max published facets/cell — the empirical bound for sizing a shrunk shared cell
1050 // (vertices ~ 2·facets - 4). Reduce over the per-cell facet count.
1051 int maxF = 0;
1052 auto fc = facetCount;
1053 Kokkos::parallel_reduce(
1054 "tess.maxFacets", Kokkos::RangePolicy<Exec>(0, N),
1055 KOKKOS_LAMBDA(const int c, int& m) { m = fc(c) > m ? fc(c) : m; }, Kokkos::Max<int>(maxF));
1056 std::fprintf(stderr, "[tess N=%d] maxFacets/cell=%d (=> maxVerts ~ %d; CAP=%d)\n", N, maxF,
1057 2 * maxF - 4, kMaxT);
1058}
1059} // namespace detail
1060
1085template <class Real, bool Weighted, class Sdf = NoSdf, int MAXP = kMaxPlanes,
1086 int MAXT = kMaxTriangles>
1088 const Kokkos::View<Real*, peclet::core::MemSpace>& posFlat,
1089 const Kokkos::View<Real*, peclet::core::MemSpace>& weight, int N, const Real L[3],
1090 int sw = kSearchWindow, int densityCount = -1,
1091 Kokkos::View<long*, peclet::core::MemSpace> gid = {}, Sdf sdf = {}, bool withForceGeom = true,
1092 int nBuild = -1, Kokkos::View<int*, peclet::core::MemSpace> outNp = {},
1093 Kokkos::View<int*, peclet::core::MemSpace> outNt = {},
1094 Kokkos::View<int*, peclet::core::MemSpace> outPnbr = {},
1095 Kokkos::View<unsigned*, peclet::core::MemSpace> outTri = {},
1096 Kokkos::View<int*, peclet::core::MemSpace> outCand = {},
1097 Kokkos::View<int*, peclet::core::MemSpace> outCandCnt = {}, int candCap = 0,
1098 WorklistCache<Real>* wlc = nullptr, WallStore<Real> outWall = {}, bool withAreaGrad = false,
1099 Kokkos::View<int*, peclet::core::MemSpace> outNear = {},
1100 Kokkos::View<int*, peclet::core::MemSpace> outNearCnt = {}, int nearCap = 0,
1101 Real nearMargin = Real(0), bool withWallFD = false, bool withMoments = false,
1102 bool profile = false) {
1103 using peclet::core::MemSpace;
1104 using Exec = peclet::core::ExecSpace;
1105 // Part-II optional outputs (see CellBuilder): emit the resident topology store / candidate skin
1106 // list only when the caller supplies sized views (so existing callers, passing none, are
1107 // byte-for-byte unaffected).
1108 const bool emitTopo = outNp.extent(0) == static_cast<size_t>(N);
1109 const bool emitCand = outCand.extent(0) > 0 && candCap > 0;
1110 // Optional global ids: skip a candidate sharing the cell's own id (its periodic
1111 // self-image, which can wrap exactly onto the seed -> a degenerate zero-distance
1112 // cut). Mirrors the legacy processNbrs `itr->id == m_id` guard. In the
1113 // single-domain case (gid empty) only the same local index is skipped.
1114 const bool haveGid = gid.extent(0) == static_cast<size_t>(N);
1115 // Seeds with original index >= nBuildEff are candidate-only (their cell is skipped).
1116 const int nBuildEff = (nBuild >= 0 && nBuild < N) ? nBuild : N;
1117
1118 // `profile`: the timing / over-buffer report on stderr (the API's profile switch —
1119 // Tessellation.diagnostics.set_profile — not an environment variable, QUALITY_PLAN D3/G.7).
1120 const bool prof = profile;
1121 Kokkos::Timer ptimer;
1122 double tGrid = 0, tBuild = 0, tCsr = 0;
1123
1124 // Counting-sort grid + presorted worklist. Factored into buildTessGrid so the SAME grid backs
1125 // both this cold build and the moving-point subset gather (device/subset_gather.hpp); pure code
1126 // motion, so the cold-build output is byte-for-byte unchanged.
1127 auto grid = buildTessGrid<Real, Weighted>(posFlat, weight, N, L, sw, densityCount, gid, wlc);
1128 // The window the grid was actually built with: buildTessGrid clamps sw to (minDim-1)/2-1 on a
1129 // coarse grid (N ≲ 1300 at sw = 4), and the completeness flag below must judge against the
1130 // walked window, not the requested one.
1131 sw = grid.sw;
1132 const Real Lx = grid.Lx, Ly = grid.Ly, Lz = grid.Lz;
1133 const Real icx = grid.icx, icy = grid.icy, icz = grid.icz, minCsz = grid.minCsz;
1134 const int dimx = grid.dimx, dimy = grid.dimy, dimz = grid.dimz;
1135 const int nOff = grid.nOff, wlS = grid.wlS;
1136 const bool useMorton = grid.useMorton;
1137
1138 if (prof) {
1139 Kokkos::fence();
1140 tGrid = ptimer.seconds();
1141 ptimer.reset();
1142 }
1143
1144 // --- pass 1: build each cell, record volume / facet count / status and the
1145 // per-cell facet records (neighbour id + area vector) into a temp slab ---
1146 Kokkos::View<Real*, MemSpace> cellVol("cellVol", N);
1147 Kokkos::View<int*, MemSpace> facetCount("facetCount", N);
1148 Kokkos::View<int*, MemSpace> status("status", N);
1149 Kokkos::View<int*, MemSpace> cellFacetBase("cellFacetBase", N); // per-cell facet base
1150 // Facet over-buffer + atomic cursor: the build packs each cell's facets directly into
1151 // a single contiguous CSR-layout buffer via atomic_fetch_add (one-pass "fusion") — no
1152 // fixed-stride temp slab, no exclusive scan, and the connecting vector is the cut's own
1153 // plane vector (no minimal-image recompute). The buffer is over-allocated to a tight
1154 // facet cap; the used prefix [0,nFacets) is copied to a compact view at the end.
1155 // Per-cell facet cap: MAXF_TMP (the class constant) is the most facets one Voronoi/Power
1156 // cell may publish (a single cell rarely exceeds ~40 faces); bounds the per-cell `faces[]`
1157 // stack array.
1158 // Global over-buffer capacity: the published CSR holds the *sum* of all cells'
1159 // facets ≈ N × mean-faces-per-cell (~15.5 for random Poisson–Voronoi). Sizing it at
1160 // N × MAXF_TMP over-allocated ~3× and OOM'd the GPU at large N (≈15 GB at N=4M). A
1161 // mean-facet estimate with headroom (N×18, ~16% over the aggregate mean) is the FIRST
1162 // attempt. It is only an estimate: a wall-heavy tessellation (a concave SDF wall runs
1163 // every wall cell to the 24-cut cap, ~40 faces per wall cell) exceeds it, and the cells
1164 // that lose the race for the tail of the buffer are then published with NO facets — a
1165 // thread-scheduling-dependent set (measured: 400–600 of 12000 cavity cells, wall-facet
1166 // counts 19983 vs 20845 run to run). The cursor's final value is the EXACT demand (every
1167 // cell reserves before it checks), so on overflow the over-buffers are re-allocated at
1168 // that demand and the build is re-run — the rare case pays one more build; the result
1169 // never depends on which cells finished last.
1170 constexpr size_t kMeanFacets = 18;
1171 const size_t facetCap = (size_t)N * kMeanFacets;
1173 bufs.init(facetCap, withAreaGrad, withMoments);
1174 // Rung A1 (force half): per-cell wall FD outputs (opt-in; SDF builds only).
1175 Kokkos::View<Real*, MemSpace> oWallDV, oWallDA;
1176 if (withWallFD && !std::is_same_v<Sdf, NoSdf>) {
1177 oWallDV = Kokkos::View<Real*, MemSpace>("cellWallDV", (size_t)N * 3);
1178 oWallDA = Kokkos::View<Real*, MemSpace>("cellWallDA", (size_t)N * 3);
1179 }
1180 if (prof)
1181 std::fprintf(stderr, "[worklist] sw=%d nOff=%d\n", sw, nOff);
1182
1183 // Build each cell: one thread per cell (RangePolicy), the compact ConvexCell in the
1184 // per-thread frame, the cut applied on the fly. Same path on every backend (ConvexCell is
1185 // lean enough that the worklist + geometry run well on the GPU without a team variant).
1186 Kokkos::View<unsigned char*, MemSpace>
1187 noPoke4; // cold build does not emit the cert plane set (TrackAdj=false)
1188
1189 // Global max weight bounds the weight-aware worklist reach (Power only; 0 for Voronoi).
1190 Real wMaxAll = Real(0);
1191 if constexpr (Weighted) {
1192 if (weight.extent(0) == static_cast<size_t>(N)) {
1193 Kokkos::parallel_reduce(
1194 "wmax", Kokkos::RangePolicy<Exec>(0, N),
1195 KOKKOS_LAMBDA(int idx, Real& m) { m = weight(idx) > m ? weight(idx) : m; },
1196 Kokkos::Max<Real>(wMaxAll));
1197 }
1198 }
1199
1200 CellBuilder<Real, Weighted, Sdf, false, MAXP, MAXT> op{grid.binned,
1201 grid.posSorted,
1202 grid.wSorted,
1203 grid.gidSorted,
1204 grid.cellStart,
1205 grid.wlOff,
1206 grid.wlRmin,
1207 status,
1208 cellVol,
1209 facetCount,
1210 cellFacetBase,
1211 bufs.oNbr,
1212 bufs.oArea,
1213 bufs.oDV,
1214 bufs.oConn,
1215 bufs.facetCursor,
1216 icx,
1217 icy,
1218 icz,
1219 Lx,
1220 Ly,
1221 Lz,
1222 minCsz,
1223 wMaxAll,
1224 dimx,
1225 dimy,
1226 dimz,
1227 sw,
1228 nOff,
1229 wlS,
1230 useMorton,
1231 haveGid,
1232 withForceGeom,
1233 bufs.facetCap,
1234 sdf,
1235 outNp,
1236 outNt,
1237 outPnbr,
1238 outTri,
1239 noPoke4,
1240 outCand,
1241 outCandCnt,
1242 emitTopo,
1243 emitCand,
1244 candCap,
1245 outWall,
1246 bufs.oEdgeOff,
1247 bufs.oEdgeCnt,
1248 bufs.oEdgeFacet,
1249 bufs.oEdgeGrad,
1250 bufs.oEdgeLen,
1251 bufs.edgeCursor,
1252 bufs.edgeCap,
1253 withAreaGrad,
1254 outNear,
1255 outNearCnt,
1256 nearCap,
1257 nearMargin,
1258 oWallDV,
1259 oWallDA,
1260 bufs.oMoment2,
1261 grid.slotOf};
1262 const int nBuildL = nBuildEff;
1263 auto binnedV0 = grid.binned;
1264 const int overBufferRebuilds = detail::runCellBuild(op, bufs, binnedV0, nBuildL, N, prof);
1265
1266 if (prof) {
1267 Kokkos::fence();
1268 tBuild = ptimer.seconds();
1269 ptimer.reset();
1270 }
1271
1272 // --- pack the over-buffer into a compact CSR ordered by cell index ---
1273 // The atomic packing leaves each cell's facets contiguous at cellFacetBase(i), but the cells in
1274 // finish order, which depends on the thread schedule. The published CSR is ordered by cell index
1275 // instead: a deterministic exclusive prefix sum of the per-cell facet counts (the base
1276 // reevalPublish uses too), and each cell's facets are copied from its over-buffer base to its
1277 // published base. A cell the over-buffer could not hold (count 0, flagged kOverflow) publishes
1278 // no facets.
1279 TessellationView<Real> view;
1280 const int nFacets =
1281 detail::publishFacetCsr(view, bufs, cellFacetBase, facetCount, cellVol, oWallDV, oWallDA, N);
1282 // Rung A3: the facet-edge area-Jacobian CSR.
1283 if (withAreaGrad)
1284 detail::publishEdgeCsr(view, bufs, cellFacetBase, facetCount, N, nFacets);
1285 Kokkos::fence();
1286 bufs.oConn = Kokkos::View<Real*, MemSpace>();
1287
1288 if (prof) {
1289 tCsr = ptimer.seconds();
1290 std::fprintf(stderr, "[tess N=%d] grid=%.4fs build=%.4fs csr=%.4fs (build %.0f%%)\n", N, tGrid,
1291 tBuild, tCsr, 100.0 * tBuild / (tGrid + tBuild + tCsr));
1293 N);
1294 }
1295
1296 TessellatorResult<Real> res;
1297 res.view = view;
1298 res.status = status;
1299 res.overBufferRebuilds = overBufferRebuilds;
1300 return res;
1301}
1302
1303} // namespace peclet::voro
1304
1305#endif // PECLET_VORO_TESSELLATOR_HPP
KOKKOS_INLINE_FUNCTION Dual< Real, K > dnum(Real c)
Definition convex_cell.hpp:53
void publishEdgeCsr(TessellationView< Real > &view, TessOverBuffers< Real > &bufs, const Kokkos::View< int *, peclet::core::MemSpace > &cellFacetBase, const Kokkos::View< int *, peclet::core::MemSpace > &facetCount, int N, int nFacets)
Definition tessellator.hpp:977
int publishFacetCsr(TessellationView< Real > &view, TessOverBuffers< Real > &bufs, const Kokkos::View< int *, peclet::core::MemSpace > &cellFacetBase, const Kokkos::View< int *, peclet::core::MemSpace > &facetCount, const Kokkos::View< Real *, peclet::core::MemSpace > &cellVol, const Kokkos::View< Real *, peclet::core::MemSpace > &oWallDV, const Kokkos::View< Real *, peclet::core::MemSpace > &oWallDA, int N)
Definition tessellator.hpp:892
void printMaxFacets(const Kokkos::View< int *, peclet::core::MemSpace > &facetCount, int N)
The profile's max published facets per cell (Max-reduce over the per-cell facet count).
Definition tessellator.hpp:1047
int runCellBuild(Builder &op, TessOverBuffers< Real > &bufs, BinnedView binnedV0, int nBuildL, int N, bool prof)
Definition tessellator.hpp:827
Device-native Voronoi tessellation, geometry and finite-volume physics.
Definition convex_cell.hpp:41
void packFacetsByCell(const char *label, const Kokkos::View< D *, peclet::core::MemSpace > &dst, const Kokkos::View< S *, peclet::core::MemSpace > &src, int stride, const Kokkos::View< int *, peclet::core::MemSpace > &from, const Kokkos::View< int *, peclet::core::MemSpace > &to, const Kokkos::View< int *, peclet::core::MemSpace > &count)
Definition tessellator.hpp:746
std::int32_t gid_t
Definition tessellation_view.hpp:41
StatusBit
Per-cell status bits written by the build pass.
Definition tessellator.hpp:48
@ kOverflow
Definition tessellator.hpp:50
@ kBuried
Definition tessellator.hpp:62
@ kReachExceeded
Definition tessellator.hpp:63
@ kNegOffset
Definition tessellator.hpp:56
@ kOk
Definition tessellator.hpp:49
@ kDegenerate
Definition tessellator.hpp:67
@ kIncomplete
Definition tessellator.hpp:52
@ kEmpty
Definition tessellator.hpp:51
constexpr int kMaxPlanes
Definition params.hpp:18
constexpr int kWlOffBias
Definition tess_grid.hpp:38
constexpr int kMaxTriangles
Definition params.hpp:19
constexpr int kBoundaryFacet
Definition sdf.hpp:36
KOKKOS_INLINE_FUNCTION void sdfGradient(const Sdf &s, Real x, Real y, Real z, Real g[3])
Central-difference gradient of any provider with eval() (matches peclet::core::geom::gradient).
Definition sdf.hpp:216
KOKKOS_INLINE_FUNCTION int areaGradEnumerate(const Cell &c, const int *faces, int nf, unsigned char *part, unsigned char *pcnt, bool &full)
Definition tessellator.hpp:99
constexpr int kSearchWindow
Definition params.hpp:28
KOKKOS_INLINE_FUNCTION int morton3(int x, int y, int z)
Definition tess_grid.hpp:46
KOKKOS_INLINE_FUNCTION void areaGradFill(const Cell &c, const int *faces, int nf, const unsigned char *part, const unsigned char *pcnt, int base, int ebase, const IView &oEdgeOff, const IView &oEdgeCnt, const IView &oEdgeFacet, const RView &oEdgeGrad, const RView &oEdgeLen)
Definition tessellator.hpp:150
TessellatorResult< Real > buildTessellation(const Kokkos::View< Real *, peclet::core::MemSpace > &posFlat, const Kokkos::View< Real *, peclet::core::MemSpace > &weight, int N, const Real L[3], int sw=kSearchWindow, int densityCount=-1, Kokkos::View< long *, peclet::core::MemSpace > gid={}, Sdf sdf={}, bool withForceGeom=true, int nBuild=-1, Kokkos::View< int *, peclet::core::MemSpace > outNp={}, Kokkos::View< int *, peclet::core::MemSpace > outNt={}, Kokkos::View< int *, peclet::core::MemSpace > outPnbr={}, Kokkos::View< unsigned *, peclet::core::MemSpace > outTri={}, Kokkos::View< int *, peclet::core::MemSpace > outCand={}, Kokkos::View< int *, peclet::core::MemSpace > outCandCnt={}, int candCap=0, WorklistCache< Real > *wlc=nullptr, WallStore< Real > outWall={}, bool withAreaGrad=false, Kokkos::View< int *, peclet::core::MemSpace > outNear={}, Kokkos::View< int *, peclet::core::MemSpace > outNearCnt={}, int nearCap=0, Real nearMargin=Real(0), bool withWallFD=false, bool withMoments=false, bool profile=false)
Definition tessellator.hpp:1087
Definition tessellator.hpp:235
bool emitTopo
Definition tessellator.hpp:287
int dimx
Definition tessellator.hpp:270
Kokkos::View< int *, MemSpace > binned
Definition tessellator.hpp:247
Kokkos::View< int *, MemSpace > oNp
Definition tessellator.hpp:281
bool withAreaGrad
Definition tessellator.hpp:301
Kokkos::View< Real *, MemSpace > oEdgeLen
Definition tessellator.hpp:298
Kokkos::View< Real *, MemSpace > oWallDV
Definition tessellator.hpp:313
KOKKOS_INLINE_FUNCTION bool gatherCell(int pi, Cell &c, Real &pix, Real &piy, Real &piz, Real &wSelf, int &ncRec, int &nnRec) const
Definition tessellator.hpp:570
Kokkos::View< Real *, MemSpace > oArea
Definition tessellator.hpp:265
int wlS
Definition tessellator.hpp:270
Kokkos::View< Real *, MemSpace > posSorted
Definition tessellator.hpp:248
Kokkos::View< Real *, MemSpace > oConn
Definition tessellator.hpp:265
Kokkos::View< int *, MemSpace > edgeCursor
Definition tessellator.hpp:299
Kokkos::View< int *, MemSpace > wlOff
Definition tessellator.hpp:257
Kokkos::View< Real *, MemSpace > oEdgeGrad
Definition tessellator.hpp:297
KOKKOS_INLINE_FUNCTION int worklistCell(int base, int g, int cx, int cy, int cz) const
Decode worklist entry g (relative to base) into a grid-cell index.
Definition tessellator.hpp:384
KOKKOS_INLINE_FUNCTION void finishCell(Cell &c, int i, Real pix, Real piy, Real piz, Real covSq, Real wSelf=Real(0)) const
Definition tessellator.hpp:407
int sw
Definition tessellator.hpp:270
bool useMorton
Definition tessellator.hpp:271
Kokkos::View< int *, MemSpace > oEdgeOff
Definition tessellator.hpp:296
Real minCsz
Definition tessellator.hpp:268
Real icx
Definition tessellator.hpp:268
Real Ly
Definition tessellator.hpp:268
Kokkos::View< Real *, MemSpace > wlRmin
Definition tessellator.hpp:258
Kokkos::View< int *, MemSpace > cellFacetBase
Definition tessellator.hpp:263
Real nearMargin
Definition tessellator.hpp:310
KOKKOS_INLINE_FUNCTION int subBase(Real pix, Real piy, Real piz) const
Flat base offset into the worklist tables for the wlS^3 sub-region the seed lands in.
Definition tessellator.hpp:372
KOKKOS_INLINE_FUNCTION void homeCell(Real pix, Real piy, Real piz, int &cx, int &cy, int &cz) const
Home grid cell index (cx,cy,cz) of seed (pix,piy,piz).
Definition tessellator.hpp:364
int nearCap
Definition tessellator.hpp:309
static constexpr int kMaxP
Definition tessellator.hpp:240
Real icz
Definition tessellator.hpp:268
size_t facetCap
Definition tessellator.hpp:272
int dimy
Definition tessellator.hpp:270
KOKKOS_INLINE_FUNCTION void buildCell(int pi) const
Definition tessellator.hpp:705
Kokkos::View< Real *, MemSpace > cellVol
Definition tessellator.hpp:261
KOKKOS_INLINE_FUNCTION int gridCell(int rgx, int rgy, int rgz) const
Linear/Morton index of the grid cell at raw (periodic-unwrapped) offset.
Definition tessellator.hpp:356
Kokkos::View< Real *, MemSpace > oWallDA
Definition tessellator.hpp:313
KOKKOS_INLINE_FUNCTION void relVec(int q, Real pix, Real piy, Real piz, Real pv[3]) const
Minimal-image relative vector from the seed at (pix,piy,piz) to sorted seed q.
Definition tessellator.hpp:346
Kokkos::View< int *, MemSpace > oNear
Definition tessellator.hpp:308
size_t edgeCap
Definition tessellator.hpp:300
KOKKOS_INLINE_FUNCTION void publishAreaGrad(const Cell &c, int i, int base, const int *faces, int nf) const
Definition tessellator.hpp:326
Kokkos::View< int *, MemSpace > cellStart
Definition tessellator.hpp:251
Kokkos::View< gid_t *, MemSpace > gidSorted
Definition tessellator.hpp:250
Kokkos::View< int *, MemSpace > status
Definition tessellator.hpp:260
int candCap
Definition tessellator.hpp:288
Kokkos::View< int *, MemSpace > oNt
Definition tessellator.hpp:281
bool haveGid
Definition tessellator.hpp:271
int nOff
Definition tessellator.hpp:270
Kokkos::View< int *, MemSpace > facetCursor
Definition tessellator.hpp:266
Kokkos::View< unsigned char *, MemSpace > oPoke4
Definition tessellator.hpp:284
Real wMaxAll
Definition tessellator.hpp:269
WallStore< Real > oWall
Definition tessellator.hpp:292
int dimz
Definition tessellator.hpp:270
Kokkos::View< int *, MemSpace > oNbr
Definition tessellator.hpp:264
Kokkos::View< Real *, MemSpace > oDV
Definition tessellator.hpp:265
Kokkos::View< int *, MemSpace > oEdgeCnt
Definition tessellator.hpp:296
Real Lz
Definition tessellator.hpp:268
Kokkos::View< int *, MemSpace > facetCount
Definition tessellator.hpp:262
Kokkos::View< int *, MemSpace > oNearCnt
Definition tessellator.hpp:308
Kokkos::View< Real *, MemSpace > wSorted
Definition tessellator.hpp:249
static constexpr int kMaxFV
Definition tessellator.hpp:295
Real icy
Definition tessellator.hpp:268
bool emitCand
Definition tessellator.hpp:287
Real Lx
Definition tessellator.hpp:268
std::conditional_t< Weighted, Power, Voronoi > PlanePolicy
Definition tessellator.hpp:244
KOKKOS_INLINE_FUNCTION void emitEmptyTopo(int i) const
Definition tessellator.hpp:395
bool withForceGeom
Definition tessellator.hpp:271
Kokkos::View< int *, MemSpace > oCandCnt
Definition tessellator.hpp:286
Kokkos::View< int *, MemSpace > oTopoPnbr
Definition tessellator.hpp:281
Kokkos::View< Real *, MemSpace > oMoment2
Definition tessellator.hpp:316
static constexpr int kMaxT
Definition tessellator.hpp:241
Kokkos::View< int *, MemSpace > oCand
Definition tessellator.hpp:286
peclet::core::MemSpace MemSpace
Definition tessellator.hpp:236
Kokkos::View< int *, MemSpace > oEdgeFacet
Definition tessellator.hpp:296
static constexpr int MAXF_TMP
Definition tessellator.hpp:242
Sdf sdf
Definition tessellator.hpp:273
Kokkos::View< unsigned *, MemSpace > oTri
Definition tessellator.hpp:282
Kokkos::View< int *, MemSpace > slotOf
Definition tessellator.hpp:320
Definition convex_cell.hpp:140
KOKKOS_INLINE_FUNCTION bool facetGeometryFrom(int k, const Real r[3], Real areaVec[3], Real dv[3]) const
Definition convex_cell.hpp:2258
KOKKOS_INLINE_FUNCTION Real volumePerVertex() const
Definition convex_cell.hpp:1585
static constexpr int MAXFV
Definition convex_cell.hpp:1307
unsigned char t1[MAXT]
Definition convex_cell.hpp:156
KOKKOS_INLINE_FUNCTION Real faceMoment2(int k) const
Definition convex_cell.hpp:578
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
Real nn[MAXP]
signed offset σ·|n|²: the half-space test is n·x <= nn
Definition convex_cell.hpp:153
Real n[MAXP][3]
Definition convex_cell.hpp:152
KOKKOS_INLINE_FUNCTION bool empty() const
Definition convex_cell.hpp:1287
int pnbr[MAXP]
neighbour seed id per plane (<0 => bounding box)
Definition convex_cell.hpp:154
KOKKOS_INLINE_FUNCTION Real maxVertexRsq() const
Largest squared dual-vertex radius over live triangles (drives the security radius).
Definition convex_cell.hpp:676
unsigned char t2[MAXT]
triangle = triple of plane indices
Definition convex_cell.hpp:156
int np
number of planes
Definition convex_cell.hpp:155
KOKKOS_INLINE_FUNCTION bool clip(const Real pdir[3], Real d, int nbr, Real *gapOut=nullptr)
Definition convex_cell.hpp:895
bool degenerate
Definition convex_cell.hpp:161
unsigned char t0[MAXT]
Definition convex_cell.hpp:156
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
KOKKOS_INLINE_FUNCTION bool facetGeometry(int k, Real areaVec[3], Real dv[3], Real conn[3]) const
Definition convex_cell.hpp:2235
Definition tessellation_view.hpp:111
Kokkos::View< Real *, peclet::core::MemSpace > cellWallDV
Definition tessellation_view.hpp:151
Kokkos::View< Real *, peclet::core::MemSpace > facetConnect
Definition tessellation_view.hpp:123
Kokkos::View< Real *, peclet::core::MemSpace > facetArea
Definition tessellation_view.hpp:122
Kokkos::View< int *, peclet::core::MemSpace > facetEdgeOffset
Definition tessellation_view.hpp:138
Kokkos::View< int *, peclet::core::MemSpace > facetEdgeCount
Definition tessellation_view.hpp:139
Kokkos::View< Real *, peclet::core::MemSpace > cellVolume
Definition tessellation_view.hpp:120
Kokkos::View< Real *, peclet::core::MemSpace > facetMoment2
Definition tessellation_view.hpp:160
Kokkos::View< Real *, peclet::core::MemSpace > edgeAreaGrad
Definition tessellation_view.hpp:141
Kokkos::View< gid_t *, peclet::core::MemSpace > cellSeedId
Definition tessellation_view.hpp:119
Kokkos::View< Real *, peclet::core::MemSpace > cellWallDA
Definition tessellation_view.hpp:152
Kokkos::View< int *, peclet::core::MemSpace > cellFacetOffset
Definition tessellation_view.hpp:117
Kokkos::View< int *, peclet::core::MemSpace > edgeFacet
Definition tessellation_view.hpp:140
Kokkos::View< Real *, peclet::core::MemSpace > edgeLength
Definition tessellation_view.hpp:145
Kokkos::View< gid_t *, peclet::core::MemSpace > facetNeighbor
Definition tessellation_view.hpp:121
Kokkos::View< int *, peclet::core::MemSpace > cellFacetCount
Definition tessellation_view.hpp:118
Kokkos::View< Real *, peclet::core::MemSpace > facetConnVec
Definition tessellation_view.hpp:124
Definition tessellator.hpp:71
int overBufferRebuilds
Definition tessellator.hpp:77
Kokkos::View< int *, peclet::core::MemSpace > status
Definition tessellator.hpp:73
TessellationView< Real > view
Definition tessellator.hpp:72
Definition sdf.hpp:352
Definition tessellator.hpp:766
Kokkos::View< int *, MemSpace > oEdgeFacet
Definition tessellator.hpp:773
Kokkos::View< Real *, MemSpace > oArea
Definition tessellator.hpp:771
Kokkos::View< int *, MemSpace > edgeCursor
Definition tessellator.hpp:773
Kokkos::View< Real *, MemSpace > oEdgeLen
Definition tessellator.hpp:774
size_t edgeCap
Definition tessellator.hpp:768
bool withAreaGrad
Definition tessellator.hpp:769
Kokkos::View< int *, MemSpace > oEdgeCnt
Definition tessellator.hpp:773
Kokkos::View< int *, MemSpace > oNbr
Definition tessellator.hpp:770
size_t facetCap
Definition tessellator.hpp:768
Kokkos::View< Real *, MemSpace > oEdgeGrad
Definition tessellator.hpp:774
Kokkos::View< int *, MemSpace > oEdgeOff
Definition tessellator.hpp:773
Kokkos::View< Real *, MemSpace > oConn
Definition tessellator.hpp:771
peclet::core::MemSpace MemSpace
Definition tessellator.hpp:767
bool withMoments
Definition tessellator.hpp:769
void init(size_t facetCap_, bool withAreaGrad_, bool withMoments_)
Definition tessellator.hpp:777
void alloc()
Definition tessellator.hpp:792
Kokkos::View< int *, MemSpace > facetCursor
Definition tessellator.hpp:772
Kokkos::View< Real *, MemSpace > oMoment2
Definition tessellator.hpp:775
Kokkos::View< Real *, MemSpace > oDV
Definition tessellator.hpp:771
Published, read-only device data layer for the tessellation (migration §2.1, §3).