Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 #ifndef _included_GridUnitList_h 00002 #define _included_GridUnitList_h 00003 00009 #include "DAGHDefaults.h" 00010 #include "BBoxList.h" 00011 #include "GridUnit.h" 00012 #include "BucketType.h" 00013 #include "ObjectCounter.h" 00014 00015 #ifndef DefGridUnitListSize 00016 #define DefGridUnitListSize (128) 00017 #endif 00018 00019 #ifndef DefMinimumGUExtent 00020 #define DefMinimumGUExtent (1) 00021 #endif 00022 00023 #define GridUnitListNULL ((GridUnitList *) NULL) 00024 00025 // #ifdef __GNUG__ 00026 // template class Bucket<GridUnit>; 00027 // #endif 00028 00029 typedef Bucket<GridUnit> Bucket_GridUnit; 00030 00037 class GridUnitList : public Bucket<GridUnit>, public ObjectCounter 00038 { 00039 friend ostream& operator<<(ostream&, const GridUnitList&); 00040 friend ofstream& operator<<(ofstream&, const GridUnitList&); 00041 friend ifstream& operator>>(ifstream&, GridUnitList&); 00042 friend strstream& operator<<(strstream&, const GridUnitList&); 00043 friend strstream& operator>>(strstream&, GridUnitList&); 00044 00045 int num; 00046 00047 private: 00048 static inline void copytypedata(GridUnit *to, GridUnit const *from) 00049 { *to = *from; } 00050 00051 /*************************************************************************/ 00052 /*** Set list statistics ***/ 00053 /*************************************************************************/ 00054 inline void setstats(void) 00055 { 00056 num = 0; 00057 for (register GridUnit *g=first();g;g=next()) num++; 00058 } 00059 00060 public: 00061 /*************************************************************************/ 00062 /*** Constructors ***/ 00063 /*************************************************************************/ 00064 GridUnitList() 00065 : Bucket<GridUnit>(DefGridUnitListSize), num(0) {} 00066 00067 // We need dumarg because the SP2 does implicit conversions 00068 // from anything to this class 00069 GridUnitList(const unsigned maxnum, const int dumarg) 00070 : Bucket<GridUnit>(maxnum), num(0) {} 00071 00072 GridUnitList(const void* package) 00073 : Bucket<GridUnit>(package), num(0) { setstats(); } 00074 00075 GridUnitList(void *package) 00076 : Bucket<GridUnit>(package), num(0) { setstats(); } 00077 00078 GridUnitList(const void* package, const unsigned size, 00079 const int n) 00080 : Bucket<GridUnit>(package, size, n), num(0) 00081 { setstats(); } 00082 00083 GridUnitList(const GridUnitList& other) 00084 : Bucket<GridUnit>(other), num(other.num) {} 00085 00086 GridUnitList(GridUnitList**& levarray); 00087 00088 /*************************************************************************/ 00089 /*** Assignment operator ***/ 00090 /*************************************************************************/ 00091 GridUnitList& operator = (const GridUnitList&); 00092 00093 /*************************************************************************/ 00094 /*** The destructor ***/ 00095 /*************************************************************************/ 00096 inline ~GridUnitList(void) {} 00097 00098 /*************************************************************************/ 00099 /*** For the object counter ***/ 00100 /*************************************************************************/ 00101 inline GridUnitList *alias() 00102 { return((GridUnitList *) ObjectCounter::alias()); } 00103 00104 /*************************************************************************/ 00105 /*** GUL operators ***/ 00106 /*************************************************************************/ 00107 void operator -= (GridUnitList const &rhs); /* Difference */ 00108 void operator *= (GridUnitList const &rhs); /* Intersaction */ 00109 GridUnitList *operator - (GridUnitList const &rhs); /* Abs Difference */ 00110 GridUnitList *operator * (GridUnitList const &rhs); /* Intersection */ 00111 GridUnitList *operator + (GridUnitList const &rhs); /* Union */ 00112 00113 /*************************************************************************/ 00114 /*** GUL operations with a BBox & BBoxList ***/ 00115 /*************************************************************************/ 00116 public: 00117 void operator *= (BBox const &rhs); /* Intersection */ 00118 private: 00119 GridUnitList *operator * (BBox const &rhs); /* Intersection */ 00120 GridUnitList *operator * (BBoxList const &rhs); /* Intersection */ 00121 00122 /*************************************************************************/ 00123 /*** GUL intersection with a BBox & BBoxList ***/ 00124 /*************************************************************************/ 00125 public: 00126 void intersect(BBox const &rhs, const int lev, GridUnitList &gul, 00127 const int olap, const int extgh=0); 00128 void intersect(BBoxList const &rhs, const int lev, GridUnitList &gul, 00129 const int olap, const int extgh=0); 00130 void intersect(BBox const &rhs, const int lev, GridUnitList &gul, 00131 const short* olap, const int extgh=0); 00132 void intersect(BBoxList const &rhs, const int lev, GridUnitList &gul, 00133 const short* olap, const int extgh=0); 00134 00135 /*************************************************************************/ 00136 /*** Query functions ***/ 00137 /*************************************************************************/ 00138 public: 00139 inline int isempty() const { return(num == 0); } 00140 inline int number() const { return(num); } 00141 00142 unsigned long load(const int olap); 00143 unsigned long load(const int lev, const int olap); 00144 unsigned long numelems(const int olap); 00145 unsigned long numelems(const int lev, const int olap); 00146 00147 unsigned long load(const short* olap); 00148 unsigned long load(const int lev, const short* olap); 00149 unsigned long numelems(const short* olap); 00150 unsigned long numelems(const int lev, const short* olap); 00151 00152 int levels(void); 00153 int finest(void); 00154 int smallest(const int level); 00155 int highestbaselevel(); 00156 dMapIndex lowest(); 00157 dMapIndex lowest(const int level, const int owner, const int index); 00158 int maxindex(void); 00159 00160 /*************************************************************************/ 00161 /*** Set list stats ***/ 00162 /*************************************************************************/ 00163 private: 00164 void setindex(void); 00165 void setindex(const int idx); 00166 void setindex(const GridUnitList& cgul, const int idx); 00167 void setbbox(); 00168 public: 00169 void setowner(const int p); 00170 void setowner(const GridUnitList& cgul, const int p); 00171 /*************************************************************************/ 00172 /*** Empty the list ***/ 00173 /*************************************************************************/ 00174 inline void empty(void) 00175 { Bucket<GridUnit>::empty(); num = 0; } 00176 00177 /*************************************************************************/ 00178 /*** Inlined list manupilation functions ***/ 00179 /*************************************************************************/ 00180 inline GridUnit *add() 00181 { num++; return (Bucket<GridUnit>::add()); } 00182 inline GridUnit *add(GridUnit const &gu) 00183 { num++; return (Bucket<GridUnit>::add(gu)); } 00184 inline GridUnit *insert() 00185 { num++; return (Bucket<GridUnit>::insert()); } 00186 inline GridUnit *insert(GridUnit const &gu) 00187 { num++; return (Bucket<GridUnit>::insert(gu)); } 00188 inline void remove(void) 00189 { if (current()) { num--; Bucket<GridUnit>::remove(); }} 00190 00191 /*************************************************************************/ 00192 /*** Split the list at the current GridUnit ***/ 00193 /*************************************************************************/ 00194 void split(GridUnitList &gul); 00195 00196 /*************************************************************************/ 00197 /*** Array of GridUnitList's for the levels ***/ 00198 /*************************************************************************/ 00199 void levelarray(GridUnitList **& levarray, const int levels); 00200 00201 /*************************************************************************/ 00202 /*** GridUnitList for a particular level ***/ 00203 /*************************************************************************/ 00204 void levellist(GridUnitList &gul, 00205 const int lev); 00206 void levellist(GridUnitList &gul, 00207 const int minlev, 00208 const int maxlev); 00209 00210 /*************************************************************************/ 00211 /*** BBoxList for a particular level ***/ 00212 /*************************************************************************/ 00213 public: 00214 void bboxlistfinest(BBoxList &bbl, const int lev); 00215 void bboxlist(BBoxList &bbl, const int lev, const int olap); 00216 //, const int extgh=0); 00217 void bboxlist(BBoxList &bbl, const int lev, const int olap, 00218 const int levid); //, const int extgh=0); 00219 void bboxlist(BBoxList &bbl, const int lev, const short* olap, 00220 const int extgh); 00221 void bboxlist(BBoxList &bbl, const int lev, const short* olap, 00222 const int levid, const int extgh); 00223 /*************************************************************************/ 00225 /*************************************************************************/ 00226 GridUnitList *refinelist(const int atlev, const int levs=1); 00227 00228 /*************************************************************************/ 00229 /*** Refine as per bounding box list ***/ 00230 /*************************************************************************/ 00231 GridUnitList *refinelist(const BBoxList &bblist, 00232 const int atlev, 00233 const int minw); 00234 00235 void refinethislist(const BBoxList& bblist, 00236 const int atlev, 00237 const int minw); 00238 00239 /*************************************************************************/ 00240 /*** Operations on the current GridUnit ***/ 00241 /*************************************************************************/ 00242 private: 00243 inline void refine(const int lev = 1) 00244 { (current())->guRefine(lev); } 00245 inline void coarsen(const int lev = 1) 00246 { (current())->guCoarsen(lev); } 00247 00248 public: 00249 void decompose(const int lev = 1); 00250 00251 /*************************************************************************/ 00252 /*** Functions I'd like to have.... ***/ 00253 /*************************************************************************/ 00254 //void merge(GridUnitList const *levellist, const int level); 00255 //void coalesce(GridUnitList**& gularray, BBoxList const &bblist, 00256 // int &cnt, const int lev); 00257 }; 00258 00259 ostream& operator << (ostream& os, const GridUnitList& gul); 00260 ofstream& operator << (ofstream& ofs, const GridUnitList& gul); 00261 ifstream& operator >> (ifstream& ifs, GridUnitList& gul); 00262 strstream& operator << (strstream& ofs, const GridUnitList& gul); 00263 strstream& operator >> (strstream& ifs, GridUnitList& gul); 00264 00265 #endif
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04