56 const Kokkos::View<Real*, peclet::core::MemSpace>& pos,
57 const Kokkos::View<Real*, peclet::core::MemSpace>& vol,
int N,
59 Kokkos::View<Real*, peclet::core::MemSpace> xRef = {},
60 bool withAreaGrad =
false,
bool withMoments =
false,
61 Kokkos::View<Real*, peclet::core::MemSpace> weight = {}) {
62 using Mem = peclet::core::MemSpace;
63 using Exec = peclet::core::ExecSpace;
64 using Cell = ConvexCell<Real, MAXP, MAXT, false>;
65 using Kokkos::view_alloc;
66 using Kokkos::WithoutInitializing;
67 const Real Lx = L[0], Ly = L[1], Lz = L[2];
68 TopologyStore<MAXP, MAXT> st = store;
69 Kokkos::View<Real*, Mem> P = pos;
72 Kokkos::View<int*, Mem> facetCount(
"rp.facetCount",
static_cast<std::size_t
>(N));
73 Kokkos::View<int*, Mem> edgeCount(
"rp.edgeCount", withAreaGrad ?
static_cast<std::size_t
>(N) : 0);
74 constexpr int kMaxF = MAXP;
75 const bool wag = withAreaGrad;
77 "reevalPublish.count", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
79 st.load(i, c, Lx, Ly, Lz);
82 for (
int k = 0; k < c.np; ++k) {
84 for (
int t = 0; t < c.nt; ++t)
85 if (c.alive[t] && (c.t0[t] == k || c.t1[t] == k || c.t2[t] == k))
95 unsigned char part[kMaxF * Cell::MAXFV], pcnt[kMaxF];
97 edgeCount(i) = (nf > 0 && nf <= kMaxF)
98 ? areaGradEnumerate<Cell, kMaxF>(c, faces, nf, part, pcnt, full)
104 Kokkos::View<int*, Mem> base(view_alloc(std::string(
"rp.base"), WithoutInitializing),
105 static_cast<std::size_t
>(N));
108 Kokkos::View<int*, Mem> fc = facetCount, bs = base;
109 Kokkos::parallel_scan(
110 "reevalPublish.scan", N,
111 KOKKOS_LAMBDA(
const int i,
int& upd,
const bool final_pass) {
118 Kokkos::View<int*, Mem> ebase(view_alloc(std::string(
"rp.ebase"), WithoutInitializing),
119 withAreaGrad ?
static_cast<std::size_t
>(N) : 0);
122 Kokkos::View<int*, Mem> ec = edgeCount, eb = ebase;
123 Kokkos::parallel_scan(
124 "reevalPublish.scanEdges", N,
125 KOKKOS_LAMBDA(
const int i,
int& upd,
const bool final_pass) {
134 const std::size_t nF =
static_cast<std::size_t
>(nFacets);
135 Kokkos::View<gid_t*, Mem> fNbr(view_alloc(std::string(
"rp.fNbr"), WithoutInitializing), nF);
136 Kokkos::View<Real*, Mem> fArea(view_alloc(std::string(
"rp.fArea"), WithoutInitializing), nF * 3);
137 Kokkos::View<Real*, Mem> fDV(view_alloc(std::string(
"rp.fDV"), WithoutInitializing), nF * 3);
138 Kokkos::View<Real*, Mem> fConn(view_alloc(std::string(
"rp.fConn"), WithoutInitializing), nF * 3);
139 const std::size_t nE =
static_cast<std::size_t
>(nEdges);
140 Kokkos::View<int*, Mem> eOff(view_alloc(std::string(
"rp.eOff"), WithoutInitializing),
141 withAreaGrad ? nF : 0);
142 Kokkos::View<int*, Mem> eCnt(view_alloc(std::string(
"rp.eCnt"), WithoutInitializing),
143 withAreaGrad ? nF : 0);
144 Kokkos::View<int*, Mem> eFacet(view_alloc(std::string(
"rp.eFacet"), WithoutInitializing),
145 withAreaGrad ? nE : 0);
146 Kokkos::View<Real*, Mem> eGrad(view_alloc(std::string(
"rp.eGrad"), WithoutInitializing),
147 withAreaGrad ? nE * 3 : 0);
148 Kokkos::View<Real*, Mem> eLen(view_alloc(std::string(
"rp.eLen"), WithoutInitializing),
149 withAreaGrad ? nE * 4 : 0);
150 Kokkos::View<Real*, Mem> fM2(view_alloc(std::string(
"rp.fM2"), WithoutInitializing),
151 withMoments ? nF : 0);
152 const bool wm = withMoments;
154 Kokkos::View<int*, Mem> bs = base, eb = ebase;
155 WallStore<Real> Wl = wall;
156 Kokkos::View<Real*, Mem> XR = xRef;
157 Kokkos::View<Real*, Mem> W = weight;
158 const Real Lxh = Real(0.5) * Lx, Lyh = Real(0.5) * Ly, Lzh = Real(0.5) * Lz;
159 Kokkos::parallel_for(
160 "reevalPublish.fill", Kokkos::RangePolicy<Exec>(0, N), KOKKOS_LAMBDA(
const int i) {
162 st.load(i, c, Lx, Ly, Lz);
164 Real dx = P(3 * i) - XR(3 * i), dy = P(3 * i + 1) - XR(3 * i + 1),
165 dz = P(3 * i + 2) - XR(3 * i + 2);
166 dx = dx > Lxh ? dx - Lx : (dx < -Lxh ? dx + Lx : dx);
167 dy = dy > Lyh ? dy - Ly : (dy < -Lyh ? dy + Ly : dy);
168 dz = dz > Lzh ? dz - Lz : (dz < -Lzh ? dz + Lz : dz);
169 Wl.load(i, c, dx, dy, dz);
171 const Real* wPtr = W.data();
173 if constexpr (Policy::kHasWeightDof)
174 c.template reevalGeometry<Policy>(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx,
177 c.reevalGeometry(P(3 * i), P(3 * i + 1), P(3 * i + 2), P.data(), Lx);
181 for (
int k = 0; k < c.np; ++k) {
183 for (
int t = 0; t < c.nt; ++t)
184 if (c.alive[t] && (c.t0[t] == k || c.t1[t] == k || c.t2[t] == k))
190 Real area[3] = {0, 0, 0}, dv[3] = {0, 0, 0}, conn[3];
191 conn[0] = Real(2) * c.n[k][0];
192 conn[1] = Real(2) * c.n[k][1];
193 conn[2] = Real(2) * c.n[k][2];
194 if constexpr (Policy::kHasWeightDof) {
197 const int gk = c.pnbr[k];
199 const Real Lh = Real(0.5) * Lx;
200 Real rx = P(3 * gk) - P(3 * i), ry = P(3 * gk + 1) - P(3 * i + 1),
201 rz = P(3 * gk + 2) - P(3 * i + 2);
202 conn[0] = rx > Lh ? rx - Lx : (rx < -Lh ? rx + Lx : rx);
203 conn[1] = ry > Lh ? ry - Lx : (ry < -Lh ? ry + Lx : ry);
204 conn[2] = rz > Lh ? rz - Lx : (rz < -Lh ? rz + Lx : rz);
206 c.facetGeometryFrom(k, conn, area, dv);
209 c.facetGeometry(k, area, dv, conn);
211 const std::size_t g =
static_cast<std::size_t
>(b + idx);
212 fNbr(g) =
static_cast<gid_t>(c.pnbr[k]);
213 for (
int cc = 0; cc < 3; ++cc) {
214 fArea(3 * g + cc) = area[cc];
215 fDV(3 * g + cc) = dv[cc];
216 fConn(3 * g + cc) = conn[cc];
219 fM2(g) = c.faceMoment2(k);
222 if (wag && idx > 0 && idx <= kMaxF) {
223 unsigned char part[kMaxF * Cell::MAXFV], pcnt[kMaxF];
225 areaGradEnumerate<Cell, kMaxF>(c, faces, idx, part, pcnt, full);
226 areaGradFill<Cell, kMaxF>(c, faces, idx, part, pcnt, b, eb(i), eOff, eCnt, eFacet,
233 TessellationView<Real> view;
234 view.cellFacetOffset = base;
235 view.cellFacetCount = facetCount;
236 view.cellVolume = vol;
237 view.cellSeedId = Kokkos::View<gid_t*, Mem>(
238 view_alloc(std::string(
"rp.seedId"), WithoutInitializing),
static_cast<std::size_t
>(N));
240 Kokkos::View<gid_t*, Mem> vSeed = view.cellSeedId;
241 Kokkos::parallel_for(
242 "reevalPublish.seedId", Kokkos::RangePolicy<Exec>(0, N),
243 KOKKOS_LAMBDA(
const int i) { vSeed(i) =
static_cast<gid_t>(i); });
245 view.facetNeighbor = fNbr;
246 view.facetArea = fArea;
247 view.facetConnect = fDV;
248 view.facetConnVec = fConn;
250 view.facetMoment2 = fM2;
252 view.facetEdgeOffset = eOff;
253 view.facetEdgeCount = eCnt;
254 view.edgeFacet = eFacet;
255 view.edgeAreaGrad = eGrad;
257 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"rp.edgeLength"), WithoutInitializing), nE);
259 auto el = view.edgeLength;
260 Kokkos::parallel_for(
261 "reevalPublish.edgeLength", Kokkos::RangePolicy<Exec>(0, nE),
262 KOKKOS_LAMBDA(
const int e) { el(e) = eLen((
size_t)e * 4); });