Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridUnit_h 00002 #define _included_GridUnit_h 00003 00009 #include "DAGHParams.h" 00010 #include "DAGHSfc.h" 00011 #include "BBox.h" 00012 00013 #define GridUnitNULL ((GridUnit *) NULL) 00014 00031 class GridUnit 00032 { 00033 friend ostream& operator<<(ostream&, const GridUnit&); 00034 friend ofstream& operator<<(ofstream&, const GridUnit&); 00035 friend ifstream& operator>>(ifstream&, GridUnit&); 00036 friend strstream& operator<<(strstream&, const GridUnit&); 00037 friend strstream& operator>>(strstream&, GridUnit&); 00038 friend class GridUnitList; 00039 00040 protected: 00042 short int owner; 00044 short int index; 00046 short int rank; 00048 short int baselev; 00050 short int crslev; 00052 short int finelev; 00054 short int maxlev; 00056 short int minlev; 00058 short int levstep; 00059 00061 short int extent; 00063 int work; 00065 dMapIndex baseindex; 00067 BBox fbb; 00068 00069 public: 00071 inline GridUnit(void) 00072 : owner(DAGHNoBody), index(DAGHNull), rank(0), 00073 baselev(0), crslev(0), finelev(0), 00074 maxlev(0), minlev(0), levstep(0), 00075 extent(0), work(0) { } 00076 00086 GridUnit(const int nrank, const int clev, const int* bcoords, 00087 const int ext, const int mlev, const int lstep, 00088 const int reflev); 00089 00090 GridUnit(const int nrank, const int clev, const int bindex, 00091 const int ext, const int mlev, const int lstep, 00092 const int reflev); 00093 00094 inline GridUnit(GridUnit const &other) 00095 : owner(other.owner), index(other.index), 00096 rank(other.rank), baselev(other.baselev), 00097 crslev(other.crslev), finelev(other.finelev), 00098 maxlev(other.maxlev), minlev(other.minlev), 00099 levstep(other.levstep), extent(other.extent), 00100 work(other.work), baseindex(other.baseindex), 00101 fbb(other.fbb) 00102 { } 00103 00104 inline ~GridUnit(void) {} 00105 00106 GridUnit const &operator= (GridUnit const &other); 00107 00108 public: 00110 inline int guOwner(void) const { return (owner); } 00111 inline int guIndex(void) const { return (index); } 00112 inline int guRank(void) const { return (rank); } 00113 inline int guBaseLev(void) const { return (baselev); } 00114 inline int guFineLev(void) const { return (finelev); } 00115 inline int guCrsLev(void) const { return (crslev); } 00116 inline int guNumLev(void) const { return ((finelev-crslev)/levstep+1); } 00117 inline int guMaxLev(void) const { return (maxlev); } 00118 inline int guMinLev(void) const { return (minlev); } 00119 inline int guLevStep(void) const { return (levstep); } 00120 inline int guLevels(void) const { return ((maxlev-minlev)/levstep+1); } 00121 00122 inline int guExtent(const int lev) const 00123 { return ((lev<=finelev && lev>=crslev && extent>=(finelev-lev)) 00124 ? extent-(finelev-lev) : 0); } 00125 inline int guExtentAbs(const int lev) const 00126 { return ((extent>=(finelev-lev)) ? extent-(finelev-lev) : 0); } 00127 00128 inline void guSetWorkload(const int w) { work = w; } 00129 unsigned inline long guNum(const int overlap) const { return work; } 00130 unsigned inline long guWork(const int overlap) const { return work; } 00131 unsigned inline long guNum(const int lev, const int overlap) const { return work; } 00132 unsigned inline long guWork(const int lev, const int overlap) const { return work; } 00133 00134 unsigned inline long guNum(const short* overlap) const { return work; } 00135 unsigned inline long guWork(const short* overlap) const { return work; } 00136 unsigned inline long guNum(const int lev, const short* overlap) const { return work; } 00137 unsigned inline long guWork(const int lev, const short* overlap) const { return work; } 00138 00139 inline int guContains(const int lev) const 00140 { return (lev<=finelev && lev>=crslev); } 00141 inline int guContains(const int minlev, const int maxlev) const 00142 { return (minlev<=finelev && maxlev>=crslev); } 00143 00144 inline int guLevIndex(const int lev) const 00145 { return ((lev-minlev)/levstep); } 00146 00147 //inline void guSetIndex(const int idx) { index = idx; } 00148 inline void guSetOwner(const int p) { owner = p; } 00149 00150 inline const dMapIndex& guBaseIndex(void) const { return (baseindex); } 00151 00152 dMapIndex guTopIndex(const int lev) const; 00153 dMapIndex guMaxIndex(const int lev) const; 00154 00155 private: 00156 void guLCoords(int *c, const int lev) const; 00157 Coords guLCoords(const int lev) const; 00158 00159 void guUCoords(int *c, const int lev) const; 00160 Coords guUCoords(const int lev) const; 00161 00162 void guSetBBox(); 00163 00164 public: 00165 const BBox& guBBox() const { return (fbb); } 00166 00167 BBox guBBox(const int lev, const int olap=0, const int extgh=0) const; 00168 BBox guBBoxAbs(const int lev, const int olap=0, const int extgh=0) const; 00169 00170 BBox guBBox(const int lev, const short* olap, const int extgh=0) const; 00171 BBox guBBoxAbs(const int lev, const short* olap, const int extgh=0) const; 00172 00173 BBox guBBox(const int minl, const int maxl, 00174 const short* olap, const int extgh=0) const; 00175 00176 int guInside(const BBox& bbox, const int lev) const; 00177 00179 int operator== (GridUnit const &other) const; 00180 int operator>= (GridUnit const &other) const; 00181 int operator<= (GridUnit const &other) const; 00182 00183 /* Operations on a GridUnit */ 00187 void guRefine(const int levs = 1); 00188 void guRefine(GridUnit &gu, const int levs = 1); 00189 00193 void guCoarsen(const int levs = 1); 00194 void guCoarsen(GridUnit &gu, const int levs = 1); 00195 00198 void guDecompose(GridUnit**& gu, int& cnt, const int levs = 1) const; 00201 void guDecomposeReplicate(GridUnit**& gu, int& cnt, const int minext, 00202 const int levs = 1) const; 00203 00204 /* An operator I would like to have */ 00205 //void guRecompose(GridUnit**& gu, const int cnt) const; 00206 00210 void guGetLevels(GridUnit** &gu) const; 00211 void guGetLevels(GridUnit &gu, const int lev) const; 00212 00214 inline void guSetDecompose(GridUnit& gu, 00215 const int lev, 00216 const int cnt) 00217 { gu.baselev+=lev; gu.extent-=lev; 00218 gu.baseindex.SetIndex(cnt,gu.baselev,lev); gu.guSetBBox(); 00219 gu.guSetWorkload ( gu.guWork(0)/gu.baseindex.GetCardinality(lev) ); 00220 } 00221 00222 inline void guSetLevels(GridUnit& gu, 00223 const int lev) 00224 { gu.extent-=(gu.finelev-lev); 00225 gu.crslev=lev; gu.finelev=lev; 00226 gu.baselev = gu.finelev-gu.extent; gu.guSetBBox(); } 00227 00228 inline void guSetRefineLevel(GridUnit& gu, 00229 const int levs=1) 00230 { gu.crslev=gu.finelev+gu.levstep; gu.finelev+=(levs*gu.levstep); 00231 gu.extent+=levs*gu.levstep; gu.baselev=gu.finelev-gu.extent; 00232 gu.guSetBBox(); } 00233 00234 inline void guSetCoarsen(GridUnit& gu, 00235 const int levs=1) 00236 { gu.finelev-=(levs*gu.levstep); gu.extent-=levs*gu.levstep; 00237 gu.baselev=gu.finelev-gu.extent; gu.guSetBBox(); } 00238 inline void guSetRefine(GridUnit& gu, 00239 const int levs=1) 00240 { gu.finelev+=(levs*gu.levstep); gu.extent+=levs*gu.levstep; 00241 gu.baselev=gu.finelev-gu.extent; gu.guSetBBox(); } 00242 }; 00243 00244 ostream& operator << (ostream& os, const GridUnit& gu); 00245 ofstream& operator << (ofstream& ofs, const GridUnit& gu); 00246 ifstream& operator >> (ifstream& ifs, GridUnit& gu); 00247 strstream& operator << (strstream& ofs, const GridUnit& gu); 00248 strstream& operator >> (strstream& ifs, GridUnit& gu); 00249 00250 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04