00001 #include <cassert>
00002 #include "SPACE.H"
00003 #include "WriteRectMDArray.H"
00004 #include <math.h>
00005
00006
00007 template<class T, unsigned int C, unsigned char D, unsigned char E>
00008 LevelData<T,C,D,E>::LevelData()
00009 {
00010 }
00011
00012 template<class T, unsigned int C, unsigned char D, unsigned char E>
00013 LevelData<T, C, D, E>::
00014 ~LevelData()
00015 {
00016 }
00017
00018
00019 template<class T, unsigned int C, unsigned char D, unsigned char E>
00020 void
00021 LevelData<T, C, D, E>::
00022 define(const BoxLayout a_boxLayout, int a_ghostSize, int a_coarseningFactor)
00023 {
00024 m_boxLayout = a_boxLayout;
00025 m_ghostSize = a_ghostSize;
00026 m_coarseningFactor = a_coarseningFactor;
00027 assert(a_coarseningFactor == 1);
00028 int boxsize = a_boxLayout.getBoxsize();
00029
00030 Point lc;
00031 Point hc;
00032 vector<Point> points = m_boxLayout.getPatchLocs();
00033 m_data.resize(points.size());
00034 for (vector<Point>::iterator it = points.begin(); it != points.end(); ++it)
00035 {
00036 Point p = *it;
00037 lc = p * boxsize / m_coarseningFactor;
00038 hc = (p * boxsize + getOnes() * (boxsize-1)) / m_coarseningFactor;
00039 m_data[m_boxLayout.getPatchIndex(*it)] = RectMDArray<T,C,D,E>(Box(lc,hc).grow(m_ghostSize));
00040 }
00041 };
00042
00043
00044 template<class T, unsigned int C, unsigned char D, unsigned char E>
00045 LevelData<T, C, D, E>::
00046 LevelData(const BoxLayout a_boxLayout,int a_ghostSize,int a_coarseningFactor)
00047 {
00048 (*this).define(a_boxLayout,a_ghostSize, a_coarseningFactor);
00049 }
00050
00051 template<class T, unsigned int C, unsigned char D, unsigned char E>
00052 const RectMDArray<T, C, D, E>&
00053 LevelData<T, C, D, E>::
00054 operator[](int a_index) const
00055 {
00056 return m_data[a_index];
00057 }
00058
00059 template<class T, unsigned int C, unsigned char D, unsigned char E>
00060 const RectMDArray<T, C, D, E>&
00061 LevelData<T, C, D, E>::
00062 operator[](Point& a_pt) const
00063 {
00064
00065
00066 return m_data[m_boxLayout.getPatchIndex(a_pt)];
00067 }
00068
00069 template<class T, unsigned int C, unsigned char D, unsigned char E>
00070 RectMDArray<T, C, D, E>&
00071 LevelData<T, C, D, E>::
00072 operator[](int a_index)
00073 {
00074 return m_data[a_index];
00075 }
00076
00077 template<class T, unsigned int C, unsigned char D, unsigned char E>
00078 RectMDArray<T, C, D, E>&
00079 LevelData<T, C, D, E>::
00080 operator[](Point& a_pt)
00081 {
00082
00083
00084 return m_data[m_boxLayout.getPatchIndex(a_pt)];
00085 }
00086
00087 template<class T, unsigned int C, unsigned char D, unsigned char E>
00088 int
00089 LevelData<T, C, D, E>::
00090 getGhostSize() const
00091 {
00092 return m_ghostSize;
00093 }
00094
00095 template<class T, unsigned int C, unsigned char D, unsigned char E>
00096 T
00097 LevelData<T, C, D, E>::
00098 mod(T& a_lhs, T& a_rhs) const
00099 {
00100 return fmod(fmod(a_lhs, a_rhs) + a_rhs, a_rhs);
00101
00102 }
00103
00104 template<class T, unsigned int C, unsigned char D, unsigned char E>
00105 void
00106 LevelData<T, C, D, E>::
00107 setVal(const T & a_val)
00108 {
00109 BLIterator iterator(m_boxLayout);
00110 for (iterator = iterator.begin(); iterator != iterator.end(); ++iterator)
00111 {
00112 Point point = *iterator;
00113 RectMDArray<T, C, D, E> & thisRMDA = (*this)[point];
00114 thisRMDA.setVal(a_val);
00115 }
00116 }
00117
00118 template<class T, unsigned int C, unsigned char D, unsigned char E>
00119 void
00120 LevelData<T, C, D, E>::
00121 copyTo(LevelData& a_dest, bool a_copyGhost) const
00122 {
00123 CH_TIMERS("LevelData::copyTo");
00124 assert(m_boxLayout.getDomain()==a_dest.m_boxLayout.getDomain());
00125 if (m_boxLayout.sameBLI(a_dest.m_boxLayout))
00126 {
00127 const RectMDArray<bool>& sourceBitmap = m_boxLayout.getBitmap();
00128 const RectMDArray<bool>& destBitmap = a_dest.getBoxLayout().getBitmap();
00129 BLIterator iterator(m_boxLayout);
00130 Point no_shift(getZeros());
00131 for (iterator = iterator.begin(); iterator != iterator.end(); ++iterator)
00132 {
00133 Point point = *iterator;
00134 if (destBitmap[point]) {
00135
00136 RectMDArray<T, C, D, E> & destRMDA = a_dest[point];
00137 const RectMDArray<T, C, D, E> & sourceRMDA = (*this)[point];
00138 if (a_copyGhost) {
00139 sourceRMDA.copyTo(destRMDA);
00140 } else {
00141 sourceRMDA.copyTo(destRMDA,m_boxLayout[point],no_shift);
00142
00143 }
00144 }
00145 }
00146 }
00147
00148 else if (m_boxLayout.getBlockPower() < a_dest.m_boxLayout.getBlockPower())
00149 {
00150 int refratio = m_boxLayout.getBoxsize()/a_dest.m_boxLayout.getBoxsize();
00151 const RectMDArray<bool>& sourceBitmap = m_boxLayout.getBitmap();
00152 const RectMDArray<bool>& destBitmap = a_dest.getBoxLayout().getBitmap();
00153
00154 BLIterator iterator(a_dest.m_boxLayout);
00155 Point no_shift(getZeros());
00156
00157 for (iterator = iterator.begin(); iterator != iterator.end(); ++iterator)
00158 {
00159 Point point = *iterator;
00160 Point pointSrc = point / refratio;
00161 if (sourceBitmap[pointSrc])
00162 {
00163
00164
00165 RectMDArray<T, C, D, E> & destRMDA = a_dest[point];
00166 const RectMDArray<T, C, D, E> & sourceRMDA = (*this)[pointSrc];
00167 if (a_copyGhost) {
00168 sourceRMDA.copyTo(destRMDA);
00169 } else {
00170 sourceRMDA.copyTo(destRMDA,m_boxLayout[pointSrc],no_shift);
00171
00172
00173 }
00174 }
00175 }
00176
00177 }
00178
00179 else
00180 {
00181 int refratio = a_dest.m_boxLayout.getBoxsize()/m_boxLayout.getBoxsize();
00182 const RectMDArray<bool>& sourceBitmap = m_boxLayout.getBitmap();
00183 const RectMDArray<bool>& destBitmap = a_dest.getBoxLayout().getBitmap();
00184 BLIterator iterator(m_boxLayout);
00185 Point no_shift(getZeros());
00186
00187 for (iterator = iterator.begin(); iterator != iterator.end(); ++iterator)
00188 {
00189 Point point = *iterator;
00190 Point pointDst = point / refratio;
00191
00192 if (destBitmap[pointDst])
00193 {
00194
00195 RectMDArray<T, C, D, E> & destRMDA = a_dest[pointDst];
00196 const RectMDArray<T, C, D, E> & sourceRMDA = (*this)[point];
00197 if (a_copyGhost) {
00198 sourceRMDA.copyTo(destRMDA);
00199 } else {
00200 sourceRMDA.copyTo(destRMDA,m_boxLayout[point],no_shift);
00201 }
00202 }
00203 }
00204
00205 }
00206 }
00207
00208 template<class T, unsigned int C, unsigned char D, unsigned char E>
00209 Box
00210 LevelData<T, C, D, E>::
00211 getGhostBox(const Box& a_validBox, const int a_idir, const int& a_side)
00212 {
00213
00214 Point hi, lo;
00215 Point growVec = getUnitv(a_idir);
00216 growVec *= m_ghostSize;
00217
00218 if(a_side == 1)
00219 {
00220 hi = a_validBox.getHighCorner() + growVec;
00221 lo = a_validBox.getLowCorner() + getUnitv(a_idir)*a_validBox.size(a_idir);
00222
00223
00224 }
00225 else
00226 {
00227 lo = a_validBox.getLowCorner() - growVec;
00228 hi = a_validBox.getHighCorner() - getUnitv(a_idir)*a_validBox.size(a_idir);
00229
00230
00231 }
00232 Box retval = Box(lo,hi);
00233 return retval;
00234 }
00235
00236 template<class T, unsigned int C, unsigned char D, unsigned char E>
00237 void
00238 LevelData<T, C, D, E>::
00239 getPeriodicEdgeNeighborInfo(Point & a_neighborPt,
00240 Box & a_neighborValid,
00241 Point & a_shiftdom,
00242 const Point & a_p,
00243 const int & a_idir,
00244 const int & a_iside,
00245 const int & a_jdir,
00246 const int & a_jside)
00247 {
00248 const RectMDArray<bool>& bitmap = m_boxLayout.getBitmap();
00249
00250 Point pshifti = getUnitv(a_idir);
00251 Point pshiftj = getUnitv(a_jdir);
00252 pshifti *= a_iside;
00253 pshiftj *= a_jside;
00254 pshifti += a_p;
00255 pshiftj += a_p;
00256 if(bitmap.getBox().contains(pshifti))
00257 {
00258
00259 int domLen = m_boxLayout.getDomain().size(a_jdir);
00260 int bitmaplen = bitmap.getBox().size(a_jdir);
00261 int ishift = -(bitmaplen-1)*a_jside;
00262 a_neighborPt = pshifti;
00263 a_neighborPt[a_jdir] += ishift;
00264 a_shiftdom = getUnitv(a_jdir);
00265 a_shiftdom *= -a_jside*domLen;
00266 }
00267 else if(bitmap.getBox().contains(pshiftj))
00268 {
00269
00270 int domLen = m_boxLayout.getDomain().size(a_idir);
00271 int bitmaplen = bitmap.getBox().size(a_idir);
00272 int ishift = -(bitmaplen-1)*a_iside;
00273 a_neighborPt = pshiftj;
00274 a_neighborPt[a_idir] += ishift;
00275 a_shiftdom = getUnitv(a_idir);
00276 a_shiftdom *= -a_iside*domLen;
00277 }
00278 else
00279 {
00280
00281 int domLeni = m_boxLayout.getDomain().size(a_idir);
00282 int domLenj = m_boxLayout.getDomain().size(a_jdir);
00283 int bitmapleni = bitmap.getBox().size(a_idir);
00284 int bitmaplenj = bitmap.getBox().size(a_jdir);
00285 int ishift = -(bitmapleni-1)*a_iside;
00286 int jshift = -(bitmaplenj-1)*a_jside;
00287 a_neighborPt = a_p;
00288 a_neighborPt[a_idir] += ishift;
00289 a_neighborPt[a_jdir] += jshift;
00290 Point shiftdomi = getUnitv(a_idir);
00291 Point shiftdomj = getUnitv(a_jdir);
00292 shiftdomi *= -a_iside*domLeni;
00293 shiftdomj *= -a_jside*domLenj;
00294 a_shiftdom = shiftdomi + shiftdomj;
00295 }
00296
00297 if(bitmap[a_neighborPt])
00298 {
00299 a_neighborValid = m_boxLayout[a_neighborPt];
00300 }
00301 }
00302
00303 template<class T, unsigned int C, unsigned char D, unsigned char E>
00304 void
00305 LevelData<T, C, D, E>::
00306 getPeriodicCornerNeighborInfo(Point & a_neighborPt,
00307 Box & a_neighborValid,
00308 Point & a_shiftdom,
00309 const Point & a_p,
00310 const int & a_idir,
00311 const int & a_iside,
00312 const int & a_jdir,
00313 const int & a_jside,
00314 const int & a_kdir,
00315 const int & a_kside)
00316 {
00317 const RectMDArray<bool>& bitmap = m_boxLayout.getBitmap();
00318
00319 Point pshifti = getUnitv(a_idir);
00320 Point pshiftj = getUnitv(a_jdir);
00321 Point pshiftk = getUnitv(a_kdir);
00322 pshifti *= a_iside;
00323 pshiftj *= a_jside;
00324 pshiftk *= a_kside;
00325
00326
00327 Point ppi = a_p +pshifti;
00328 Point ppj = a_p +pshiftj;
00329 Point ppk = a_p +pshiftk;
00330
00331 if((bitmap.getBox().contains(ppi)) && (bitmap.getBox().contains(ppk)))
00332 {
00333
00334 int domLen = m_boxLayout.getDomain().size(a_jdir);
00335 int bitmaplen = bitmap.getBox().size(a_jdir);
00336 int jshift = -(bitmaplen-1)*a_jside;
00337 a_neighborPt = a_p + pshifti + pshiftk;
00338 a_neighborPt[a_jdir] += jshift;
00339 a_shiftdom = getUnitv(a_jdir);
00340 a_shiftdom *= -a_jside*domLen;
00341 }
00342 else if(bitmap.getBox().contains(ppj) && bitmap.getBox().contains(ppk))
00343 {
00344
00345 int domLen = m_boxLayout.getDomain().size(a_idir);
00346 int bitmaplen = bitmap.getBox().size(a_idir);
00347 int ishift = -(bitmaplen-1)*a_iside;
00348 a_neighborPt = a_p + pshiftj + pshiftk;
00349 a_neighborPt[a_idir] += ishift;
00350 a_shiftdom = getUnitv(a_idir);
00351 a_shiftdom *= -a_iside*domLen;
00352 }
00353 else if(bitmap.getBox().contains(ppj) && bitmap.getBox().contains(ppi))
00354 {
00355
00356 int domLen = m_boxLayout.getDomain().size(a_kdir);
00357 int bitmaplen = bitmap.getBox().size(a_kdir);
00358 int ishift = -(bitmaplen-1)*a_kside;
00359 a_neighborPt = a_p + pshifti + pshiftj;
00360 a_neighborPt[a_kdir] += ishift;
00361 a_shiftdom = getUnitv(a_kdir);
00362 a_shiftdom *= -a_iside*domLen;
00363 }
00364 else if (bitmap.getBox().contains(ppk))
00365 {
00366
00367 int domLeni = m_boxLayout.getDomain().size(a_idir);
00368 int domLenj = m_boxLayout.getDomain().size(a_jdir);
00369 int bitmapleni = bitmap.getBox().size(a_idir);
00370 int bitmaplenj = bitmap.getBox().size(a_jdir);
00371 int ishift = -(bitmapleni-1)*a_iside;
00372 int jshift = -(bitmaplenj-1)*a_jside;
00373 a_neighborPt = a_p + pshiftk;
00374 a_neighborPt[a_idir] += ishift;
00375 a_neighborPt[a_jdir] += jshift;
00376 Point shiftdomi = getUnitv(a_idir);
00377 Point shiftdomj = getUnitv(a_jdir);
00378 shiftdomi *= -a_iside*domLeni;
00379 shiftdomj *= -a_jside*domLenj;
00380 a_shiftdom = shiftdomi + shiftdomj;
00381 }
00382 else if(bitmap.getBox().contains(ppi))
00383 {
00384
00385 int domLenk = m_boxLayout.getDomain().size(a_kdir);
00386 int domLenj = m_boxLayout.getDomain().size(a_jdir);
00387 int bitmaplenk = bitmap.getBox().size(a_kdir);
00388 int bitmaplenj = bitmap.getBox().size(a_jdir);
00389 int kshift = -(bitmaplenk-1)*a_kside;
00390 int jshift = -(bitmaplenj-1)*a_jside;
00391 a_neighborPt = a_p + pshifti;
00392 a_neighborPt[a_kdir] += kshift;
00393 a_neighborPt[a_jdir] += jshift;
00394 Point shiftdomk = getUnitv(a_kdir);
00395 Point shiftdomj = getUnitv(a_jdir);
00396 shiftdomk *= -a_kside*domLenk;
00397 shiftdomj *= -a_jside*domLenj;
00398 a_shiftdom = shiftdomk + shiftdomj;
00399 }
00400 else if(bitmap.getBox().contains(ppj))
00401 {
00402
00403 int domLenk = m_boxLayout.getDomain().size(a_kdir);
00404 int domLeni = m_boxLayout.getDomain().size(a_idir);
00405 int bitmaplenk = bitmap.getBox().size(a_kdir);
00406 int bitmapleni = bitmap.getBox().size(a_idir);
00407 int kshift = -(bitmaplenk-1)*a_kside;
00408 int ishift = -(bitmapleni-1)*a_iside;
00409 a_neighborPt = a_p + pshiftj;
00410 a_neighborPt[a_kdir] += kshift;
00411 a_neighborPt[a_idir] += ishift;
00412 Point shiftdomk = getUnitv(a_kdir);
00413 Point shiftdomi = getUnitv(a_idir);
00414 shiftdomk *= -a_kside*domLenk;
00415 shiftdomi *= -a_iside*domLeni;
00416 a_shiftdom = shiftdomk + shiftdomi;
00417 }
00418 else
00419 {
00420
00421 int domLeni = m_boxLayout.getDomain().size(a_idir);
00422 int domLenj = m_boxLayout.getDomain().size(a_jdir);
00423 int domLenk = m_boxLayout.getDomain().size(a_kdir);
00424 int bitmapleni = bitmap.getBox().size(a_idir);
00425 int bitmaplenj = bitmap.getBox().size(a_jdir);
00426 int bitmaplenk = bitmap.getBox().size(a_kdir);
00427 int ishift = -(bitmapleni-1)*a_iside;
00428 int jshift = -(bitmaplenj-1)*a_jside;
00429 int kshift = -(bitmaplenk-1)*a_kside;
00430 a_neighborPt = a_p;
00431 a_neighborPt[a_idir] += ishift;
00432 a_neighborPt[a_jdir] += jshift;
00433 a_neighborPt[a_kdir] += kshift;
00434 Point shiftdomi = getUnitv(a_idir);
00435 Point shiftdomj = getUnitv(a_jdir);
00436 Point shiftdomk = getUnitv(a_kdir);
00437 shiftdomi *= -a_iside*domLeni;
00438 shiftdomj *= -a_jside*domLenj;
00439 shiftdomk *= -a_kside*domLenk;
00440 a_shiftdom = shiftdomi + shiftdomj + shiftdomk;
00441 }
00442
00443 if(bitmap[a_neighborPt])
00444 {
00445 a_neighborValid = m_boxLayout[a_neighborPt];
00446 }
00447 }
00448
00449 template<class T, unsigned int C, unsigned char D, unsigned char E>
00450 void
00451 LevelData<T, C, D, E>::
00452 getPeriodicFlapNeighborInfo(Point & a_neighborPt,
00453 Box & a_neighborValid,
00454 Point & a_shiftdom,
00455 const Point & a_p,
00456 const int & a_idir,
00457 const int & a_iside)
00458 {
00459 const RectMDArray<bool>& bitmap = m_boxLayout.getBitmap();
00460 int bitmaplen = bitmap.getBox().size(a_idir);
00461 int ishift = -(bitmaplen-1)*a_iside;
00462 a_neighborPt = a_p;
00463 a_neighborPt[a_idir] += ishift;
00464
00465
00466 if(bitmap[a_neighborPt])
00467 {
00468 a_neighborValid = m_boxLayout[a_neighborPt];
00469 int domLen = m_boxLayout.getDomain().size(a_idir);
00470 a_shiftdom = getUnitv(a_idir);
00471 a_shiftdom *= -a_iside*domLen;
00472 }
00473 }
00474
00475
00476 template<class T, unsigned int C, unsigned char D, unsigned char E>
00477 void
00478 LevelData<T, C, D, E>::
00479 exchangeSingleBox(const Point& a_p)
00480 {
00481 int kDest = m_boxLayout.getPatchIndex(a_p);
00482 RectMDArray<double, C, D, E>& RMDADest = m_data[kDest];
00483 Box bxKernel(getOnes()*(-1),getOnes());
00484 Point noshift = getZeros();
00485 for (Point pt=bxKernel.getLowCorner();bxKernel.notDone(pt);bxKernel.increment(pt))
00486 {
00487 if (m_boxLayout.getBitBox().contains(pt+a_p))
00488 {
00489 if (m_boxLayout.getBitmap()[pt+a_p])
00490 {
00491 int kSrc = m_boxLayout.getPatchIndex(pt + a_p);
00492 RectMDArray<double, C, D, E>& RMDASrc = m_data[kSrc];
00493
00494 if (kSrc != kDest)
00495 {
00496 RectMDArray<double, C, D, E>& RMDASrc = m_data[kSrc];
00497 RMDASrc.copyTo(RMDADest,m_boxLayout[pt+a_p],noshift);
00498 }
00499 }
00500 }
00501 else
00502 {
00503 Point shiftedPt = m_boxLayout.getBitmap().getBox().mod(pt + a_p);
00504
00505 if (m_boxLayout.getBitBox().contains(shiftedPt))
00506 {
00507 int n1D = m_boxLayout.getBoxsize();
00508 int kSrc = m_boxLayout.getPatchIndex(shiftedPt);
00509 Point patchShift = (pt + a_p - shiftedPt)*(-n1D);
00510 RectMDArray<double, C, D, E>& RMDASrc = m_data[kSrc];
00511 RMDASrc.copyTo(RMDADest,m_boxLayout[shiftedPt],patchShift);
00512 }
00513 }
00514 }
00515 };
00516
00517 template<class T, unsigned int C, unsigned char D, unsigned char E>
00518 void
00519 LevelData<T, C, D, E>::
00520 exchange()
00521 {
00522 CH_TIMERS("LevelData::exchange");
00523 RectMDArray<bool> bitmap = m_boxLayout.getBitmap();
00524 Box bitMapBox = bitmap.getBox();
00525 for (Point p = bitMapBox.getLowCorner(); bitMapBox.notDone(p); bitMapBox.increment(p))
00526 {
00527 if (bitmap[p])
00528 {
00529 exchangeSingleBox(p);
00530 }
00531 }
00532 };
00533
00534 template<class T, unsigned int C, unsigned char D, unsigned char E>
00535 void
00536 LevelData<T, C, D, E>::
00537 generateBoxes(const Box& a_box, const Point& a_dir, Box& a_ghostCells, Box& a_neighborBox)
00538 {
00539 Point actualLc = a_box.getLowCorner();
00540 Point actualHc = a_box.getHighCorner();
00541
00542
00543 int ghostLcCoord[DIM];
00544 int ghostHcCoord[DIM];
00545 for (int i = 0; i < DIM; i++)
00546 {
00547 if (a_dir[i] < 0)
00548 {
00549 ghostLcCoord[i] = actualLc[i] - (m_ghostSize);
00550 ghostHcCoord[i] = actualHc[i] - (BLOCKSIZE / m_coarseningFactor);
00551 }
00552 else if (a_dir[i] > 0)
00553 {
00554 ghostLcCoord[i] = actualLc[i] + (BLOCKSIZE / m_coarseningFactor);
00555 ghostHcCoord[i] = actualHc[i] + (m_ghostSize);
00556 }
00557 else
00558 {
00559 ghostLcCoord[i] = actualLc[i];
00560 ghostHcCoord[i] = actualHc[i];
00561 }
00562 }
00563 Point ghostLc(ghostLcCoord);
00564 Point ghostHc(ghostHcCoord);
00565 a_ghostCells = Box(ghostLc, ghostHc);
00566
00567
00568 Box neighborBox;
00569 if (m_boxLayout.getDomain().coarsen(m_coarseningFactor).contains(ghostLc))
00570 {
00571 a_neighborBox = a_ghostCells;
00572 }
00573 else
00574 {
00575 int copyLcCoord[DIM];
00576 int copyHcCoord[DIM];
00577 Point domainLc = m_boxLayout.getDomain().getLowCorner();
00578 Point domainHc = m_boxLayout.getDomain().getHighCorner();
00579 for (int i = 0; i < DIM; i++)
00580 {
00581 T one = T(1);
00582 T lcLHS = (T) ghostLc[i];
00583 T lcRHS = (T) ((domainHc[i] - domainLc[i])/m_coarseningFactor) + one;
00584 T hcLHS = (T) ghostHc[i];
00585 T hcRHS = (T) ((domainHc[i] - domainLc[i])/m_coarseningFactor) + one;
00586 copyLcCoord[i] = mod(lcLHS, lcRHS);
00587 copyHcCoord[i] = mod(hcLHS, hcRHS);
00588
00589 }
00590 a_neighborBox = Box(Point(copyLcCoord), Point(copyHcCoord));
00591 }
00592 }
00593
00594 template<class T, unsigned int C, unsigned char D, unsigned char E>
00595 Point
00596 LevelData<T, C, D, E>::
00597 getNeighbor(const Point& a_p, const Point& a_dir)
00598 {
00599 CH_TIMERS("LevelData::getNeighbor");
00600 int patch[DIM];
00601 RectMDArray<bool> bitmap = m_boxLayout.getBitmap();
00602 Box bitBox = bitmap.getBox();
00603 Point lc = bitBox.getLowCorner();
00604 Point hc = bitBox.getHighCorner();
00605
00606 for (int i = 0; i < DIM; i++)
00607 {
00608 T one = T(1);
00609 T leftSide = (T) a_p[i] + a_dir[i];
00610 T rightSide = (T) hc[i] - lc[i] + one;
00611 assert(rightSide != 0);
00612 patch[i] = mod(leftSide, rightSide);
00613 }
00614
00615 return Point(patch);
00616 }
00617
00618 template<class T, unsigned int C, typename Func>
00619 void forall(LevelData<T,C>& a_lhs, const LevelData<T,C>& a_rhs, const Func& F)
00620 {
00621 const BoxLayout& layout = a_lhs.getBoxLayout();
00622 for(BLIterator blit(layout); blit != blit.end(); ++blit)
00623 {
00624 F(a_lhs[*blit], a_rhs[*blit]);
00625 }
00626 }
00627 template<class T, unsigned int C, typename Func>
00628 void forall(LevelData<T,C>& a_lhs, const LevelData<T,C>& a_rhs0, const LevelData<T,C>& a_rhs1, const Func& F)
00629 {
00630 const BoxLayout& layout = a_lhs.getBoxLayout();
00631 for(BLIterator blit(layout); blit != blit.end(); ++blit)
00632 {
00633 F(a_lhs[*blit], a_rhs0[*blit],a_rhs1[*blit]);
00634 }
00635 }
00636
00637 template<class T, unsigned int C, typename Func>
00638 void forall(LevelData<T,C>& a_lhs, const LevelData<T,C>& a_rhs0, const LevelData<T,C>& a_rhs1,
00639 const LevelData<T,C>& a_rhs2, const Func& F)
00640 {
00641 const BoxLayout& layout = a_lhs.getBoxLayout();
00642 for(BLIterator blit(layout); blit != blit.end(); ++blit)
00643 {
00644 F(a_lhs[*blit], a_rhs0[*blit],a_rhs1[*blit],a_rhs2[*blit]);
00645 }
00646 }