00001 /* _______ __ 00002 / ___/ / ___ __ _ / / ___ 00003 / /__/ _ \/ _ \/ ' \/ _ \/ _ \ 00004 \___/_//_/\___/_/_/_/_.__/\___/ 00005 */ 00006 // 00007 // This software is copyright (C) by the Lawrence Berkeley 00008 // National Laboratory. Permission is granted to reproduce 00009 // this software for non-commercial purposes provided that 00010 // this notice is left intact. 00011 // 00012 // It is acknowledged that the U.S. Government has rights to 00013 // this software under Contract DE-AC03-765F00098 between 00014 // the U.S. Department of Energy and the University of 00015 // California. 00016 // 00017 // This software is provided as a professional and academic 00018 // contribution for joint exchange. Thus it is experimental, 00019 // is provided ``as is'', with no warranties of any kind 00020 // whatsoever, no support, no promise of updates, or printed 00021 // documentation. By using this software, you acknowledge 00022 // that the Lawrence Berkeley National Laboratory and 00023 // Regents of the University of California shall have no 00024 // liability with respect to the infringement of other 00025 // copyrights by any part of this software. 00026 // 00027 00028 #ifndef DENSEINTVECTSET_H 00029 #define DENSEINTVECTSET_H 00030 00031 #include "BitSet.H" 00032 #include "IntVect.H" 00033 #include "Box.H" 00034 #include "Vector.H" 00035 #include "ProblemDomain.H" 00036 00037 class ProblemDomain; 00038 class DenseIntVectSetIterator; 00040 00044 class DenseIntVectSet 00045 { 00046 public: 00048 DenseIntVectSet(){;} 00049 00051 00052 DenseIntVectSet(const Box& a_domain, bool init = true); 00053 // copy, and operator= should be fine 00054 00056 00059 DenseIntVectSet& operator-=(const Box& box); 00060 00062 00065 DenseIntVectSet& operator-=(const IntVect& intvect); 00066 00068 00071 DenseIntVectSet& operator-=(const DenseIntVectSet& ivs); 00072 00074 00077 DenseIntVectSet& operator&=(const Box& box); 00078 00080 00083 DenseIntVectSet& operator&=(const ProblemDomain& domain); 00084 00086 00091 DenseIntVectSet& operator|=(const IntVect& intvect); 00092 00094 00099 DenseIntVectSet& operator|=(const Box& b); 00100 00102 00107 DenseIntVectSet& operator|=(const DenseIntVectSet& b); 00108 00110 00113 DenseIntVectSet& operator&=(const DenseIntVectSet& ivs); 00114 00116 00119 void shift(const IntVect& iv); 00120 00121 // 00122 /* slower, constant time pointwise access. 00123 You should not build a BoxIterator, then access this 00124 method if you intend to iterate over the objects true 00125 or false terms. you should build a DenseIntVectSetIterator */ 00126 bool operator[](const IntVect& index) const; 00127 00129 00131 bool contains(const Box& box) const; 00132 00134 00137 void coarsen(int iref); 00138 00140 00143 void refine(int iref); 00144 00146 00149 void grow(int igrow); 00150 00152 00155 void grow(int idir, int igrow); 00156 00158 00163 DenseIntVectSet chop(int dir, int chop_pnt); 00164 00165 inline const Box& box() const; 00166 00168 00170 void nestingRegion(int a_radius, const Box& a_domain); 00171 00173 00175 void nestingRegion(int a_radius, const ProblemDomain& a_domain); 00176 00178 00181 bool isEmpty() const; //cheaper than numPts by wide margin 00182 00184 00187 bool isFull() const; // cheaper than numPts, bu significant margin 00188 00190 00193 int numPts() const; 00194 00196 00199 Vector<Box> createBoxes() const; 00201 00205 void compact() const ; 00206 00207 void recalcMinBox() const; 00208 00209 const Box& mBox() const {return m_minBox;} 00210 00211 private: 00212 00213 void grow(const IntVect& iv); 00214 // version without checking intersect or empty 00215 DenseIntVectSet& intersect(const DenseIntVectSet& rhs); 00216 Box m_domain; 00217 BitSet m_bits; 00218 friend class DenseIntVectSetIterator; 00219 Box m_minBox; 00220 }; 00221 00223 00225 class DenseIntVectSetIterator 00226 { 00227 public: 00228 00230 DenseIntVectSetIterator(); 00231 00233 DenseIntVectSetIterator(const DenseIntVectSet& ivs); 00234 00236 void define(const DenseIntVectSet& ivs); 00237 //default null, assignment, copy and destructor should work fine. 00238 00240 const IntVect& operator()() const ; 00241 00243 bool ok() const; 00244 00246 void operator++(); 00247 00249 void begin(); 00250 00252 void end(); 00253 00254 static DenseIntVectSet emptyDenseIntVectSet; 00255 00256 private: 00257 BitSetIterator m_iterator; 00258 IntVect m_current; 00259 const DenseIntVectSet* m_ivsPtr; 00260 int isize, ijsize, bigi, bigj; 00261 00262 void nextIntVect(); 00263 void nextIntVect(int skip); 00264 00265 }; 00266 00267 //=================================================================== 00268 00269 // inline functions 00270 00271 00272 inline 00273 const Box& DenseIntVectSet::box() const { return m_domain;} 00274 00275 00276 00277 inline 00278 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect) 00279 { 00280 if(m_domain.contains(intvect)) 00281 m_bits.setFalse(m_domain.index(intvect)); 00282 return *this; 00283 } 00284 00285 inline void DenseIntVectSet::shift(const IntVect& iv) 00286 { 00287 m_domain.shift(iv); 00288 m_minBox.shift(iv); 00289 } 00290 00291 inline 00292 DenseIntVectSetIterator::DenseIntVectSetIterator() 00293 : m_ivsPtr(&emptyDenseIntVectSet) 00294 { 00295 ; 00296 } 00297 00298 inline 00299 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs) 00300 { 00301 m_ivsPtr = &ivs; 00302 begin(); 00303 } 00304 00305 inline 00306 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs) 00307 : m_ivsPtr(&ivs) 00308 { 00309 begin(); 00310 } 00311 00312 inline 00313 const IntVect& DenseIntVectSetIterator::operator()() const 00314 { 00315 return m_current; 00316 } 00317 00318 inline 00319 bool DenseIntVectSetIterator::ok() const 00320 { 00321 return m_iterator.ok(); 00322 } 00323 00324 00325 inline 00326 void DenseIntVectSetIterator::end() 00327 { 00328 m_iterator.end(); 00329 } 00330 00331 // inline 00332 // void DenseIntVectSetIterator::operator++() 00333 // { 00334 // ++m_iterator; 00335 // nextIntVect(); 00336 // while(!m_iterator() && m_iterator.ok()) 00337 // { 00338 // ++m_iterator; // next bit please 00339 // nextIntVect(); 00340 // } 00341 // } 00342 inline 00343 void DenseIntVectSetIterator::operator++() 00344 { 00345 ++m_iterator; 00346 int i=1; 00347 while(m_iterator.ok() && !m_iterator()) 00348 { 00349 ++m_iterator; // next bit please 00350 ++i; 00351 } 00352 nextIntVect(i); 00353 } 00354 00355 #endif