50 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
51 const Kokkos::View<Real*, peclet::core::MemSpace>& vol,
int N,
53 Kokkos::View<Real*, peclet::core::MemSpace> xRef = {},
54 bool withAreaGrad =
false,
bool withMoments =
false) {
55 using Mem = peclet::core::MemSpace;
56 using Exec = peclet::core::ExecSpace;
57 using Cell = ConvexCell<Real, MAXP, MAXT, false>;
58 using Kokkos::view_alloc;
59 using Kokkos::WithoutInitializing;
60 const Real Lx = L[0], Ly = L[1], Lz = L[2];
61 TopologyStore<MAXP, MAXT> st = store;
62 Kokkos::View<Real*, Mem> P = pos;
65 Kokkos::View<int*, Mem> facetCount(
"rp.facetCount",
static_cast<std::size_t
>(N));
66 Kokkos::View<int*, Mem> edgeCount(
"rp.edgeCount", withAreaGrad ?
static_cast<std::size_t
>(N) : 0);
67 constexpr int kMaxF = MAXP;
68 const bool wag = withAreaGrad;
70 "reevalPublish.count", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
72 st.load(i, c, Lx, Ly, Lz);
75 for (
int k = 0; k < c.np; ++k) {
77 for (
int t = 0; t < c.nt; ++t)
78 if (c.alive[t] && (c.t0[t] == k || c.t1[t] == k || c.t2[t] == k))
88 unsigned char part[kMaxF * Cell::MAXFV], pcnt[kMaxF];
90 edgeCount(i) = (nf > 0 && nf <= kMaxF)
91 ? areaGradEnumerate<Cell, kMaxF>(c, faces, nf, part, pcnt, full)
97 Kokkos::View<int*, Mem> base(view_alloc(std::string(
"rp.base"), WithoutInitializing),
98 static_cast<std::size_t
>(N));
101 Kokkos::View<int*, Mem> fc = facetCount, bs = base;
102 Kokkos::parallel_scan(
103 "reevalPublish.scan", N,
104 KOKKOS_LAMBDA(
const int i,
int& upd,
const bool final_pass) {
111 Kokkos::View<int*, Mem> ebase(view_alloc(std::string(
"rp.ebase"), WithoutInitializing),
112 withAreaGrad ?
static_cast<std::size_t
>(N) : 0);
115 Kokkos::View<int*, Mem> ec = edgeCount, eb = ebase;
116 Kokkos::parallel_scan(
117 "reevalPublish.scanEdges", N,
118 KOKKOS_LAMBDA(
const int i,
int& upd,
const bool final_pass) {
127 const std::size_t nF =
static_cast<std::size_t
>(nFacets);
128 Kokkos::View<gid_t*, Mem> fNbr(view_alloc(std::string(
"rp.fNbr"), WithoutInitializing), nF);
129 Kokkos::View<Real*, Mem> fArea(view_alloc(std::string(
"rp.fArea"), WithoutInitializing), nF * 3);
130 Kokkos::View<Real*, Mem> fDV(view_alloc(std::string(
"rp.fDV"), WithoutInitializing), nF * 3);
131 Kokkos::View<Real*, Mem> fConn(view_alloc(std::string(
"rp.fConn"), WithoutInitializing), nF * 3);
132 const std::size_t nE =
static_cast<std::size_t
>(nEdges);
133 Kokkos::View<int*, Mem> eOff(view_alloc(std::string(
"rp.eOff"), WithoutInitializing),
134 withAreaGrad ? nF : 0);
135 Kokkos::View<int*, Mem> eCnt(view_alloc(std::string(
"rp.eCnt"), WithoutInitializing),
136 withAreaGrad ? nF : 0);
137 Kokkos::View<int*, Mem> eFacet(view_alloc(std::string(
"rp.eFacet"), WithoutInitializing),
138 withAreaGrad ? nE : 0);
139 Kokkos::View<Real*, Mem> eGrad(view_alloc(std::string(
"rp.eGrad"), WithoutInitializing),
140 withAreaGrad ? nE * 3 : 0);
141 Kokkos::View<Real*, Mem> eLen(view_alloc(std::string(
"rp.eLen"), WithoutInitializing),
142 withAreaGrad ? nE * 4 : 0);
143 Kokkos::View<Real*, Mem> fM2(view_alloc(std::string(
"rp.fM2"), WithoutInitializing),
144 withMoments ? nF : 0);
145 const bool wm = withMoments;
147 Kokkos::View<int*, Mem> bs = base, eb = ebase;
148 WallStore<Real> Wl = wall;
149 Kokkos::View<Real*, Mem> XR = xRef;
150 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
151 Kokkos::parallel_for(
152 "reevalPublish.fill", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
154 st.load(i, c, Lx, Ly, Lz);
156 Real dx = P(3 * i) - XR(3 * i), dy = P(3 * i + 1) - XR(3 * i + 1),
157 dz = P(3 * i + 2) - XR(3 * i + 2);
158 dx = dx > Lxh ? dx - Lx : (dx < -Lxh ? dx + Lx : dx);
159 dy = dy > Lyh ? dy - Ly : (dy < -Lyh ? dy + Ly : dy);
160 dz = dz > Lzh ? dz - Lz : (dz < -Lzh ? dz + Lz : dz);
161 Wl.load(i, c, dx, dy, dz);
163 c.reevalGeometry(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx);
167 for (
int k = 0; k < c.np; ++k) {
169 for (
int t = 0; t < c.nt; ++t)
170 if (c.alive[t] && (c.t0[t] == k || c.t1[t] == k || c.t2[t] == k))
176 Real area[3] = {0, 0, 0}, dv[3] = {0, 0, 0}, conn[3];
177 conn[0] = Real(2) * c.n[k][0];
178 conn[1] = Real(2) * c.n[k][1];
179 conn[2] = Real(2) * c.n[k][2];
180 c.facetGeometry(k, area, dv, conn);
181 const std::size_t g =
static_cast<std::size_t
>(b + idx);
182 fNbr(g) =
static_cast<gid_t>(c.pnbr[k]);
183 for (
int cc = 0; cc < 3; ++cc) {
184 fArea(3 * g + cc) = area[cc];
185 fDV(3 * g + cc) = dv[cc];
186 fConn(3 * g + cc) = conn[cc];
189 fM2(g) = c.faceMoment2(k);
192 if (wag && idx > 0 && idx <= kMaxF) {
193 unsigned char part[kMaxF * Cell::MAXFV], pcnt[kMaxF];
195 areaGradEnumerate<Cell, kMaxF>(c, faces, idx, part, pcnt, full);
196 areaGradFill<Cell, kMaxF>(c, faces, idx, part, pcnt, b, eb(i), eOff, eCnt, eFacet,
203 TessellationView<Real> view;
204 view.cellFacetOffset = base;
205 view.cellFacetCount = facetCount;
206 view.cellVolume = vol;
207 view.cellSeedId = Kokkos::View<gid_t*, Mem>(
208 view_alloc(std::string(
"rp.seedId"), WithoutInitializing),
static_cast<std::size_t
>(N));
210 Kokkos::View<gid_t*, Mem> vSeed = view.cellSeedId;
211 Kokkos::parallel_for(
212 "reevalPublish.seedId", Kokkos::RangePolicy<Exec>(0, N),
213 KOKKOS_LAMBDA(
const int i) { vSeed(i) =
static_cast<gid_t>(i); });
215 view.facetNeighbor = fNbr;
216 view.facetArea = fArea;
217 view.facetConnect = fDV;
218 view.facetConnVec = fConn;
220 view.facetMoment2 = fM2;
222 view.facetEdgeOffset = eOff;
223 view.facetEdgeCount = eCnt;
224 view.edgeFacet = eFacet;
225 view.edgeAreaGrad = eGrad;
227 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"rp.edgeLength"), WithoutInitializing), nE);
229 auto el = view.edgeLength;
230 Kokkos::parallel_for(
231 "reevalPublish.edgeLength", Kokkos::RangePolicy<Exec>(0, nE),
232 KOKKOS_LAMBDA(
const int e) { el(e) = eLen((
size_t)e * 4); });