Block-Structured AMR Software Framework
AMReX_BoxIterator.H
Go to the documentation of this file.
1 #ifndef AMREX_BOXITERATOR_H_
2 #define AMREX_BOXITERATOR_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_BLassert.H>
6 #include <AMReX_Box.H>
7 #include <AMReX_REAL.H>
8 #include <AMReX_SPACE.H>
9 #include <AMReX_IntVect.H>
10 
11 #include <cstdlib>
12 
13 namespace amrex
14 {
33  {
34  public:
36 
40  BoxIterator () noexcept = default;
41 
43 
48  explicit BoxIterator (const Box& a_bx) noexcept;
49 
50  void setBox (const Box& a_bx) noexcept;
51 
53 
58  void define (const Box& a_bx) noexcept;
59 
61 
66  void begin () noexcept;
67 
69 
74  void reset () noexcept;
75 
77 
82  void operator ++ () noexcept;
83 
84  void next () noexcept;
85 
87 
91  [[nodiscard]] const IntVect& operator () () const noexcept;
92 
94 
97  [[nodiscard]] bool ok () noexcept;
98 
99  protected:
100  IntVect m_current = IntVect::TheUnitVector();
101  IntVect m_boxLo = IntVect::TheUnitVector();
102  IntVect m_boxHi = IntVect::TheZeroVector();
103  };
104 
105  inline
106  BoxIterator::BoxIterator (const Box& a_bx) noexcept
107  {
108  define(a_bx);
109  }
110 
111  inline
112  void BoxIterator::begin () noexcept
113  {
114  if (m_boxLo <= m_boxHi) { m_current = m_boxLo; }
115  }
116 
117  inline
118  void BoxIterator::reset () noexcept
119  {
120  begin();
121  }
122 
123  inline
125  {
126  next();
127  }
128 
129  inline
130  void BoxIterator::next () noexcept
131  {
132  m_current[0]++;
133 #if AMREX_SPACEDIM >= 2
134  if (m_current[0] > m_boxHi[0])
135  {
136  m_current[0] = m_boxLo[0];
137  m_current[1]++;
138 #if AMREX_SPACEDIM >= 3
139  if (m_current[1] > m_boxHi[1])
140  {
141  m_current[1] = m_boxLo[1];
142  m_current[2]++;
143  }
144 #endif
145  }
146 #endif
147  }
148 
149  inline
150  const IntVect& BoxIterator::operator () () const noexcept
151  {
154  return m_current;
155  }
156 
157  inline
158  bool BoxIterator::ok () noexcept
159  {
160  return (m_current <= m_boxHi);
161  }
162 }
163 #endif
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
iterates through the IntVects of a Box
Definition: AMReX_BoxIterator.H:33
void operator++() noexcept
Definition: AMReX_BoxIterator.H:124
void setBox(const Box &a_bx) noexcept
Definition: AMReX_BoxIterator.cpp:21
IntVect m_boxHi
Definition: AMReX_BoxIterator.H:102
const IntVect & operator()() const noexcept
Definition: AMReX_BoxIterator.H:150
void define(const Box &a_bx) noexcept
Definition: AMReX_BoxIterator.cpp:5
BoxIterator() noexcept=default
void next() noexcept
Definition: AMReX_BoxIterator.H:130
void reset() noexcept
Definition: AMReX_BoxIterator.H:118
IntVect m_current
Definition: AMReX_BoxIterator.H:100
bool ok() noexcept
Definition: AMReX_BoxIterator.H:158
IntVect m_boxLo
Definition: AMReX_BoxIterator.H:101
void begin() noexcept
Definition: AMReX_BoxIterator.H:112
Definition: AMReX_Amr.cpp:49