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

IntVectSet.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 _INTVECTSET_H_
00029 #define _INTVECTSET_H_
00030 
00031 //
00032 // $Id: IntVectSet.H,v 1.19 2004/04/09 20:43:17 graves Exp $
00033 //
00034 
00035 #include "SPACE.H"
00036 
00037 #ifndef WRAPPER
00038 #include <iostream>
00039 #include "Box.H"
00040 #include "IntVect.H"
00041 #include "TreeIntVectSet.H"
00042 #include "DenseIntVectSet.H"
00043 #include "parstream.H"
00044 
00045 #endif
00046 
00048 
00064 class IntVectSet
00065 {
00066 public:
00067   friend
00068   class IVSIterator;
00069 
00074 
00075 
00076   ~IntVectSet();
00077 
00079   IntVectSet();
00081   void
00082   define();
00083 
00084 
00086   IntVectSet(const IntVectSet& ivs);
00088   void
00089   define(const IntVectSet& ivs);
00091   void
00092   define_intvectset(const IntVectSet& ivs){ define(ivs);}
00094   IntVectSet
00095   copy() const {return *this;}
00096 
00097 
00099   explicit
00100   IntVectSet(const DenseIntVectSet& a_dense);
00102   void
00103   define (const DenseIntVectSet& a_dense);
00105   explicit
00106   IntVectSet(const TreeIntVectSet& a_tree);
00108   void
00109   define (const TreeIntVectSet& a_tree);
00110 
00111 
00113 
00114   explicit
00115   IntVectSet(const IntVect& iv);
00117   void
00118   define(const IntVect& iv);
00120   void
00121   define_intvect(const IntVect& iv){define(iv);}
00122 
00124 
00125   explicit
00126   IntVectSet(const Box& b);
00128 
00129   void
00130   define(const Box& b);
00132   void
00133   define_box(const Box& b){define(b);}
00134 
00142 
00144   IntVectSet&
00145   operator|=(const IntVectSet& ivs);
00146 
00148   void
00149   or_intvectset(const IntVectSet& ivs) { *this |= ivs;}
00150 
00151 
00153   IntVectSet&
00154   operator|=(const IntVect& iv);
00156   void
00157   or_intvect(const IntVect& ivs) { *this |= ivs;}
00158 
00159 
00160 
00162   IntVectSet&
00163   operator|=(const Box& b);
00165   void
00166   or_box(const Box& b) { *this |= b;}
00167 
00169   friend
00170   IntVectSet
00171   operator|(const IntVectSet& ivs1, const IntVectSet& ivs2);
00172 
00174   friend
00175   IntVectSet
00176   operator|(const IntVectSet& ivs, const IntVect& iv);
00177 
00179   friend
00180   IntVectSet
00181   operator|(const IntVect& iv, const IntVectSet& ivs);
00182 
00184   friend
00185   IntVectSet
00186   operator|(const IntVectSet& ivs, const Box& b);
00187 
00189   friend
00190   IntVectSet
00191   operator|(const Box& b, const IntVectSet& ivs);
00192 
00193 
00202 
00204   IntVectSet
00205   operator-(const IntVectSet& ivs) const;
00206 
00208   IntVectSet
00209   operator-(const Box& b) const;
00210 
00212   IntVectSet
00213   operator-(const IntVect& iv) const;
00214 
00215 
00216 
00218 
00222   IntVectSet&
00223   operator-=(const IntVectSet& ivs);
00225   void
00226   minus(const IntVectSet& ivs){*this -= ivs;}
00227 
00228 
00230 
00234   IntVectSet&
00235   operator-=(const Box& b);
00237   void
00238   minus_box(const Box& b){ *this -=b;}
00239 
00240 
00242 
00246   IntVectSet&
00247   operator-=(const IntVect& iv);
00249   void
00250   minus_intvect(const IntVect& iv){ *this -=iv;}
00251 
00258 
00260 
00263   friend
00264   IntVectSet
00265   operator&(const IntVectSet& ivs1, const IntVectSet& ivs2);
00266 
00268 
00271   friend
00272   IntVectSet
00273   operator&(const IntVectSet& ivs, const Box& b);
00274 
00276 
00279   friend
00280   IntVectSet
00281   operator&(const Box& b, const IntVectSet& ivs);
00282 
00283 
00285   IntVectSet&
00286   operator&=(const IntVectSet& ivs);
00288   void
00289   and_intvectset(const IntVectSet& ivs){*this &= ivs;}
00290 
00292   IntVectSet&
00293   operator&=(const Box& b);
00295   void
00296   and_box(const Box& b){*this &= b;}
00297 
00299   IntVectSet&
00300   operator&=(const ProblemDomain& domain);
00302   void
00303   and_domain(const ProblemDomain& d){*this &= d;}
00304 
00311 
00312 
00314 
00319   void
00320   grow(int igrow);
00321 
00323 
00328   friend
00329   IntVectSet
00330   grow(const IntVectSet& ivs, int igrow);
00331 
00332 
00334 
00339   IntVectSet&
00340   grow(int idir, int igrow);
00342   void
00343   grow_dir(int idir, int igrow){grow(idir, igrow);}
00344 
00345 
00347 
00353   IntVectSet&
00354   refine(int iref = 2);
00355 
00356 
00358 
00365   friend
00366   IntVectSet
00367   refine(const IntVectSet& ivs, int iref = 2);
00368 
00369 
00371 
00377   IntVectSet&
00378   coarsen(int iref = 2);
00379 
00380 
00382 
00389   friend
00390   IntVectSet
00391   coarsen(const IntVectSet& ivs, int iref = 2);
00392 
00393 
00395   void
00396   shift(const IntVect& iv);
00397 
00398 
00400 
00406   void
00407   nestingRegion(int radius, const Box& domain, int granularity  = 1);
00408 
00409 
00411 
00417   void
00418   nestingRegion(int radius, const ProblemDomain& probdomain, int granularity = 1);
00420   void
00421   nestingRegion_prob(int radius, const ProblemDomain& probdomain)
00422   {
00423     nestingRegion(radius, probdomain);
00424   }
00425 
00426 
00428   void
00429   makeEmpty();
00430 
00431 
00433 
00440   IntVectSet
00441   chop(int dir, int chop_pnt);
00442 
00444 
00448   void setMaxDense(const int& a_maxDense);
00449 
00456 
00457 
00459   int
00460   numPts() const;
00461 
00462 
00464   const Box&
00465   minBox() const;
00466 
00467 
00469   void
00470   recalcMinBox() const;
00471 
00472 
00474   bool
00475   isEmpty() const;
00476 
00477 
00479   bool
00480   isDense() const;
00481 
00482 
00484   bool
00485   contains(const IntVect& iv) const;
00486 
00487 
00489   bool
00490   contains(const IntVectSet& ivs) const;
00492   bool
00493   contains_intvectset(const IntVectSet& ivs) const {return contains(ivs);}
00494 
00495 
00497 
00501   bool
00502   contains(const Box& box) const;
00504   bool
00505   contains_box(const Box& b) const {return contains(b);}
00506 
00507 
00509 
00513   Vector<Box>
00514   boxes() const;
00515 
00516 
00518 
00523   void
00524   compact() const;
00525 
00532 
00534   int
00535   linearSize() const;
00536 
00538   void
00539   linearIn(const void* const a_inBuf);
00540 
00542 
00545   void
00546   linearOut(void* const a_outBuf) const;
00547 
00551 
00552   bool
00553   operator==(const IntVectSet& a_ivs) const;
00554 
00555 
00557   void
00558   printBoxes(std::ostream& a_ostream) const;
00559 
00561   void
00562   p() const { printBoxes(pout());}
00563 
00565   friend
00566   std::ostream&
00567   operator<<(std::ostream& os, const IntVectSet& ivs);
00568 
00569 
00570   void convert() const; // turn dense rep into Tree rep.  very costly.
00571                         // it is 'logically' const, but does modify data structures;
00572 
00573   // not for public consumption.  used in memory tracking.
00574   static long int count;
00575   static long int peakcount;
00576 
00577   //set to 10000 as default.  resettable. 
00578   static int s_maxDense;
00579 
00580 private:
00581 
00582   bool m_isdense;
00583   TreeIntVectSet m_ivs;
00584   DenseIntVectSet m_dense;
00585   // not a user function.  called by memory tracking system on
00586   // exit to clean up static allocation pools used for the optimization
00587   // of these routines.
00588   friend void dumpmemoryatexit();
00589   static void clearStaticMemory(); // after this functon is called, you cannot
00590                               // do any other operations with IntVectSet.
00591 };
00592 
00593 
00594 
00595 
00596 
00598 
00614 class IVSIterator
00615 {
00616 public:
00617 
00622   IVSIterator():m_isdense(true) {;}
00623 
00628   IVSIterator(const IntVectSet& ivs);
00629 
00630   ~IVSIterator(){;}
00631 
00636   void define(const IntVectSet& ivs);
00637 
00639   const IntVect& operator()() const ;
00640 
00642   const IntVect& iv() const { return this->operator()();}
00643 
00645   bool ok() const;
00646 
00648   void operator++();
00649 
00651   void incr() { ++(*this);}
00652 
00654   void begin();
00655 
00657   void reset();
00658 
00660 
00661   void end();
00662 
00663 private:
00664   bool m_isdense;
00665   DenseIntVectSetIterator m_dense;
00666   TreeIntVectSetIterator  m_tree;
00667 };
00668 
00669 
00670 
00671 #ifndef WRAPPER
00672 
00673 
00674 
00675 inline const IntVect& IVSIterator::operator()() const
00676 {
00677   if(m_isdense) return m_dense();
00678   return m_tree();
00679 }
00680 
00681 inline bool IVSIterator::ok() const
00682 {
00683   if(m_isdense) return m_dense.ok();
00684   return m_tree.ok();
00685 }
00686 
00687 inline void  IVSIterator::operator++()
00688 {
00689   if(m_isdense) ++m_dense;
00690   else          ++m_tree;
00691 }
00692 inline void IVSIterator::reset()
00693 {
00694   begin();
00695 }
00696 
00697 inline void IVSIterator::begin()
00698 {
00699   if(m_isdense) m_dense.begin();
00700   else          m_tree.begin();
00701 }
00702 
00703 inline void IVSIterator::end()
00704 {
00705   if(m_isdense) m_dense.end();
00706   else          m_tree.end();
00707 }
00708 
00709 
00710 inline IntVectSet::IntVectSet(): m_isdense(true)
00711 {
00712   count++;
00713   if(count > peakcount) peakcount = count;
00714 }
00715 
00716 inline void IntVectSet::define(const IntVectSet& ige_in)
00717 {
00718   *this = ige_in;
00719 }
00720 
00721 inline IntVectSet::IntVectSet(const IntVectSet& ige_in)
00722 {
00723   count++;
00724   if(count > peakcount) peakcount = count;
00725 
00726   *this = ige_in;
00727 }
00728 
00729 inline   bool
00730 IntVectSet::isDense() const
00731 {
00732   return m_isdense;
00733 }
00734 
00735 #endif /* WRAPPER */
00736 
00737 #endif /*_INTVECTSET_H_*/

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