peclet.voro 1.0.0
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
transpose.hpp
Go to the documentation of this file.
1
15#ifndef PECLET_VORO_TRANSPOSE_HPP
16#define PECLET_VORO_TRANSPOSE_HPP
17
18#include <Kokkos_Core.hpp>
19
20#include "peclet/core/common/view.hpp"
22
23namespace peclet::voro {
24
25template <class Real>
26struct AuxMaps {
27 Kokkos::View<int*, peclet::core::MemSpace> recip; // nFacets: reciprocal facet, or -1
28 Kokkos::View<int*, peclet::core::MemSpace> cellOfFacet; // nFacets: owning cell index
29};
30
32template <class Real>
34 using Exec = peclet::core::ExecSpace;
35 const int N = view.numCells();
36 const int nF = view.numFacets();
37 AuxMaps<Real> aux;
38 aux.recip = Kokkos::View<int*, peclet::core::MemSpace>("recip", nF);
39 aux.cellOfFacet = Kokkos::View<int*, peclet::core::MemSpace>("cellOfFacet", nF);
40 auto recip = aux.recip;
41 auto cellOfFacet = aux.cellOfFacet;
42
43 Kokkos::parallel_for(
44 "aux.cellOfFacet", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int i) {
45 for (int f = view.facetBegin(i); f < view.facetEnd(i); ++f)
46 cellOfFacet(f) = i;
47 });
48
49 Kokkos::parallel_for(
50 "aux.recip", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(const int i) {
51 const gid_t idi = view.cellSeed(i);
52 for (int g = view.facetBegin(i); g < view.facetEnd(i); ++g) {
53 const gid_t j = view.facetNbr(g);
54 recip(g) = -1;
55 if (j < 0 || j >= N)
56 continue;
57 int best = -1;
58 Real bestErr = Real(1e300);
59 for (int h = view.facetBegin((int)j); h < view.facetEnd((int)j); ++h) {
60 if (view.facetNbr(h) != idi)
61 continue;
62 Real e = 0; // area-vector negation picks the matching interface
63 for (int c = 0; c < 3; ++c) {
64 Real s = view.area(g, c) + view.area(h, c);
65 e += s * s;
66 }
67 if (e < bestErr) {
68 bestErr = e;
69 best = h;
70 }
71 }
72 recip(g) = best;
73 }
74 });
75 Kokkos::fence();
76 return aux;
77}
78
79} // namespace peclet::voro
80
81#endif // PECLET_VORO_TRANSPOSE_HPP
Definition convex_cell.hpp:40
std::int32_t gid_t
Definition tessellation_view.hpp:41
AuxMaps< Real > buildAuxMaps(const TessellationView< Real > &view)
Build {recip, cellOfFacet} on device from a published view (dense single-domain).
Definition transpose.hpp:33
Definition transpose.hpp:26
Kokkos::View< int *, peclet::core::MemSpace > recip
Definition transpose.hpp:27
Kokkos::View< int *, peclet::core::MemSpace > cellOfFacet
Definition transpose.hpp:28
Definition tessellation_view.hpp:111
KOKKOS_INLINE_FUNCTION Real area(int f, int c) const
Definition tessellation_view.hpp:144
KOKKOS_INLINE_FUNCTION int facetEnd(int i) const
Definition tessellation_view.hpp:140
KOKKOS_INLINE_FUNCTION gid_t facetNbr(int f) const
Definition tessellation_view.hpp:143
KOKKOS_INLINE_FUNCTION gid_t cellSeed(int i) const
Definition tessellation_view.hpp:137
KOKKOS_INLINE_FUNCTION int facetBegin(int i) const
Definition tessellation_view.hpp:139
KOKKOS_INLINE_FUNCTION int numFacets() const
Definition tessellation_view.hpp:136
KOKKOS_INLINE_FUNCTION int numCells() const
Definition tessellation_view.hpp:131
Published, read-only device data layer for the tessellation (migration §2.1, §3).