70 using Mem = peclet::core::MemSpace;
71 using Exec = peclet::core::ExecSpace;
72 using Kokkos::view_alloc;
73 using Kokkos::WithoutInitializing;
76 const int nOwn = (nOwned >= 0 && nOwned < N) ? nOwned : N;
79 auto recip = aux.
recip;
82 Kokkos::View<int*, Mem> kind(
"fv.kind", nF);
84 "fv.kind", Kokkos::RangePolicy<Exec>(0, nF), KOKKOS_LAMBDA(
const int f) {
90 else if (recip(f) >= 0)
91 kind(f) = (f < recip(f)) ? 1 : 0;
98 Kokkos::parallel_reduce(
99 "fv.dropped", Kokkos::RangePolicy<Exec>(0, nF),
100 KOKKOS_LAMBDA(
const int f,
int& acc) { acc += kind(f) == 3 ? 1 : 0; }, nd);
104 Kokkos::View<int*, Mem> idxI(view_alloc(std::string(
"fv.idxI"), WithoutInitializing), nF);
105 Kokkos::View<int*, Mem> idxB(view_alloc(std::string(
"fv.idxB"), WithoutInitializing), nF);
107 Kokkos::parallel_scan(
109 KOKKOS_LAMBDA(
const int f,
int& upd,
const bool fin) {
112 upd += (kind(f) == 1) ? 1 : 0;
115 Kokkos::parallel_scan(
117 KOKKOS_LAMBDA(
const int f,
int& upd,
const bool fin) {
120 upd += (kind(f) == 2) ? 1 : 0;
125 const int nFaces = m.
nFaces;
127 Kokkos::View<int*, Mem>(view_alloc(std::string(
"fv.A"), WithoutInitializing), nFaces);
129 Kokkos::View<int*, Mem>(view_alloc(std::string(
"fv.B"), WithoutInitializing), nFaces);
131 Kokkos::View<int*, Mem>(view_alloc(std::string(
"fv.facet"), WithoutInitializing), nFaces);
133 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.area"), WithoutInitializing), nFaces);
134 m.
faceNormal = Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.normal"), WithoutInitializing),
137 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.dist"), WithoutInitializing), nFaces);
139 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.ha"), WithoutInitializing), nFaces);
141 Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.hb"), WithoutInitializing), nFaces);
142 m.
faceCentroid = Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.cen"), WithoutInitializing),
144 m.
faceConn = Kokkos::View<Real*, Mem>(view_alloc(std::string(
"fv.conn"), WithoutInitializing),
157 Kokkos::parallel_for(
158 "fv.fill", Kokkos::RangePolicy<Exec>(0, nF), KOKKOS_LAMBDA(
const int f) {
159 const int k = kind(f);
160 if (k == 0 || k == 3)
162 const int g = (k == 1) ? idxI(f) : nI + idxB(f);
163 const int i = cellOf(f);
166 B(g) = (k == 1) ? (recip(f) >= 0 ? cellOf(recip(f)) : view.
facetNbr(f)) : -1;
168 const Real ax = view.
area(f, 0), ay = view.
area(f, 1), az = view.
area(f, 2);
169 const Real ar = Kokkos::sqrt(ax * ax + ay * ay + az * az);
171 const Real iar = ar > Real(0) ? Real(1) / ar : Real(0);
172 NM(3 * g) = ax * iar;
173 NM(3 * g + 1) = ay * iar;
174 NM(3 * g + 2) = az * iar;
176 const Real rl = Kokkos::sqrt(rx * rx + ry * ry + rz * rz);
178 const Real ha = Real(0.5) * rl;
181 const Real s = (ar > Real(0)) ? rl / ar : Real(0);
182 CE(3 * g) = rx - dvx * s;
183 CE(3 * g + 1) = ry - dvy * s;
184 CE(3 * g + 2) = rz - dvz * s;
193 CN(3 * g) = CN(3 * g + 1) = CN(3 * g + 2) = Real(0);
201 Kokkos::View<int*, Mem> cnt(
"fv.cnt", N + 1);
205 Kokkos::parallel_for(
206 "fv.count", Kokkos::RangePolicy<Exec>(0, nFaces), KOKKOS_LAMBDA(
const int g) {
207 Kokkos::atomic_inc(&cnt(A(g)));
208 if (B(g) >= 0 && B(g) < nOwn)
209 Kokkos::atomic_inc(&cnt(B(g)));
212 m.
cellFaceOffset = Kokkos::View<int*, Mem>(
"fv.cellFaceOffset", N + 1);
215 Kokkos::parallel_scan(
216 "fv.scanCells", N + 1, KOKKOS_LAMBDA(
const int i,
int& upd,
const bool fin) {
219 upd += (i < N) ? cnt(i) : 0;
222 const int nEntries = 2 * nI + nB;
223 m.
cellFace = Kokkos::View<int*, Mem>(view_alloc(std::string(
"fv.cellFace"), WithoutInitializing),
226 view_alloc(std::string(
"fv.cellFaceSign"), WithoutInitializing), nEntries);
228 Kokkos::View<int*, Mem> cursor(
"fv.cursor", N);
234 Kokkos::parallel_for(
235 "fv.fillCells", Kokkos::RangePolicy<Exec>(0, nFaces), KOKKOS_LAMBDA(
const int g) {
237 const int pa = off(a) + Kokkos::atomic_fetch_add(&cursor(a), 1);
241 if (b >= 0 && b < nOwn) {
242 const int pb = off(b) + Kokkos::atomic_fetch_add(&cursor(b), 1);