Chombo + EB  3.2
BoundaryIterator.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 _BOUNDARYITERATOR_H_
12 #define _BOUNDARYITERATOR_H_
13 
14 #include <cstdlib>
15 
16 #include "Box.H"
17 #include "REAL.H"
18 #include "SPACE.H"
19 #include "IntVect.H"
20 #include "BoxIterator.H"
21 #include "NamespaceHeader.H"
22 
23 ///iterates through the IntVects on the surface of a Box
24 /**
25  BoundaryIterator iterates through the IntVects on the surface of a box. The actual
26  sqeuence of IntVects is implementation-specific.
27  Typical usage:
28 
29  Box b;
30  ...
31  BoundaryIterator bit (b);
32  for (bit.begin(); bit.ok(); ++bit)
33  {
34  IntVect iv = bit();
35  (do operations involving iv)
36  }
37 */
39 {
40 public:
41  ///
42  /**
43  Default constructor. This constructs an invalid iterator.
44  The user must call define before using.
45  */
47 
48  ///
49  /**
50  Constructs a BoundaryIterator and associates it with a Box.
51  Arguments:
52  a_bx (not modified) the Box to iterate over.
53  */
54  BoundaryIterator(const Box& a_bx);
55 
56  void setBox(const Box& a_bx);
57 
58  ///
59  /**
60  Associates a Box with this BoundaryIterator.
61  Arguments:
62  a_bx (not modified) the Box to iterate over.
63  */
64  void define(const Box& a_bx);
65 
66 
67  ///
69  {
70  }
71 
72  ///
73  /**
74  Sets this BoundaryIterator to the first IntVect in its Box. The
75  definition of the "first" IntVect is
76  implementation-dependent.
77  */
78  void begin();
79 
80  ///
81  /**
82  Sets this BoundaryIterator to the first IntVect in its Box. The
83  definition of the "first" IntVect is
84  implementation-dependent.
85  */
86  void reset();
87 
88  ///
89  /**
90  Modifies this BoundaryIterator to set it to the next location in its
91  Box. The definition of the "next location" of a Box is
92  implementation-dependent.
93  */
94  void operator ++ ();
95 
96  void next();
97 
98  ///
99  /**
100  Returns the value of the InVect for the current location of this
101  BoundaryIterator.
102  */
103  const IntVect& operator () () const;
104 
105  ///
106  /**
107  Returns true if this BoundaryIterator's location is within its Box.
108  */
109  bool ok() const;
110 
111  ///
112  /**
113  Can request the current boundary box that this iterator is working on
114  */
115  const Box& box() const;
116 
117  ///
118  /** skip to the next boundary box in this iterator
119  */
120  void nextBox();
121 
122 protected:
125  int m_sdir;
126 };
127 
128 inline
130 {
132 }
133 
134 inline
136 {
137  define(a_bx);
138 }
139 
140 inline
142 {
143  CH_assert(ok());
144  return m_box[m_sdir];
145 }
146 
147 inline
149 {
150  m_sdir++;
151  if(ok())
153 }
154 
155 inline
157 {
158  m_sdir=0;
159  m_current.define(m_box[0]);
160 }
161 
162 inline
164 {
165  begin();
166 }
167 
168 inline
170 {
171  next();
172 }
173 
174 inline
176 {
177  m_current.next();
178  if(!m_current.ok())
179  {
180  m_sdir++;
181  if(m_sdir > 2*CH_SPACEDIM) return;
182  else
183  {
185  m_current.begin();
186  }
187  }
188 }
189 
190 inline
192 {
193 
194  return m_current();
195 }
196 
197 inline
199 {
200  return m_sdir<2*CH_SPACEDIM;
201 }
202 
203 #include "NamespaceFooter.H"
204 #endif
bool ok()
Definition: BoxIterator.H:281
void define(const Box &a_bx)
#define CH_SPACEDIM
Definition: SPACE.H:51
#define CH_assert(cond)
Definition: CHArray.H:37
const IntVect & operator()() const
Definition: BoundaryIterator.H:191
void begin()
Definition: BoundaryIterator.H:156
void define(const Box &a_bx)
void reset()
Definition: BoundaryIterator.H:163
iterates through the IntVects of a Box
Definition: BoxIterator.H:37
iterates through the IntVects on the surface of a Box
Definition: BoundaryIterator.H:38
~BoundaryIterator()
Definition: BoundaryIterator.H:68
void nextBox()
Definition: BoundaryIterator.H:148
BoundaryIterator()
Definition: BoundaryIterator.H:129
Box m_box[CH_SPACEDIM *2]
Definition: BoundaryIterator.H:124
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
const Box & box() const
Definition: BoundaryIterator.H:141
void begin()
Definition: BoxIterator.H:150
void operator++()
Definition: BoundaryIterator.H:169
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
void next()
Definition: BoundaryIterator.H:175
void next()
Definition: BoxIterator.H:168
bool ok() const
Definition: BoundaryIterator.H:198
void setBox(const Box &a_bx)
int m_sdir
Definition: BoundaryIterator.H:125
BoxIterator m_current
Definition: BoundaryIterator.H:123