Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

Box.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef CH_BOX_H
00029 #define CH_BOX_H
00030 
00031 #ifdef NODEV
00032 #undef NODEV
00033 #endif
00034 
00035 #include "SPACE.H"
00036 
00037 #ifndef WRAPPER
00038 #include <iostream>
00039 
00040 
00041 
00042 #include "IntVect.H"
00043 #include "Misc.H"
00044 #include "LoHiSide.H"
00045 
00046 
00048 
00056 class IndexType
00057 {
00058 public:
00060 
00064   enum CellIndex { CELL = 0, NODE = 1 };
00065 
00067 
00071   IndexType ();
00072 
00074 
00078   IndexType (const IndexType& rhs);
00079 
00081 
00085   explicit IndexType (const IntVect& iv);
00086 
00088 
00092   IndexType& operator= (const IndexType& rhs);
00093 
00095 
00101   IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k));
00102 
00104 
00108   void set (int dir);
00109 
00111 
00115   void unset (int dir);
00116 
00118 
00122   bool test (int dir) const;
00123 
00125 
00129   void setall ();
00130 
00132 
00136   void clear ();
00137 
00139 
00143   bool any () const;
00144 
00146 
00150   bool ok () const;
00151 
00153 
00158   void flip (int i);
00159 
00161 
00165   bool operator== (const IndexType& t) const;
00166 
00168 
00172   bool operator!= (const IndexType& t) const;
00173 
00175 
00179   bool cellCentered () const;
00180 
00182 
00186   bool nodeCentered () const;
00187 
00189 
00193   void setType (int       dir,
00194                 CellIndex t);
00195 
00197 
00201   CellIndex ixType (int dir) const;
00202 
00204 
00208   int operator[] (int dir) const;
00209 
00211 
00216   IntVect ixType () const;
00217 
00219 
00226   static IndexType TheCellType ();
00227 
00229 
00236   static IndexType TheNodeType ();
00237 
00239 
00243   friend std::ostream& operator<< (std::ostream&         os,
00244                                    const IndexType& itype);
00245 
00247 
00251   friend std::istream& operator>> (std::istream&   is,
00252                                    IndexType& itype);
00253 private:
00254   //
00255   // Returns 1<<k.
00256   //
00257   static int mask (int k);
00258   //
00259   // An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1.
00260   //
00261   unsigned int itype;
00262 };
00263 
00264 //
00265 // Inlines.
00266 //
00267 
00268 
00269 inline
00270 int
00271 IndexType::mask (int k)
00272 {
00273   return 1<<k;
00274 }
00275 
00276 inline
00277 IndexType::IndexType ()
00278   : itype(0)
00279 {}
00280 
00281 inline
00282 IndexType::IndexType (const IndexType& bt)
00283   : itype(bt.itype)
00284 {}
00285 
00286 inline
00287 IndexType& IndexType::operator= (const IndexType& bt)
00288 {
00289   itype = bt.itype;
00290   return *this;
00291 }
00292 
00293 inline
00294 IndexType::IndexType (const IntVect& iv)
00295 {
00296   itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00297 }
00298 
00299 inline
00300 IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
00301 {
00302   itype = D_TERM(i, | (j<<1), | (k<<2));
00303 }
00304 
00305 inline
00306 void
00307 IndexType::set (int dir)
00308 {
00309   itype |= mask(dir);
00310 }
00311 
00312 inline
00313 void
00314 IndexType::unset (int dir)
00315 {
00316   itype &= ~mask(dir);
00317 }
00318 
00319 inline
00320 bool
00321 IndexType::test (int dir) const
00322 {
00323   return (itype & mask(dir)) != 0;
00324 }
00325 
00326 inline
00327 void
00328 IndexType::setall ()
00329 {
00330   itype = (1 << SpaceDim) - 1;
00331 }
00332 
00333 inline
00334 void
00335 IndexType::clear ()
00336 {
00337   itype = 0;
00338 }
00339 
00340 inline
00341 bool
00342 IndexType::any () const
00343 {
00344   return itype != 0;
00345 }
00346 
00347 inline
00348 bool
00349 IndexType::ok () const
00350 {
00351   return itype < (1 << SpaceDim);
00352 }
00353 
00354 inline
00355 void
00356 IndexType::flip (int i)
00357 {
00358   itype ^= mask(i);
00359 }
00360 
00361 inline
00362 bool
00363 IndexType::operator== (const IndexType& t) const
00364 {
00365   return t.itype == itype;
00366 }
00367 
00368 inline
00369 bool
00370 IndexType::operator!= (const IndexType& t) const
00371 {
00372   return t.itype != itype;
00373 }
00374 
00375 inline
00376 bool
00377 IndexType::cellCentered () const
00378 {
00379   return itype == 0;
00380 }
00381 
00382 inline
00383 bool
00384 IndexType::nodeCentered () const
00385 {
00386   return itype == (1<<SpaceDim)-1;
00387 }
00388 
00389 inline
00390 void
00391 IndexType::setType (int       dir,
00392                     CellIndex t)
00393 {
00394   t == CELL ? unset(dir) : set(dir);
00395 }
00396 
00397 inline
00398 IndexType::CellIndex
00399 IndexType::ixType (int dir) const
00400 {
00401   return (CellIndex) ((itype & (1<<dir)) >> dir);
00402 }
00403 
00404 inline
00405 int
00406 IndexType::operator[] (int dir) const
00407 {
00408   return test(dir);
00409 }
00410 
00411 inline
00412 IntVect
00413 IndexType::ixType () const
00414 {
00415   return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
00416 }
00417 
00418 #endif /* WRAPPER */
00419 
00420 //
00422 
00435 class Box
00436 {
00437 public:
00438 
00440 
00442 
00446   Box ();
00447 
00449 
00453   ~Box () {;}
00454 
00455 
00457 
00462   Box (const IntVect& small,
00463        const IntVect& big);
00464 
00466 
00471   void define(const IntVect& small, const IntVect& big);
00472 
00474 
00479   Box (const IntVect& small,
00480        const int*     vec_len);
00481 
00483 
00490   Box (const IntVect& small,
00491        const IntVect& big,
00492        const IntVect& typ);
00493 
00495 
00501   Box (const IntVect&   small,
00502        const IntVect&   big,
00503        const IndexType& t);
00504 
00506 
00510   Box (const Box& b);
00511 
00512   void define(const Box& b);
00513 
00514   Box copy() const {return *this;}
00515 
00517 
00519 
00523   const IntVect& smallEnd () const;
00524 
00526 
00530   IntVect sideEnd(Side::LoHiSide a_side) const;
00531 
00532 
00534 
00540   int smallEnd (int dir) const;
00541 
00543 
00547   const IntVect& bigEnd () const;
00548 
00550 
00556   int bigEnd (int dir) const;
00557 
00559 
00565   const int* loVect () const;
00566 
00568 
00574   const int* hiVect () const;
00575 
00577 
00583   const int* getVect () const;
00584 
00586 
00592   long index (const IntVect& v) const;
00593 
00595 
00597 
00601   IndexType ixType () const;
00602 
00604 
00608   IntVect type () const;
00609 
00611 
00617   IndexType::CellIndex type (int dir) const;
00618 
00620 
00622 
00627   const IntVect& size () const;
00628 
00630 
00636   int size (int dir) const;
00637 
00639 
00643   bool numPtsOK () const;
00644 
00646 
00652   long numPts () const;
00653 
00655 
00659   bool volumeOK () const;
00660 
00662 
00668   long volume () const;
00669 
00671 
00677   int longside (int& dir) const;
00678 
00680 
00684   int longside () const;
00685 
00687 
00693   int shortside (int& dir) const;
00694 
00696 
00700   int shortside () const;
00701 
00702 
00704 
00706 
00710   bool isEmpty () const;
00711 
00713 
00719   bool contains (const IntVect& p) const;
00720 
00722 
00728   bool contains (const Box& b) const;
00729 
00731 
00737   bool intersects (const Box& b) const;
00738 
00740 
00748   bool intersectsNotEmpty (const Box& b) const;
00749 
00751 
00756   bool sameSize (const Box& b) const;
00757 
00759 
00763   bool sameType (const Box &b) const;
00764 
00766 
00771   bool operator== (const Box& b) const;
00772 
00773   bool eq(const Box& b) const;
00775 
00779   bool operator!= (const Box& b) const;
00780 
00781   bool neq(const Box& b) const;
00783 
00788   bool cellCentered () const;
00789 
00790   // following operators added Sept. 14, 1999.  bvs
00792 
00800   bool operator < (const Box& rhs) const;
00801 
00802   bool lt(const Box& rhs) const;
00803 
00804 
00806 
00808 
00812   Box& operator= (const Box& b);
00813 
00815 
00821   Box& setSmall (const IntVect& sm);
00822 
00824 
00831   Box& setSmall (int dir,
00832                  int sm_index);
00833 
00835 
00841   Box& setBig (const IntVect& bg);
00842 
00844 
00851   Box& setBig (int dir,
00852                int bg_index);
00853 
00855 
00860   Box& setRange (int dir,
00861                  int sm_index,
00862                  int n_cells = 1);
00863 
00865 
00867 
00878   Box& convert (IndexType typ);
00879 
00881 
00890   Box& convert (const IntVect& typ);
00891 
00893 
00905   Box& convert (int                  dir,
00906                 IndexType::CellIndex typ);
00907 
00909 
00916   Box& surroundingNodes ();
00917 
00919 
00927   Box& surroundingNodes (int dir);
00928 
00929   Box& surroundingNodes_int(int dir);
00931 
00940   friend  Box surroundingNodes (const Box& b,
00941                                 int        dir);
00942 
00943   
00945 
00953   friend Box surroundingNodes (const Box& b);
00954 
00956 
00963   Box& enclosedCells ();
00964 
00966 
00974   Box& enclosedCells (int dir);
00975 
00976   Box& enclosedCells_int (int dir);
00977 
00979 
00988   friend Box enclosedCells (const Box& b,
00989                             int        dir);
00990 
00992 
01000   friend Box enclosedCells (const Box& b);
01001 
01003 
01005 
01012   Box& shift (int dir,
01013               int nzones);
01014 
01016 
01022   Box& shift (const IntVect& iv);
01023   
01024   Box& shift_intvect (const IntVect& iv);
01025 
01027 
01039   Box& shiftHalf (int dir,
01040                   int num_halfs);
01041 
01043 
01049   Box& shiftHalf (const IntVect& iv);
01050   Box& shiftHalf_intvect (const IntVect& iv);
01051 
01053 
01058   Box& operator+= (const IntVect& v);
01059 
01061 
01066   Box  operator+  (const IntVect& v) const;
01067 
01069 
01074   Box& operator-= (const IntVect& v);
01075 
01077 
01082   Box  operator-  (const IntVect& v) const;
01083 
01085 
01087   friend Box bdryBox(const Box& b,
01088                      int        dir,
01089                      Side::LoHiSide a_sd,
01090                      int        len);
01091 
01092 
01094 
01102   friend Box bdryLo (const Box& b,
01103                      int        dir,
01104                      int        len);
01105 
01107 
01115   friend Box bdryHi (const Box& b,
01116                      int        dir,
01117                      int        len);
01118 
01120 
01143   friend Box adjCellLo (const Box& b,
01144                         int        dir,
01145                         int        len);
01146 
01148 
01171   friend Box adjCellHi (const Box& b,
01172                         int        dir,
01173                         int        len);
01174 
01175 
01177 
01179 
01186   Box operator& (const Box&) const;
01187 
01189 
01195   Box& operator&= (const Box&);
01196 
01197 
01199   friend Box adjCellBox (const Box& b,
01200                          int        dir,
01201                          Side::LoHiSide a_side,
01202                          int        len);
01204 
01209   Box& minBox (const Box& b);
01210 
01212 
01217   friend Box minBox (const Box& b1,
01218                      const Box& b2);
01219 
01221 
01223 
01231   Box& grow (int i);
01232 
01234 
01242   friend Box grow (const Box& b,
01243                    int        i);
01244 
01246 
01254   Box& grow (const IntVect& v);
01255 
01257 
01265   friend  Box grow (const Box&     b,
01266                     const IntVect& v);
01267 
01269 
01278   Box& grow (int idir,
01279              int n_cell);
01280 
01282 
01291   Box& growLo (int idir,
01292                int n_cell=1);
01293 
01295 
01299   Box& growDir (int a_idir,
01300                 const Side::LoHiSide& a_sd,
01301                 int a_cell);
01302 
01304 
01313   Box& growHi (int idir,
01314                int n_cell=1);
01315 
01317 
01319 
01330   Box& refine (int refinement_ratio);
01331 
01333 
01345   friend Box refine (const Box& b,
01346                      int        refinement_ratio);
01347 
01349 
01360   Box& refine (const IntVect& refinement_ratio);
01361 
01363 
01375   friend Box refine (const Box&     b,
01376                      const IntVect& refinement_ratio);
01377 
01379 
01381 
01396   Box& coarsen (int refinement_ratio);
01397 
01399 
01414   friend Box coarsen (const Box& b,
01415                       int        refinement_ratio);
01416 
01418 
01432   Box& coarsen (const IntVect& refinement_ratio);
01433 
01435 
01450   friend Box coarsen (const Box&     b,
01451                       const IntVect& refinement_ratio);
01452 
01453   // next(...) is out of favor.  use BoxIterator.
01454   /*
01455     Step through the rectangle.  It is a runtime error to give
01456     a point not inside rectangle.  Iteration may not be efficient.
01457   */
01458   void next (IntVect &) const;
01459 
01460   /*
01461     Scan argument IntVect over object second arg is
01462     increment vector.  Runtime error if IntVect is not
01463     contained in object Box.  Iteration may not be efficient.
01464   */
01465   void next (IntVect&   p,
01466              const int* shv) const;
01467 
01468 
01470 
01472 
01485   Box chop (int dir,
01486             int chop_pnt);
01487 
01489 
01491 
01495   friend std::ostream& operator<< (std::ostream&   os,
01496                                    const Box& bx);
01497 
01499 
01503   friend std::istream& operator>> (std::istream& os,
01504                                    Box&     bx);
01505 
01506 
01508 
01511   void p() const;
01512 
01514 
01519   void dumpOn (std::ostream& strm) const;
01520 
01522 
01524 
01528   //static const Box Empty;
01529 
01530 
01531   // TheUnitBox is out of favor.
01532   /*
01533     This static member function returns a constant reference to 
01534     an object of type Box representing the unit box in
01535     BL\_SPACEDIM-dimensional space.
01536   */
01537 
01538   //static const Box& TheUnitBox ();
01539 
01540   //
01541   // Sets the 'len' element of the Box.  Aborts on integer overflow.
01542   //
01543   void computeBoxLen ();
01544   void computeBoxLenNotEmpty();
01545 
01546 protected:
01547   friend class HDF5Handle;
01548   //
01549   // A helper function for numPtsOK() and numPts().
01550   //
01551   bool numPtsOK (long& N) const;
01552   //
01553   // A helper function for volumeOK() and volume().
01554   //
01555   bool volumeOK (long& N) const;
01556 
01557   IntVect   smallend;
01558   IntVect   bigend;
01559   IntVect   len;
01560   IndexType btype;
01561 
01562 };
01563 
01564 // global function prototypes
01565 Box surroundingNodes (const Box& b,
01566                       int        dir);
01567 Box surroundingNodes (const Box& b);
01568 Box enclosedCells (const Box& b,
01569                    int        dir);
01570 Box enclosedCells (const Box& b);
01571 Box bdryBox(const Box& b,
01572             int        dir,
01573             Side::LoHiSide a_sd,
01574             int        len=1);
01575 Box bdryLo (const Box& b,
01576             int        dir,
01577             int        len=1);
01578 Box bdryHi (const Box& b,
01579             int        dir,
01580             int        len=1);
01581 Box adjCellLo (const Box& b,
01582                int        dir,
01583                int        len=1);
01584 Box adjCellHi (const Box& b,
01585                int        dir,
01586                int        len=1);
01587 Box minBox (const Box& b1,
01588             const Box& b2);
01589 //
01590 // Inlines. 
01591 //
01592 
01593 #ifndef WRAPPER
01594 
01595 inline
01596 Box::Box (const Box& b)
01597   : smallend(b.smallend),
01598     bigend(b.bigend),
01599     btype(b.btype)
01600 {
01601   D_EXPR(len[0] = b.len[0],
01602          len[1] = b.len[1],
01603          len[2] = b.len[2]);
01604 }
01605 
01606 inline
01607 Box&
01608 Box::operator= (const Box& b)
01609 {
01610   smallend = b.smallend;
01611   bigend = b.bigend;
01612   btype = b.btype;
01613   D_EXPR(len[0] = b.len[0],
01614          len[1] = b.len[1],
01615          len[2] = b.len[2]);
01616   return *this;
01617 }
01618 
01619 inline
01620 IntVect
01621 Box::sideEnd(Side::LoHiSide a_side) const
01622 {
01623   IntVect retval;
01624   if(a_side == Side::Lo)
01625     retval = smallEnd();
01626   else
01627     retval = bigEnd();
01628   return retval;
01629 }
01630 
01631 inline
01632 const IntVect&
01633 Box::smallEnd () const
01634 {
01635   return smallend;
01636 }
01637 
01638 inline
01639 int
01640 Box::smallEnd (int dir) const
01641 {
01642   return smallend[dir];
01643 }
01644 
01645 inline
01646 const IntVect&
01647 Box::bigEnd () const
01648 {
01649   return bigend;
01650 }
01651 
01652 inline
01653 int
01654 Box::bigEnd (int dir) const
01655 {
01656   return bigend[dir];
01657 }
01658 
01659 inline
01660 IndexType
01661 Box::ixType () const
01662 {
01663   return btype;
01664 }
01665 
01666 inline
01667 IntVect
01668 Box::type () const
01669 {
01670   return btype.ixType();
01671 }
01672 
01673 inline
01674 IndexType::CellIndex
01675 Box::type (int dir) const
01676 {
01677   return btype.ixType(dir);
01678 }
01679 
01680 inline
01681 const IntVect&
01682 Box::size () const
01683 {
01684   return len;
01685 }
01686 
01687 inline
01688 int
01689 Box::size (int dir) const
01690 {
01691   return len[dir];
01692 }
01693 
01694 inline
01695 const int*
01696 Box::loVect () const
01697 {
01698   return smallend.getVect();
01699 }
01700 
01701 inline
01702 const int*
01703 Box::hiVect () const
01704 {
01705   return bigend.getVect();
01706 }
01707 
01708 inline
01709 const int*
01710 Box::getVect () const
01711 {
01712   return smallend.getVect();
01713 }
01714 
01715 
01716 inline
01717 bool
01718 Box::numPtsOK () const
01719 {
01720   long ignore;
01721   return numPtsOK(ignore);
01722 }
01723 
01724 inline
01725 bool
01726 Box::isEmpty () const
01727 {
01728   //    return numPts() == 0;
01729   return (!(bigend >= smallend));
01730 }
01731 
01732 inline
01733 bool
01734 Box::contains (const IntVect& p) const
01735 {
01736 
01737   return ( !isEmpty() && (p >= smallend && p <= bigend) );
01738 }
01739 
01740 inline
01741 bool
01742 Box::sameType (const Box &b) const
01743 {
01744   return btype == b.btype;
01745 }
01746 
01747 inline
01748 bool
01749 Box::contains (const Box& b) const
01750 {
01751   assert(sameType(b));
01752   return ( b.isEmpty() ||
01753            (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
01754 }
01755 
01756 inline
01757 bool
01758 Box::sameSize (const Box& b) const
01759 {
01760   assert(sameType(b));
01761   return D_TERM(len[0] == b.len[0],
01762              && len[1] == b.len[1],
01763              && len[2] == b.len[2]);
01764 }
01765 
01766 inline
01767 bool
01768 Box::operator== (const Box& b) const
01769 {
01770   return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01771 }
01772 
01773 inline
01774 bool
01775 Box::operator!= (const Box& b) const
01776 {
01777   return !operator==(b);
01778 }
01779 
01780 inline
01781 bool
01782 Box::cellCentered () const
01783 {
01784   return !btype.any();
01785 }
01786 
01787 inline
01788 bool
01789 Box::volumeOK () const
01790 {
01791   return numPtsOK();
01792 }
01793 
01794 inline
01795 long
01796 Box::index (const IntVect& v) const
01797 {
01798   long result = v.vect[0]-smallend.vect[0];
01799 #if   CH_SPACEDIM==2
01800   result += len[0]*(v.vect[1]-smallend.vect[1]);
01801 #elif CH_SPACEDIM==3
01802   result += len[0]*(v.vect[1]-smallend.vect[1]
01803                     +(v.vect[2]-smallend.vect[2])*len[1]);
01804 #endif
01805   return result;
01806 }
01807 
01808 inline
01809 void
01810 Box::computeBoxLen ()
01811 {
01812   if (isEmpty())
01813     {
01814       len = IntVect::Zero;
01815     }
01816   else
01817     {
01818       D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01819              len[1] = bigend[1]-smallend[1] + 1,
01820              len[2] = bigend[2]-smallend[2] + 1);
01821     }
01822 }
01823 
01824 inline
01825 void
01826 Box::computeBoxLenNotEmpty()
01827 {
01828   D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01829          len[1] = bigend[1]-smallend[1] + 1,
01830          len[2] = bigend[2]-smallend[2] + 1);
01831 }
01832 
01833 inline
01834 Box&
01835 Box::setSmall (const IntVect& sm)
01836 {
01837   assert (sm <= bigend);
01838 
01839   smallend = sm;
01840   computeBoxLen();
01841   return *this;
01842 }
01843 
01844 inline
01845 Box&
01846 Box::setSmall (int dir,
01847                int sm_index)
01848 {
01849   assert (sm_index <= bigend[dir]);
01850 
01851   smallend.setVal(dir,sm_index);
01852   computeBoxLen();
01853   return *this;
01854 }
01855 
01856 inline
01857 Box&
01858 Box::setBig (const IntVect& bg)
01859 {
01860   assert (bg >= smallend);
01861 
01862   bigend = bg;
01863   computeBoxLen();
01864   return *this;
01865 }
01866 
01867 inline
01868 Box&
01869 Box::setBig (int dir,
01870              int bg_index)
01871 {
01872   assert (bg_index >= smallend[dir]);
01873 
01874   bigend.setVal(dir,bg_index);
01875   computeBoxLen();
01876   return *this;
01877 }
01878 
01879 inline
01880 Box&
01881 Box::setRange (int dir,
01882                int sm_index,
01883                int n_cells)
01884 {
01885   assert (n_cells > 0);
01886 
01887   smallend.setVal(dir,sm_index);
01888   bigend.setVal(dir,sm_index+n_cells-1);
01889   computeBoxLen();
01890   return *this;
01891 }
01892 
01893 inline
01894 Box&
01895 Box::shift (int dir,
01896             int nzones)
01897 {
01898   if (!isEmpty())
01899     {
01900       smallend.shift(dir,nzones);
01901       bigend.shift(dir,nzones);
01902     }
01903   return *this;
01904 }
01905 
01906 inline
01907 Box&
01908 Box::shift (const IntVect& iv)
01909 {
01910   if (!isEmpty())
01911     {
01912       smallend.shift(iv);
01913       bigend.shift(iv);
01914     }
01915   return *this;
01916 }
01917 
01918 inline
01919 Box&
01920 Box::convert (const IntVect& typ)
01921 {
01922   assert(typ >= IntVect::TheZeroVector() && typ <= IntVect::TheUnitVector());
01923   if (!isEmpty())
01924     {
01925       IntVect shft(typ - btype.ixType());
01926       bigend += shft;
01927     }
01928   btype = IndexType(typ);
01929   computeBoxLen();
01930   return *this;
01931 }
01932 
01933 inline
01934 Box&
01935 Box::surroundingNodes (int dir)
01936 {
01937   if (!(btype[dir]))
01938     {
01939       if (!isEmpty())
01940         {
01941           bigend.shift(dir,1);
01942         }
01943       //
01944       // Set dir'th bit to 1 = IndexType::NODE.
01945       //
01946       btype.set(dir);
01947       computeBoxLen();
01948     }
01949   return *this;
01950 }
01951 
01952 inline
01953 Box&
01954 Box::enclosedCells (int dir)
01955 {
01956   if (btype[dir])
01957     {
01958       if (!isEmpty())
01959         {
01960           bigend.shift(dir,-1);
01961         }
01962       //
01963       // Set dir'th bit to 0 = IndexType::CELL.
01964       //
01965       btype.unset(dir);
01966       computeBoxLen();
01967     }
01968   return *this;
01969 }
01970 
01971 inline
01972 Box
01973 surroundingNodes (const Box& b,
01974                   int        dir)
01975 {
01976   Box bx(b);
01977   return bx.surroundingNodes(dir);
01978 }
01979 
01980 inline
01981 Box
01982 surroundingNodes (const Box& b)
01983 {
01984   Box bx(b);
01985   return bx.surroundingNodes();
01986 }
01987 
01988 inline
01989 Box
01990 enclosedCells (const Box& b,
01991                int        dir)
01992 {
01993   Box bx(b);
01994   return bx.enclosedCells(dir);
01995 }
01996 
01997 inline
01998 Box
01999 enclosedCells (const Box& b)
02000 {
02001   Box bx(b);
02002   return bx.enclosedCells();
02003 }
02004 
02005 inline
02006 Box&
02007 Box::operator+= (const IntVect& v)
02008 {
02009   if (!isEmpty())
02010     {
02011       smallend += v;
02012       bigend += v;
02013     }
02014   return *this;
02015 }
02016 
02017 inline
02018 Box
02019 Box::operator+  (const IntVect& v) const
02020 {
02021   if (isEmpty())
02022     {
02023       return(Box().convert(btype));
02024     }
02025   else
02026     {
02027       IntVect small(smallend);
02028       small += v;
02029       IntVect big(bigend);
02030       big += v;
02031       return Box(small,big,btype);
02032     }
02033 }
02034 
02035 inline
02036 Box&
02037 Box::operator-= (const IntVect& v)
02038 {
02039   if (!isEmpty())
02040     {
02041       smallend -= v;
02042       bigend -= v;
02043     }
02044   return *this;
02045 }
02046 
02047 inline
02048 bool 
02049 Box::operator < (const Box& rhs) const
02050 {
02051   return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02052 }
02053 
02054 inline
02055 Box
02056 Box::operator-  (const IntVect& v) const
02057 {
02058   if (isEmpty())
02059     {
02060       return(Box().convert(btype));
02061     }
02062   else
02063     {
02064       IntVect small = smallend;
02065       small -= v;
02066       IntVect big = bigend;
02067       big -= v;
02068       return Box(small,big,btype);
02069     }
02070 }
02071 
02072 inline
02073 Box&
02074 Box::grow (int i)
02075 {
02076   if (!isEmpty())
02077     {
02078       smallend.diagShift(-i);
02079       bigend.diagShift(i);
02080       if (!(bigend >= smallend)) *this = Box().convert(btype);
02081       computeBoxLen();
02082     }
02083   return *this;
02084 }
02085 
02086 inline
02087 Box
02088 grow (const Box& b,
02089       int        i)
02090 {
02091   if (b.isEmpty())
02092     {
02093       return (Box().convert(b.btype));
02094     }
02095   else
02096     {
02097       IntVect small = diagShift(b.smallend,-i);
02098       IntVect big   = diagShift(b.bigend,i);
02099       if (!(big >= small))
02100         {
02101           return(Box().convert(b.btype));
02102         }
02103       else
02104         {
02105           return Box(small,big,b.btype);
02106         }
02107     }
02108 }
02109 
02110 inline
02111 Box&
02112 Box::grow (const IntVect& v)
02113 {
02114   if (!isEmpty())
02115     {
02116       smallend -= v;
02117       bigend   += v;
02118       if (!(bigend >= smallend)) *this = Box().convert(btype);
02119       computeBoxLen();
02120     }
02121   return *this;
02122 }
02123 
02124 inline
02125 Box
02126 grow (const Box&     b,
02127       const IntVect& v)
02128 {
02129   if (b.isEmpty())
02130     {
02131       return(Box().convert(b.btype));
02132     }
02133   else
02134     {
02135       IntVect small = b.smallend - v;
02136       IntVect big   = b.bigend   + v;
02137       if (!(big >= small))
02138         {
02139           return(Box().convert(b.btype));
02140         }
02141       else
02142         {
02143           return Box(small,big,b.btype);
02144         }
02145     }
02146 }
02147 
02148 inline
02149 Box&
02150 Box::grow (int idir,
02151            int n_cell)
02152 {
02153   if (!isEmpty())
02154     {
02155       smallend.shift(idir, -n_cell);
02156       bigend.shift(idir, n_cell);
02157       if (!(bigend >= smallend)) *this = Box().convert(btype);
02158       computeBoxLen();
02159     }
02160   return *this;
02161 }
02162 
02163 inline
02164 Box&
02165 Box::growLo (int idir,
02166              int n_cell)
02167 {
02168   if (!isEmpty())
02169     {
02170       smallend.shift(idir, -n_cell);
02171       if (!(bigend >= smallend)) *this = Box().convert(btype);
02172       computeBoxLen();
02173     }
02174   return *this;
02175 }
02176 
02177 inline
02178 Box&
02179 Box::growDir (int idir,
02180               const Side::LoHiSide& a_sd,
02181               int n_cell)
02182 {
02183   if(a_sd == Side::Lo)
02184     {
02185       growLo(idir, n_cell);
02186     }
02187   else
02188     {
02189       growHi(idir, n_cell);
02190     }
02191   return *this;
02192 }
02193 
02194 inline
02195 Box&
02196 Box::growHi (int idir,
02197              int n_cell)
02198 {
02199   if (!isEmpty())
02200     {
02201       bigend.shift(idir,n_cell);
02202       if (!(bigend >= smallend)) *this = Box().convert(btype);
02203       computeBoxLen();
02204     }
02205   return *this;
02206 }
02207 
02208 
02209 inline
02210 Box
02211 Box::operator& (const Box& rhs) const
02212 {
02213   Box lhs(*this);
02214   return lhs &= rhs;
02215 }
02216 
02217 #endif /* WRAPPER */
02218 
02219 #endif /*CH_BOX_H*/

Generated on Wed Jun 2 13:53:32 2004 for Chombo&INSwithParticles by doxygen 1.3.2