PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
callbacks.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 <ArborX_Point.hpp>
10#include <ArborX_Sphere.hpp>
11
12#include "common/concepts.hpp"
13#include "common/types.hpp"
14#include "utils/operators.hpp"
15
16namespace PACMAN {
17namespace RbfPum {
18
21template <KokkosViewRank<1> ViewType> struct DistanceToKNearest {
22 const int_t k;
23 ViewType samples;
24};
25
29 template <typename Predicate, typename Value, typename OutputFunctor>
31 OutputFunctor const &out) const {
32 out(SquaredDifference(ArborX::getData(predicate), value.value));
33 }
34};
35
38template <KokkosViewRank<1> ViewType> struct Projection { ViewType centers; };
39
43 template <typename Predicate, typename Value, typename OutputFunctor>
45 OutputFunctor const &out) const {
46 // <center, projection>
47 out(Kokkos::make_pair(ArborX::getData(predicate), value.value));
48 }
49};
50
53template <KokkosViewRank<1> ViewType> struct TagEmptyCenters {
55};
56
60template <KokkosViewRank<1> ViewType> struct TagEmptyCentersCallback {
63
64 template <typename Predicate, typename Value>
66 Value const &value) const {
67 const int center_index = ArborX::getData(predicate);
68 // The center should be removed
70 threshold) {
71 // Only one match per center, so centersCandidates(center_index) is
72 // accessed only once
73 // No need of atomic operation here
75 }
76 }
77};
78
81template <KokkosViewRank<1> ViewType> struct TransformToNearest {
83};
84
88template <KokkosViewRank<1> ViewType> struct TransformToNearestCallback {
90 template <typename Predicate, typename Value>
92 Value const &value) const {
93 // The center must be projected to the nearest point (value)
94 centersCandidates(ArborX::getData(predicate)) = value.value;
95 }
96};
97
100template <KokkosViewRank<1> ViewType> struct GetClustersPoints {
101 ViewType centers;
103};
104
109 template <typename Predicate, typename Value, typename OutputFunctor>
110 KOKKOS_FUNCTION void operator()(Predicate /* predicate */, Value const &value,
111 OutputFunctor const &out) const {
112 out(value.index);
113 }
114};
115
116} // namespace RbfPum
117} // namespace PACMAN
118
119namespace ArborX {
120
124template <PACMAN::KokkosViewRank<1> ViewType>
125struct AccessTraits<PACMAN::RbfPum::DistanceToKNearest<ViewType>> {
126 using memory_space = typename ViewType::memory_space;
128 static KOKKOS_FUNCTION size_t size(const Self &self) {
129 return self.samples.extent(0);
130 }
131 static KOKKOS_FUNCTION auto get(const Self &self, size_t i) {
132 return attach(nearest(self.samples(i), self.k), self.samples(i));
133 }
134};
135
139template <PACMAN::KokkosViewRank<1> ViewType>
140struct AccessTraits<PACMAN::RbfPum::Projection<ViewType>> {
141 using memory_space = typename ViewType::memory_space;
143 static KOKKOS_FUNCTION size_t size(const Self &self) {
144 return self.centers.extent(0);
145 }
146 static KOKKOS_FUNCTION auto get(const Self &self, size_t i) {
147 return attach(nearest(self.centers(i), 1), self.centers(i));
148 }
149};
150
154template <PACMAN::KokkosViewRank<1> ViewType>
155struct AccessTraits<PACMAN::RbfPum::TagEmptyCenters<ViewType>> {
156 using memory_space = typename ViewType::memory_space;
158 using Point = typename ViewType::non_const_value_type;
159 static KOKKOS_FUNCTION size_t size(const Self &self) {
160 return self.centersCandidates.extent(0);
161 }
162 static KOKKOS_FUNCTION auto get(const Self &self, size_t i) {
163 // isNaN
164 if (self.centersCandidates(i)[0] != self.centersCandidates(i)[0]) {
165 return attach(nearest(Point{}, 0), -1);
166 }
167 return attach(nearest(self.centersCandidates(i), 1), (int)i);
168 }
169};
170
174template <PACMAN::KokkosViewRank<1> ViewType>
175struct AccessTraits<PACMAN::RbfPum::TransformToNearest<ViewType>> {
176 using memory_space = typename ViewType::memory_space;
178 using Point = typename ViewType::non_const_value_type;
179 static KOKKOS_FUNCTION size_t size(const Self &self) {
180 return self.centersCandidates.extent(0);
181 }
182 static KOKKOS_FUNCTION auto get(const Self &self, size_t i) {
183 // isNaN
184 if (self.centersCandidates(i)[0] != self.centersCandidates(i)[0]) {
185 return attach(nearest(Point{}, 0), -1);
186 }
187 return attach(nearest(self.centersCandidates(i), 1), (int)i);
188 }
189};
190
194template <PACMAN::KokkosViewRank<1> ViewType>
195struct AccessTraits<PACMAN::RbfPum::GetClustersPoints<ViewType>> {
196 using memory_space = typename ViewType::memory_space;
198 static KOKKOS_FUNCTION size_t size(const Self &self) {
199 return self.centers.extent(0);
200 }
201 static KOKKOS_FUNCTION auto get(const Self &self, size_t i) {
202 return intersects(Sphere(self.centers(i), self.radius));
203 }
204};
205} // namespace ArborX
KOKKOS_INLINE_FUNCTION fp_t SquaredDifference(const ::ArborX::Point< Dim, coordinates_t > &lhs, const ::ArborX::Point< Dim, coordinates_t > &rhs) noexcept
Returns the squared distance between two points, and check for NaN values.
int32_t int_t
Definition types.hpp:18
static KOKKOS_FUNCTION size_t size(const Self &self)
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
static KOKKOS_FUNCTION size_t size(const Self &self)
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
static KOKKOS_FUNCTION size_t size(const Self &self)
static KOKKOS_FUNCTION size_t size(const Self &self)
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
static KOKKOS_FUNCTION size_t size(const Self &self)
static KOKKOS_FUNCTION auto get(const Self &self, size_t i)
Custom ArborX callback which returns the squared distance between a cluster center and its nearest po...
Definition callbacks.hpp:28
KOKKOS_FUNCTION void operator()(Predicate predicate, Value const &value, OutputFunctor const &out) const
Definition callbacks.hpp:30
Support struct for an ArborX predicate.
Definition callbacks.hpp:21
A custon ArborX callback which returns the indices of the points inside of each region (according to ...
KOKKOS_FUNCTION void operator()(Predicate, Value const &value, OutputFunctor const &out) const
Support struct for an ArborX predicate.
A custom ArborX callback which returns the nearest mesh point of a given value (the nearest projectio...
Definition callbacks.hpp:42
KOKKOS_FUNCTION void operator()(Predicate predicate, Value const &value, OutputFunctor const &out) const
Definition callbacks.hpp:44
Support struct for an ArborX predicate.
Definition callbacks.hpp:38
A custon ArborX callback which tags empty regions centers, by setting the x axis value of the center ...
Definition callbacks.hpp:60
KOKKOS_FUNCTION void operator()(Predicate predicate, Value const &value) const
Definition callbacks.hpp:65
Support struct for an ArborX predicate.
Definition callbacks.hpp:53
A custom ArborX callback which performs a nearest point projection for all the ArborX::Point in the g...
Definition callbacks.hpp:88
KOKKOS_FUNCTION void operator()(Predicate predicate, Value const &value) const
Definition callbacks.hpp:91
Support struct for an ArborX predicate.
Definition callbacks.hpp:81