Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

DenseIntVectSet.H

Go to the documentation of this file.
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 
00054 class DenseIntVectSet
00055 {
00056 public:
00058   DenseIntVectSet(){;}
00059 
00061 
00062   DenseIntVectSet(const Box& a_domain, bool init = true);
00063   // copy, and operator= should be fine
00064 
00066 
00069   DenseIntVectSet& operator-=(const Box& box);
00070 
00072 
00075   DenseIntVectSet& operator-=(const IntVect& intvect);
00076 
00078 
00081   DenseIntVectSet& operator-=(const DenseIntVectSet& ivs);
00082 
00084 
00087   DenseIntVectSet& operator&=(const Box& box);
00088  
00090 
00093   DenseIntVectSet& operator&=(const ProblemDomain& domain);
00094 
00096 
00101   DenseIntVectSet& operator|=(const IntVect& intvect);
00102 
00104 
00109   DenseIntVectSet& operator|=(const Box& b);
00110 
00112 
00117   DenseIntVectSet& operator|=(const DenseIntVectSet& b);
00118 
00120 
00123   DenseIntVectSet& operator&=(const DenseIntVectSet& ivs);
00124 
00126 
00129   void shift(const IntVect& iv);
00130 
00132   /* slower, constant time pointwise access.
00133      You should not build a BoxIterator, then access this
00134      method if you intend to iterate over the objects true
00135      or false terms.  you should build a DenseIntVectSetIterator */
00136   bool operator[](const IntVect& index) const;
00137 
00139 
00141   bool contains(const Box& box) const;
00142 
00144 
00147   void coarsen(int iref);
00148 
00150 
00153   void refine(int iref);
00154 
00156 
00159   void grow(int igrow);
00160 
00162 
00165   void grow(int idir, int igrow);
00166 
00168 
00173   DenseIntVectSet chop(int dir, int chop_pnt);
00174 
00175   inline const Box& box() const;
00176 
00178 
00180   void nestingRegion(int a_radius, const Box& a_domain);
00181 
00183  
00184   void nestingRegion(int a_radius, const ProblemDomain& a_domain);
00185 
00187 
00190   bool isEmpty() const; //cheaper than numPts by wide margin
00191 
00193 
00196   bool isFull() const;  // cheaper than numPts, bu significant margin
00197 
00199 
00202   int  numPts() const;
00203 
00205   bool operator==(const DenseIntVectSet& a_lhs) const;
00206 
00208 
00211   Vector<Box> createBoxes() const;
00213 
00217   void compact() const ; 
00218 
00219   void recalcMinBox() const;
00220 
00221   const Box& mBox() const {return m_minBox;}
00222 
00223 
00226   int linearSize() const;
00227 
00228   void linearIn(const void* const inBuf);
00229 
00230   void linearOut(void* const a_outBuf) const;
00231 
00233 private:
00234 
00235   void grow(const IntVect& iv);
00236   // version without checking intersect or empty
00237   DenseIntVectSet& intersect(const DenseIntVectSet& rhs);
00238   Box m_domain;
00239   BitSet m_bits;
00240   friend class DenseIntVectSetIterator;
00241   Box m_minBox;
00242 };
00243 
00245 
00247 class DenseIntVectSetIterator
00248 {
00249 public:
00250 
00252   DenseIntVectSetIterator();
00253 
00255   DenseIntVectSetIterator(const DenseIntVectSet& ivs);
00256 
00258   void define(const DenseIntVectSet& ivs);
00259   //default null, assignment, copy and destructor should work fine.
00260 
00262   const IntVect& operator()() const ;
00263 
00265   bool ok() const;
00266 
00268   void operator++();
00269 
00271   void begin();
00272 
00274   void end();
00275 
00276   static DenseIntVectSet    emptyDenseIntVectSet;
00277 
00278 private:
00279   BitSetIterator m_iterator;
00280   IntVect        m_current;
00281   const DenseIntVectSet*    m_ivsPtr;
00282   int isize, ijsize, bigi, bigj;
00283 
00284   void nextIntVect();
00285   void nextIntVect(int skip);
00286 
00287 };
00288 
00289 //===================================================================
00290 
00291 // inline functions
00292 
00293 
00294 inline
00295 const Box& DenseIntVectSet::box() const { return m_domain;}
00296 
00297 
00298 
00299 inline
00300 DenseIntVectSet& DenseIntVectSet::operator-=(const IntVect& intvect)
00301 {
00302   if(m_domain.contains(intvect))
00303     m_bits.setFalse(m_domain.index(intvect));
00304   return *this;
00305 }
00306 
00307 inline void DenseIntVectSet::shift(const IntVect& iv)
00308 {
00309   m_domain.shift(iv);
00310   m_minBox.shift(iv);
00311 }
00312 
00313 inline
00314 DenseIntVectSetIterator::DenseIntVectSetIterator()
00315   : m_ivsPtr(&emptyDenseIntVectSet)
00316 {
00317   ;
00318 }
00319 
00320 inline
00321 void DenseIntVectSetIterator::define(const DenseIntVectSet& ivs)
00322 {
00323   m_ivsPtr = &ivs;
00324   begin();
00325 }
00326 
00327 inline
00328 DenseIntVectSetIterator::DenseIntVectSetIterator(const DenseIntVectSet& ivs)
00329   : m_ivsPtr(&ivs)
00330 {
00331   begin();
00332 }
00333 
00334 inline
00335 const IntVect& DenseIntVectSetIterator::operator()() const
00336 {
00337   return m_current;
00338 }
00339 
00340 inline
00341 bool DenseIntVectSetIterator::ok() const
00342 {
00343   return m_iterator.ok();
00344 }
00345 
00346 
00347 inline 
00348 void DenseIntVectSetIterator::end()
00349 {
00350   m_iterator.end();
00351 }
00352 
00353 //  inline 
00354 //  void DenseIntVectSetIterator::operator++()
00355 //  {
00356 //    ++m_iterator;
00357 //    nextIntVect();
00358 //    while(!m_iterator() && m_iterator.ok())
00359 //      {
00360 //        ++m_iterator; // next bit please
00361 //        nextIntVect();
00362 //      }
00363 //  }
00364 inline 
00365 void DenseIntVectSetIterator::operator++()
00366 {
00367   ++m_iterator;
00368   int i=1;
00369   while(m_iterator.ok() && !m_iterator())
00370     {
00371       ++m_iterator; // next bit please
00372       ++i;
00373     }
00374   nextIntVect(i);
00375 }
00376 
00377 #endif

Generated on Wed Jun 2 13:53:32 2004 for Chombo&INSwithParticles by doxygen 1.3.2