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

TreeIntVectSet.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 _TREEINTVECTSET_H_
00053 #define _TREEINTVECTSET_H_
00054 
00055 #include "Box.H"
00056 #include "Pool.H"
00057 
00058 class IntVectSet;
00059 class ProblemDomain;
00060 
00061 // xlC doesn't like the static const int inside this class.
00062 // so instead of a nice variable we have a macro: TIVS_NODESIZE
00063 // Currently, this only affects two files:  this one and the .cpp
00064 #if (CH_SPACEDIM==2)
00065 #define TIVS_NODESIZE 4
00066 #elif (CH_SPACEDIM==3)
00067 #define TIVS_NODESIZE 8
00068 #else
00069 //error -- only tested for dimensions 2 and 3 (ndk)
00070 #error TIVS_NODESIZE is only defined for 2D and 3D
00071 #endif
00072 
00074 
00122 class TreeIntVectSet
00123 {
00124 public:
00126   inline TreeIntVectSet();
00127 
00129   TreeIntVectSet(const Box&);
00130 
00132   TreeIntVectSet(const TreeIntVectSet& a_sivs);
00133 
00135   ~TreeIntVectSet();
00136 
00138   void define(const Box&);
00139 
00141   void define(const TreeIntVectSet& a_sivs);
00142 
00144   TreeIntVectSet& operator=(const TreeIntVectSet& a_sivs);
00145 
00147   TreeIntVectSet& operator|=(const TreeIntVectSet& a_sivs);
00148 
00150   TreeIntVectSet& operator|=(const IntVect& a_iv);
00151 
00153   TreeIntVectSet& operator|=(const Box& a_box);
00154 
00156   TreeIntVectSet& operator&=(const TreeIntVectSet& s_sivs);
00157 
00159   TreeIntVectSet& operator&=(const Box& a_box);
00160 
00162   TreeIntVectSet& operator&=(const ProblemDomain& a_domain);
00163 
00165   TreeIntVectSet& operator-=(const TreeIntVectSet& a_sivs);
00166 
00168   TreeIntVectSet& operator-=(const IntVect& a_iv);
00169 
00171   TreeIntVectSet& operator-=(const Box& a_box);
00172 
00174   bool operator==(const TreeIntVectSet& lhs) const;
00175 
00182   bool operator<(const TreeIntVectSet& a_sivs) const;
00183 
00185 
00188   Vector<Box> createBoxes() const;
00189 
00191 
00194   void createBoxes(Vector<Box>& boxes, int& size) const;
00195 
00197   bool contains(const IntVect& iv) const;
00198 
00200   bool contains(const Box& box) const;
00201 
00203 
00206   TreeIntVectSet chop(int idir, int chop_pnt);
00207 
00209 
00212   void grow(int igrow);
00213 
00215 
00218   void grow(int idir, int igrow);
00219 
00221 
00224   void refine(int iref = 2);
00225 
00227 
00230   void coarsen(int iref = 2);
00231 
00233 
00236   void shift(const IntVect& iv);
00237 
00239   void clear();
00240 
00242   void nestingRegion(int a_radius, const Box& a_domain, int granularity);
00243 
00245   void nestingRegion(int a_radius, const ProblemDomain& a_domain, int granularity);
00246 
00248   inline const Box& minBox() const;
00249 
00251   bool isEmpty() const;
00252 
00254   int numPts() const;
00255 
00256   friend void dumpTree(const TreeIntVectSet* set);
00257 
00259   void compact() const;  // logically const operation;
00260 
00262   void recalcMinBox() const;
00263 
00266   int linearSize() const;
00267 
00268   void linearIn(const void* const inBuf);
00269 
00270   void linearOut(void* const a_outBuf) const;
00273 private:
00274 
00275   friend class TreeIntVectSetIterator;
00276 
00277 #ifndef DOXYGEN
00278   struct TreeNode {
00279     TreeNode* nodes;
00280     TreeNode():nodes(0)
00281     {}
00282   };
00283 #endif
00284 
00285   TreeNode m_tree;
00286   Box m_minBox, m_spanBox;
00287   int m_depth;
00288 
00289   void trimCoarsen(int icoarse);
00290 
00291   //===============
00292   static Pool treeNodePool;
00293 
00294   static void   quadrantBox(const Box& inputBox, int quadrant, Box& outputQuadrant);
00295   static void clearTree(TreeNode& tree);
00296   static void expandNode(TreeNode& node);
00297   void growTree();
00298 
00299   static int  oppositeQuadrant(int index);
00300   static bool nextIntVect(const Box& box, IntVect& iv);
00301   static void nextNode(int& currentDepth);
00302   static void cloneNode(const TreeNode& src, TreeNode& dest);
00303   // data structures that are needed again and again in the routines
00304   // that only change their size during grow() operations.  Keep them
00305   // around so that we don't have to create and destroy them on every function
00306   // call
00307   static Vector<int> index, bufferOffset;
00308   static Vector<TreeNode*> parents;
00309   static Vector<Box> boxes;
00310 
00311   // xlC wasn't like this
00312   // so instead of a nice const static integer, we have a MACRO TIVS_NODESIZE
00313   //const static int  nodeSize = D_TERM(2,*2,*2);
00314   static TreeNode full;
00315   friend struct Flag;
00316   friend class IntVectSet;
00317 };
00318 
00319 class TreeIntVectSetIterator
00320 {
00321 public:
00322   TreeIntVectSetIterator();
00323   TreeIntVectSetIterator(const TreeIntVectSet& ivs);
00324   void define(const TreeIntVectSet& ivs);
00325   const IntVect& operator()() const ;
00326   bool ok() const;
00327   void operator++();
00328   void begin();
00329   void end();
00330   void clear();
00331 private:
00332   const TreeIntVectSet* m_ivs;
00333   Vector<const TreeIntVectSet::TreeNode*> nodes;
00334   Vector<Box>   boxes;
00335   Vector<int>   index;
00336   int           m_depth;
00337   IntVect       m_current;
00338 
00339   void findNextNode();
00340   void findNext(); // parse tree, starting at [depth, index], set m_current
00341   //when you find an entry, might run to end of iterator.
00342 };
00343 
00344 inline
00345 TreeIntVectSetIterator::TreeIntVectSetIterator():m_ivs(0), m_depth(-1)
00346 {}
00347 
00348 inline
00349 TreeIntVectSetIterator::TreeIntVectSetIterator(const TreeIntVectSet& ivs)
00350 {
00351   define(ivs);
00352 }
00353 
00354 inline
00355 void TreeIntVectSetIterator::clear()
00356 {
00357   m_depth = -1;
00358   m_ivs = 0;
00359 }
00360 
00361 inline
00362 void TreeIntVectSetIterator::define(const TreeIntVectSet& ivs)
00363 {
00364   m_ivs = &ivs;
00365   int max = ivs.index.size();
00366   //  if(max==10) printf("max=10 \n");
00367   if(boxes.size() < max)
00368     {
00369       boxes.resize(max);
00370       index.resize(max);
00371       nodes.resize(max);
00372     }
00373   begin();
00374 }
00375 
00376 inline
00377 bool TreeIntVectSetIterator::ok() const
00378 {
00379   return m_depth >= 0;
00380 }
00381 
00382 inline
00383 void TreeIntVectSetIterator::end()
00384 {
00385   m_depth = -1;
00386 }
00387 
00388 inline
00389 TreeIntVectSet& TreeIntVectSet::operator|=(const IntVect& iv)
00390 {
00391   return *this|=Box(iv, iv);
00392 }
00393 
00394 inline
00395 TreeIntVectSet& TreeIntVectSet::operator-=(const IntVect& iv)
00396 {
00397   return *this-=Box(iv, iv);
00398 }
00399 
00400 inline
00401 void TreeIntVectSetIterator::operator++()
00402 {
00403   findNext();
00404 }
00405 
00406 inline
00407 const IntVect& TreeIntVectSetIterator::operator()() const
00408 {
00409   return m_current;
00410 }
00411 
00412 //=======================================================
00413 
00414 inline
00415 TreeIntVectSet::~TreeIntVectSet()
00416 {
00417   clearTree(m_tree);
00418 }
00419 inline
00420 TreeIntVectSet::TreeIntVectSet(const TreeIntVectSet& a_tivs)
00421 {
00422   define(a_tivs);
00423 }
00424 
00425 inline
00426 TreeIntVectSet::TreeIntVectSet(const Box& a_box)
00427 {
00428   define(a_box);
00429 }
00430 
00431 inline
00432 TreeIntVectSet::TreeIntVectSet()
00433 {
00434   m_tree.nodes = 0;
00435   m_depth=1;
00436 
00437 }
00438 
00439 inline
00440 const Box&
00441 TreeIntVectSet::minBox() const
00442 {
00443   return m_minBox;
00444 }
00445 
00446 inline void TreeIntVectSet::nextNode(int& depth)
00447 {
00448   index[0] = 0;
00449   index[depth]++;
00450   while(index[depth] == TIVS_NODESIZE)
00451     {
00452       index[depth] = 0;
00453       depth--;
00454       index[depth]++;
00455     }
00456 }
00457 
00458 #endif //  TREEINTVECTSET_H

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