PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
operators.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_Point.hpp>
9#include <Kokkos_Core.hpp>
10#include <iomanip>
11
12#include "common/types.hpp"
13#include "utils/utils.hpp"
14
15namespace ArborX {
16
23template <int Dim>
24KOKKOS_INLINE_FUNCTION constexpr bool
25operator==(const ArborX::Point<Dim, PACMAN::coordinates_t> &lhs,
26 const ArborX::Point<Dim, PACMAN::coordinates_t> &rhs) noexcept {
27 for (int i = 0; i < Dim; ++i) {
28 if (lhs[i] != rhs[i] && (lhs[i] == lhs[i] && rhs[i] == rhs[i])) {
29 return false;
30 }
31 }
32 return true;
33}
34
42template <int Dim>
43KOKKOS_INLINE_FUNCTION constexpr bool
44operator!=(const ArborX::Point<Dim, PACMAN::coordinates_t> &lhs,
45 const ArborX::Point<Dim, PACMAN::coordinates_t> &rhs) noexcept {
46 return !(lhs == rhs);
47}
48
57template <int Dim>
58KOKKOS_INLINE_FUNCTION bool constexpr
59operator<(const ArborX::Point<Dim, PACMAN::coordinates_t> &lhs,
60 const ArborX::Point<Dim, PACMAN::coordinates_t> &rhs) noexcept {
61 const bool is_lhs_nan = lhs[0] != lhs[0];
62 const bool is_rhs_nan = rhs[0] != rhs[0];
63 if (is_lhs_nan != is_rhs_nan) {
64 return !is_lhs_nan;
65 }
66 for (int axis = 0; axis < Dim; ++axis) {
67 if (lhs[axis] < rhs[axis]) {
68 return true;
69 }
70 if (lhs[axis] > rhs[axis]) {
71 return false;
72 }
73 }
74 return false;
75}
76
85template <int Dim>
86KOKKOS_INLINE_FUNCTION bool constexpr
87operator>(const ArborX::Point<Dim, PACMAN::coordinates_t> &lhs,
88 const ArborX::Point<Dim, PACMAN::coordinates_t> &rhs) noexcept {
89 return !(lhs == rhs) && !(lhs < rhs);
90}
91
99// LCOV_EXCL_START
100template <int Dim>
101std::ostream &
102operator<<(std::ostream &os,
103 const ArborX::Point<Dim, PACMAN::coordinates_t> &point) {
104 std::ostringstream strs;
106 strs << "ArborX::Point(";
107 for (int i = 0; i < Dim - 1; i++) {
108 strs << point[i] << ", ";
109 }
110 strs << point[Dim - 1] << ")";
111 os << strs.str();
112 return os;
113}
114// LCOV_EXCL_STOP
115} // namespace ArborX
116
117namespace PACMAN {
118namespace RbfPum {
119
127template <int_t Dim>
128KOKKOS_INLINE_FUNCTION fp_t
129SquaredDifference(const ::ArborX::Point<Dim, coordinates_t> &lhs,
130 const ::ArborX::Point<Dim, coordinates_t> &rhs) noexcept {
131 if (rhs[0] != rhs[0] || lhs[0] != lhs[0]) {
132 return -fp_consts::one();
133 }
134 fp_t acc = fp_consts::zero();
135 for (int_t i = 0; i < Dim; ++i) {
136 acc += (rhs[i] - lhs[i]) * (rhs[i] - lhs[i]);
137 }
138 return acc;
139}
140
148template <int_t Dim>
149KOKKOS_INLINE_FUNCTION fp_t
150Distance(const ::ArborX::Point<Dim, coordinates_t> &lhs,
151 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
152 const fp_t d = SquaredDifference(lhs, rhs);
153 if (d < fp_consts::zero()) {
154 return -fp_consts::one();
155 }
156 return Kokkos::sqrt(d);
157}
158
165template <int_t Dim>
166KOKKOS_INLINE_FUNCTION fp_t
167SquaredDifferenceNoCheck(const ::ArborX::Point<Dim, coordinates_t> &lhs,
168 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
169 fp_t acc = fp_consts::zero();
170 for (int_t i = 0; i < Dim; ++i) {
171 acc += (rhs[i] - lhs[i]) * (rhs[i] - lhs[i]);
172 }
173 return acc;
174}
175
182template <int_t Dim>
183KOKKOS_INLINE_FUNCTION fp_t
184DistanceNoCheck(const ::ArborX::Point<Dim, coordinates_t> &lhs,
185 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
186 return Kokkos::sqrt(SquaredDifferenceNoCheck(lhs, rhs));
187}
188
193
197template <typename ExecSpace> struct OffsetsScan {
198 Kokkos::View<offset_t *, ExecSpace> sourceOffsets;
199 Kokkos::View<offset_t *, ExecSpace> targetOffsets;
200
201 Kokkos::View<offset_t *, ExecSpace> rbfMatOffsets;
202 Kokkos::View<offset_t *, ExecSpace> evalMatOffsets;
203
204 KOKKOS_FUNCTION void operator()(const int &i, OffsetsScanPair &pair,
205 const bool &final) const {
206 const offset_t n = sourceOffsets(i + 1) - sourceOffsets(i);
207 const offset_t m = targetOffsets(i + 1) - targetOffsets(i);
208 pair.sourceCurrent += n * n;
209 pair.targetCurrent += n * m;
210
211 if (final) {
212 rbfMatOffsets(i + 1) = pair.sourceCurrent;
213 evalMatOffsets(i + 1) = pair.targetCurrent;
214 }
215 }
216
217 KOKKOS_FUNCTION void init(OffsetsScanPair &pair) const {
218 pair.sourceCurrent = 0;
219 pair.targetCurrent = 0;
220 }
221
222 KOKKOS_FUNCTION void join(OffsetsScanPair &dest,
223 const OffsetsScanPair &src) const {
224 dest.sourceCurrent += src.sourceCurrent;
225 dest.targetCurrent += src.targetCurrent;
226 }
227};
228} // namespace RbfPum
229} // namespace PACMAN
KOKKOS_INLINE_FUNCTION bool constexpr operator<(const ArborX::Point< Dim, PACMAN::coordinates_t > &lhs, const ArborX::Point< Dim, PACMAN::coordinates_t > &rhs) noexcept
Custom operator overload for operator< to compare two ArborX::Point using the values of each point.
Definition operators.hpp:59
std::ostream & operator<<(std::ostream &os, const ArborX::Point< Dim, PACMAN::coordinates_t > &point)
Custom operator overload for operator<< to print a ArborX::Point with a nice format (ArborX::Point(x,...
KOKKOS_INLINE_FUNCTION constexpr bool operator==(const ArborX::Point< Dim, PACMAN::coordinates_t > &lhs, const ArborX::Point< Dim, PACMAN::coordinates_t > &rhs) noexcept
Custom operator overload for operator== to compare two ArborX::Point using the values of each point,...
Definition operators.hpp:25
KOKKOS_INLINE_FUNCTION constexpr bool operator!=(const ArborX::Point< Dim, PACMAN::coordinates_t > &lhs, const ArborX::Point< Dim, PACMAN::coordinates_t > &rhs) noexcept
Custom operator overload for operator!= to compare two ArborX::Point using the values of each point,...
Definition operators.hpp:44
KOKKOS_INLINE_FUNCTION bool constexpr operator>(const ArborX::Point< Dim, PACMAN::coordinates_t > &lhs, const ArborX::Point< Dim, PACMAN::coordinates_t > &rhs) noexcept
Custom operator overload for operator> to compare two ArborX::Point using the values of each point.
Definition operators.hpp:87
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.
KOKKOS_INLINE_FUNCTION fp_t Distance(const ::ArborX::Point< Dim, coordinates_t > &lhs, const ::ArborX::Point< Dim, coordinates_t > &rhs)
Returns the euclidian norm between two points by performing a square root operation on the SquaredDif...
KOKKOS_INLINE_FUNCTION fp_t DistanceNoCheck(const ::ArborX::Point< Dim, coordinates_t > &lhs, const ::ArborX::Point< Dim, coordinates_t > &rhs)
Returns the euclidian norm between two points by performing a square root operation on the SquaredDif...
KOKKOS_INLINE_FUNCTION fp_t SquaredDifferenceNoCheck(const ::ArborX::Point< Dim, coordinates_t > &lhs, const ::ArborX::Point< Dim, coordinates_t > &rhs)
Returns the squared distance between two points, and don't check for NaN values.
KOKKOS_INLINE_FUNCTION consteval fp_t zero(void)
Definition types.hpp:92
auto set_precision(void)
Definition types.hpp:101
KOKKOS_INLINE_FUNCTION consteval fp_t one(void)
Definition types.hpp:95
double fp_t
Definition types.hpp:15
int32_t offset_t
Definition types.hpp:21
int32_t int_t
Definition types.hpp:18
Struct used to build multiple matrices access offsets with one scan loop only, during the systems sol...
Kokkos::View< offset_t *, ExecSpace > targetOffsets
KOKKOS_FUNCTION void operator()(const int &i, OffsetsScanPair &pair, const bool &final) const
Kokkos::View< offset_t *, ExecSpace > sourceOffsets
Kokkos::View< offset_t *, ExecSpace > evalMatOffsets
Kokkos::View< offset_t *, ExecSpace > rbfMatOffsets
KOKKOS_FUNCTION void init(OffsetsScanPair &pair) const
KOKKOS_FUNCTION void join(OffsetsScanPair &dest, const OffsetsScanPair &src) const