Block-Structured AMR Software Framework
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>
8 #include <AMReX_GpuQualifiers.H>
9 
10 #include <iosfwd>
11 
12 namespace amrex {
13 
14 enum class Direction : int { AMREX_D_DECL(x = 0, y = 1, z = 2) };
15 
16 class OrientationIter;
17 
29 {
30 public:
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 
120 private:
123  Orientation (int v) noexcept : val(v) {}
124  //
126  int val = -1;
127 };
128 
130 std::ostream& operator<< (std::ostream& os, const Orientation& o);
131 
132 
135 {
136 
137 public:
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 
188 private:
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
An Iterator over the Orientation of Faces of a Box.
Definition: AMReX_Orientation.H:135
AMREX_GPU_HOST_DEVICE OrientationIter & operator++() noexcept
Pre-increment.
Definition: AMReX_Orientation.H:162
AMREX_GPU_HOST_DEVICE bool operator!=(const OrientationIter &oi) const noexcept
The inequality operator.
Definition: AMReX_Orientation.H:183
AMREX_GPU_HOST_DEVICE OrientationIter(int _face) noexcept
Construct an iterator on the face.
Definition: AMReX_Orientation.H:193
AMREX_GPU_HOST_DEVICE bool operator==(const OrientationIter &oi) const noexcept
The equality operator.
Definition: AMReX_Orientation.H:177
int face
Definition: AMReX_Orientation.H:190
AMREX_GPU_HOST_DEVICE void rewind() noexcept
Reset (rewind) the iterator.
Definition: AMReX_Orientation.H:147
AMREX_GPU_HOST_DEVICE OrientationIter & operator--() noexcept
Pre-decrement.
Definition: AMReX_Orientation.H:159
AMREX_GPU_HOST_DEVICE bool isValid() const noexcept
Is the iterator valid?
Definition: AMReX_Orientation.H:156
AMREX_GPU_HOST_DEVICE Orientation operator()() const noexcept
Return the orientation of the face.
Definition: AMReX_Orientation.H:150
constexpr OrientationIter() noexcept=default
The default constructor.
Encapsulation of the Orientation of the Faces of a Box.
Definition: AMReX_Orientation.H:29
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int zhi() noexcept
Int value of the z-hi-face.
Definition: AMReX_Orientation.H:118
AMREX_GPU_HOST_DEVICE bool operator==(const Orientation &o) const noexcept
Logical equality.
Definition: AMReX_Orientation.H:52
friend std::istream & operator>>(std::istream &is, Orientation &o)
Read from an istream.
Definition: AMReX_Orientation.cpp:26
AMREX_GPU_HOST_DEVICE bool operator!=(const Orientation &o) const noexcept
Logical inequality.
Definition: AMReX_Orientation.H:55
AMREX_GPU_HOST_DEVICE Orientation flip() const noexcept
Return opposite orientation.
Definition: AMReX_Orientation.H:77
constexpr AMREX_GPU_HOST_DEVICE Orientation(Direction dir, Side side) noexcept
Definition: AMReX_Orientation.H:46
int val
The data.
Definition: AMReX_Orientation.H:126
AMREX_GPU_HOST_DEVICE bool operator<(const Orientation &o) const noexcept
Less-than.
Definition: AMReX_Orientation.H:58
constexpr Orientation() noexcept=default
The default constructor.
AMREX_GPU_HOST_DEVICE bool operator>(const Orientation &o) const noexcept
Greater-than.
Definition: AMReX_Orientation.H:64
AMREX_GPU_HOST_DEVICE int coordDir() const noexcept
Returns the coordinate direction.
Definition: AMReX_Orientation.H:83
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int yhi() noexcept
Int value of the y-hi-face.
Definition: AMReX_Orientation.H:110
AMREX_GPU_HOST_DEVICE Orientation(int v) noexcept
Used internally.
Definition: AMReX_Orientation.H:123
AMREX_GPU_HOST_DEVICE bool isLow() const noexcept
Returns true if Orientation is low.
Definition: AMReX_Orientation.H:89
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int ylo() noexcept
Int value of the y-lo-face.
Definition: AMReX_Orientation.H:106
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xlo() noexcept
Int value of the x-lo-face.
Definition: AMReX_Orientation.H:98
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
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int xhi() noexcept
Int value of the x-hi-face.
Definition: AMReX_Orientation.H:102
AMREX_GPU_HOST_DEVICE Side faceDir() const noexcept
Returns the orientation of the face – low or high.
Definition: AMReX_Orientation.H:86
AMREX_GPU_HOST_DEVICE bool isHigh() const noexcept
Returns true if Orientation is high.
Definition: AMReX_Orientation.H:92
AMREX_GPU_HOST_DEVICE static constexpr AMREX_FORCE_INLINE int zlo() noexcept
Int value of the z-lo-face.
Definition: AMReX_Orientation.H:114
AMREX_GPU_HOST_DEVICE bool operator>=(const Orientation &o) const noexcept
Greater-than or equal.
Definition: AMReX_Orientation.H:67
AMREX_GPU_HOST_DEVICE bool operator<=(const Orientation &o) const noexcept
Less-than or equal.
Definition: AMReX_Orientation.H:61
Definition: AMReX_Amr.cpp:49
Direction
Definition: AMReX_Orientation.H:14
const int[]
Definition: AMReX_BLProfiler.cpp:1664
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Definition: AMReX_AmrMesh.cpp:1236