IPPL API Reference
Independent Parallel Particle Layer C++ API
Loading...
Searching...
No Matches
NDRegion.hpp
1//
2// Class NDRegion
3// NDRegion is a simple container of N PRegion objects. It is templated
4// on the type of data (T) and the number of PRegions (Dim).
5//
6#include <iostream>
7
8namespace ippl {
9 template <typename T, unsigned Dim>
10 template <
11 class... Args,
12 typename std::enable_if<
13 sizeof...(Args) == Dim && (std::is_convertible_v<Args, PRegion<T>> && ...), bool>::type>
14 KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(const Args&... args)
15 : regions_m{args...} {}
16
17 template <typename T, unsigned Dim>
18 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>::NDRegion(const NDRegion<T, Dim>& nr) {
19 for (unsigned int i = 0; i < Dim; i++) {
20 regions_m[i] = nr.regions_m[i];
21 }
22 }
23
24 template <typename T, unsigned Dim>
25 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator=(
26 const NDRegion<T, Dim>& nr) {
27 for (unsigned int i = 0; i < Dim; i++) {
28 regions_m[i] = nr.regions_m[i];
29 }
30 return *this;
31 }
32
33 template <typename T, unsigned Dim>
34 KOKKOS_INLINE_FUNCTION const PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) const {
35 return regions_m[d];
36 }
37
38 template <typename T, unsigned Dim>
39 KOKKOS_INLINE_FUNCTION PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) {
40 return regions_m[d];
41 }
43 template <typename T, unsigned Dim>
44 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator+=(const T t) {
45 for (unsigned int i = 0; i < Dim; i++) {
46 regions_m[i] += t;
47 }
48 return *this;
49 }
50
51 template <typename T, unsigned Dim>
52 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator-=(const T t) {
53 for (unsigned int i = 0; i < Dim; i++) {
54 regions_m[i] -= t;
55 }
56 return *this;
57 }
58
59 template <typename T, unsigned Dim>
60 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator*=(const T t) {
61 for (unsigned int i = 0; i < Dim; i++) {
62 regions_m[i] *= t;
63 }
64 return *this;
65 }
66
67 template <typename T, unsigned Dim>
68 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator/=(const T t) {
69 if (t != 0) {
70 for (unsigned int i = 0; i < Dim; i++) {
71 regions_m[i] /= t;
72 }
73 }
74 return *this;
75 }
76
77 template <typename T, unsigned Dim>
78 KOKKOS_INLINE_FUNCTION bool NDRegion<T, Dim>::empty() const {
79 bool isEmpty = true;
80 for (unsigned int i = 0; i < Dim; i++) {
81 isEmpty &= regions_m[i].empty();
82 }
83 return isEmpty;
84 }
85
86 template <typename T, unsigned Dim>
87 inline std::ostream& operator<<(std::ostream& out, const NDRegion<T, Dim>& idx) {
88 out << '{';
89 for (unsigned d = 0; d < Dim; ++d) {
90 out << idx[d] << ((d == Dim - 1) ? '}' : ',');
91 }
92 return out;
93 }
94} // namespace ippl
Definition NDRegion.h:20
KOKKOS_FUNCTION NDRegion()
Definition NDRegion.h:26
Definition Archive.h:20