00001 /* _______ __ 00002 / ___/ / ___ __ _ / / ___ 00003 / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00004 \___/_//_/\___/_/_/_/_.__/\___/ 00005 */ 00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of 00007 // California, through Lawrence Berkeley National Laboratory (subject to 00008 // receipt of any required approvals from U.S. Dept. of Energy). All 00009 // rights reserved. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are met: 00013 // 00014 // (1) Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // (2) Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S. 00020 // Dept. of Energy nor the names of its contributors may be used to endorse 00021 // or promote products derived from this software without specific prior 00022 // written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 // You are under no obligation whatsoever to provide any bug fixes, 00037 // patches, or upgrades to the features, functionality or performance of 00038 // the source code ("Enhancements") to anyone; however, if you choose to 00039 // make your Enhancements available either publicly, or directly to 00040 // Lawrence Berkeley National Laboratory, without imposing a separate 00041 // written license agreement for such Enhancements, then you hereby grant 00042 // the following license: a non-exclusive, royalty-free perpetual license 00043 // to install, use, modify, prepare derivative works, incorporate into 00044 // other computer software, distribute, and sublicense such Enhancements or 00045 // derivative works thereof, in binary and source code form. 00046 // 00047 // TRADEMARKS. Product and company names mentioned herein may be the 00048 // trademarks of their respective owners. Any rights not expressly granted 00049 // herein are reserved. 00050 // 00051 00052 #ifndef _DENSEINTVECTSET_H_ 00053 #define _DENSEINTVECTSET_H_ 00054 00055 #include "BitSet.H" 00056 #include "IntVect.H" 00057 #include "Box.H" 00058 #include "Vector.H" 00059 #include "ProblemDomain.H" 00060 00061 class ProblemDomain; 00062 class DenseIntVectSetIterator; 00064 00078 class DenseIntVectSet 00079 { 00080 public: 00082 DenseIntVectSet() 00083 {} 00084 00086 00087 DenseIntVectSet(const Box& a_domain, bool init = true); 00088 // copy, and operator= should be fine 00089 00091 00094 DenseIntVectSet& operator-=(const Box& box); 00095 00097 00100 DenseIntVectSet& operator-=(const IntVect& intvect); 00101 00103 00106 DenseIntVectSet& operator-=(const DenseIntVectSet& ivs); 00107 00109 00112 DenseIntVectSet& operator&=(const Box& box); 00113 00115 00118 DenseIntVectSet& operator&=(const ProblemDomain& domain); 00119 00121 00126 DenseIntVectSet& operator|=(const IntVect& intvect); 00127 00129 00134 DenseIntVectSet& operator|=(const Box& b); 00135 00137 00142 DenseIntVectSet& operator|=(const DenseIntVectSet& b); 00143 00145 00148 DenseIntVectSet& operator&=(const DenseIntVectSet& ivs); 00149 00151 00154 void shift(const IntVect& iv); 00155 00157 /* slower, constant time pointwise access. 00158 You should not build a BoxIterator, then access this 00159 method if you intend to iterate over the objects true 00160 or false terms. you should build a DenseIntVectSetIterator */ 00161 bool operator[](const IntVect& index) const; 00162 00164 00166 bool contains(const Box& box) const; 00167 00169 00172 void coarsen(int iref); 00173 00175 00178 void refine(int iref); 00179 00181 00184 void grow(int igrow); 00185 00187 00190 void grow(int idir, int igrow); 00191 00193 00198 DenseIntVectSet chop(int dir, int chop_pnt); 00199 00200 inline const Box& box() const; 00201 00203 00205 void nestingRegion(int a_radius, const Box& a_domain); 00206 00208 00209 void nestingRegion(int a_radius, const ProblemDomain& a_domain); 00210 00212 00215 bool isEmpty() const; //cheaper than numPts by wide margin 00216 00218 00221 bool isFull() const; // cheaper than numPts, bu significant margin 00222 00224 00227 int numPts() const; 00228 00230 bool operator==(const DenseIntVectSet& a_lhs) const; 00231 00232 00237 bool operator<(const DenseIntVectSet& a_ivs) const; 00238 00240 00243 Vector<Box> createBoxes() const; 00245 00249 void compact() const ; 00250 00251 void recalcMinBox() const; 00252 00253 const Box& mBox() const {return m_minBox;} 00254 00257 int linearSize() const; 00258 00259 void linearIn(const void* const inBuf); 00260 00261 void linearOut(void* const a_outBuf) const; 00262 00264 private: 00265 00266 void grow(const IntVect& iv); 00267 // version without checking intersect or empty 00268 DenseIntVectSet& intersect(const DenseIntVectSet& rhs); 00269 Box m_domain; 00270 BitSet m_bits; 00271 friend class DenseIntVectSetIterator; 00272 Box m_minBox; 00273 }; 00274 00276 00278 class DenseIntVectSetIterator 00279 { 00280 public: 00281 00283 DenseIntVectSetIterator(); 00284 00286 DenseIntVectSetIterator(const DenseIntVectSet& ivs); 00287 00289 void define(const DenseIntVectSet& ivs); 00290 //default null, assignment, copy and destructor should work fine. 00291 00293 const IntVect& operator()() const ; 00294 00296 bool ok() const; 00297 00299 void operator++(); 00300 00302 void begin(); 00303 00305 void end(); 00306 00307 static DenseIntVectSet emptyDenseIntVectSet; 00308 00309 private: 00310 BitSetIterator m_iterator; 00311 IntVect m_current; 00312 const DenseIntVectSet* m_ivsPtr; 00313 int isize, ijsize, bigi, bigj; 00314 00315 void nextIntVect(); 00316 void nextIntVect(int skip); 00317 00318 }; 00319 00320 //=================================================================== 00321 00322 // inline functions 00323 00324 inline 00325 const Box& DenseIntVectSet::box() const { return m_domain;} 00326 00327 inline 00328 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect) 00329 { 00330 if(m_domain.contains(intvect)) 00331 m_bits.setFalse(m_domain.index(intvect)); 00332 return *this; 00333 } 00334 00335 inline void DenseIntVectSet::shift(const IntVect& iv) 00336 { 00337 m_domain.shift(iv); 00338 m_minBox.shift(iv); 00339 } 00340 00341 inline 00342 DenseIntVectSetIterator::DenseIntVectSetIterator() 00343 : m_ivsPtr(&emptyDenseIntVectSet) 00344 { 00345 ; 00346 } 00347 00348 inline 00349 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs) 00350 { 00351 m_ivsPtr = &ivs; 00352 begin(); 00353 } 00354 00355 inline 00356 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs) 00357 : m_ivsPtr(&ivs) 00358 { 00359 begin(); 00360 } 00361 00362 inline 00363 const IntVect& DenseIntVectSetIterator::operator()() const 00364 { 00365 return m_current; 00366 } 00367 00368 inline 00369 bool DenseIntVectSetIterator::ok() const 00370 { 00371 return m_iterator.ok(); 00372 } 00373 00374 inline 00375 void DenseIntVectSetIterator::end() 00376 { 00377 m_iterator.end(); 00378 } 00379 00380 // inline 00381 // void DenseIntVectSetIterator::operator++() 00382 // { 00383 // ++m_iterator; 00384 // nextIntVect(); 00385 // while(!m_iterator() && m_iterator.ok()) 00386 // { 00387 // ++m_iterator; // next bit please 00388 // nextIntVect(); 00389 // } 00390 // } 00391 inline 00392 void DenseIntVectSetIterator::operator++() 00393 { 00394 ++m_iterator; 00395 int i=1; 00396 while(m_iterator.ok() && !m_iterator()) 00397 { 00398 ++m_iterator; // next bit please 00399 ++i; 00400 } 00401 nextIntVect(i); 00402 } 00403 00404 #endif