69 Kokkos::Profiling::pushRegion(
"Compute Linear Skin");
71 using MemorySpace =
typename ExecSpace::memory_space;
72 ExecSpace execSpace{};
77 Kokkos::DefaultHostExecutionSpace::memory_space,
78 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
79 LFPE_val_vec.data(), LFPE_val_vec.size());
80 auto linearFacesPadded_val =
81 Kokkos::create_mirror_view_and_copy(execSpace, LFPE_val);
84 Kokkos::View<
offset_t *, Kokkos::DefaultHostExecutionSpace::memory_space,
85 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
86 LFPE_off_vec.data(), LFPE_off_vec.size());
87 auto linearFacesPadded_off =
88 Kokkos::create_mirror_view_and_copy(execSpace, LFPE_off);
92 Kokkos::DefaultHostExecutionSpace::memory_space,
93 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
94 TF_val_vec.data(), TF_val_vec.size());
95 auto TriFaces_val = Kokkos::create_mirror_view_and_copy(execSpace, TF_val);
98 Kokkos::View<
offset_t *, Kokkos::DefaultHostExecutionSpace::memory_space,
99 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(TF_off_vec.data(),
101 auto TriFaces_off = Kokkos::create_mirror_view_and_copy(execSpace, TF_off);
105 Kokkos::DefaultHostExecutionSpace::memory_space,
106 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(
107 TLF_val_vec.data(), TLF_val_vec.size());
108 auto TriLocFaces_val =
109 Kokkos::create_mirror_view_and_copy(execSpace, TLF_val);
112 Kokkos::View<
offset_t *, Kokkos::DefaultHostExecutionSpace::memory_space,
113 Kokkos::MemoryTraits<Kokkos::Unmanaged>>(TLF_off_vec.data(),
115 auto TriLocFaces_off =
116 Kokkos::create_mirror_view_and_copy(execSpace, TLF_off);
118 auto nbNode = transfer.sourcePoints.extent_int(0);
119 auto nbLinFaces = transfer.nbLinearSkinFaces;
120 auto CellTypesPtr = transfer.cellTypes;
121 auto connValPtr = transfer.connValues;
122 auto connOffPtr = transfer.connOffsets;
124 auto nbElem = CellTypesPtr.extent(0);
126 int_t nodesPerFace = -1;
141 std::cerr <<
"Invalid Dim " << Dim << std::endl;
146 auto linFaces = Kokkos::View<int_t **, ExecSpace>(
147 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
"linFaces"),
148 nbLinFaces, nodesPerFace + 1);
149 auto allFaceId = Kokkos::View<int_t *, ExecSpace>(
150 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
"allFaceId"),
152 auto allFaceLocId = Kokkos::View<int_t *, ExecSpace>(
153 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
156 auto allParents = Kokkos::View<int_t *, ExecSpace>(
157 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
"allParents"),
160 constexpr int_t maxi = std::numeric_limits<int_t>::max();
162 Kokkos::Profiling::pushRegion(
"Fill all faces and sort per row permute");
164 Kokkos::parallel_scan(
165 "Fill all faces and sort per row : Col permutation",
166 Kokkos::RangePolicy(execSpace, 0, nbElem),
167 KOKKOS_LAMBDA(
const index_t &i,
index_t &partial_sum,
bool is_final) {
168 auto ielType =
static_cast<cell_t>(CellTypesPtr(i));
169 auto facesPadded = Kokkos::subview(
170 linearFacesPadded_val,
171 Kokkos::make_pair(linearFacesPadded_off(ielType),
172 linearFacesPadded_off(ielType + 1)));
173 auto localnbFaces = facesPadded.extent_int(0) / nodesPerFace;
174 auto firstIndex = partial_sum;
175 partial_sum += localnbFaces;
177 auto localConnectivity = Kokkos::subview(
178 connValPtr, Kokkos::make_pair(connOffPtr(i), connOffPtr(i + 1)));
179 for (
index_t j = 0; j < localnbFaces; j++) {
181 Kokkos::subview(linFaces, firstIndex + j, Kokkos::ALL());
182 allParents(firstIndex + j) = i;
183 allFaceId(firstIndex + j) = firstIndex + j;
184 allFaceLocId(firstIndex + j) = j;
185 for (
index_t k = 0; k < nodesPerFace - 1;
187 auto index = facesPadded(j * nodesPerFace + k);
188 linFaces_sv(k) = localConnectivity(index);
190 auto index = facesPadded((j + 1) * nodesPerFace - 1);
191 linFaces_sv(nodesPerFace - 1) =
192 (index == -1) ? maxi : localConnectivity(index);
193 using subviewType =
decltype(linFaces_sv);
195 linFaces_sv(nodesPerFace) = ielType;
199 Kokkos::Profiling::popRegion();
201 Kokkos::Profiling::pushRegion(
202 "Create permutation vector to sort linFaces by row");
203 auto firstNodeIds = Kokkos::subview(linFaces, Kokkos::ALL(), 0);
205 using IdViewType =
decltype(firstNodeIds);
206 using CompType = Kokkos::BinOp1D<IdViewType>;
207 using DeviceType = Kokkos::Device<ExecSpace, MemorySpace>;
209 Kokkos::BinSort<IdViewType, CompType, DeviceType, int_t> bin_sort(
210 firstNodeIds, CompType(nbLinFaces, 0, nbNode),
true );
211 bin_sort.create_permute_vector();
212 auto permutationVector = bin_sort.get_permute_vector();
213 Kokkos::Profiling::popRegion();
215 Kokkos::Profiling::pushRegion(
"Permute and Compute Nbtris");
218 Kokkos::parallel_reduce(
219 "Permute and Compute NbTris",
220 Kokkos::RangePolicy(execSpace, 0, nbLinFaces),
222 auto index = permutationVector(i);
226 auto vect = Kokkos::subview(linFaces, index, Kokkos::ALL());
232 while (curr > 0 && linFaces(permutationVector(curr), 0) == vect(0)) {
236 if (linFaces(permutationVector(curr), 0) != vect(0)) {
240 while (curr <= nbLinFaces - 1 &&
241 linFaces(permutationVector(curr), 0) == vect(0)) {
248 for (
index_t t = 1; t < nodesPerFace + 1; ++t)
249 if (linFaces(permutationVector(curr), t) != vect(t)) {
260 if (curr_row_occur == 2) {
261 allFaceId(index) = -1;
263 auto ielType = (int)CellTypesPtr(allParents(index));
264 auto iTriLocFaces = Kokkos::subview(
265 TriLocFaces_val, Kokkos::make_pair(TriLocFaces_off(ielType),
266 TriLocFaces_off(ielType + 1)));
267 auto iloc = allFaceLocId(index);
268 sum += (iTriLocFaces(iloc + 1) - iTriLocFaces(iloc)) / Dim;
272 Kokkos::Profiling::popRegion();
274 Kokkos::Profiling::pushRegion(
"Remove");
277 const auto end = Kokkos::Experimental::remove(execSpace, allFaceId, -1);
279 Kokkos::Experimental::distance(Kokkos::Experimental::begin(allFaceId),
282 Kokkos::Profiling::popRegion();
284 Kokkos::Profiling::pushRegion(
"Finalize: compute linear skin");
286 auto skinFaces = Kokkos::View<int_t **, ExecSpace>(
287 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
"skinFaces"),
289 auto skinParents = Kokkos::View<int_t *, ExecSpace>(
290 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
"skinParents"),
293 Kokkos::parallel_scan(
294 "Fill Skin Faces & Parents", Kokkos::RangePolicy(execSpace, 0, dist),
295 KOKKOS_LAMBDA(
const index_t &i,
index_t &partial_sum,
bool is_final) {
296 auto index = allFaceId(i);
297 auto iParent = allParents(index);
298 auto ielType =
static_cast<cell_t>(CellTypesPtr(iParent));
299 auto iTriFaces = Kokkos::subview(
300 TriFaces_val, Kokkos::make_pair(TriFaces_off(ielType),
301 TriFaces_off(ielType + 1)));
302 auto iTriLocFaces = Kokkos::subview(
303 TriLocFaces_val, Kokkos::make_pair(TriLocFaces_off(ielType),
304 TriLocFaces_off(ielType + 1)));
305 auto iloc = allFaceLocId(index);
306 auto localnbFaces = (iTriLocFaces(iloc + 1) - iTriLocFaces(iloc)) / Dim;
307 auto firstIndex = partial_sum;
308 partial_sum += localnbFaces;
310 auto localConnectivity = Kokkos::subview(
312 Kokkos::make_pair(connOffPtr(iParent), connOffPtr(iParent + 1)));
313 for (
index_t j = 0; j < localnbFaces; j++) {
314 skinParents(firstIndex + j) = iParent;
315 auto pos = iTriLocFaces(iloc) + j * Dim;
316 for (
int_t k = 0; k < Dim; k++) {
317 const auto iconn = iTriFaces(pos + k);
318 skinFaces(firstIndex + j, k) = localConnectivity(iconn);
323 transfer.skinFaces = skinFaces;
324 transfer.skinParents = skinParents;
326 Kokkos::Profiling::popRegion();
328 Kokkos::Profiling::popRegion();