Chombo + EB + MF  3.2
BoxIterator.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _BOXITERATOR_H_
12 #define _BOXITERATOR_H_
13 
14 #include <cstdlib>
15 
16 #include "Box.H"
17 #include "REAL.H"
18 #include "SPACE.H"
19 #include "IntVect.H"
20 #include "NamespaceHeader.H"
21 
22 ///iterates through the IntVects of a Box
23 /**
24  BoxIterator iterates through the IntVects of a box. The actual
25  sqeuence of IntVects is implementation-specific.
26  Typical usage:
27 
28  Box b;
29  ...
30  BoxIterator bit (b);
31  for (bit.begin(); bit.ok(); ++bit)
32  {
33  IntVect iv = bit();
34  (do operations involving iv)
35  }
36 */
38 {
39 public:
40  ///
41  /**
42  Default constructor. This constructs an invalid iterator.
43  The user must call define before using.
44  */
45  BoxIterator();
46 
47  ///
48  /**
49  Constructs a BoxIterator and associates it with a Box.
50  Arguments:
51  a_bx (not modified) the Box to iterate over.
52  */
53  BoxIterator(const Box& a_bx);
54 
55  void setBox(const Box& a_bx);
56 
57  ///
58  /**
59  Associates a Box with this BoxIterator.
60  Arguments:
61  a_bx (not modified) the Box to iterate over.
62  */
63  void define(const Box& a_bx);
64 
65  ///
66  /**
67  Copy constructor.
68  Arguments:
69  a_iterIn (not modified) the BoxIterator to copy.
70  */
71  BoxIterator(const BoxIterator& a_iterIn);
72 
73  ///
75  {
76  }
77 
78  ///
79  /**
80  Sets this BoxIterator to the first IntVect in its Box. The
81  definition of the "first" IntVect is
82  implementation-dependent.
83  */
84  void begin();
85 
86  ///
87  /**
88  Sets this BoxIterator to the first IntVect in its Box. The
89  definition of the "first" IntVect is
90  implementation-dependent.
91  */
92  void reset();
93 
94  ///
95  /**
96  Modifies this BoxIterator to set it to the next location in its
97  Box. The definition of the "next location" of a Box is
98  implementation-dependent.
99  */
100  void operator ++ ();
101 
102  void next();
103 
104  ///
105  /**
106  Returns the value of the InVect for the current location of this
107  BoxIterator.
108  */
109  const IntVect& operator () () const;
110 
111  ///
112  /**
113  Returns true if this BoxIterator's location is within its Box.
114  */
115  bool ok();
116 
117  unsigned long long size() const;
118 
119  IntVect at(unsigned long long pt) const;
120 
121 protected:
125 };
126 
127 inline
129 {
133 }
134 
135 inline
137 {
138  define(a_bx);
139 }
140 
141 inline
143 {
144  m_current = a_iterIn.m_current;
145  m_boxLo = a_iterIn.m_boxLo;
146  m_boxHi = a_iterIn.m_boxHi;
147 }
148 
149 inline
151 {
152  if (m_boxLo <= m_boxHi) m_current = m_boxLo;
153 }
154 
155 inline
157 {
158  begin();
159 }
160 
161 inline
163 {
164  next();
165 }
166 
167 inline
169 {
170  m_current[0]++;
171 #if CH_SPACEDIM >= 2
172  if (m_current[0] > m_boxHi[0])
173  {
174  m_current[0] = m_boxLo[0];
175  m_current[1]++;
176 #if CH_SPACEDIM >= 3
177  if (m_current[1] > m_boxHi[1])
178  {
179  m_current[1] = m_boxLo[1];
180  m_current[2]++;
181 #if CH_SPACEDIM >= 4
182  if (m_current[2] > m_boxHi[2])
183  {
184  m_current[2] = m_boxLo[2];
185  m_current[3]++;
186 #if CH_SPACEDIM >= 5
187  if (m_current[3] > m_boxHi[3])
188  {
189  m_current[3] = m_boxLo[3];
190  m_current[4]++;
191 #if CH_SPACEDIM == 6
192  if (m_current[4] > m_boxHi[4])
193  {
194  m_current[4] = m_boxLo[4];
195  m_current[5]++;
196  }
197 #elif CH_SPACEDIM > 6
198  SPACEDIM > 6 undefined!;
199 #endif
200  }
201 #endif
202  }
203 #endif
204  }
205 #endif
206  }
207 #endif
208 }
209 
210 inline
211 unsigned long long BoxIterator::size() const
212 {
213  unsigned long long rtn = (m_boxHi[0]-m_boxLo[0]+1);
214 #if CH_SPACEDIM >= 2
215  rtn *= (m_boxHi[1]-m_boxLo[1]+1);
216 #if CH_SPACEDIM >= 3
217  rtn *= (m_boxHi[2]-m_boxLo[2]+1);
218 #if CH_SPACEDIM >= 4
219  rtn *= (m_boxHi[3]-m_boxLo[3]+1);
220 #if CH_SPACEDIM >= 5
221  rtn *= (m_boxHi[4]-m_boxLo[4]+1);
222 #if CH_SPACEDIM == 6
223  rtn *= (m_boxHi[5]-m_boxLo[5]+1);
224 #elif CH_SPACEDIM > 6
225  SPACEDIM > 6 undefined!;
226 #endif
227 
228 #endif
229 
230 #endif
231 
232 #endif
233 
234 #endif
235  return rtn;
236 }
237 
238 inline
239 IntVect BoxIterator::at(unsigned long long int pt) const
240 {
241  IntVect rtn;
242  rtn[0]=m_boxLo[0]+ pt%(m_boxHi[0]-m_boxLo[0]+1);
243 #if CH_SPACEDIM >= 2
244  pt/=(m_boxHi[0]-m_boxLo[0]+1);
245  rtn[1]=m_boxLo[1]+ pt%(m_boxHi[1]-m_boxLo[1]+1);
246 #if CH_SPACEDIM >= 3
247  pt/=(m_boxHi[1]-m_boxLo[1]+1);
248  rtn[2]=m_boxLo[2]+ pt%(m_boxHi[2]-m_boxLo[2]+1);
249 #if CH_SPACEDIM >= 4
250  pt/=(m_boxHi[2]-m_boxLo[2]+1);
251  rtn[3]=m_boxLo[3]+ pt%(m_boxHi[3]-m_boxLo[3]+1);
252 #if CH_SPACEDIM >= 5
253  pt/=(m_boxHi[3]-m_boxLo[3]+1);
254  rtn[4]=m_boxLo[4]+ pt%(m_boxHi[4]-m_boxLo[4]+1);
255 #if CH_SPACEDIM == 6
256  pt/=(m_boxHi[4]-m_boxLo[4]+1);
257  rtn[5]=m_boxLo[5]+ pt%(m_boxHi[5]-m_boxLo[5]+1);
258 #elif CH_SPACEDIM > 6
259  SPACEDIM > 6 undefined!;
260 #endif
261 
262 #endif
263 
264 #endif
265 
266 #endif
267 
268 #endif
269  return rtn;
270 }
271 
272 inline
274 {
277  return m_current;
278 }
279 
280 inline
282 {
283  return (m_current <= m_boxHi);
284 }
285 
286 #include "NamespaceFooter.H"
287 #endif
IntVect m_boxLo
Definition: BoxIterator.H:123
bool ok()
Definition: BoxIterator.H:281
void define(const Box &a_bx)
void reset()
Definition: BoxIterator.H:156
#define CH_assert(cond)
Definition: CHArray.H:37
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
IntVect at(unsigned long long pt) const
Definition: BoxIterator.H:239
~BoxIterator()
Definition: BoxIterator.H:74
const IntVect & operator()() const
Definition: BoxIterator.H:273
static const IntVect Unit
Definition: IntVect.H:663
IntVect m_current
Definition: BoxIterator.H:122
unsigned long long size() const
Definition: BoxIterator.H:211
static const IntVect Zero
Definition: IntVect.H:658
void operator++()
Definition: BoxIterator.H:162
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
void begin()
Definition: BoxIterator.H:150
void setBox(const Box &a_bx)
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void next()
Definition: BoxIterator.H:168
IntVect m_boxHi
Definition: BoxIterator.H:124
BoxIterator()
Definition: BoxIterator.H:128