IPPL (Independent Parallel Particle Layer)
IPPL
Loading...
Searching...
No Matches
PRegion.hpp
Go to the documentation of this file.
1//
2// Class PRegion
3// PRegion represents a (possibly continuous) numeric interval. It is
4// similar to Index, with the following differences:
5// 1. It is templated on the data type; Index always uses integers
6// 2. A PRegion is defined between two endpoints A and B; the PRegion
7// includes values X where A <= X < B (i.e., X in [A,B) )
8// 3. PRegion does not keep track of a base Index, and does not
9// supply the plugBase operation. It is not designed for use in
10// Field operations like Index is, it is meant instead for use in
11// Particle construction and usage.
12//
13// PRegion<T>() --> make a PRegion on [0,1)
14// PRegion<T>(B) --> make a PRegion on [0,B)
15// PRegion<T>(A,B) --> make a PRegion on [A,B)
16//
17#include <algorithm>
18#include <iostream>
19
20#include "Utility/PAssert.h"
21
22namespace ippl {
23 template <typename T>
24 KOKKOS_FUNCTION PRegion<T>::PRegion()
25 : PRegion(0, 1) {}
26
27 template <typename T>
28 KOKKOS_FUNCTION PRegion<T>::PRegion(T b)
29 : PRegion(0, b) {}
30
31 template <typename T>
32 KOKKOS_FUNCTION PRegion<T>::PRegion(T a, T b)
33 : a_m(a)
34 , b_m(b) {
35 PAssert(a_m < b_m);
36 }
37
38 template <typename T>
39 KOKKOS_FUNCTION PRegion<T>::PRegion(const PRegion<T>& pregion) {
40 a_m = pregion.a_m;
41 b_m = pregion.b_m;
42 }
43
44 template <typename T>
45 KOKKOS_INLINE_FUNCTION PRegion<T>& PRegion<T>::operator=(const PRegion<T>& pregion) {
46 a_m = pregion.a_m;
47 b_m = pregion.b_m;
48 return *this;
49 }
50
51 template <typename T>
52 KOKKOS_INLINE_FUNCTION T PRegion<T>::min() const noexcept {
53 return a_m;
54 }
55
56 template <typename T>
57 KOKKOS_INLINE_FUNCTION T PRegion<T>::max() const noexcept {
58 return b_m;
59 }
60
61 template <typename T>
62 KOKKOS_INLINE_FUNCTION T PRegion<T>::length() const noexcept {
63 return b_m - a_m;
64 }
65
66 template <typename T>
67 KOKKOS_INLINE_FUNCTION bool PRegion<T>::empty() const noexcept {
68 return (a_m == b_m);
69 }
70
71 template <typename T>
72 KOKKOS_INLINE_FUNCTION PRegion<T>& PRegion<T>::operator+=(T t) noexcept {
73 a_m += t;
74 b_m += t;
75 return *this;
76 }
77
78 template <typename T>
79 KOKKOS_INLINE_FUNCTION PRegion<T>& PRegion<T>::operator-=(T t) noexcept {
80 a_m -= t;
81 b_m -= t;
82 return *this;
83 }
84
85 template <typename T>
86 KOKKOS_INLINE_FUNCTION PRegion<T>& PRegion<T>::operator*=(T t) noexcept {
87 a_m *= t;
88 b_m *= t;
89 return *this;
90 }
91
92 template <typename T>
93 KOKKOS_INLINE_FUNCTION PRegion<T>& PRegion<T>::operator/=(T t) noexcept {
94 if (t != 0) {
95 a_m /= t;
96 b_m /= t;
97 }
98 return *this;
99 }
100
101 template <typename T>
102 inline std::ostream& operator<<(std::ostream& out, const PRegion<T>& r) {
103 out << '[' << r.min();
104 out << ',' << r.max();
105 out << ')';
106 return out;
107 }
108} // namespace ippl
#define PAssert(c)
Definition PAssert.h:116
Definition Archive.h:20
std::ostream & operator<<(std::ostream &os, const BConds< Field, Dim > &bc)
Definition BConds.h:49
KOKKOS_INLINE_FUNCTION PRegion< T > & operator/=(T t) noexcept
Definition PRegion.hpp:93
KOKKOS_INLINE_FUNCTION T max() const noexcept
Definition PRegion.hpp:57
KOKKOS_INLINE_FUNCTION PRegion< T > & operator-=(T t) noexcept
Definition PRegion.hpp:79
KOKKOS_INLINE_FUNCTION PRegion< T > & operator*=(T t) noexcept
Definition PRegion.hpp:86
KOKKOS_INLINE_FUNCTION T min() const noexcept
Definition PRegion.hpp:52
T b_m
Interval end point.
Definition PRegion.h:87
KOKKOS_FUNCTION PRegion()
Definition PRegion.hpp:24
KOKKOS_INLINE_FUNCTION PRegion< T > & operator=(const PRegion< T > &rhs)
Definition PRegion.hpp:45
T a_m
Interval start point.
Definition PRegion.h:84
KOKKOS_INLINE_FUNCTION bool empty() const noexcept
Definition PRegion.hpp:67
KOKKOS_INLINE_FUNCTION T length() const noexcept
Definition PRegion.hpp:62
KOKKOS_INLINE_FUNCTION PRegion< T > & operator+=(T t) noexcept
Definition PRegion.hpp:72