Block-Structured AMR Software Framework
 
Loading...
Searching...
No Matches
AMReX_Orientation.H
Go to the documentation of this file.
1
2#ifndef BL_ORIENTATION_H
3#define BL_ORIENTATION_H
4#include <AMReX_Config.H>
5
6#include <AMReX_BLassert.H>
7#include <AMReX_SPACE.H>
9
10#include <iosfwd>
11
12namespace amrex {
13
14enum class Direction : int { AMREX_D_DECL(x = 0, y = 1, z = 2) };
15
16class OrientationIter;
17
29{
30public:
31
32 friend class OrientationIter;
34 enum Side { low = 0, high = 1 };
36 constexpr Orientation () noexcept = default;
39 Orientation (int dir, Side side) noexcept
40 :
41 val(AMREX_SPACEDIM*side + dir)
42 {
43 BL_ASSERT(0 <= dir && dir < AMREX_SPACEDIM);
44 }
46 constexpr Orientation (Direction dir, Side side) noexcept
47 : val(AMREX_SPACEDIM*side + static_cast<int>(dir))
48 {}
49
52 bool operator== (const Orientation& o) const noexcept { return val == o.val; }
55 bool operator!= (const Orientation& o) const noexcept { return val != o.val; }
58 bool operator< (const Orientation& o) const noexcept { return val < o.val; }
61 bool operator<= (const Orientation& o) const noexcept { return val <= o.val; }
64 bool operator> (const Orientation& o) const noexcept { return val > o.val; }
67 bool operator>= (const Orientation& o) const noexcept { return val >= o.val; }
74 constexpr operator int () const noexcept { return val; }
76 [[nodiscard]] AMREX_GPU_HOST_DEVICE
77 Orientation flip () const noexcept
78 {
79 return Orientation(val < AMREX_SPACEDIM ? val+AMREX_SPACEDIM : val-AMREX_SPACEDIM);
80 }
82 [[nodiscard]] AMREX_GPU_HOST_DEVICE
83 int coordDir () const noexcept { return val%AMREX_SPACEDIM; }
85 [[nodiscard]] AMREX_GPU_HOST_DEVICE
86 Side faceDir () const noexcept { return Side(val/AMREX_SPACEDIM); }
88 [[nodiscard]] AMREX_GPU_HOST_DEVICE
89 bool isLow () const noexcept { return val < AMREX_SPACEDIM; }
91 [[nodiscard]] AMREX_GPU_HOST_DEVICE
92 bool isHigh () const noexcept { return val >= AMREX_SPACEDIM; }
94 friend std::istream& operator>> (std::istream& is, Orientation& o);
95
98 static constexpr int xlo () noexcept { return 0; }
99
102 static constexpr int xhi () noexcept { return AMREX_SPACEDIM; }
103
106 static constexpr int ylo () noexcept { return 1; }
107
110 static constexpr int yhi () noexcept { return 1+AMREX_SPACEDIM; }
111
114 static constexpr int zlo () noexcept { return 2; }
115
118 static constexpr int zhi () noexcept { return 2+AMREX_SPACEDIM; }
119
120private:
123 Orientation (int v) noexcept : val(v) {}
124 //
126 int val = -1;
127};
128
130std::ostream& operator<< (std::ostream& os, const Orientation& o);
131
132
135{
136
137public:
139 constexpr OrientationIter () noexcept = default;
142 OrientationIter (const Orientation& _face) noexcept
143 :
144 face(_face) {}
147 void rewind () noexcept { face = 0; }
150 Orientation operator() () const noexcept { BL_ASSERT(isValid()); return Orientation(face); }
153 operator void* () noexcept { return 0 <= face && face < 2*AMREX_SPACEDIM ? this : nullptr; }
155 [[nodiscard]] AMREX_GPU_HOST_DEVICE
156 bool isValid () const noexcept { return 0 <= face && face < 2*AMREX_SPACEDIM; }
159 OrientationIter& operator-- () noexcept { BL_ASSERT(isValid()); --face; return *this; }
162 OrientationIter& operator++ () noexcept { BL_ASSERT(isValid()); ++face; return *this; }
166 {
167 BL_ASSERT(isValid()); OrientationIter it(face); --face; return it;
168 }
172 {
173 BL_ASSERT(isValid()); OrientationIter it(face); ++face; return it;
174 }
177 bool operator== (const OrientationIter& oi) const noexcept
178 {
179 BL_ASSERT(isValid() && oi.isValid()); return face == oi.face;
180 }
183 bool operator!= (const OrientationIter& oi) const noexcept
184 {
185 BL_ASSERT(isValid() && oi.isValid()); return face != oi.face;
186 }
187
188private:
189
190 int face = 0;
193 OrientationIter (int _face) noexcept : face(_face) {}
194};
195
196}
197
198#endif /*BL_ORIENTATION_H*/
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
__host__ __device__ OrientationIter(int _face) noexcept
Construct an iterator on the face.
Definition AMReX_Orientation.H:193
int face
Definition AMReX_Orientation.H:190
__host__ __device__ bool isValid() const noexcept
Is the iterator valid?
Definition AMReX_Orientation.H:156
__host__ __device__ OrientationIter & operator++() noexcept
Pre-increment.
Definition AMReX_Orientation.H:162
__host__ __device__ Orientation operator()() const noexcept
Return the orientation of the face.
Definition AMReX_Orientation.H:150
__host__ __device__ bool operator==(const OrientationIter &oi) const noexcept
The equality operator.
Definition AMReX_Orientation.H:177
__host__ __device__ OrientationIter & operator--() noexcept
Pre-decrement.
Definition AMReX_Orientation.H:159
__host__ __device__ void rewind() noexcept
Reset (rewind) the iterator.
Definition AMReX_Orientation.H:147
__host__ __device__ bool operator!=(const OrientationIter &oi) const noexcept
The inequality operator.
Definition AMReX_Orientation.H:183
constexpr OrientationIter() noexcept=default
The default constructor.
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
__host__ __device__ bool operator==(const Orientation &o) const noexcept
Logical equality.
Definition AMReX_Orientation.H:52
__host__ static __device__ constexpr int zhi() noexcept
Int value of the z-hi-face.
Definition AMReX_Orientation.H:118
__host__ __device__ bool isHigh() const noexcept
Returns true if Orientation is high.
Definition AMReX_Orientation.H:92
__host__ __device__ bool operator!=(const Orientation &o) const noexcept
Logical inequality.
Definition AMReX_Orientation.H:55
__host__ static __device__ constexpr int zlo() noexcept
Int value of the z-lo-face.
Definition AMReX_Orientation.H:114
int val
The data.
Definition AMReX_Orientation.H:126
constexpr Orientation() noexcept=default
The default constructor.
__host__ __device__ bool isLow() const noexcept
Returns true if Orientation is low.
Definition AMReX_Orientation.H:89
__host__ __device__ int coordDir() const noexcept
Returns the coordinate direction.
Definition AMReX_Orientation.H:83
__host__ __device__ Side faceDir() const noexcept
Returns the orientation of the face – low or high.
Definition AMReX_Orientation.H:86
__host__ __device__ Orientation flip() const noexcept
Return opposite orientation.
Definition AMReX_Orientation.H:77
Side
In each dimension a face is either low or high.
Definition AMReX_Orientation.H:34
@ low
Definition AMReX_Orientation.H:34
@ high
Definition AMReX_Orientation.H:34
friend std::istream & operator>>(std::istream &is, Orientation &o)
Read from an istream.
Definition AMReX_Orientation.cpp:26
__host__ __device__ Orientation(int v) noexcept
Used internally.
Definition AMReX_Orientation.H:123
__host__ __device__ bool operator>(const Orientation &o) const noexcept
Greater-than.
Definition AMReX_Orientation.H:64
__host__ __device__ constexpr Orientation(Direction dir, Side side) noexcept
Definition AMReX_Orientation.H:46
__host__ static __device__ constexpr int xhi() noexcept
Int value of the x-hi-face.
Definition AMReX_Orientation.H:102
__host__ __device__ bool operator>=(const Orientation &o) const noexcept
Greater-than or equal.
Definition AMReX_Orientation.H:67
__host__ static __device__ constexpr int yhi() noexcept
Int value of the y-hi-face.
Definition AMReX_Orientation.H:110
__host__ __device__ bool operator<(const Orientation &o) const noexcept
Less-than.
Definition AMReX_Orientation.H:58
__host__ __device__ bool operator<=(const Orientation &o) const noexcept
Less-than or equal.
Definition AMReX_Orientation.H:61
__host__ static __device__ constexpr int xlo() noexcept
Int value of the x-lo-face.
Definition AMReX_Orientation.H:98
__host__ static __device__ constexpr int ylo() noexcept
Int value of the y-lo-face.
Definition AMReX_Orientation.H:106
Definition AMReX_Amr.cpp:49
Direction
Definition AMReX_Orientation.H:14
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition AMReX_AmrMesh.cpp:1236