PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
ArborXCallbacks.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 <ArborX.hpp>
9#include <algorithms/ArborX_ClosestPoint.hpp>
10
11#include "common/concepts.hpp"
12#include "common/transfer.hxx"
13#include "common/types.hpp"
15
21namespace PACMAN {
22namespace FiniteElements {
23
26template <KokkosViewRank<1> ViewType> struct PointNearest { ViewType points; };
27
31template <typename ExecSpace, int_t Dim>
33 using MemorySpace = typename ExecSpace::memory_space;
34
36 Kokkos::View<int *, MemorySpace> parents;
37
39 template <typename Predicate, typename Value>
41 const Value &value) const {
42
43 const int predicate_index = ArborX::getData(predicate);
44 const int_t curElem = parents(value.index); // RAMZI: is it needed ?
45 const auto cellType = transfer.cellTypes(curElem);
46
47 Kokkos::Array<fp_t, MaxNodesPerElt> warr;
48 Kokkos::Array<coordinates_t, MaxNodesPerElt * Dim> Xarr;
49 Kokkos::Array<coordinates_t, Dim> tpa;
50 Kokkos::View<coordinates_t *, ExecSpace> tp(tpa.data(), Dim);
51
52 for (int_t j = 0; j < Dim; j++) {
53 tp(j) = transfer.targetPoints(predicate_index, j);
54 }
55 const auto localConn =
56 Kokkos::subview(transfer.connValues,
57 Kokkos::make_pair(transfer.connOffsets(curElem),
58 transfer.connOffsets(curElem + 1)));
59 const offset_t nbConnNodes =
60 transfer.connOffsets(curElem + 1) - transfer.connOffsets(curElem);
61 Kokkos::View<fp_t *, ExecSpace> weights(warr.data(), nbConnNodes);
62 Kokkos::View<coordinates_t **, ExecSpace> Xcoor(Xarr.data(), nbConnNodes,
63 Dim);
64 for (int_t j = 0; j < nbConnNodes; ++j) {
65 const auto nodeId = localConn(j);
66 for (int_t k = 0; k < Dim; ++k) {
67 Xcoor(j, k) = transfer.sourcePoints(nodeId)[k];
68 }
69 }
71 weights /*, false*/)) {
72 for (int_t j = 0; j < nbConnNodes; ++j) {
73 const auto nodeId = localConn(j);
74 transfer.targetValues(predicate_index) +=
75 weights[j] * transfer.sourceValues(nodeId);
76 }
78 return ArborX::CallbackTreeTraversalControl::early_exit;
79 } else {
80 return ArborX::CallbackTreeTraversalControl::normal_continuation;
81 }
82 }
83};
84
88template <typename ExecSpace, int_t Dim> struct PointTriangleProjection {
89 using MemorySpace = typename ExecSpace::memory_space;
90
91 Kokkos::View<coordinates_t **, MemorySpace> targetPointsPtr;
92 Kokkos::View<int_t *, MemorySpace> parentElt;
93 Kokkos::View<TransferStatus *, MemorySpace> status;
94 Kokkos::View<int_t *, MemorySpace> skinParents;
95
97 template <typename Predicate, typename Value, typename OutputFunctor>
99 const Value &value,
100 const OutputFunctor &out) const {
101 const int predicate_index = ArborX::getData(predicate);
102
104 ArborX::Point<Dim, coordinates_t> targetPoint;
105 for (int_t k = 0; k < Dim; k++) {
107 }
108
109 auto triangle = value.value;
110
111 using PointTag = ArborX::GeometryTraits::PointTag;
112 using TriangleTag = ArborX::GeometryTraits::TriangleTag;
113 using Point = decltype(targetPoint);
114 using Triangle = decltype(triangle);
115
116 ArborX::Details::Dispatch::distance<PointTag, TriangleTag, Point,
117 Triangle>
118 dist{};
119 targetPoint = ArborX::Experimental::closestPoint(targetPoint, triangle);
120 for (int_t k = 0; k < Dim; k++) {
122 }
125 }
126 }
127};
128
133template <typename ExecSpace, int Dim> struct PointTriangleProjectionExtrapol {
134 using MemorySpace = typename ExecSpace::memory_space;
135
136 Kokkos::View<int_t *, MemorySpace> parentElt;
137 Kokkos::View<TransferStatus *, MemorySpace> status;
138 Kokkos::View<int_t *, MemorySpace> skinParents;
139
141 template <typename Predicate, typename Value, typename OutputFunctor>
143 const Value &value,
144 const OutputFunctor &out) const {
145 const int predicate_index = ArborX::getData(predicate);
146
150 }
151 }
152};
153
156 template <typename Predicate, typename Value, typename OutputFunctor>
158 const OutputFunctor &out) const {
159 out(value.index);
160 }
161};
162
166template <typename MemorySpace, int Dim> struct PointCloudNearest {
167 Kokkos::View<coordinates_t **, MemorySpace> points;
168};
169
172template <typename MemorySpace> struct NearestExtractIndex {
173 Kokkos::View<fp_t *, MemorySpace> sourceValues;
174 Kokkos::View<fp_t *, MemorySpace> targetValues;
175
176 template <typename Predicate, typename Value>
178 const Value &value) const {
179 const int predicate_index = ArborX::getData(predicate);
181 }
182};
183
187template <typename MemorySpace, int_t Dim> struct PointIntersect {
188 Kokkos::View<coordinates_t **, MemorySpace> points;
189};
190
191} // namespace FiniteElements
192
193} // namespace PACMAN
194
195namespace ArborX {
197template <PACMAN::KokkosViewRank<1> ViewType>
198struct AccessTraits<PACMAN::FiniteElements::PointNearest<ViewType>> {
199 using memory_space = typename ViewType::memory_space;
201 KOKKOS_FUNCTION
202 static size_t size(const Self &self) { return self.points.extent(0); }
203 KOKKOS_FUNCTION
204 static auto get(const Self &self, size_t i) {
205 return attach(nearest(self.points(i), 1), (int)i);
206 }
207};
208
210template <typename MemorySpace, int Dim>
211struct AccessTraits<
212 PACMAN::FiniteElements::PointCloudNearest<MemorySpace, Dim>> {
213 using memory_space = MemorySpace;
215
216 KOKKOS_FUNCTION
217 static size_t size(const Self &self) { return self.points.extent(0); }
218 KOKKOS_FUNCTION
219 static auto get(const Self &self, size_t i) {
220 Point<Dim, PACMAN::coordinates_t> point;
221 for (int k = 0; k < Dim; k++) {
222 point[k] = self.points(i, k);
223 }
224 return attach(nearest(point, 1), (int)i);
225 }
226};
227
229template <typename MemorySpace, int Dim>
230struct AccessTraits<PACMAN::FiniteElements::PointIntersect<MemorySpace, Dim>> {
231 using memory_space = MemorySpace;
233
234 KOKKOS_FUNCTION
235 static size_t size(const Self &self) { return self.points.extent(0); }
236 KOKKOS_FUNCTION
237 static auto get(const Self &self, size_t i) {
238 Point<Dim, PACMAN::coordinates_t> point;
239 for (int k = 0; k < Dim; k++) {
240 point[k] = self.points(i, k);
241 }
242 return attach(intersects(point), (int)i);
243 }
244};
245
246} // namespace ArborX
int32_t int_t
Definition types.hpp:18
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
Generic callback extracting index from ArborX query values.
KOKKOS_FUNCTION void operator()(Predicate, const Value &value, const OutputFunctor &out) const
Callback assigning source value at nearest-neighbor index.
KOKKOS_FUNCTION void operator()(const Predicate &predicate, const Value &value) const
Kokkos::View< fp_t *, MemorySpace > sourceValues
Kokkos::View< fp_t *, MemorySpace > targetValues
Predicate wrapper for nearest-neighbor queries over point clouds.
Kokkos::View< coordinates_t **, MemorySpace > points
Point-finite element intersection and interplolation callback.
KOKKOS_FUNCTION auto operator()(const Predicate &predicate, const Value &value) const
ArborX callback: project one outside target point and emit output.
Predicate wrapper for point/box intersection queries.
Kokkos::View< coordinates_t **, MemorySpace > points
Wrapper for nearest-neighbor predicates built from 1D point views.
ArborX callback variant for extrapolation mode.
KOKKOS_FUNCTION void operator()(const Predicate &predicate, const Value &value, const OutputFunctor &out) const
ArborX callback: assign nearest skin parent for outside points.
Kokkos::View< TransferStatus *, MemorySpace > status
Project outside target points onto nearest 3D skin triangle.
Kokkos::View< int_t *, MemorySpace > skinParents
KOKKOS_FUNCTION void operator()(const Predicate &predicate, const Value &value, const OutputFunctor &out) const
ArborX callback: project one outside target point and emit output.
Kokkos::View< coordinates_t **, MemorySpace > targetPointsPtr
typename ExecSpace::memory_space MemorySpace
Kokkos::View< int_t *, MemorySpace > parentElt
Kokkos::View< TransferStatus *, MemorySpace > status