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 
00099 class TreeIntVectSet
00100 {
00101 public:
00103   inline TreeIntVectSet();
00104 
00106   TreeIntVectSet(const Box&);
00107 
00109   TreeIntVectSet(const TreeIntVectSet& a_sivs);
00110 
00112   ~TreeIntVectSet();
00113 
00115   void define(const Box&);
00116 
00118   void define(const TreeIntVectSet& a_sivs);
00119 
00121   TreeIntVectSet& operator=(const TreeIntVectSet& a_sivs);
00122 
00124   TreeIntVectSet& operator|=(const TreeIntVectSet& a_sivs);
00125 
00127   TreeIntVectSet& operator|=(const IntVect& a_iv);
00128 
00130   TreeIntVectSet& operator|=(const Box& a_box);
00131 
00133   TreeIntVectSet& operator&=(const TreeIntVectSet& s_sivs);
00134 
00136   TreeIntVectSet& operator&=(const Box& a_box);
00137 
00139   TreeIntVectSet& operator&=(const ProblemDomain& a_domain);
00140 
00142   TreeIntVectSet& operator-=(const TreeIntVectSet& a_sivs);
00143 
00145   TreeIntVectSet& operator-=(const IntVect& a_iv);
00146 
00148   TreeIntVectSet& operator-=(const Box& a_box);
00149 
00151   bool operator==(const TreeIntVectSet& lhs) const;
00152 
00154 
00157   Vector<Box> createBoxes() const;
00158 
00160 
00163   void createBoxes(Vector<Box>& boxes, int& size) const;
00164 
00166   bool contains(const IntVect& iv) const;
00167 
00169   bool contains(const Box& box) const;
00170 
00172 
00175   TreeIntVectSet chop(int idir, int chop_pnt); 
00176 
00178 
00181   void grow(int igrow);           
00182 
00184 
00187   void grow(int idir, int igrow);
00188 
00190 
00193   void refine(int iref = 2); 
00194 
00196 
00199   void coarsen(int iref = 2); 
00200 
00202 
00205   void shift(const IntVect& iv); 
00206 
00208   void clear();
00209 
00211   void nestingRegion(int a_radius, const Box& a_domain, int granularity);
00212 
00214   void nestingRegion(int a_radius, const ProblemDomain& a_domain, int granularity);
00215 
00217   inline const Box& minBox() const;
00218 
00220   bool isEmpty() const;
00221 
00223   int numPts() const;
00224 
00225   friend void dumpTree(const TreeIntVectSet* set);
00226 
00228   void compact() const;  // logically const operation;
00229 
00231   void recalcMinBox() const;
00232 
00235   int linearSize() const;
00236 
00237   void linearIn(const void* const inBuf);
00238 
00239   void linearOut(void* const a_outBuf) const;
00242 private:
00243 
00244   friend class TreeIntVectSetIterator;
00245 
00246 #ifndef DOXYGEN
00247   struct TreeNode {
00248     TreeNode* nodes;
00249     TreeNode():nodes(0){;}
00250   };
00251 #endif
00252 
00253   TreeNode m_tree;
00254   Box m_minBox, m_spanBox;
00255   int m_depth;
00256 
00257   void trimCoarsen(int icoarse);
00258 
00259   //===============
00260   static Pool treeNodePool;
00261 
00262   static void   quadrantBox(const Box& inputBox, int quadrant, Box& outputQuadrant);
00263   static void clearTree(TreeNode& tree);
00264   static void expandNode(TreeNode& node);
00265   void growTree();
00266 
00267 
00268   static int  oppositeQuadrant(int index);
00269   static bool nextIntVect(const Box& box, IntVect& iv);
00270   static void nextNode(int& currentDepth);
00271   static void cloneNode(const TreeNode& src, TreeNode& dest);
00272   // data structures that are needed again and again in the routines
00273   // that only change their size during grow() operations.  Keep them
00274   // around so that we don't have to create and destroy them on every function
00275   // call
00276   static Vector<int> index, bufferOffset;
00277   static Vector<TreeNode*> parents;
00278   static Vector<Box> boxes;
00279 
00280   // xlC isn't working me on this one.
00281   // so istead of a nice const static integer, we have a MACRO TIVS_NODESIZE
00282   //const static int  nodeSize = D_TERM(2,*2,*2);
00283   static TreeNode full; 
00284   friend struct Flag;
00285   friend class IntVectSet;
00286 };
00287 
00288 
00289 class TreeIntVectSetIterator
00290 {
00291 public:
00292   TreeIntVectSetIterator();
00293   TreeIntVectSetIterator(const TreeIntVectSet& ivs);
00294   void define(const TreeIntVectSet& ivs);
00295   const IntVect& operator()() const ;
00296   bool ok() const;
00297   void operator++();
00298   void begin();
00299   void end();
00300   void clear();
00301 private:
00302   const TreeIntVectSet* m_ivs;
00303   Vector<const TreeIntVectSet::TreeNode*> nodes;
00304   Vector<Box>   boxes;
00305   Vector<int>   index;
00306   int           m_depth;
00307   IntVect       m_current;
00308 
00309   void findNextNode();
00310   void findNext(); // parse tree, starting at [depth, index], set m_current
00311   //when you find an entry, might run to end of iterator.
00312 };
00313 
00314 inline
00315 TreeIntVectSetIterator::TreeIntVectSetIterator():m_ivs(0), m_depth(-1) {;}
00316 
00317 inline 
00318 TreeIntVectSetIterator::TreeIntVectSetIterator(const TreeIntVectSet& ivs)
00319 {
00320   define(ivs);
00321 }
00322 
00323 inline
00324 void TreeIntVectSetIterator::clear()
00325 {
00326   m_depth = -1;
00327   m_ivs = 0;
00328 }
00329 
00330 // apparently, someone was debugging and left this include in here for
00331 // the printf below. i just didn't like the stdio.h, so changed it to
00332 // cstdio -- but then realized it prolly was meant to be commented
00333 // out. (ndk)
00334 //#include <cstdio>
00335 
00336 inline
00337 void TreeIntVectSetIterator::define(const TreeIntVectSet& ivs)
00338 {
00339   m_ivs = &ivs;
00340   int max = ivs.index.size();
00341   //  if(max==10) printf("max=10 \n");
00342   if(boxes.size() < max)
00343     {
00344       boxes.resize(max);
00345       index.resize(max);
00346       nodes.resize(max);
00347     }
00348   begin();
00349 }
00350 
00351 inline
00352 bool TreeIntVectSetIterator::ok() const
00353 {
00354   return m_depth >= 0;
00355 }
00356 
00357 inline
00358 void TreeIntVectSetIterator::end()
00359 {
00360   m_depth = -1;
00361 }  
00362 
00363 inline
00364 TreeIntVectSet& TreeIntVectSet::operator|=(const IntVect& iv)
00365 {
00366   return *this|=Box(iv, iv);
00367 }
00368 
00369 inline
00370 TreeIntVectSet& TreeIntVectSet::operator-=(const IntVect& iv)
00371 {
00372   return *this-=Box(iv, iv);
00373 }
00374 
00375 inline
00376 void TreeIntVectSetIterator::operator++()
00377 {
00378   findNext();
00379 }
00380 
00381 inline 
00382 const IntVect& TreeIntVectSetIterator::operator()() const
00383 {
00384   return m_current;
00385 }
00386 
00387 //=======================================================
00388 
00389 inline
00390 TreeIntVectSet::~TreeIntVectSet()
00391 {
00392   clearTree(m_tree);
00393 }
00394 inline
00395 TreeIntVectSet::TreeIntVectSet(const TreeIntVectSet& a_tivs)
00396 {
00397   define(a_tivs);
00398 }
00399 
00400 inline
00401 TreeIntVectSet::TreeIntVectSet(const Box& a_box)
00402 {
00403   define(a_box);
00404 }
00405 
00406 inline
00407 TreeIntVectSet::TreeIntVectSet()
00408 {
00409   m_tree.nodes = 0;
00410   m_depth=1;
00411 
00412 }
00413 
00414 inline
00415 const Box&
00416 TreeIntVectSet::minBox() const
00417 {
00418   return m_minBox;
00419 }
00420 
00421 inline void TreeIntVectSet::nextNode(int& depth)
00422 {
00423   index[0] = 0;
00424   index[depth]++;
00425   while(index[depth] == TIVS_NODESIZE)
00426     {
00427       index[depth] = 0;
00428       depth--;
00429       index[depth]++;
00430     }
00431 }
00432 
00433 #endif //  TREEINTVECTSET_H

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