IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
NDRegion.hpp
Go to the documentation of this file.
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 <class... Args>
11 KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(const Args&... args)
12 : NDRegion({args...}) {
13 static_assert(Dim == sizeof...(args), "Wrong number of arguments.");
14 }
15
16 template <typename T, unsigned Dim>
17 KOKKOS_FUNCTION NDRegion<T, Dim>::NDRegion(std::initializer_list<PRegion<T>> regions) {
18 unsigned int i = 0;
19 for (auto& r : regions) {
20 regions_m[i] = r;
21 ++i;
22 }
23 }
24
25 template <typename T, unsigned Dim>
26 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>::NDRegion(const NDRegion<T, Dim>& nr) {
27 for (unsigned int i = 0; i < Dim; i++) {
28 regions_m[i] = nr.regions_m[i];
29 }
30 }
31
32 template <typename T, unsigned Dim>
34 const NDRegion<T, Dim>& nr) {
35 for (unsigned int i = 0; i < Dim; i++) {
36 regions_m[i] = nr.regions_m[i];
37 }
38 return *this;
39 }
40
41 template <typename T, unsigned Dim>
42 KOKKOS_INLINE_FUNCTION const PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) const {
43 return regions_m[d];
44 }
45
46 template <typename T, unsigned Dim>
47 KOKKOS_INLINE_FUNCTION PRegion<T>& NDRegion<T, Dim>::operator[](unsigned d) {
48 return regions_m[d];
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 for (unsigned int i = 0; i < Dim; i++) {
70 regions_m[i] *= t;
71 }
72 return *this;
73 }
74
75 template <typename T, unsigned Dim>
76 KOKKOS_INLINE_FUNCTION NDRegion<T, Dim>& NDRegion<T, Dim>::operator/=(const T t) {
77 if (t != 0) {
78 for (unsigned int i = 0; i < Dim; i++) {
79 regions_m[i] /= t;
80 }
81 }
82 return *this;
83 }
84
85 template <typename T, unsigned Dim>
86 KOKKOS_INLINE_FUNCTION bool NDRegion<T, Dim>::empty() const {
87 bool isEmpty = true;
88 for (unsigned int i = 0; i < Dim; i++) {
89 isEmpty &= regions_m[i].empty();
90 }
91 return isEmpty;
92 }
93
94 template <typename T, unsigned Dim>
95 inline std::ostream& operator<<(std::ostream& out, const NDRegion<T, Dim>& idx) {
96 out << '{';
97 for (unsigned d = 0; d < Dim; ++d) {
98 out << idx[d] << ((d == Dim - 1) ? '}' : ',');
99 }
100 return out;
101 }
102} // namespace ippl
constexpr unsigned Dim
Definition Archive.h:20
std::ostream & operator<<(std::ostream &os, const BConds< Field, Dim > &bc)
Definition BConds.h:49
PRegion< T > regions_m[Dim]
Array of PRegions.
Definition NDRegion.h:64
KOKKOS_INLINE_FUNCTION NDRegion< T, Dim > & operator*=(const T t)
Definition NDRegion.hpp:68
KOKKOS_INLINE_FUNCTION NDRegion< T, Dim > & operator-=(const T t)
Definition NDRegion.hpp:60
KOKKOS_INLINE_FUNCTION bool empty() const
Definition NDRegion.hpp:86
KOKKOS_INLINE_FUNCTION NDRegion< T, Dim > & operator=(const NDRegion< T, Dim > &nr)
Definition NDRegion.hpp:33
KOKKOS_FUNCTION NDRegion()
Definition NDRegion.h:26
KOKKOS_INLINE_FUNCTION NDRegion< T, Dim > & operator+=(const T t)
Definition NDRegion.hpp:52
KOKKOS_INLINE_FUNCTION NDRegion< T, Dim > & operator/=(const T t)
Definition NDRegion.hpp:76
KOKKOS_INLINE_FUNCTION const PRegion< T > & operator[](unsigned d) const
Definition NDRegion.hpp:42