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
99template <int Dim>
100std::ostream &
101operator<<(std::ostream &os,
102 const ArborX::Point<Dim, PACMAN::coordinates_t> &point) {
103 std::ostringstream strs;
105 strs << "ArborX::Point(";
106 for (int i = 0; i < Dim - 1; i++) {
107 strs << point[i] << ", ";
108 }
109 strs << point[Dim - 1] << ")";
110 os << strs.str();
111 return os;
112}
113} // namespace ArborX
114
115namespace PACMAN {
116namespace RbfPum {
117
125template <int_t Dim>
126KOKKOS_INLINE_FUNCTION fp_t
127SquaredDifference(const ::ArborX::Point<Dim, coordinates_t> &lhs,
128 const ::ArborX::Point<Dim, coordinates_t> &rhs) noexcept {
129 if (rhs[0] != rhs[0] || lhs[0] != lhs[0]) {
130 return -fp_consts::one();
131 }
133 for (int_t i = 0; i < Dim; ++i) {
134 acc += (rhs[i] - lhs[i]) * (rhs[i] - lhs[i]);
135 }
136 return acc;
137}
138
146template <int_t Dim>
148Distance(const ::ArborX::Point<Dim, coordinates_t> &lhs,
149 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
150 const fp_t d = SquaredDifference(lhs, rhs);
151 if (d < fp_consts::zero()) {
152 return -fp_consts::one();
153 }
154 return Kokkos::sqrt(d);
155}
156
163template <int_t Dim>
165SquaredDifferenceNoCheck(const ::ArborX::Point<Dim, coordinates_t> &lhs,
166 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
168 for (int_t i = 0; i < Dim; ++i) {
169 acc += (rhs[i] - lhs[i]) * (rhs[i] - lhs[i]);
170 }
171 return acc;
172}
173
180template <int_t Dim>
182DistanceNoCheck(const ::ArborX::Point<Dim, coordinates_t> &lhs,
183 const ::ArborX::Point<Dim, coordinates_t> &rhs) {
184 return Kokkos::sqrt(SquaredDifferenceNoCheck(lhs, rhs));
185}
186
191
195template <typename ExecSpace> struct OffsetsScan {
196 Kokkos::View<offset_t *, ExecSpace> sourceOffsets;
197 Kokkos::View<offset_t *, ExecSpace> targetOffsets;
198
199 Kokkos::View<offset_t *, ExecSpace> rbfMatOffsets;
200 Kokkos::View<offset_t *, ExecSpace> evalMatOffsets;
201
203 const bool &final) const {
204 const offset_t n = sourceOffsets(i + 1) - sourceOffsets(i);
205 const offset_t m = targetOffsets(i + 1) - targetOffsets(i);
206 pair.sourceCurrent += n * n;
207 pair.targetCurrent += n * m;
208
209 if (final) {
210 rbfMatOffsets(i + 1) = pair.sourceCurrent;
211 evalMatOffsets(i + 1) = pair.targetCurrent;
212 }
213 }
214
216 pair.sourceCurrent = 0;
217 pair.targetCurrent = 0;
218 }
219
221 const OffsetsScanPair &src) const {
222 dest.sourceCurrent += src.sourceCurrent;
223 dest.targetCurrent += src.targetCurrent;
224 }
225};
226} // namespace RbfPum
227} // 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
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