Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

IntVectSet.H

Go to the documentation of this file.
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 _INTVECTSET_H_
00053 #define _INTVECTSET_H_
00054 
00055 #include "SPACE.H"
00056 
00057 #ifndef WRAPPER
00058 #include <iostream>
00059 #include "Box.H"
00060 #include "IntVect.H"
00061 #include "TreeIntVectSet.H"
00062 #include "DenseIntVectSet.H"
00063 #include "parstream.H"
00064 
00065 #endif
00066 
00068 
00084 class IntVectSet
00085 {
00086 public:
00087   friend
00088   class IVSIterator;
00089 
00095 
00096   ~IntVectSet();
00097 
00099   IntVectSet();
00101   void
00102   define();
00103 
00105   IntVectSet(const IntVectSet& ivs);
00107   void
00108   define(const IntVectSet& ivs);
00110   void
00111   define_intvectset(const IntVectSet& ivs){ define(ivs);}
00113   IntVectSet
00114   copy() const {return *this;}
00115 
00117   explicit
00118   IntVectSet(const DenseIntVectSet& a_dense);
00120   void
00121   define (const DenseIntVectSet& a_dense);
00123   explicit
00124   IntVectSet(const TreeIntVectSet& a_tree);
00126   void
00127   define (const TreeIntVectSet& a_tree);
00128 
00130 
00131   explicit
00132   IntVectSet(const IntVect& iv);
00134   void
00135   define(const IntVect& iv);
00137   void
00138   define_intvect(const IntVect& iv){define(iv);}
00139 
00141 
00142   explicit
00143   IntVectSet(const Box& b);
00145 
00146   void
00147   define(const Box& b);
00149   void
00150   define_box(const Box& b){define(b);}
00151 
00158 
00160   IntVectSet&
00161   operator|=(const IntVectSet& ivs);
00162 
00164   void
00165   or_intvectset(const IntVectSet& ivs) { *this |= ivs;}
00166 
00168   IntVectSet&
00169   operator|=(const IntVect& iv);
00171   void
00172   or_intvect(const IntVect& ivs) { *this |= ivs;}
00173 
00175   IntVectSet&
00176   operator|=(const Box& b);
00178   void
00179   or_box(const Box& b) { *this |= b;}
00180 
00182   friend
00183   IntVectSet
00184   operator|(const IntVectSet& ivs1, const IntVectSet& ivs2);
00185 
00187   friend
00188   IntVectSet
00189   operator|(const IntVectSet& ivs, const IntVect& iv);
00190 
00192   friend
00193   IntVectSet
00194   operator|(const IntVect& iv, const IntVectSet& ivs);
00195 
00197   friend
00198   IntVectSet
00199   operator|(const IntVectSet& ivs, const Box& b);
00200 
00202   friend
00203   IntVectSet
00204   operator|(const Box& b, const IntVectSet& ivs);
00205 
00212 
00214   IntVectSet
00215   operator-(const IntVectSet& ivs) const;
00216 
00218   IntVectSet
00219   operator-(const Box& b) const;
00220 
00222   IntVectSet
00223   operator-(const IntVect& iv) const;
00224 
00226 
00230   IntVectSet&
00231   operator-=(const IntVectSet& ivs);
00233   void
00234   minus(const IntVectSet& ivs){*this -= ivs;}
00235 
00237 
00241   IntVectSet&
00242   operator-=(const Box& b);
00244   void
00245   minus_box(const Box& b){ *this -=b;}
00246 
00248 
00252   IntVectSet&
00253   operator-=(const IntVect& iv);
00255   void
00256   minus_intvect(const IntVect& iv){ *this -=iv;}
00257 
00263 
00265 
00268   friend
00269   IntVectSet
00270   operator&(const IntVectSet& ivs1, const IntVectSet& ivs2);
00271 
00273 
00276   friend
00277   IntVectSet
00278   operator&(const IntVectSet& ivs, const Box& b);
00279 
00281 
00284   friend
00285   IntVectSet
00286   operator&(const Box& b, const IntVectSet& ivs);
00287 
00289   IntVectSet&
00290   operator&=(const IntVectSet& ivs);
00292   void
00293   and_intvectset(const IntVectSet& ivs){*this &= ivs;}
00294 
00296   IntVectSet&
00297   operator&=(const Box& b);
00299   void
00300   and_box(const Box& b){*this &= b;}
00301 
00303   IntVectSet&
00304   operator&=(const ProblemDomain& domain);
00306   void
00307   and_domain(const ProblemDomain& d){*this &= d;}
00308 
00314 
00316 
00321   void
00322   grow(int igrow);
00323 
00325 
00330   friend
00331   IntVectSet
00332   grow(const IntVectSet& ivs, int igrow);
00333 
00335 
00340   IntVectSet&
00341   grow(int idir, int igrow);
00343   void
00344   grow_dir(int idir, int igrow){grow(idir, igrow);}
00345 
00347 
00353   IntVectSet&
00354   refine(int iref = 2);
00355 
00357 
00364   friend
00365   IntVectSet
00366   refine(const IntVectSet& ivs, int iref = 2);
00367 
00369 
00375   IntVectSet&
00376   coarsen(int iref = 2);
00377 
00379 
00386   friend
00387   IntVectSet
00388   coarsen(const IntVectSet& ivs, int iref = 2);
00389 
00391   void
00392   shift(const IntVect& iv);
00393 
00395 
00401   void
00402   nestingRegion(int radius, const Box& domain, int granularity  = 1);
00403 
00405 
00411   void
00412   nestingRegion(int radius, const ProblemDomain& probdomain, int granularity = 1);
00414   void
00415   nestingRegion_prob(int radius, const ProblemDomain& probdomain)
00416   {
00417     nestingRegion(radius, probdomain);
00418   }
00419 
00421   void
00422   makeEmpty();
00423 
00425 
00432   IntVectSet
00433   chop(int dir, int chop_pnt);
00434 
00436 
00440   void setMaxDense(const int& a_maxDense);
00441 
00447 
00449   int
00450   numPts() const;
00451 
00453   const Box&
00454   minBox() const;
00455 
00457   void
00458   recalcMinBox() const;
00459 
00461   bool
00462   isEmpty() const;
00463 
00465   bool
00466   isDense() const;
00467 
00469   bool
00470   contains(const IntVect& iv) const;
00471 
00473   bool
00474   contains(const IntVectSet& ivs) const;
00476   bool
00477   contains_intvectset(const IntVectSet& ivs) const {return contains(ivs);}
00478 
00480 
00484   bool
00485   contains(const Box& box) const;
00487   bool
00488   contains_box(const Box& b) const {return contains(b);}
00489 
00491 
00495   Vector<Box>
00496   boxes() const;
00497 
00499 
00504   void
00505   compact() const;
00506 
00512 
00514   int
00515   linearSize() const;
00516 
00518   void
00519   linearIn(const void* const a_inBuf);
00520 
00522 
00525   void
00526   linearOut(void* const a_outBuf) const;
00527 
00530 
00531   bool
00532   operator==(const IntVectSet& a_ivs) const;
00533 
00544   bool
00545   operator<(const IntVectSet& a_ivs) const;
00546 
00548   void
00549   printBoxes(std::ostream& a_ostream) const;
00550 
00552   void
00553   p() const { printBoxes(pout());}
00554 
00556   friend
00557   std::ostream&
00558   operator<<(std::ostream& os, const IntVectSet& ivs);
00559 
00560   void convert() const; // turn dense rep into Tree rep.  very costly.
00561                         // it is 'logically' const, but does modify data structures;
00562 
00563   // not for public consumption.  used in memory tracking.
00564   static long int count;
00565   static long int peakcount;
00566 
00567   //set to 10000 as default.  resettable.
00568   static int s_maxDense;
00569 
00570 private:
00571 
00572   bool m_isdense;
00573   TreeIntVectSet m_ivs;
00574   DenseIntVectSet m_dense;
00575   // not a user function.  called by memory tracking system on
00576   // exit to clean up static allocation pools used for the optimization
00577   // of these routines.
00578   friend void dumpmemoryatexit();
00579   static void clearStaticMemory(); // after this functon is called, you cannot
00580                               // do any other operations with IntVectSet.
00581 };
00582 
00584 
00600 class IVSIterator
00601 {
00602 public:
00603 
00608   IVSIterator():m_isdense(true)
00609   {}
00610 
00615   IVSIterator(const IntVectSet& ivs);
00616 
00617   ~IVSIterator()
00618   {}
00619 
00624   void define(const IntVectSet& ivs);
00625 
00627   const IntVect& operator()() const ;
00628 
00630   const IntVect& iv() const { return this->operator()();}
00631 
00633   bool ok() const;
00634 
00636   void operator++();
00637 
00639   void incr() { ++(*this);}
00640 
00642   void begin();
00643 
00645   void reset();
00646 
00648 
00649   void end();
00650 
00651 private:
00652   bool m_isdense;
00653   DenseIntVectSetIterator m_dense;
00654   TreeIntVectSetIterator  m_tree;
00655 };
00656 
00657 #ifndef WRAPPER
00658 
00659 inline const IntVect& IVSIterator::operator()() const
00660 {
00661   if(m_isdense) return m_dense();
00662   return m_tree();
00663 }
00664 
00665 inline bool IVSIterator::ok() const
00666 {
00667   if(m_isdense) return m_dense.ok();
00668   return m_tree.ok();
00669 }
00670 
00671 inline void  IVSIterator::operator++()
00672 {
00673   if(m_isdense) ++m_dense;
00674   else          ++m_tree;
00675 }
00676 inline void IVSIterator::reset()
00677 {
00678   begin();
00679 }
00680 
00681 inline void IVSIterator::begin()
00682 {
00683   if(m_isdense) m_dense.begin();
00684   else          m_tree.begin();
00685 }
00686 
00687 inline void IVSIterator::end()
00688 {
00689   if(m_isdense) m_dense.end();
00690   else          m_tree.end();
00691 }
00692 
00693 inline IntVectSet::IntVectSet(): m_isdense(true)
00694 {
00695   count++;
00696   if(count > peakcount) peakcount = count;
00697 }
00698 
00699 inline void IntVectSet::define(const IntVectSet& ige_in)
00700 {
00701   *this = ige_in;
00702 }
00703 
00704 inline IntVectSet::IntVectSet(const IntVectSet& ige_in)
00705 {
00706   count++;
00707   if(count > peakcount) peakcount = count;
00708 
00709   *this = ige_in;
00710 }
00711 
00712 inline   bool
00713 IntVectSet::isDense() const
00714 {
00715   return m_isdense;
00716 }
00717 
00718 #endif /* WRAPPER */
00719 
00720 #endif

Generated on Wed Oct 5 13:52:08 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1