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    / /__/ _ \/ _ \/  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 
00535   void
00536   printBoxes(std::ostream& a_ostream) const;
00537 
00539   void
00540   p() const { printBoxes(pout());}
00541 
00543   friend
00544   std::ostream&
00545   operator<<(std::ostream& os, const IntVectSet& ivs);
00546 
00547   void convert() const; // turn dense rep into Tree rep.  very costly.
00548                         // it is 'logically' const, but does modify data structures;
00549 
00550   // not for public consumption.  used in memory tracking.
00551   static long int count;
00552   static long int peakcount;
00553 
00554   //set to 10000 as default.  resettable.
00555   static int s_maxDense;
00556 
00557 private:
00558 
00559   bool m_isdense;
00560   TreeIntVectSet m_ivs;
00561   DenseIntVectSet m_dense;
00562   // not a user function.  called by memory tracking system on
00563   // exit to clean up static allocation pools used for the optimization
00564   // of these routines.
00565   friend void dumpmemoryatexit();
00566   static void clearStaticMemory(); // after this functon is called, you cannot
00567                               // do any other operations with IntVectSet.
00568 };
00569 
00571 
00587 class IVSIterator
00588 {
00589 public:
00590 
00595   IVSIterator():m_isdense(true)
00596   {}
00597 
00602   IVSIterator(const IntVectSet& ivs);
00603 
00604   ~IVSIterator()
00605   {}
00606 
00611   void define(const IntVectSet& ivs);
00612 
00614   const IntVect& operator()() const ;
00615 
00617   const IntVect& iv() const { return this->operator()();}
00618 
00620   bool ok() const;
00621 
00623   void operator++();
00624 
00626   void incr() { ++(*this);}
00627 
00629   void begin();
00630 
00632   void reset();
00633 
00635 
00636   void end();
00637 
00638 private:
00639   bool m_isdense;
00640   DenseIntVectSetIterator m_dense;
00641   TreeIntVectSetIterator  m_tree;
00642 };
00643 
00644 #ifndef WRAPPER
00645 
00646 inline const IntVect& IVSIterator::operator()() const
00647 {
00648   if(m_isdense) return m_dense();
00649   return m_tree();
00650 }
00651 
00652 inline bool IVSIterator::ok() const
00653 {
00654   if(m_isdense) return m_dense.ok();
00655   return m_tree.ok();
00656 }
00657 
00658 inline void  IVSIterator::operator++()
00659 {
00660   if(m_isdense) ++m_dense;
00661   else          ++m_tree;
00662 }
00663 inline void IVSIterator::reset()
00664 {
00665   begin();
00666 }
00667 
00668 inline void IVSIterator::begin()
00669 {
00670   if(m_isdense) m_dense.begin();
00671   else          m_tree.begin();
00672 }
00673 
00674 inline void IVSIterator::end()
00675 {
00676   if(m_isdense) m_dense.end();
00677   else          m_tree.end();
00678 }
00679 
00680 inline IntVectSet::IntVectSet(): m_isdense(true)
00681 {
00682   count++;
00683   if(count > peakcount) peakcount = count;
00684 }
00685 
00686 inline void IntVectSet::define(const IntVectSet& ige_in)
00687 {
00688   *this = ige_in;
00689 }
00690 
00691 inline IntVectSet::IntVectSet(const IntVectSet& ige_in)
00692 {
00693   count++;
00694   if(count > peakcount) peakcount = count;
00695 
00696   *this = ige_in;
00697 }
00698 
00699 inline   bool
00700 IntVectSet::isDense() const
00701 {
00702   return m_isdense;
00703 }
00704 
00705 #endif /* WRAPPER */
00706 
00707 #endif

Generated on Wed Jan 19 17:51:25 2005 for Chombo&INSwithParticles by doxygen1.2.16