peclet.voro 1.0.0
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
topology_store.hpp
Go to the documentation of this file.
1
26#ifndef PECLET_VORO_TOPOLOGY_STORE_HPP
27#define PECLET_VORO_TOPOLOGY_STORE_HPP
28
29#include <Kokkos_Core.hpp>
30#include <string>
31
32#include "peclet/core/common/view.hpp"
33
34namespace peclet::voro {
35
38template <int MAXP, int MAXT>
40 using MemSpace = peclet::core::MemSpace;
41 int N = 0;
42 Kokkos::View<int*, MemSpace> np; // N
43 Kokkos::View<int*, MemSpace> nt; // N
44 Kokkos::View<int*, MemSpace> pnbr; // N*MAXP : neighbour seed id per plane (<0 = box)
45 Kokkos::View<unsigned*, MemSpace> tri; // N*MAXT : t0 | t1<<8 | t2<<16 | alive<<24
46 Kokkos::View<unsigned char*, MemSpace>
47 poke4; // N*MAXT*4 : per-triangle local-cert plane set (3 edge-
48 // opposite + 4th-face), computed by ConvexCell::computePoke4() at
49 // gather/rebuild and read directly by isLocallyConvex each step.
50 // Allocated via allocPoke4(); written/read OUTSIDE save()/load()
51 // (the gather computes it; the cert reads its pointer).
52
53 void alloc(int n) {
54 using Kokkos::view_alloc;
55 using Kokkos::WithoutInitializing;
56 N = n;
57 np = Kokkos::View<int*, MemSpace>("topo.np", n);
58 nt = Kokkos::View<int*, MemSpace>("topo.nt", n);
59 pnbr = Kokkos::View<int*, MemSpace>(view_alloc(std::string("topo.pnbr"), WithoutInitializing),
60 (size_t)n * MAXP);
61 tri = Kokkos::View<unsigned*, MemSpace>(
62 view_alloc(std::string("topo.tri"), WithoutInitializing), (size_t)n * MAXT);
63 }
64
67 void allocPoke4() {
68 poke4 = Kokkos::View<unsigned char*, MemSpace>(
69 Kokkos::view_alloc(std::string("topo.poke4"), Kokkos::WithoutInitializing),
70 (size_t)N * MAXT * 4);
71 }
72
74 template <class Cell>
75 KOKKOS_INLINE_FUNCTION void save(int i, const Cell& c) const {
76 np(i) = c.np;
77 nt(i) = c.nt;
78 for (int k = 0; k < c.np; ++k)
79 pnbr((size_t)i * MAXP + k) = c.pnbr[k];
80 for (int t = 0; t < c.nt; ++t)
81 tri((size_t)i * MAXT + t) = (unsigned)c.t0[t] | ((unsigned)c.t1[t] << 8) |
82 ((unsigned)c.t2[t] << 16) | ((c.alive[t] ? 1u : 0u) << 24);
83 // NOTE: the local-cert `poke4` table is NOT part of the topology snapshot — it is computed by
84 // the caller (ConvexCell::computePoke4) directly into `poke4` at gather/rebuild, and read by
85 // the cert.
86 }
87
92 template <class Cell, class Real>
93 KOKKOS_INLINE_FUNCTION void load(int i, Cell& c, Real L0, Real L1, Real L2) const {
94 c.initBoxPlanes(L0, L1, L2);
95 const int npi = np(i), nti = nt(i);
96 c.np = npi;
97 c.nt = nti;
98 c.overflow = false;
99 for (int k = 6; k < npi; ++k)
100 c.pnbr[k] = pnbr((size_t)i * MAXP + k);
101 for (int t = 0; t < nti; ++t) {
102 const unsigned w = tri((size_t)i * MAXT + t);
103 c.t0[t] = (unsigned char)(w & 0xffu);
104 c.t1[t] = (unsigned char)((w >> 8) & 0xffu);
105 c.t2[t] = (unsigned char)((w >> 16) & 0xffu);
106 c.alive[t] = ((w >> 24) & 1u) != 0u;
107 }
108 // `poke4` is read by the certificate directly from this store (a pointer), not loaded into the
109 // cell; `adj` (if the cell is TrackAdj) is rebuilt by the caller when it needs it
110 // (rebuildAdjAll / the gather).
111 }
112};
113
114} // namespace peclet::voro
115
116#endif // PECLET_VORO_TOPOLOGY_STORE_HPP
Definition convex_cell.hpp:40
Definition topology_store.hpp:39
void alloc(int n)
Definition topology_store.hpp:53
int N
Definition topology_store.hpp:41
Kokkos::View< int *, MemSpace > np
Definition topology_store.hpp:42
Kokkos::View< unsigned char *, MemSpace > poke4
Definition topology_store.hpp:47
peclet::core::MemSpace MemSpace
Definition topology_store.hpp:40
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