Blockstructured Adaptive Mesh Refinement in object-oriented C++
00001 00006 #include "sfcIndex.h" 00007 00008 /* 00009 ************************************************************************* 00010 * * 00011 * sfcIndex const &sfcIndex::operator= (sfcIndex const &other) * 00012 * * 00013 * Overload the assignment operator for sfcIndex * 00014 * * 00015 ************************************************************************* 00016 */ 00017 00018 sfcIndex const &sfcIndex::operator= (sfcIndex const &other) 00019 { 00020 if(this != &other) 00021 { 00022 BitVec::operator=(other); 00023 sfcdim = other.sfcdim; 00024 sfclevs = other.sfclevs; 00025 sfcbase = other.sfcbase; 00026 sfcbasew = other.sfcbasew; 00027 sfcdigitw = other.sfcdigitw; 00028 00029 } 00030 return(*this); 00031 } 00032 00033 /* 00034 ************************************************************************* 00035 * * 00036 * int sfcIndex::operator== (sfcIndex const &other) const * 00037 * * 00038 * Overload the equality operator for sfcIndex * 00039 * * 00040 ************************************************************************* 00041 */ 00042 00043 int sfcIndex::operator== (sfcIndex const &other) const 00044 { 00045 #ifdef DEBUG_PRINT 00046 assert(sfcdim == other.sfcdim && 00047 sfclevs == other.sfclevs && 00048 sfcbase == other.sfcbase); 00049 #endif 00050 if(this == &other) return(1); 00051 return ( (BitVec::operator==(other)) ? 1 : 0 ); 00052 } 00053 00054 /* 00055 ************************************************************************* 00056 * * 00057 * int sfcIndex::operator> (sfcIndex const &other) const * 00058 * * 00059 * Overload the greater than operator for sfcIndex * 00060 * * 00061 ************************************************************************* 00062 */ 00063 00064 int sfcIndex::operator> (sfcIndex const &other) const 00065 { 00066 #ifdef DEBUG_PRINT 00067 assert(sfcdim == other.sfcdim && 00068 sfclevs == other.sfclevs && 00069 sfcbase == other.sfcbase); 00070 #endif 00071 if(this == &other) return(0); 00072 return ( (BitVec::operator>(other)) ? 1 : 0 ); 00073 } 00074 00075 /* 00076 ************************************************************************* 00077 * * 00078 * int sfcIndex::operator< (sfcIndex const &other) const * 00079 * * 00080 * Overload the less than operator for sfcIndex * 00081 * * 00082 ************************************************************************* 00083 */ 00084 00085 int sfcIndex::operator< (sfcIndex const &other) const 00086 { 00087 #ifdef DEBUG_PRINT 00088 assert(sfcdim == other.sfcdim && 00089 sfclevs == other.sfclevs && 00090 sfcbase == other.sfcbase); 00091 #endif 00092 if(this == &other) return(0); 00093 return ( (BitVec::operator<(other)) ? 1 : 0 ); 00094 } 00095 00096 /* 00097 ************************************************************************* 00098 * * 00099 * int sfcIndex::operator!= (sfcIndex const &other) const * 00100 * * 00101 * Overload the inequality operator for sfcIndex * 00102 * * 00103 ************************************************************************* 00104 */ 00105 00106 int sfcIndex::operator!= (sfcIndex const &other) const 00107 { 00108 #ifdef DEBUG_PRINT 00109 assert(sfcdim == other.sfcdim && 00110 sfclevs == other.sfclevs && 00111 sfcbase == other.sfcbase); 00112 #endif 00113 if(this == &other) return(0); 00114 return ( (BitVec::operator!=(other)) ? 1 : 0 ); 00115 } 00116 00117 /* 00118 ************************************************************************* 00119 * * 00120 * int sfcIndex::operator>= (sfcIndex const &other) const * 00121 * * 00122 * Overload the >= operator for sfcIndex * 00123 * * 00124 ************************************************************************* 00125 */ 00126 00127 int sfcIndex::operator>= (sfcIndex const &other) const 00128 { 00129 #ifdef DEBUG_PRINT 00130 assert(sfcdim == other.sfcdim && 00131 sfclevs == other.sfclevs && 00132 sfcbase == other.sfcbase); 00133 #endif 00134 if(this == &other) return(1); 00135 return ( (BitVec::operator>=(other)) ? 1 : 0 ); 00136 } 00137 00138 /* 00139 ************************************************************************* 00140 * * 00141 * int sfcIndex::operator<= (sfcIndex const &other) const * 00142 * * 00143 * Overload the <= operator for sfcIndex * 00144 * * 00145 ************************************************************************* 00146 */ 00147 00148 int sfcIndex::operator<= (sfcIndex const &other) const 00149 { 00150 #ifdef DEBUG_PRINT 00151 assert(sfcdim == other.sfcdim && 00152 sfclevs == other.sfclevs && 00153 sfcbase == other.sfcbase); 00154 #endif 00155 if(this == &other) return(1); 00156 return ( (BitVec::operator<=(other)) ? 1 : 0 ); 00157 } 00158 00159 /* 00160 ************************************************************************* 00161 * * 00162 * int sfcIndex::sfcGetDigit(const int level) const * 00163 * * 00164 * Member function sfcGetDigit returns the sfcIndexUnit (sfcdigitw bits) * 00165 * corresponding to level "level" of the sfc. * 00166 * * 00167 * Remember that the most-significant sfcIndexUnit corresponds to * 00168 * level 1. * 00169 * * 00170 ************************************************************************* 00171 */ 00172 int sfcIndex::sfcGetDigit(const int level) const 00173 { 00174 #ifdef DEBUG_PRINT 00175 assert(level>0 && level<=sfclevs); 00176 #endif 00177 int digit = IsolateBit((level-1)*sfcdigitw,sfcdigitw); 00178 return digit; 00179 } 00180 00181 /* 00182 ************************************************************************* 00183 * * 00184 * void sfcIndex::sfcSetDigit(const int level, const int digit) * 00185 * * 00186 * Member function sfcSetDigit sets the sfcIndexUnit (sfcdigitw bits) * 00187 * corresponding to level "level" of the sfc using "digit". * 00188 * * 00189 * Remember that the most-significant sfcIndexUnit corresponds to * 00190 * level 1. * 00191 * * 00192 ************************************************************************* 00193 */ 00194 00195 void sfcIndex::sfcSetDigit(const int level, 00196 const int digit) 00197 { 00198 #ifdef DEBUG_PRINT 00199 assert(level>0 && level<=sfclevs); 00200 #endif 00201 00202 for (register int i=0;i<sfcdigitw;i++) 00203 if((digit>>(sfcdigitw-1-i) & 1)) 00204 sfcSetDigitBit(level,i); 00205 else 00206 sfcUnsetDigitBit(level,i); 00207 } 00208 00209 /* 00210 ************************************************************************* 00211 * * 00212 * void sfcIndex::sfcUnsetDigit(const int level) * 00213 * * 00214 * Member function sfcUnsetDigit resets the sfcIndexUnit (sfcdigitw bits)* 00215 * corresponding to level "level" of the sfc. * 00216 * * 00217 * Remember that the most-significant sfcIndexUnit corresponds to * 00218 * level 1. * 00219 * * 00220 ************************************************************************* 00221 */ 00222 00223 void sfcIndex::sfcUnsetDigit(const int level) 00224 { 00225 #ifdef DEBUG_PRINT 00226 assert(level>0 && level<=sfclevs); 00227 #endif 00228 00229 for (register int i=0;i<sfcdigitw;i++) 00230 sfcUnsetDigitBit(level,i); 00231 } 00232 00233 /* 00234 ************************************************************************* 00235 * * 00236 * void sfcIndex::sfcMaxDigit(const int level) * 00237 * * 00238 * Member function sfcUnsetDigit set to all 1's the sfcIndexUnit * 00239 * (sfcdigitw bits) corresponding to level "level" of the sfc. * 00240 * * 00241 * Remember that the most-significant sfcIndexUnit corresponds to * 00242 * level 1. * 00243 * * 00244 ************************************************************************* 00245 */ 00246 00247 void sfcIndex::sfcMaxDigit(const int level) 00248 { 00249 #ifdef DEBUG_PRINT 00250 assert(level>0 && level<=sfclevs); 00251 #endif 00252 00253 for (register int i=0;i<sfcdigitw;i++) 00254 sfcSetDigitBit(level,i); 00255 } 00256 00257 /* 00258 ************************************************************************* 00259 * * 00260 * void sfcIndex::sfcSwapDigitWd(const int level, const int pos1, * 00261 * const int pos2) * 00262 * * 00263 * Member function sfcSwapDigitWd swaps sfcbasew bits at positions * 00264 * pos1 and pos2 in the sfcIndexUnit corresponding to level "level". * 00265 * sfcIndexUnit bits are numbered from 0 with the MSB being 0. * 00266 * * 00267 * Remember that the most-significant sfcIndexUnit corresponds to * 00268 * level 1. * 00269 * * 00270 ************************************************************************* 00271 */ 00272 00273 void sfcIndex::sfcSwapDigitWd(const int level, 00274 const int pos1, 00275 const int pos2) 00276 { 00277 00278 #ifdef DEBUG_PRINT 00279 assert(level>0 && level<=sfclevs && 00280 pos1>=0 && pos1<=(sfcdigitw-sfcbasew) && 00281 pos2>=0 && pos2<=(sfcdigitw-sfcbasew)); 00282 #endif 00283 00284 if (pos1 == pos2) return; 00285 00286 register int off1 = ((level-1)*sfcdim + pos1)*sfcbasew; 00287 register int off2 = ((level-1)*sfcdim + pos2)*sfcbasew; 00288 00289 for (register int i=0;i<sfcbasew;i++) 00290 SwapBit(off1+i, off2+i); 00291 } 00292 00293 /* 00294 ************************************************************************* 00295 * * 00296 * void sfcIndex::sfcToggleDigitWd(const int level, const int pos) * 00297 * * 00298 * Member function sfcToggleDigitWd toggles sfcbasew bits at pos in the * 00299 * sfcIndexUnit corresponding to level "level". * 00300 * sfcIndexUnit bits are numbered from 0 with the MSB being 0. * 00301 * * 00302 * Remember that the most-significant sfcIndexUnit corresponds to * 00303 * level 1. * 00304 * * 00305 ************************************************************************* 00306 */ 00307 00308 void sfcIndex::sfcToggleDigitWd(const int level, 00309 const int pos) 00310 { 00311 00312 #ifdef DEBUG_PRINT 00313 assert(level>0 && level<=sfclevs && 00314 pos>=0 && pos<=sfcdigitw-sfcbasew); 00315 #endif 00316 00317 for (register int i=0;i<sfcbasew;i++) 00318 sfcToggleDigitBit(level,pos+i); 00319 } 00320 00321 /* 00322 ************************************************************************* 00323 * * 00324 * void sfcIndex::sfcGetDigitArray(int *digits) const * 00325 * * 00326 * Member function sfcGetDigitArray returns the sfcdigitw bits * 00327 * corresponding to each sfcIndexUnit as an array of int. * 00328 * * 00329 ************************************************************************* 00330 */ 00331 00332 void sfcIndex::sfcGetDigitArray(int *digits) const 00333 { 00334 for (register int i=1;i<=sfclevs;i++) 00335 digits[i-1] = sfcGetDigit(i); 00336 } 00337 00338 /* 00339 ************************************************************************* 00340 * * 00341 * int sfcIndex::sfcGetIndex() const * 00342 * * 00343 * Member function sfcGetIndex returns the (int) integer value of * 00344 * the index. * 00345 * * 00346 ************************************************************************* 00347 */ 00348 00349 int sfcIndex::sfcGetIndex() const 00350 { 00351 int digit = 0; 00352 if(sfcbase == 2) 00353 { 00354 for (register int i=1;i<=sfclevs;i++) 00355 digit = (digit<<sfcdim) | sfcGetDigit(i); 00356 } 00357 else 00358 { 00359 register int off = 0; 00360 register int i = 0, j = 0; 00361 for (i=1;i<=sfclevs;i++) { 00362 off = (i-1)*sfcdigitw; 00363 for (j=0;j<sfcdim;j++) 00364 digit = digit*sfcbase + 00365 IsolateBit(off+(j*sfcbasew),sfcbasew); 00366 } 00367 } 00368 00369 return digit; 00370 } 00371 00372 /* 00373 ************************************************************************* 00374 * * 00375 * int sfcIndex::sfcGetIndex(const int lev) const * 00376 * * 00377 * Member function sfcGetIndex returns the (int) integer value of * 00378 * the index at level lev; i.e. only the first lev digits of the * 00379 * sfcIndex. * 00380 * * 00381 ************************************************************************* 00382 */ 00383 00384 int sfcIndex::sfcGetIndex(const int lev) const 00385 { 00386 #ifdef DEBUG_PRINT 00387 assert(lev > 0 && lev <= sfclevs); 00388 #endif 00389 00390 int digit = 0; 00391 if(sfcbase == 2) 00392 { 00393 for (register int i=1;i<=lev;i++) 00394 digit = (digit<<sfcdim) | sfcGetDigit(i); 00395 00396 return (digit); 00397 00398 /* left shift by (sfclevs-lev)*sfcdigitw bits. 00399 //return (digit << (sfclevs-lev)*sfcdim); 00400 */ 00401 } 00402 else 00403 { 00404 register int off = 0; 00405 register int i = 0, j = 0; 00406 for (i=1;i<=lev;i++) { 00407 off = (i-1)*sfcdigitw; 00408 for (j=0;j<sfcdim;j++) 00409 digit = digit*sfcbase + 00410 IsolateBit(off+(j*sfcbasew),sfcbasew); 00411 } 00412 /* left shift by (sfclevs-lev)*sfcdigitw bits. 00413 //for (i=lev+1;i<=sfclevs;i++) { 00414 // for (j=0;j<sfcdim;j++) 00415 // digit = digit*sfcbase; 00416 //} 00417 */ 00418 00419 return digit; 00420 } 00421 } 00422 00423 /* 00424 ************************************************************************* 00425 * * 00426 * int sfcIndex::sfcGetIndex(const int lev, const int nlev) const * 00427 * * 00428 * Member function sfcGetIndex returns the (int) integer value of * 00429 * the index from level lev-nlev+1 to level lev; * 00430 * * 00431 ************************************************************************* 00432 */ 00433 00434 int sfcIndex::sfcGetIndex(const int lev, const int nlev) const 00435 { 00436 #ifdef DEBUG_PRINT 00437 assert(lev > 0 && lev <= sfclevs); 00438 #endif 00439 00440 int digit = 0; 00441 if(sfcbase == 2) 00442 { 00443 for (register int i=lev-nlev+1;i<=lev;i++) 00444 digit = (digit<<sfcdim) | sfcGetDigit(i); 00445 00446 return digit; 00447 } 00448 else 00449 { 00450 register int off = 0; 00451 register int i = 0, j = 0; 00452 for (i=lev-nlev+1;i<=lev;i++) { 00453 off = (i-1)*sfcdigitw; 00454 for (j=0;j<sfcdim;j++) 00455 digit = digit*sfcbase + 00456 IsolateBit(off+(j*sfcbasew),sfcbasew); 00457 } 00458 00459 return digit; 00460 } 00461 } 00462 00463 /* 00464 ************************************************************************* 00465 * * 00466 * void sfcIndex::sfcSetIndex(const int index) * 00467 * * 00468 * Member function sfcSetIndex set the (int) integer value of * 00469 * the sfcIndex to "index". * 00470 * * 00471 ************************************************************************* 00472 */ 00473 00474 void sfcIndex::sfcSetIndex(const int index) 00475 { 00476 register int mask = ~((~0)<<sfcdigitw); 00477 00478 for (register int i=1;i<=sfclevs;i++) 00479 sfcSetDigit(i,(index>>sfcdigitw*(sfclevs-i))&mask); 00480 } 00481 00482 /* 00483 ************************************************************************* 00484 * * 00485 * void sfcIndex::sfcSetIndex(const int index, const int lev) * 00486 * * 00487 * Member function sfcSetIndex sets the (int) integer value of * 00488 * the sfcIndex at level lev (i.e. MSB lev*sfcdigitw bits) to "index". * 00489 * * 00490 ************************************************************************* 00491 */ 00492 00493 void sfcIndex::sfcSetIndex(const int index, const int lev) 00494 { 00495 #ifdef DEBUG_PRINT 00496 assert(lev > 0 && lev <= sfclevs); 00497 #endif 00498 00499 register int mask = ~((~0)<<sfcdigitw); 00500 00501 for (register int i=1;i<=lev;i++) 00502 sfcSetDigit(i,(index>>sfcdigitw*(lev-i))&mask); 00503 } 00504 00505 /* 00506 ************************************************************************* 00507 * * 00508 * void sfcIndex::sfcSetIndex(const int index, const int lev, * 00509 * const int nlev) * 00510 * * 00511 * Member function sfcSetIndex sets the (int) integer value of * 00512 * the sfcIndex from lev to lev+nlev-1 to "index". * 00513 * * 00514 ************************************************************************* 00515 */ 00516 00517 void sfcIndex::sfcSetIndex(const int index, const int lev, 00518 const int nlev) 00519 { 00520 #ifdef DEBUG_PRINT 00521 assert(lev >= nlev && lev <=sfclevs); 00522 #endif 00523 00524 register int mask = ~((~0)<<sfcdigitw); 00525 00526 for (register int i=nlev-1;i>=0;i--) 00527 sfcSetDigit(lev-i,(index>>(sfcdigitw*i))&mask); 00528 } 00529 00530 /* 00531 ************************************************************************* 00532 * * 00533 * void sfcIndex::sfcMaxIndex(const int lev) * 00534 * * 00535 ************************************************************************* 00536 */ 00537 00538 void sfcIndex::sfcMaxIndex(const int lev) 00539 { 00540 #ifdef DEBUG_PRINT 00541 assert(lev > 0 && lev <= sfclevs); 00542 #endif 00543 for (register int i=1;i<=lev;i++) sfcMaxDigit(i); 00544 } 00545 00546 /* 00547 ************************************************************************* 00548 * * 00549 * void sfcIndex::sfcCreateLocNum(const int *coords) * 00550 * * 00551 * Member function sfcCreateLocNum given the coordinates as follows: * 00552 * For example (3-D) let the coordinates be: * 00553 * x = xb1 xb2 xb3 ...... * 00554 * y = yb1 yb2 yb3 ...... * 00555 * z = zb1 zb2 zb3 ...... * 00556 * where xbi, ybj, zbk are base sfcbase (sfcbasew bits). * 00557 * Then the location number is defined as follows: * 00558 * (xb1 yb1 zb1) (xb2 yb2 zb2) (xb3 yb3 zb3)) ..... * 00559 * * 00560 ************************************************************************* 00561 */ 00562 00563 void sfcIndex::sfcCreateLocNum(const int *coords) 00564 { 00565 ResetVec(); 00566 register int i = 0, j = 0, k = 0; 00567 for (i=sfclevs;i>0;i--) 00568 for (j=0;j<sfcdim;j++) 00569 for (k=0;k<sfcbasew;k++) 00570 if (coords[j]>>((sfclevs-i)*sfcbasew+(sfcbasew-k-1)) & (int)1) 00571 sfcSetDigitBit(i,j*sfcbasew+k); 00572 } 00573 00574 /* 00575 ************************************************************************* 00576 * * 00577 * void sfcIndex::sfcGetCoords(int *coords) * 00578 * * 00579 * Member function sfcGetCoords returns an array of coordinates from the * 00580 * locations number. * 00581 * For example (3-D) let the location number be: * 00582 * (xb1 yb1 zb1) (xb2 yb2 zb2) (xb3 yb3 zb3)) ..... * 00583 * where xbi, ybj, zbk are base sfcbase (sfcbasew bits). * 00584 * Then the cordinates are as follows: * 00585 * x = xb1 xb2 xb3 ...... * 00586 * y = yb1 yb2 yb3 ...... * 00587 * z = zb1 zb2 zb3 ...... * 00588 * * 00589 ************************************************************************* 00590 */ 00591 00592 void sfcIndex::sfcGetCoords(int *coords) const 00593 { 00594 register int i = 0, j = 0; 00595 for (i=0;i<sfcdim;i++) 00596 coords[i] = 0; 00597 00598 register int off=0; 00599 for (i=1;i<=sfclevs;i++) { 00600 off = (i-1)*sfcdigitw; 00601 for (j=0;j<sfcdim;j++) { 00602 coords[j] = ((coords[j])<<sfcbasew) | 00603 IsolateBit(off+(j*sfcbasew),sfcbasew); 00604 } 00605 } 00606 } 00607 00608 ostream& operator << (ostream& os, sfcIndex const &si) 00609 { 00610 if (&si == (sfcIndex *)NULL) return os; 00611 for (register int i=1;i<=si.sfclevs;i++) 00612 os << si.sfcGetIndex(i,1); 00613 return os; 00614 }
Quickstart Users Guide Programmers Reference Installation Examples Download
AMROC Main Home Contactlast update: 06/01/04