peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
subset_gather.hpp
Go to the documentation of this file.
1
20#ifndef PECLET_VORO_SUBSET_GATHER_HPP
21#define PECLET_VORO_SUBSET_GATHER_HPP
22
23#include <Kokkos_Core.hpp>
24#include <string>
25
26#include "peclet/core/common/view.hpp"
28#include "peclet/voro/tessellator.hpp" // CellBuilder, StatusBit, NoSdf
29
30namespace peclet::voro {
31
35template <class Real>
37 Kokkos::View<int*, peclet::core::MemSpace>
38 status; // N : per-cell StatusBit mask (subset entries written)
39};
40
55template <class Real, bool Weighted = false, bool TrackAdj = false, class Sdf = NoSdf>
57 const TessGrid<Real>& grid, const Kokkos::View<int*, peclet::core::MemSpace>& indices,
58 int nSubset, const Kokkos::View<int*, peclet::core::MemSpace>& outNp,
59 const Kokkos::View<int*, peclet::core::MemSpace>& outNt,
60 const Kokkos::View<int*, peclet::core::MemSpace>& outPnbr,
61 const Kokkos::View<unsigned*, peclet::core::MemSpace>& outTri,
62 const Kokkos::View<Real*, peclet::core::MemSpace>& cellVol,
63 const Kokkos::View<unsigned char*, peclet::core::MemSpace>& outPoke4 = {}, Sdf sdf = {},
64 bool withForceGeom = false, WallStore<Real> outWall = {},
65 Kokkos::View<int*, peclet::core::MemSpace> outNear = {},
66 Kokkos::View<int*, peclet::core::MemSpace> outNearCnt = {}, int nearCap = 0,
67 Real nearMargin = Real(0)) {
68 using peclet::core::MemSpace;
69 using Exec = peclet::core::ExecSpace;
70 using Builder = CellBuilder<Real, Weighted, Sdf, TrackAdj>;
71 const int N = grid.N;
72 using Kokkos::view_alloc;
73 using Kokkos::WithoutInitializing;
74
75 // Power reach needs the global max weight (see CellBuilder::blockReachSq); 0 for Voronoi. The
76 // grid carries the per-slot weights (wSorted), so reduce over those.
77 Real wMaxAll = Real(0);
78 if constexpr (Weighted) {
79 if (grid.wSorted.extent(0) == static_cast<size_t>(N)) {
80 auto ws = grid.wSorted;
81 Kokkos::parallel_reduce(
82 "subset.wmax", Kokkos::RangePolicy<Exec>(0, N),
83 KOKKOS_LAMBDA(int idx, Real& m) { m = ws(idx) > m ? ws(idx) : m; },
84 Kokkos::Max<Real>(wMaxAll));
85 }
86 }
87
88 SubsetGatherResult<Real> res;
89 res.status = Kokkos::View<int*, MemSpace>("subset.status", N); // zero-init (unwritten = kOk)
90
91 // Throwaway facet over-buffer: buildCell reserves a contiguous CSR range per cell and writes the
92 // neighbour id (+ optional geometry) there. Sized for the subset (mean ~15.5 faces/cell +
93 // headroom); the topology store is the published Phase-1 output, this buffer is just buildCell's
94 // scratch.
95 Kokkos::View<int*, MemSpace> facetCount("subset.facetCount", N);
96 Kokkos::View<int*, MemSpace> cellFacetBase("subset.cellFacetBase", N);
97 // Worst case per cell (MAXF_TMP): a subset of wall-clipped cells carries far more faces than the
98 // Poisson mean, and the buffer is only scratch.
99 const size_t facetCap = (size_t)(nSubset > 0 ? nSubset : 1) * (size_t)Builder::MAXF_TMP;
100 Kokkos::View<int*, MemSpace> oNbr(view_alloc(std::string("subset.oNbr"), WithoutInitializing),
101 facetCap);
102 Kokkos::View<Real*, MemSpace> oArea(view_alloc(std::string("subset.oArea"), WithoutInitializing),
103 facetCap * 3);
104 Kokkos::View<Real*, MemSpace> oDV(view_alloc(std::string("subset.oDV"), WithoutInitializing),
105 facetCap * 3);
106 Kokkos::View<Real*, MemSpace> oConn(view_alloc(std::string("subset.oConn"), WithoutInitializing),
107 facetCap * 3);
108 Kokkos::View<int*, MemSpace> facetCursor("subset.facetCursor", 1);
109
110 // Empty candidate-list outputs (skin emission is not wanted for the subset gather).
111 Kokkos::View<int*, MemSpace> noCand, noCandCnt;
112
113 Builder op{grid.binned,
114 grid.posSorted,
115 grid.wSorted, // per-slot weights (empty for Voronoi; read only when Weighted)
116 grid.gidSorted,
117 grid.cellStart,
118 grid.wlOff,
119 grid.wlRmin,
120 res.status,
121 cellVol,
122 facetCount,
123 cellFacetBase,
124 oNbr,
125 oArea,
126 oDV,
127 oConn,
128 facetCursor,
129 grid.icx,
130 grid.icy,
131 grid.icz,
132 grid.Lx,
133 grid.Ly,
134 grid.Lz,
135 grid.minCsz,
136 wMaxAll,
137 grid.dimx,
138 grid.dimy,
139 grid.dimz,
140 grid.sw,
141 grid.nOff,
142 grid.wlS,
143 grid.useMorton,
144 grid.haveGid,
145 withForceGeom,
146 facetCap,
147 sdf,
148 outNp,
149 outNt,
150 outPnbr,
151 outTri,
152 outPoke4,
153 noCand,
154 noCandCnt,
155 /*emitTopo=*/true,
156 /*emitCand=*/false,
157 /*candCap=*/0,
158 outWall,
159 /*oEdgeOff=*/{},
160 /*oEdgeCnt=*/{},
161 /*oEdgeFacet=*/{},
162 /*oEdgeGrad=*/{},
163 /*oEdgeLen=*/{},
164 /*edgeCursor=*/{},
165 /*edgeCap=*/0,
166 /*withAreaGrad=*/false,
167 outNear,
168 outNearCnt,
169 nearCap,
170 nearMargin,
171 /*oWallDV=*/{},
172 /*oWallDA=*/{},
173 /*oMoment2=*/{}};
174
175 auto slotOf = grid.slotOf;
176 auto idx = indices;
177 Kokkos::parallel_for(
178 "subset.build", Kokkos::RangePolicy<Exec>(0, nSubset), KOKKOS_LAMBDA(const int s) {
179 const int i = idx(s); // original seed index to rebuild
180 op.buildCell(
181 slotOf(i)); // grid-sorted slot of that seed; writes outputs at binned(slot)==i
182 });
183 Kokkos::fence();
184 return res;
185}
186
187} // namespace peclet::voro
188
189#endif // PECLET_VORO_SUBSET_GATHER_HPP
Device-native Voronoi tessellation, geometry and finite-volume physics.
Definition convex_cell.hpp:41
SubsetGatherResult< Real > subsetGather(const TessGrid< Real > &grid, const Kokkos::View< int *, peclet::core::MemSpace > &indices, int nSubset, const Kokkos::View< int *, peclet::core::MemSpace > &outNp, const Kokkos::View< int *, peclet::core::MemSpace > &outNt, const Kokkos::View< int *, peclet::core::MemSpace > &outPnbr, const Kokkos::View< unsigned *, peclet::core::MemSpace > &outTri, const Kokkos::View< Real *, peclet::core::MemSpace > &cellVol, const Kokkos::View< unsigned char *, peclet::core::MemSpace > &outPoke4={}, Sdf sdf={}, bool withForceGeom=false, WallStore< Real > outWall={}, Kokkos::View< int *, peclet::core::MemSpace > outNear={}, Kokkos::View< int *, peclet::core::MemSpace > outNearCnt={}, int nearCap=0, Real nearMargin=Real(0))
Definition subset_gather.hpp:56
Definition subset_gather.hpp:36
Kokkos::View< int *, peclet::core::MemSpace > status
Definition subset_gather.hpp:38
Definition tess_grid.hpp:56
int dimz
Definition tess_grid.hpp:71
int dimy
Definition tess_grid.hpp:71
Real minCsz
Definition tess_grid.hpp:70
int wlS
Definition tess_grid.hpp:71
int dimx
Definition tess_grid.hpp:71
Kokkos::View< gid_t *, MemSpace > gidSorted
Definition tess_grid.hpp:64
Kokkos::View< Real *, MemSpace > wSorted
Definition tess_grid.hpp:63
Kokkos::View< int *, MemSpace > binned
Definition tess_grid.hpp:59
Kokkos::View< int *, MemSpace > cellStart
Definition tess_grid.hpp:65
Real icz
Definition tess_grid.hpp:70
bool useMorton
Definition tess_grid.hpp:72
int sw
Definition tess_grid.hpp:71
bool haveGid
Definition tess_grid.hpp:72
Real icx
Definition tess_grid.hpp:70
int nOff
Definition tess_grid.hpp:71
Kokkos::View< Real *, MemSpace > posSorted
Definition tess_grid.hpp:62
Kokkos::View< int *, MemSpace > slotOf
Definition tess_grid.hpp:61
int N
Definition tess_grid.hpp:71
Real Ly
Definition tess_grid.hpp:70
Real icy
Definition tess_grid.hpp:70
Real Lx
Definition tess_grid.hpp:70
Real Lz
Definition tess_grid.hpp:70
Kokkos::View< Real *, MemSpace > wlRmin
Definition tess_grid.hpp:68
Kokkos::View< int *, MemSpace > wlOff
Definition tess_grid.hpp:67