00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _BOUNDARYITERATOR_H_ 00012 #define _BOUNDARYITERATOR_H_ 00013 00014 #include <cstdlib> 00015 00016 #include "Box.H" 00017 #include "REAL.H" 00018 #include "SPACE.H" 00019 #include "IntVect.H" 00020 #include "BoxIterator.H" 00021 #include "NamespaceHeader.H" 00022 00023 ///iterates through the IntVects on the surface of a Box 00024 /** 00025 BoundaryIterator iterates through the IntVects on the surface of a box. The actual 00026 sqeuence of IntVects is implementation-specific. 00027 Typical usage: 00028 00029 Box b; 00030 ... 00031 BoundaryIterator bit (b); 00032 for (bit.begin(); bit.ok(); ++bit) 00033 { 00034 IntVect iv = bit(); 00035 (do operations involving iv) 00036 } 00037 */ 00038 class BoundaryIterator 00039 { 00040 public: 00041 /// 00042 /** 00043 Default constructor. This constructs an invalid iterator. 00044 The user must call define before using. 00045 */ 00046 BoundaryIterator(); 00047 00048 /// 00049 /** 00050 Constructs a BoundaryIterator and associates it with a Box. 00051 Arguments: 00052 a_bx (not modified) the Box to iterate over. 00053 */ 00054 BoundaryIterator(const Box& a_bx); 00055 00056 void setBox(const Box& a_bx); 00057 00058 /// 00059 /** 00060 Associates a Box with this BoundaryIterator. 00061 Arguments: 00062 a_bx (not modified) the Box to iterate over. 00063 */ 00064 void define(const Box& a_bx); 00065 00066 00067 /// 00068 ~BoundaryIterator () 00069 { 00070 } 00071 00072 /// 00073 /** 00074 Sets this BoundaryIterator to the first IntVect in its Box. The 00075 definition of the "first" IntVect is 00076 implementation-dependent. 00077 */ 00078 void begin(); 00079 00080 /// 00081 /** 00082 Sets this BoundaryIterator to the first IntVect in its Box. The 00083 definition of the "first" IntVect is 00084 implementation-dependent. 00085 */ 00086 void reset(); 00087 00088 /// 00089 /** 00090 Modifies this BoundaryIterator to set it to the next location in its 00091 Box. The definition of the "next location" of a Box is 00092 implementation-dependent. 00093 */ 00094 void operator ++ (); 00095 00096 void next(); 00097 00098 /// 00099 /** 00100 Returns the value of the InVect for the current location of this 00101 BoundaryIterator. 00102 */ 00103 const IntVect& operator () () const; 00104 00105 /// 00106 /** 00107 Returns true if this BoundaryIterator's location is within its Box. 00108 */ 00109 bool ok() const; 00110 00111 /// 00112 /** 00113 Can request the current boundary box that this iterator is working on 00114 */ 00115 const Box& box() const; 00116 00117 /// 00118 /** skip to the next boundary box in this iterator 00119 */ 00120 void nextBox(); 00121 00122 protected: 00123 BoxIterator m_current; 00124 Box m_box[CH_SPACEDIM*2]; 00125 int m_sdir; 00126 }; 00127 00128 inline 00129 BoundaryIterator::BoundaryIterator() 00130 { 00131 m_sdir=2*CH_SPACEDIM; 00132 } 00133 00134 inline 00135 BoundaryIterator::BoundaryIterator(const Box& a_bx) 00136 { 00137 define(a_bx); 00138 } 00139 00140 inline 00141 const Box& BoundaryIterator::box() const 00142 { 00143 CH_assert(ok()); 00144 return m_box[m_sdir]; 00145 } 00146 00147 inline 00148 void BoundaryIterator::nextBox() 00149 { 00150 m_sdir++; 00151 if(ok()) 00152 m_current.define(m_box[m_sdir]); 00153 } 00154 00155 inline 00156 void BoundaryIterator::begin() 00157 { 00158 m_sdir=0; 00159 m_current.define(m_box[0]); 00160 } 00161 00162 inline 00163 void BoundaryIterator::reset() 00164 { 00165 begin(); 00166 } 00167 00168 inline 00169 void BoundaryIterator::operator ++ () 00170 { 00171 next(); 00172 } 00173 00174 inline 00175 void BoundaryIterator::next() 00176 { 00177 m_current.next(); 00178 if(!m_current.ok()) 00179 { 00180 m_sdir++; 00181 if(m_sdir > 2*CH_SPACEDIM) return; 00182 else 00183 { 00184 m_current.define(m_box[m_sdir]); 00185 m_current.begin(); 00186 } 00187 } 00188 } 00189 00190 inline 00191 const IntVect& BoundaryIterator::operator () () const 00192 { 00193 00194 return m_current(); 00195 } 00196 00197 inline 00198 bool BoundaryIterator::ok() const 00199 { 00200 return m_sdir<2*CH_SPACEDIM; 00201 } 00202 00203 #include "NamespaceFooter.H" 00204 #endif