peclet.voro 1.0.0
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) {
65 using peclet::core::MemSpace;
66 using Exec = peclet::core::ExecSpace;
67 using Builder = CellBuilder<Real, Weighted, Sdf, TrackAdj>;
68 const int N = grid.N;
69 using Kokkos::view_alloc;
70 using Kokkos::WithoutInitializing;
71
72 // Power reach needs the global max weight (see CellBuilder::blockReachSq); 0 for Voronoi. The grid
73 // carries the per-slot weights (wSorted), so reduce over those.
74 Real wMaxAll = Real(0);
75 if constexpr (Weighted) {
76 if (grid.wSorted.extent(0) == static_cast<size_t>(N)) {
77 auto ws = grid.wSorted;
78 Kokkos::parallel_reduce(
79 "subset.wmax", Kokkos::RangePolicy<Exec>(0, N),
80 KOKKOS_LAMBDA(int idx, Real& m) { m = ws(idx) > m ? ws(idx) : m; },
81 Kokkos::Max<Real>(wMaxAll));
82 }
83 }
84
85 SubsetGatherResult<Real> res;
86 res.status = Kokkos::View<int*, MemSpace>("subset.status", N); // zero-init (unwritten = kOk)
87
88 // Throwaway facet over-buffer: buildCell reserves a contiguous CSR range per cell and writes the
89 // neighbour id (+ optional geometry) there. Sized for the subset (mean ~15.5 faces/cell +
90 // headroom); the topology store is the published Phase-1 output, this buffer is just buildCell's
91 // scratch.
92 Kokkos::View<int*, MemSpace> facetCount("subset.facetCount", N);
93 Kokkos::View<int*, MemSpace> cellFacetBase("subset.cellFacetBase", N);
94 constexpr size_t kMeanFacets = 18;
95 const size_t facetCap = (size_t)(nSubset > 0 ? nSubset : 1) * kMeanFacets;
96 Kokkos::View<int*, MemSpace> oNbr(view_alloc(std::string("subset.oNbr"), WithoutInitializing),
97 facetCap);
98 Kokkos::View<Real*, MemSpace> oArea(view_alloc(std::string("subset.oArea"), WithoutInitializing),
99 facetCap * 3);
100 Kokkos::View<Real*, MemSpace> oDV(view_alloc(std::string("subset.oDV"), WithoutInitializing),
101 facetCap * 3);
102 Kokkos::View<Real*, MemSpace> oConn(view_alloc(std::string("subset.oConn"), WithoutInitializing),
103 facetCap * 3);
104 Kokkos::View<int*, MemSpace> facetCursor("subset.facetCursor", 1);
105
106 // Empty candidate-list outputs (skin emission is not wanted for the subset gather).
107 Kokkos::View<int*, MemSpace> noCand, noCandCnt;
108
109 Builder op{grid.binned,
110 grid.posSorted,
111 grid.wSorted, // per-slot weights (empty for Voronoi; read only when Weighted)
112 grid.gidSorted,
113 grid.cellStart,
114 grid.wlOff,
115 grid.wlRmin,
116 res.status,
117 cellVol,
118 facetCount,
119 cellFacetBase,
120 oNbr,
121 oArea,
122 oDV,
123 oConn,
124 facetCursor,
125 grid.icx,
126 grid.icy,
127 grid.icz,
128 grid.Lx,
129 grid.Ly,
130 grid.Lz,
131 grid.minCsz,
132 wMaxAll,
133 grid.dimx,
134 grid.dimy,
135 grid.dimz,
136 grid.sw,
137 grid.nOff,
138 grid.wlS,
139 grid.useMorton,
140 grid.haveGid,
141 withForceGeom,
142 facetCap,
143 sdf,
144 outNp,
145 outNt,
146 outPnbr,
147 outTri,
148 outPoke4,
149 noCand,
150 noCandCnt,
151 /*emitTopo=*/true,
152 /*emitCand=*/false,
153 /*candCap=*/0};
154
155 auto slotOf = grid.slotOf;
156 auto idx = indices;
157 Kokkos::parallel_for(
158 "subset.build", Kokkos::RangePolicy<Exec>(0, nSubset), KOKKOS_LAMBDA(const int s) {
159 const int i = idx(s); // original seed index to rebuild
160 op.buildCell(
161 slotOf(i)); // grid-sorted slot of that seed; writes outputs at binned(slot)==i
162 });
163 Kokkos::fence();
164 return res;
165}
166
167} // namespace peclet::voro
168
169#endif // PECLET_VORO_SUBSET_GATHER_HPP
Definition convex_cell.hpp:40
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)
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:55
int dimz
Definition tess_grid.hpp:70
int dimy
Definition tess_grid.hpp:70
Real minCsz
Definition tess_grid.hpp:69
int wlS
Definition tess_grid.hpp:70
int dimx
Definition tess_grid.hpp:70
Kokkos::View< gid_t *, MemSpace > gidSorted
Definition tess_grid.hpp:63
Kokkos::View< Real *, MemSpace > wSorted
Definition tess_grid.hpp:62
Kokkos::View< int *, MemSpace > binned
Definition tess_grid.hpp:58
Kokkos::View< int *, MemSpace > cellStart
Definition tess_grid.hpp:64
Real icz
Definition tess_grid.hpp:69
bool useMorton
Definition tess_grid.hpp:71
int sw
Definition tess_grid.hpp:70
bool haveGid
Definition tess_grid.hpp:71
Real icx
Definition tess_grid.hpp:69
int nOff
Definition tess_grid.hpp:70
Kokkos::View< Real *, MemSpace > posSorted
Definition tess_grid.hpp:61
Kokkos::View< int *, MemSpace > slotOf
Definition tess_grid.hpp:60
int N
Definition tess_grid.hpp:70
Real Ly
Definition tess_grid.hpp:69
Real icy
Definition tess_grid.hpp:69
Real Lx
Definition tess_grid.hpp:69
Real Lz
Definition tess_grid.hpp:69
Kokkos::View< Real *, MemSpace > wlRmin
Definition tess_grid.hpp:67
Kokkos::View< int *, MemSpace > wlOff
Definition tess_grid.hpp:66