Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 00006 #include "BBox.h" 00007 00008 #define MATCH(s, c) while ((s).get() != (c)) 00009 00010 /*************************************************************************/ 00011 /* Static empty bbox */ 00012 /*************************************************************************/ 00013 class BBox BBox::_empty_bbox; 00014 /*************************************************************************/ 00015 00016 /* 00017 ************************************************************************* 00018 * * 00019 * istream& operator >> (istream& s, BBox &bb) * 00020 * * 00021 * Operator >> reads in BBox information in the form [lower, upper, step]* 00022 * * 00023 ************************************************************************* 00024 */ 00025 00026 istream& operator >> (istream& s, BBox &bb) 00027 { 00028 Coords low(bb.rank,0), high(bb.rank,0); 00029 Coords step(bb.rank,0); 00030 00031 MATCH(s, '['); 00032 s >> low; 00033 MATCH(s, ','); 00034 s >> high; 00035 MATCH(s, ','); 00036 s >> step; 00037 MATCH(s, ']'); 00038 00039 BBox newbb(low, high, step); 00040 bb = newbb; 00041 return(s); 00042 } 00043 00044 /* 00045 ************************************************************************* 00046 * * 00047 * ostream& operator << (ostream& s, BBox const &bb) * 00048 * * 00049 * Operator << writes the point information in bb as [lower, upper]. * 00050 * * 00051 ************************************************************************* 00052 */ 00053 00054 ostream& operator << (ostream& s, BBox const &bb) 00055 { 00056 if (bb.empty()) 00057 s << "[(),()]"; 00058 else { 00059 s << '['; 00060 s << bb.lower(); 00061 s << ','; 00062 s << bb.upper(); 00063 s << ','; 00064 s << bb.stepsize(); 00065 s << ','; 00066 s << bb.rank; 00067 s << ']'; 00068 } 00069 return(s); 00070 } 00071 00072 /* 00073 ************************************************************************* 00074 * * 00075 * ifstream& operator >> (ifstream& s, BBox& bb) * 00076 * ofstream& operator << (ofstream& s, const BBox& bb) * 00077 * * 00078 ************************************************************************* 00079 */ 00080 00081 ifstream& operator >> (ifstream& s, BBox& bb) 00082 { 00083 if (&bb == (BBox *)NULL) return s; 00084 00085 s.read((char*)&bb,sizeof(BBox)); 00086 00087 return s; 00088 } 00089 00090 ofstream& operator << (ofstream& s, const BBox& bb) 00091 { 00092 if (&bb == (BBox *)NULL) return s; 00093 00094 s.write((char*)&bb,sizeof(BBox)); 00095 00096 return s; 00097 } 00098 00099 /* 00100 ************************************************************************* 00101 * * 00102 * strstream& operator >> (strstream& s, BBox& bb) * 00103 * strstream& operator << (strstream& s, const BBox& bb) * 00104 * * 00105 ************************************************************************* 00106 */ 00107 00108 strstream& operator >> (strstream& s, BBox& bb) 00109 { 00110 if (&bb == (BBox *)NULL) return s; 00111 00112 s.read((char*)&bb,sizeof(BBox)); 00113 00114 return s; 00115 } 00116 00117 strstream& operator << (strstream& s, const BBox& bb) 00118 { 00119 if (&bb == (BBox *)NULL) return s; 00120 00121 s.write((char*)&bb,sizeof(BBox)); 00122 00123 return s; 00124 } 00125 00126 /* 00127 ************************************************************************* 00128 * * 00129 * BBox &BBox::operator += (BBox cosnt &rhs) * 00130 * int BBox::operator == (BBox cosnt &rhs) const * 00131 * * 00132 ************************************************************************* 00133 */ 00134 00135 /*$BBox &BBox::operator += (Coords const &rhs) 00136 { 00137 if (empty()) { lb = rhs; ub = rhs; return(*this); } 00138 lb.min(rhs); 00139 ub.max(rhs); 00140 return(*this); 00141 } 00142 00143 BBox &BBox::operator += (BBox const &rhs) 00144 { 00145 if (empty()) return(*this = rhs); 00146 if (rhs.empty()) return(*this); 00147 lb.min(rhs.lb); 00148 ub.max(rhs.ub); 00149 return(*this); 00150 } 00151 00152 int BBox::operator == (BBox const &rhs) const 00153 { 00154 return(((ub == rhs.ub) && (lb == rhs.lb)) || (empty() && rhs.empty())); 00155 }$*/ 00156 00157 /* 00158 ************************************************************************* 00159 * * 00160 * The mergable functions checks is two bounding boxes are mergable in * 00161 * a given direction. * 00162 * * 00163 ************************************************************************* 00164 */ 00165 00166 /*$int BBox::mergable(BBox const &rhs, const short* olap) const 00167 { 00168 int flag = 0; 00169 for (int r=rank-1;r>=0;r--) 00170 flag = (flag || mergable(rhs, r, olap[r])); 00171 00172 return flag; 00173 } 00174 00175 int BBox::mergable(BBox const &rhs, const int d, const int olap) const 00176 { 00177 int flag = 0; 00178 00179 switch (rank) 00180 { 00181 case 1: 00182 assert (d < 1); 00183 flag = (abs(lb(d) - rhs.ub(d)) == (1-olap)*step(d)) || 00184 (abs(ub(d) - rhs.lb(d)) == (1-olap)*step(d)); 00185 break; 00186 case 2: 00187 assert (d < 2); 00188 flag = compatible(rhs,(d+1)%2) && 00189 ((abs(lb(d) - rhs.ub(d)) == (1-olap)*step(d)) || 00190 (abs(ub(d) - rhs.lb(d)) == (1-olap)*step(d))); 00191 break; 00192 case 3: 00193 assert (d < 3); 00194 flag = compatible(rhs,(d+1)%3) && 00195 compatible(rhs,(d+2)%3) && 00196 ((abs(lb(d) - rhs.ub(d)) == (1-olap)*step(d)) || 00197 (abs(ub(d) - rhs.lb(d)) == (1-olap)*step(d))); 00198 break; 00199 } 00200 00201 return flag; 00202 }$*/ 00203 00204 /* 00205 ************************************************************************* 00206 * * 00207 * The accrete() and grow() functions increase the size of a region. * 00208 * Both accrete() and grow() do the same thing. The CC compiler had * 00209 * some trouble inlining them, so we define them here. * 00210 * * 00211 ************************************************************************* 00212 */ 00213 00214 /*$BBox accrete(BBox const &bbox, Coords const &c) 00215 { 00216 if (bbox.empty()) return(bbox); 00217 return(BBox(bbox.lower()-c*bbox.stepsize(), bbox.upper()+c*bbox.stepsize(), 00218 bbox.stepsize())); 00219 } 00220 00221 BBox grow(BBox const &bbox, Coords const &c) 00222 { 00223 if (bbox.empty()) return(bbox); 00224 return(BBox(bbox.lower()-c*bbox.stepsize(), bbox.upper()+c*bbox.stepsize(), 00225 bbox.stepsize())); 00226 } 00227 00228 BBox accrete(BBox const &bbox, const int c) 00229 { 00230 if (bbox.empty()) return(bbox); 00231 return(BBox(bbox.lower()-bbox.stepsize()*c, bbox.upper()+bbox.stepsize()*c, 00232 bbox.stepsize())); 00233 } 00234 00235 BBox grow(BBox const &bbox, const int c) 00236 { 00237 if (bbox.empty()) return(bbox); 00238 return(BBox(bbox.lower()-bbox.stepsize()*c, bbox.upper()+bbox.stepsize()*c, 00239 bbox.stepsize())); 00240 }$*/ 00241 00242 BBox* accrete(BBox const *const bbox, const int n, const int c) 00243 { 00244 BBox **accreted = new BBox *[n]; 00245 for (register int i = 0; i < n; i++) 00246 accreted[i] = new BBox(accrete(bbox[i], c)); 00247 00248 return(*accreted); 00249 } 00250 00251 BBox* grow(BBox const *const bbox, const int n, const int c) 00252 { 00253 BBox **grown = new BBox *[n]; 00254 for (register int i = 0; i < n; i++) 00255 grown[i] = new BBox(grow(bbox[i], c)); 00256 00257 return(*grown); 00258 } 00259 00260 BBox* accrete(BBox const *const bbox, const int n, Coords const &c) 00261 { 00262 BBox **accreted = new BBox *[n]; 00263 for (register int i = 0; i < n; i++) 00264 accreted[i] = new BBox(accrete(bbox[i], c)); 00265 00266 return(*accreted); 00267 } 00268 00269 BBox* grow(BBox const *const bbox, const int n, Coords const &c) 00270 { 00271 BBox **grown = new BBox *[n]; 00272 for (register int i = 0; i < n; i++) 00273 grown[i] = new BBox(grow(bbox[i], c)); 00274 00275 return(*grown); 00276 } 00277 00278 /*$BBox growupper(BBox const &bbox, const int c) 00279 { 00280 if (bbox.empty()) return(bbox); 00281 return(BBox(bbox.lower(), bbox.upper()+bbox.stepsize()*c, bbox.stepsize())); 00282 } 00283 00284 BBox growlower(BBox const &bbox, const int c) 00285 { 00286 if (bbox.empty()) return(bbox); 00287 return(BBox(bbox.lower()+bbox.stepsize()*c, bbox.upper(), bbox.stepsize())); 00288 } 00289 00290 BBox growupper(BBox const &bbox, const int d, const int c) 00291 { 00292 if (bbox.empty()) return(bbox); 00293 Coords u = bbox.upper(); u(d) += c*bbox.stepsize(d); 00294 return(BBox(bbox.lower(), u, bbox.stepsize())); 00295 } 00296 00297 BBox growlower(BBox const &bbox, const int d, const int c) 00298 { 00299 if (bbox.empty()) return(bbox); 00300 Coords l = bbox.lower(); l(d) += c*bbox.stepsize(d); 00301 return(BBox(l, bbox.upper(), bbox.stepsize())); 00302 }$*/ 00303 00304 /*$BBox growbydim (BBox const &bbox, const short *c) 00305 { 00306 BBox bb(bbox); 00307 if (bb.empty()) return(bb); 00308 for (int i=0;i<bb.rank;i++) { 00309 bb.lower(i) -= (bb.stepsize(i)*c[2*i]); 00310 bb.upper(i) += (bb.stepsize(i)*c[2*i+1]); 00311 } 00312 return bb; 00313 } 00314 00315 BBox growupperbydim (BBox const &bbox, const short *c) 00316 { 00317 BBox bb(bbox); 00318 if (bb.empty()) return(bb); 00319 for (int i=0;i<bb.rank;i++) { 00320 bb.upper(i) += (bb.stepsize(i)*c[i]); 00321 } 00322 return bb; 00323 } 00324 00325 BBox growlowerbydim (BBox const &bbox, const short *c) 00326 { 00327 BBox bb(bbox); 00328 if (bb.empty()) return(bb); 00329 for (int i=0;i<bb.rank;i++) { 00330 bb.lower(i) += (bb.stepsize(i)*c[i]); 00331 } 00332 return bb; 00333 } 00334 00335 BBox shrinkbydim (BBox const &bbox, const short *c) 00336 { 00337 BBox bb(bbox); 00338 if (bb.empty()) return(bb); 00339 for (int i=0;i<bb.rank;i++) { 00340 bb.lower(i) += (bb.stepsize(i)*c[2*i]); 00341 bb.upper(i) -= (bb.stepsize(i)*c[2*i+1]); 00342 } 00343 return bb; 00344 } 00345 00346 BBox shrinkupperbydim (BBox const &bbox, const short *c) 00347 { 00348 BBox bb(bbox); 00349 if (bb.empty()) return(bb); 00350 for (int i=0;i<bb.rank;i++) { 00351 bb.upper(i) -= (bb.stepsize(i)*c[i]); 00352 } 00353 return bb; 00354 } 00355 00356 BBox shrinklowerbydim (BBox const &bbox, const short *c) 00357 { 00358 BBox bb(bbox); 00359 if (bb.empty()) return(bb); 00360 for (int i=0;i<bb.rank;i++) { 00361 bb.lower(i) -= (bb.stepsize(i)*c[i]); 00362 } 00363 return bb; 00364 }$*/ 00365 00366 /* Function shift() shifts the space of the region */ 00367 /*$BBox shiftabs(BBox const &bb, const int c) 00368 { return(BBox(bb.lower()+c, bb.upper()+c, bb.stepsize())); } 00369 BBox shiftabs(BBox const &bb, Coords const &c) 00370 { return(BBox(bb.lower()+c, bb.upper()+c, bb.stepsize())); } 00371 00372 BBox shift(BBox const &bb, const int c) 00373 { return(BBox(bb.lower()+bb.stepsize()*c, bb.upper()+bb.stepsize()*c, 00374 bb.stepsize())); } 00375 BBox shift(BBox const &bb, Coords const &c) 00376 { return(BBox(bb.lower()+c*bb.stepsize(), bb.upper()+c*bb.stepsize(), 00377 bb.stepsize())); } 00378 00379 BBox shiftabs(BBox const &bbox, const int d, const int c) 00380 { 00381 if (bbox.empty()) return(bbox); 00382 Coords u = bbox.upper(); u(d) += c; 00383 Coords l = bbox.lower(); l(d) += c; 00384 return(BBox(l, u, bbox.stepsize())); 00385 } 00386 00387 BBox shift(BBox const &bbox, const int d, const int c) 00388 { 00389 if (bbox.empty()) return(bbox); 00390 Coords u = bbox.upper(); u(d) += c*bbox.stepsize(d); 00391 Coords l = bbox.lower(); l(d) += c*bbox.stepsize(d); 00392 return(BBox(l, u, bbox.stepsize())); 00393 }$*/ 00394 00395 /* Function coarsen() coarsens the BBox by a given factor */ 00396 /*$BBox coarsen(BBox const &bbox, const int by) 00397 { 00398 if (bbox.empty()) return(bbox); 00399 Coords s = bbox.stepsize() * by; 00400 Coords l = (bbox.lower() / s ) * s; 00401 Coords u = (bbox.upper() / s ) * s; 00402 return(BBox(l, u, s)); 00403 } 00404 00405 BBox coarsen(BBox const &bbox, Coords const by) 00406 { 00407 if (bbox.empty()) return(bbox); 00408 Coords s = bbox.stepsize() * by; 00409 Coords l = (bbox.lower() / s ) * s; 00410 Coords u = (bbox.upper() / s ) * s; 00411 return(BBox(l, u, s)); 00412 } 00413 00414 BBox coarsen(BBox const &bbox, const int d, const int by) 00415 { 00416 if (bbox.empty()) return(bbox); 00417 Coords s = bbox.stepsize(); s(d) *= by; 00418 Coords l = (bbox.lower() / s ) * s; 00419 Coords u = (bbox.upper() / s ) * s; 00420 return(BBox(l, u, s)); 00421 }$*/ 00422
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04