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

TreeIntVectSet.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 TREEINTVECTSET_H
00029 #define TREEINTVECTSET_H
00030 
00031 
00032 #include "Box.H"
00033 #include "Pool.H"
00034 class IntVectSet;
00035 class ProblemDomain;
00036 
00037 // xlC doesn't like the static const int inside this class.
00038 // so istead of a nice we have a macro: TIVS_NODESIZE
00039 // Currently, this only affects two files:  this one and the .cpp
00040 #if (CH_SPACEDIM==2)
00041 #define TIVS_NODESIZE 4
00042 #elif (CH_SPACEDIM==3)
00043 #define TIVS_NODESIZE 8
00044 #else
00045 //error -- only tested for dimensions 2 and 3 (ndk)
00046 // just cause a compile time bug -- not sure what the best way is.
00047 error_only_tested_for_2D_and_3D
00048 #endif
00049 
00051 
00054 class TreeIntVectSet
00055 {
00056 public:
00058   inline TreeIntVectSet();
00059 
00061   TreeIntVectSet(const Box&);
00062 
00064   TreeIntVectSet(const TreeIntVectSet& a_sivs);
00065 
00067   ~TreeIntVectSet();
00068 
00070   void define(const Box&);
00071 
00073   void define(const TreeIntVectSet& a_sivs);
00074 
00076   TreeIntVectSet& operator=(const TreeIntVectSet& a_sivs);
00077 
00079   TreeIntVectSet& operator|=(const TreeIntVectSet& a_sivs);
00080 
00082   TreeIntVectSet& operator|=(const IntVect& a_iv);
00083 
00085   TreeIntVectSet& operator|=(const Box& a_box);
00086 
00088   TreeIntVectSet& operator&=(const TreeIntVectSet& s_sivs);
00089 
00091   TreeIntVectSet& operator&=(const Box& a_box);
00092 
00094   TreeIntVectSet& operator&=(const ProblemDomain& a_domain);
00095 
00097   TreeIntVectSet& operator-=(const TreeIntVectSet& a_sivs);
00098 
00100   TreeIntVectSet& operator-=(const IntVect& a_iv);
00101 
00103   TreeIntVectSet& operator-=(const Box& a_box);
00104 
00106 
00109   Vector<Box> createBoxes() const;
00110 
00111 
00112   void createBoxes(Vector<Box>& boxes, int& size) const;
00113 
00115   bool contains(const IntVect& iv) const;
00116 
00118   bool contains(const Box& box) const;
00119 
00121 
00124   TreeIntVectSet chop(int idir, int chop_pnt); 
00125 
00127 
00130   void grow(int igrow);           
00131 
00133 
00136   void grow(int idir, int igrow);
00137 
00139 
00142   void refine(int iref = 2); 
00143 
00145 
00148   void coarsen(int iref = 2); 
00149 
00151 
00154   void shift(const IntVect& iv); 
00155 
00157   void clear();
00158 
00160   void nestingRegion(int a_radius, const Box& a_domain);
00161 
00163   void nestingRegion(int a_radius, const ProblemDomain& a_domain);
00164 
00166   inline const Box& minBox() const;
00167 
00169   bool isEmpty() const;
00170 
00172   int numPts() const;
00173 
00174   friend void dumpTree(const TreeIntVectSet* set);
00175 
00177   void compact() const;  // logically const operation;
00178 
00180   void recalcMinBox() const;
00181 
00182   int linearSize() const;
00183 
00184   void linearIn(const void* const inBuf);
00185 
00186   void linearOut(void* const a_outBuf) const;
00187 
00188 
00189 private:
00190 
00191   friend class TreeIntVectSetIterator;
00192 
00193   struct TreeNode {
00194     TreeNode* nodes;
00195     TreeNode():nodes(0){;}
00196   };
00197 
00198   TreeNode m_tree;
00199   Box m_minBox, m_spanBox;
00200   int m_depth;
00201 
00202 
00203   //===============
00204   static Pool treeNodePool;
00205 
00206   static void   quadrantBox(const Box& inputBox, int quadrant, Box& outputQuadrant);
00207   static void clearTree(TreeNode& tree);
00208   static void expandNode(TreeNode& node);
00209   void growTree();
00210 
00211 
00212   static int  oppositeQuadrant(int index);
00213   static bool nextIntVect(const Box& box, IntVect& iv);
00214   static void nextNode(int& currentDepth);
00215   static void cloneNode(const TreeNode& src, TreeNode& dest);
00216   // data structures that are needed again and again in the routines
00217   // that only change their size during grow() operations.  Keep them
00218   // around so that we don't have to create and destroy them on every function
00219   // call
00220   static Vector<int> index, bufferOffset;
00221   static Vector<TreeNode*> parents;
00222   static Vector<Box> boxes;
00223 
00224   // xlC isn't working me on this one.
00225   // so istead of a nice const static integer, we have a MACRO TIVS_NODESIZE
00226   //const static int  nodeSize = D_TERM(2,*2,*2);
00227   static TreeNode full; 
00228   friend struct Flag;
00229   friend class IntVectSet;
00230 };
00231 
00232 
00233 class TreeIntVectSetIterator
00234 {
00235 public:
00236   TreeIntVectSetIterator();
00237   TreeIntVectSetIterator(const TreeIntVectSet& ivs);
00238   void define(const TreeIntVectSet& ivs);
00239   const IntVect& operator()() const ;
00240   bool ok() const;
00241   void operator++();
00242   void begin();
00243   void end();
00244   void clear();
00245 private:
00246   const TreeIntVectSet* m_ivs;
00247   Vector<const TreeIntVectSet::TreeNode*> nodes;
00248   Vector<Box>   boxes;
00249   Vector<int>   index;
00250   int           m_depth;
00251   IntVect       m_current;
00252 
00253   void findNextNode();
00254   void findNext(); // parse tree, starting at [depth, index], set m_current
00255   //when you find an entry, might run to end of iterator.
00256 };
00257 
00258 inline
00259 TreeIntVectSetIterator::TreeIntVectSetIterator():m_ivs(0), m_depth(-1) {;}
00260 
00261 inline 
00262 TreeIntVectSetIterator::TreeIntVectSetIterator(const TreeIntVectSet& ivs)
00263 {
00264   define(ivs);
00265 }
00266 
00267 inline
00268 void TreeIntVectSetIterator::clear()
00269 {
00270   m_depth = -1;
00271   m_ivs = 0;
00272 }
00273 
00274 // apparently, someone was debugging and left this include in here for
00275 // the printf below. i just didn't like the stdio.h, so changed it to
00276 // cstdio -- but then realized it prolly was meant to be commented
00277 // out. (ndk)
00278 //#include <cstdio>
00279 
00280 inline
00281 void TreeIntVectSetIterator::define(const TreeIntVectSet& ivs)
00282 {
00283   m_ivs = &ivs;
00284   int max = ivs.index.size();
00285   //  if(max==10) printf("max=10 \n");
00286   if(boxes.size() < max)
00287     {
00288       boxes.resize(max);
00289       index.resize(max);
00290       nodes.resize(max);
00291     }
00292   begin();
00293 }
00294 
00295 inline
00296 bool TreeIntVectSetIterator::ok() const
00297 {
00298   return m_depth >= 0;
00299 }
00300 
00301 inline
00302 void TreeIntVectSetIterator::end()
00303 {
00304   m_depth = -1;
00305 }  
00306 
00307 inline
00308 TreeIntVectSet& TreeIntVectSet::operator|=(const IntVect& iv)
00309 {
00310   return *this|=Box(iv, iv);
00311 }
00312 
00313 inline
00314 TreeIntVectSet& TreeIntVectSet::operator-=(const IntVect& iv)
00315 {
00316   return *this-=Box(iv, iv);
00317 }
00318 
00319 inline
00320 void TreeIntVectSetIterator::operator++()
00321 {
00322   findNext();
00323 }
00324 
00325 inline 
00326 const IntVect& TreeIntVectSetIterator::operator()() const
00327 {
00328   return m_current;
00329 }
00330 
00331 //=======================================================
00332 
00333 inline
00334 TreeIntVectSet::~TreeIntVectSet()
00335 {
00336   clearTree(m_tree);
00337 }
00338 inline
00339 TreeIntVectSet::TreeIntVectSet(const TreeIntVectSet& a_tivs)
00340 {
00341   define(a_tivs);
00342 }
00343 
00344 inline
00345 TreeIntVectSet::TreeIntVectSet(const Box& a_box)
00346 {
00347   define(a_box);
00348 }
00349 
00350 inline
00351 TreeIntVectSet::TreeIntVectSet()
00352 {
00353   m_tree.nodes = 0;
00354   m_depth=1;
00355 
00356 }
00357 
00358 inline
00359 const Box&
00360 TreeIntVectSet::minBox() const
00361 {
00362   return m_minBox;
00363 }
00364 
00365 inline void TreeIntVectSet::nextNode(int& depth)
00366 {
00367   index[0] = 0;
00368   index[depth]++;
00369   while(index[depth] == TIVS_NODESIZE)
00370     {
00371       index[depth] = 0;
00372       depth--;
00373       index[depth]++;
00374     }
00375 }
00376 
00377 #endif //  TREEINTVECTSET_H

Generated on Thu Aug 29 11:05:46 2002 for Chombo&INS by doxygen1.2.16