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

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