PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
FTUtils.hpp
Go to the documentation of this file.
1//
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4//
5
6#pragma once
7
8#include <Kokkos_Abort.hpp>
9#include <stdexcept>
10
14
15namespace PACMAN {
16
17namespace FiniteElements {
18
19template <typename ExecSpace, int_t Dim>
34 Kokkos::Profiling::pushRegion(
35 "FiniteElement::ComputeBoxTargetPointIntersection");
36 if (transfer.nbSpaceDimElements == 0) {
37 return;
38 }
39
40 using MemorySpace = typename ExecSpace::memory_space;
41 using Box = ArborX::Box<Dim, coordinates_t>;
42
44
45 Kokkos::Profiling::pushRegion(
46 "copy pointers and allocate auxiliary data structures");
47
48 auto sourcePointsPtr = transfer.sourcePoints;
49 auto sourceValuesPtr = transfer.sourceValues;
50
51 auto targetPointsPtr = transfer.targetPoints;
52 auto targetValuesPtr = transfer.targetValues;
53 auto targetStatusPtr = transfer.targetStatus;
54 auto nbtargetPoints = targetPointsPtr.extent_int(0);
55
56 auto connValPtr = transfer.connValues;
57 auto connOffPtr = transfer.connOffsets;
58 auto CellTypesPtr = transfer.cellTypes;
59
60 Kokkos::Profiling::popRegion();
61
62 Kokkos::Profiling::pushRegion(
63 "Allocate auxiliary data structures for box-point intersection");
64 Kokkos::View<Box *, MemorySpace> bboxes(
65 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
66 "Boundary boxes of elements"),
67 transfer.nbSpaceDimElements);
68 Kokkos::View<int *, MemorySpace> parents(
69 Kokkos::view_alloc(execSpace, Kokkos::WithoutInitializing,
70 "Parents of Bboxes"),
71 transfer.nbSpaceDimElements);
72 Kokkos::Profiling::popRegion();
73
74 // Kokkos::parallel_scan(
75 // "Compute element bounding boxes functor",
76 // Kokkos::RangePolicy(execSpace, 0, transfer.nbElems),
77 // KOKKOS_LAMBDA(const int_t &i, int_t &partial_sum, bool is_final) {
78 // const CellType cellType = static_cast<CellType>(CellTypesPtr(i));
79 // const int_t elemToTreat =
80 // static_cast<int_t>(getDimension(cellType) == Dim);
81 // const int_t firstIndex = partial_sum;
82 // partial_sum += elemToTreat;
83 // if (is_final) {
84 // for (int_t j = firstIndex; j < firstIndex + elemToTreat; j++) {
85 // bboxes(j) = Box();
86 // auto localConn = Kokkos::subview(
87 // connValPtr,
88 // Kokkos::make_pair(connOffPtr(i), connOffPtr(i + 1)));
89 // const int_t nbConnNodes = connOffPtr(i + 1) - connOffPtr(i);
90 // for (int_t k = 0; k < nbConnNodes; k++) {
91 // ArborX::Details::expand(bboxes(j),
92 // sourcePointsPtr(localConn(k)));
93 // }
94 // parents(j) = i;
95 // }
96 // }
97 // });
98
99 Kokkos::parallel_for(
100 "Compute element bounding boxes functor",
101 Kokkos::RangePolicy(execSpace, 0, transfer.nbElems),
102 KOKKOS_LAMBDA(const int_t &i) {
103 ArborX::Point<Dim, coordinates_t> pmin;
104 ArborX::Point<Dim, coordinates_t> pmax;
105 for (int d = 0; d < Dim; ++d) {
106 pmin[d] = 9999999.0;
107 pmax[d] = -9999999.0;
108 }
109 for (int_t k = connOffPtr(i); k < connOffPtr(i + 1); k++) {
110 for (int d = 0; d < Dim; ++d) {
111 pmin[d] = Kokkos::min(pmin[d], sourcePointsPtr(connValPtr(k))[d]);
112 pmax[d] = Kokkos::max(pmax[d], sourcePointsPtr(connValPtr(k))[d]);
113 }
114 }
115 bboxes(i) = Box(pmin, pmax);
116 parents(i) = i;
117 });
118
119 ArborX::BoundingVolumeHierarchy bvhBoxes(
120 execSpace, ArborX::Experimental::attach_indices(bboxes));
121
122 PointIntersect<MemorySpace, Dim> pi{targetPointsPtr};
123 bvhBoxes.query(
124 execSpace, pi,
126
127 Kokkos::Profiling::popRegion(); // ComputeBoxTargetPointIntersection
128}
129
130} // namespace FiniteElements
131} // namespace PACMAN
ArborX predicate/callback helpers for PACMAN finite-elements kernels.
Finite-element geometric helpers and Lagrange-space specializations.
void ComputeBoxTargetPointIntersection(Transfer< ExecSpace, Dim > &transfer)
Intersect target points with source-element bounding boxes, then evaluate FE interpolation for inters...
Definition FTUtils.hpp:33