00001 #ifndef _BOXLAYOUT_H_ 00002 #define _BOXLAYOUT_H_ 00003 00004 #include "SPACE.H" 00005 #include "RectMDArray.H" 00006 #include "Box.H" 00007 #include "Point.H" 00008 #include "PowerItoI.H" 00009 #include <iostream> 00010 #include <vector> 00011 #include <map> 00012 #include <memory> 00013 using namespace std; 00014 //yusing namespace std::tr1; 00015 class BLIterator; 00016 00017 /// An organization of Boxes that represents the computational domain. 00018 class BoxLayout { 00019 00020 public: 00021 /// Default Constructor 00022 BoxLayout(); 00023 00024 /// Construct a BoxLayout from an integer and a vector of Points. 00025 /** 00026 \param a_M Desired value of m_blockPower. Each direction in the domain will contain Pow(2,a_M) blocks. 00027 \param a_points Vector of Point objects. Each Point is in bit space and represents the lowCorner of a patch in the domain. 00028 */ 00029 BoxLayout(int a_M, const vector<Point>& a_points); 00030 00031 /// Construct a BoxLayout with (2^a_M)^DIM boxes of equal size. The domain is all of *this.m_domain 00032 00033 BoxLayout(int a_M); 00034 00035 /// Destructor 00036 ~BoxLayout(); 00037 00038 /// Return a Boolean, scalar valued RectMDArray which defines the computational domain. 00039 const RectMDArray<bool>& getBitmap() const; 00040 00041 /// Return a Box object which encloses the entire computational domain. 00042 const Box& getDomain() const; 00043 00044 /// Return a Box object which encloses the entire computational domain. 00045 const Box& getBitBox() const{return m_bitbox;}; 00046 00047 /// Returns the linear dimension of a single Box. 00048 int getBoxsize() const{return Power(2,m_blocksize);}; 00049 00050 /// Returns a coarsened version of the present BoxLayout. 00051 BoxLayout coarsen(unsigned int a_numLevels=1) const; 00052 00053 /// Determines whether the current BL can be coarsened. 00054 bool canCoarsen(unsigned int a_numLevels=1) const; 00055 00056 /// Returns a BL that covers the same region. 00057 BoxLayout deepCoarsen(unsigned int a_numLevels=1) const; 00058 00059 /// Determines whether the current BL can be coarsened. 00060 bool sameBLI(const BoxLayout& a_bli) const; 00061 00062 /// Returns a Box representing the patch corresponding to this point in the bitmap. 00063 /** 00064 *bi, where bi is a BoxIterator, is an appropriate argument. Returns the Box for which a_pt maps to the lowCorner. 00065 \param a_pt A Point in the bit space. 00066 */ 00067 inline Box operator[](const Point& a_pt) const 00068 { 00069 Point lc = a_pt * Power(2,m_blocksize); 00070 Point incr = getOnes()*(Power(2,m_blocksize)-1); 00071 Point hc = lc + incr; 00072 return Box(lc,hc); 00073 }; 00074 00075 /// Return the linear index of the patch whose lowCorner is a_point. 00076 /** 00077 The returned index is associated with the patch that has a_point as the lowCorner. If a_point is not associated with a patch in the domain, -1 is returned. 00078 \param a_point A Point in the bitbox space (not in the physical domain) 00079 */ 00080 int getPatchIndex(const Point& a_point) const; 00081 00082 // REDUNDANT 00083 //**************************************************************************************************************** 00084 // int getPatchIndexFromBitpoint(const Point& a_point) const; 00085 //**************************************************************************************************************** 00086 00087 /// Returns the low corner (in physical space) of the patch specified by a_point (in bit space). 00088 /** 00089 \param a_point Point in bitspace representing the low corner of the desired patch. 00090 */ 00091 Point getCornerFromBitpoint(const Point& a_point); 00092 00093 /// Check if a neighboring patch is in the domain. 00094 /** 00095 Returns true if neighboring patch is in the domain. Returns false if neighboring patch is not in the domain (either because it has a FALSE bitmap value or because it is not within the bitbox) 00096 \param a_p Point in bit space 00097 \param a_dir Direction of neighbor relative to a_p 00098 \param a_face Integer representing orientation of neighbor. a_face = 0 represents -a_dir direction, otherwise direction is +a_dir 00099 */ 00100 bool neighborExists(const Point& a_p, const int a_dir, const int a_face); 00101 00102 /// Returns a vector of Points in bit space representing the patches that make up the domain. 00103 /** 00104 Each Point in the output is the lowCorner of the Box that represents the patch in the domain. 00105 */ 00106 vector<Point>& getPatchLocs() const; 00107 00108 /// Returns the number of patches in the domain. 00109 int size(){return m_getPatches->size();}; 00110 00111 /// Outputs the Point associated with the neighboring patch to a_p in the direction a_dir. 00112 /* 00113 This function returns the point a_p + a_dir, assuming that m_bitbox is periodic. Despite the function name, the output patch will not, in general, be adjacent to the reference patch. There is also no guarantee that the output patch is a member of the domain (i.e. the output may have a bitmap value of FALSE) 00114 \param a_p Point representing the reference patch 00115 \param a_dir Point representing the direction of the desired neighbor. 00116 **/ 00117 Point getNeighbor(const Point& a_p, const Point& a_dir); 00118 00119 // UNUSED 00120 // //there has to be a better way of doing this 00121 // Point getCorner(const int index); 00122 00123 ///\bug Determine the purpose of this function. It appears unfinished. 00124 Box shift(const Box& a_bx,const Point& a_pt); 00125 00126 /// Return m_blockPower 00127 int getBlockPower() const 00128 { 00129 return m_blockPower; 00130 } 00131 00132 /// Prints information about *this to the command line. 00133 void print() const { 00134 cout << "Domain: "; 00135 m_domain.print(); 00136 cout << "Bitbox: "; 00137 m_bitbox.print(); 00138 cout << "blockPower: " << m_blockPower << endl; 00139 cout << "Bitmap: " << endl; 00140 if (m_bitmap) { 00141 (*m_bitmap).print(); 00142 } 00143 } 00144 private: 00145 // BoxLayout* m_boxLayoutPtr; 00146 Box m_domain; ///< Box representing the physical domain. A refinement of m_bitbox by Power(2,m_blocksize) 00147 Box m_bitbox; ///< Box representing an array of blocks. Each Point in m_bitbox corresponds to a block. 00148 int m_blockPower; ///< Determines the number N of blocks in any direction. N = 2^m_blockPower 00149 int m_blocksize; ///< Size of a single block = 2^m_blocksize. MINBLOCKSIZE_EXP<= m_blocksize <= MAXBLOCKSIZE_EXP. 00150 shared_ptr<RectMDArray<bool>> m_bitmap; ///< Boolean, scalar valued RectMDArray. Defines which Boxes are members of the domain. 00151 shared_ptr<vector<Point>> m_patchlocs; ///< Vector of Points each of which is associated with a block in the domain. 00152 shared_ptr<map<Point, int > > m_getPatches; ///< Maps Points in m_patchlocs to an index. 00153 friend ostream& operator<<(ostream& os, const BoxLayout& a_bl); 00154 }; 00155 00156 #endif // _BOXLAYOUT_H_