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 
00047 //
00048 //@Man:
00049 //@Memo: Cell-Based or Node-Based Indices
00050 /*@Doc:
00051 
00052   The class IndexType defines an index as being cell based or node (face)
00053   based in each of the CH\_SPACEDIM directions.  This class defines an
00054   enumerated type CellIndex to be either CELL or NODE; i.e. each of the
00055   CH\_SPACEDIM dimensions must be either CELL or NODE.
00056 */
00057 
00058 class IndexType
00059 {
00060 public:
00062 
00066   enum CellIndex { CELL = 0, NODE = 1 };
00067 
00069 
00073   IndexType ();
00074 
00076 
00080   IndexType (const IndexType& rhs);
00081 
00083 
00087   explicit IndexType (const IntVect& iv);
00088 
00090 
00094   IndexType& operator= (const IndexType& rhs);
00095 
00097 
00103   IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k));
00104 
00106 
00110   void set (int dir);
00111 
00113 
00117   void unset (int dir);
00118 
00120 
00124   bool test (int dir) const;
00125 
00127 
00131   void setall ();
00132 
00134 
00138   void clear ();
00139 
00141 
00145   bool any () const;
00146 
00148 
00152   bool ok () const;
00153 
00155 
00160   void flip (int i);
00161 
00163 
00167   bool operator== (const IndexType& t) const;
00168 
00170 
00174   bool operator!= (const IndexType& t) const;
00175 
00177 
00181   bool cellCentered () const;
00182 
00184 
00188   bool nodeCentered () const;
00189 
00191 
00195   void setType (int       dir,
00196                 CellIndex t);
00197 
00199 
00203   CellIndex ixType (int dir) const;
00204 
00206 
00210   int operator[] (int dir) const;
00211 
00213 
00218   IntVect ixType () const;
00219 
00221 
00228   static IndexType TheCellType ();
00229 
00231 
00238   static IndexType TheNodeType ();
00239 
00241 
00245   friend std::ostream& operator<< (std::ostream&         os,
00246                                    const IndexType& itype);
00247 
00249 
00253   friend std::istream& operator>> (std::istream&   is,
00254                                    IndexType& itype);
00255 private:
00256   //
00257   // Returns 1<<k.
00258   //
00259   static int mask (int k);
00260   //
00261   // An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1.
00262   //
00263   unsigned int itype;
00264 };
00265 
00266 //
00267 // Inlines.
00268 //
00269 
00270 
00271 inline
00272 int
00273 IndexType::mask (int k)
00274 {
00275   return 1<<k;
00276 }
00277 
00278 inline
00279 IndexType::IndexType ()
00280   : itype(0)
00281 {}
00282 
00283 inline
00284 IndexType::IndexType (const IndexType& bt)
00285   : itype(bt.itype)
00286 {}
00287 
00288 inline
00289 IndexType& IndexType::operator= (const IndexType& bt)
00290 {
00291   itype = bt.itype;
00292   return *this;
00293 }
00294 
00295 inline
00296 IndexType::IndexType (const IntVect& iv)
00297 {
00298   itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00299 }
00300 
00301 inline
00302 IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
00303 {
00304   itype = D_TERM(i, | (j<<1), | (k<<2));
00305 }
00306 
00307 inline
00308 void
00309 IndexType::set (int dir)
00310 {
00311   itype |= mask(dir);
00312 }
00313 
00314 inline
00315 void
00316 IndexType::unset (int dir)
00317 {
00318   itype &= ~mask(dir);
00319 }
00320 
00321 inline
00322 bool
00323 IndexType::test (int dir) const
00324 {
00325   return (itype & mask(dir)) != 0;
00326 }
00327 
00328 inline
00329 void
00330 IndexType::setall ()
00331 {
00332   itype = (1 << SpaceDim) - 1;
00333 }
00334 
00335 inline
00336 void
00337 IndexType::clear ()
00338 {
00339   itype = 0;
00340 }
00341 
00342 inline
00343 bool
00344 IndexType::any () const
00345 {
00346   return itype != 0;
00347 }
00348 
00349 inline
00350 bool
00351 IndexType::ok () const
00352 {
00353   return itype < (1 << SpaceDim);
00354 }
00355 
00356 inline
00357 void
00358 IndexType::flip (int i)
00359 {
00360   itype ^= mask(i);
00361 }
00362 
00363 inline
00364 bool
00365 IndexType::operator== (const IndexType& t) const
00366 {
00367   return t.itype == itype;
00368 }
00369 
00370 inline
00371 bool
00372 IndexType::operator!= (const IndexType& t) const
00373 {
00374   return t.itype != itype;
00375 }
00376 
00377 inline
00378 bool
00379 IndexType::cellCentered () const
00380 {
00381   return itype == 0;
00382 }
00383 
00384 inline
00385 bool
00386 IndexType::nodeCentered () const
00387 {
00388   return itype == (1<<SpaceDim)-1;
00389 }
00390 
00391 inline
00392 void
00393 IndexType::setType (int       dir,
00394                     CellIndex t)
00395 {
00396   t == CELL ? unset(dir) : set(dir);
00397 }
00398 
00399 inline
00400 IndexType::CellIndex
00401 IndexType::ixType (int dir) const
00402 {
00403   return (CellIndex) ((itype & (1<<dir)) >> dir);
00404 }
00405 
00406 inline
00407 int
00408 IndexType::operator[] (int dir) const
00409 {
00410   return test(dir);
00411 }
00412 
00413 inline
00414 IntVect
00415 IndexType::ixType () const
00416 {
00417   return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
00418 }
00419 
00420 #endif /* WRAPPER */
00421 
00422 //
00423 //@Man:
00424 //@Memo: A Rectangular Domain on an Integer Lattice
00425 /*@Doc: 
00426 
00427   A Box is an abstraction for defining discrete rectangular regions of
00428   SpaceDim-dimensioned indexing space.  Boxes have an IndexType, which
00429   defines IndexType::CELL or IndexType::NODE based points for each
00430   direction and a low and high IntVect which defines the lower and
00431   upper corners of the Box.  Boxes can exist in positive and negative
00432   indexing space.
00433 
00434   There is a set of canonical Empty Boxes, once for each centering
00435   type.  The cell-centered Empty Box can be accessed as Box::Empty.
00436 
00437   Box is a dimension dependent class, so SpaceDim must be 
00438   defined as either 1, 2, or 3 when compiling.  
00439 
00440 */
00441 
00442 class Box
00443 {
00444 public:
00445 
00447 
00449 
00453   Box ();
00454 
00456 
00460   ~Box () {;}
00461 
00462 
00464 
00469   Box (const IntVect& small,
00470        const IntVect& big);
00471 
00473 
00478   void define(const IntVect& small, const IntVect& big);
00479 
00481 
00486   Box (const IntVect& small,
00487        const int*     vec_len);
00488 
00490 
00497   Box (const IntVect& small,
00498        const IntVect& big,
00499        const IntVect& typ);
00500 
00502 
00508   Box (const IntVect&   small,
00509        const IntVect&   big,
00510        const IndexType& t);
00511 
00513 
00517   Box (const Box& b);
00518 
00519   void define(const Box& b);
00520 
00521   Box copy() const {return *this;}
00522 
00524 
00526 
00530   const IntVect& smallEnd () const;
00531 
00533 
00537   IntVect sideEnd(Side::LoHiSide a_side) const;
00538 
00539 
00541 
00547   int smallEnd (int dir) const;
00548 
00550 
00554   const IntVect& bigEnd () const;
00555 
00557 
00563   int bigEnd (int dir) const;
00564 
00566 
00572   const int* loVect () const;
00573 
00575 
00581   const int* hiVect () const;
00582 
00584 
00590   const int* getVect () const;
00591 
00593 
00599   long index (const IntVect& v) const;
00600 
00602 
00604 
00608   IndexType ixType () const;
00609 
00611 
00615   IntVect type () const;
00616 
00618 
00624   IndexType::CellIndex type (int dir) const;
00625 
00627 
00629 
00634   const IntVect& size () const;
00635 
00637 
00643   int size (int dir) const;
00644 
00646 
00650   bool numPtsOK () const;
00651 
00653 
00659   long numPts () const;
00660 
00662 
00666   bool volumeOK () const;
00667 
00669 
00675   long volume () const;
00676 
00678 
00684   int longside (int& dir) const;
00685 
00687 
00691   int longside () const;
00692 
00694 
00700   int shortside (int& dir) const;
00701 
00703 
00707   int shortside () const;
00708 
00709 
00711 
00713 
00717   bool isEmpty () const;
00718 
00720 
00726   bool contains (const IntVect& p) const;
00727 
00729 
00735   bool contains (const Box& b) const;
00736 
00738 
00744   bool intersects (const Box& b) const;
00745 
00747 
00755   bool intersectsNotEmpty (const Box& b) const;
00756 
00758 
00763   bool sameSize (const Box& b) const;
00764 
00766 
00770   bool sameType (const Box &b) const;
00771 
00773 
00778   bool operator== (const Box& b) const;
00779 
00780   bool eq(const Box& b) const;
00782 
00786   bool operator!= (const Box& b) const;
00787 
00788   bool neq(const Box& b) const;
00790 
00795   bool cellCentered () const;
00796 
00797   // following operators added Sept. 14, 1999.  bvs
00799 
00807   bool operator < (const Box& rhs) const;
00808 
00809   bool lt(const Box& rhs) const;
00810 
00811 
00813 
00815 
00819   Box& operator= (const Box& b);
00820 
00822 
00828   Box& setSmall (const IntVect& sm);
00829 
00831 
00838   Box& setSmall (int dir,
00839                  int sm_index);
00840 
00842 
00848   Box& setBig (const IntVect& bg);
00849 
00851 
00858   Box& setBig (int dir,
00859                int bg_index);
00860 
00862 
00867   Box& setRange (int dir,
00868                  int sm_index,
00869                  int n_cells = 1);
00870 
00872 
00874 
00885   Box& convert (IndexType typ);
00886 
00888 
00897   Box& convert (const IntVect& typ);
00898 
00900 
00912   Box& convert (int                  dir,
00913                 IndexType::CellIndex typ);
00914 
00916 
00923   Box& surroundingNodes ();
00924 
00926 
00934   Box& surroundingNodes (int dir);
00935 
00936   Box& surroundingNodes_int(int dir);
00938 
00947   friend  Box surroundingNodes (const Box& b,
00948                                 int        dir);
00949 
00950   
00952 
00960   friend Box surroundingNodes (const Box& b);
00961 
00963 
00970   Box& enclosedCells ();
00971 
00973 
00981   Box& enclosedCells (int dir);
00982 
00983   Box& enclosedCells_int (int dir);
00984 
00986 
00995   friend Box enclosedCells (const Box& b,
00996                             int        dir);
00997 
00999 
01007   friend Box enclosedCells (const Box& b);
01008 
01010 
01012 
01019   Box& shift (int dir,
01020               int nzones);
01021 
01023 
01029   Box& shift (const IntVect& iv);
01030   
01031   Box& shift_intvect (const IntVect& iv);
01032 
01034 
01046   Box& shiftHalf (int dir,
01047                   int num_halfs);
01048 
01050 
01056   Box& shiftHalf (const IntVect& iv);
01057   Box& shiftHalf_intvect (const IntVect& iv);
01058 
01060 
01065   Box& operator+= (const IntVect& v);
01066 
01068 
01073   Box  operator+  (const IntVect& v) const;
01074 
01076 
01081   Box& operator-= (const IntVect& v);
01082 
01084 
01089   Box  operator-  (const IntVect& v) const;
01090 
01092 
01094   friend Box bdryBox(const Box& b,
01095                      int        dir,
01096                      Side::LoHiSide a_sd,
01097                      int        len);
01098 
01099 
01101 
01109   friend Box bdryLo (const Box& b,
01110                      int        dir,
01111                      int        len);
01112 
01114 
01122   friend Box bdryHi (const Box& b,
01123                      int        dir,
01124                      int        len);
01125 
01127 
01150   friend Box adjCellLo (const Box& b,
01151                         int        dir,
01152                         int        len);
01153 
01155 
01178   friend Box adjCellHi (const Box& b,
01179                         int        dir,
01180                         int        len);
01181 
01182 
01184 
01186 
01193   Box operator& (const Box&) const;
01194 
01196 
01202   Box& operator&= (const Box&);
01203 
01204 
01206   friend Box adjCellBox (const Box& b,
01207                          int        dir,
01208                          Side::LoHiSide a_side,
01209                          int        len);
01211 
01216   Box& minBox (const Box& b);
01217 
01219 
01224   friend Box minBox (const Box& b1,
01225                      const Box& b2);
01226 
01228 
01230 
01238   Box& grow (int i);
01239 
01241 
01249   friend Box grow (const Box& b,
01250                    int        i);
01251 
01253 
01261   Box& grow (const IntVect& v);
01262 
01264 
01272   friend  Box grow (const Box&     b,
01273                     const IntVect& v);
01274 
01276 
01285   Box& grow (int idir,
01286              int n_cell);
01287 
01289 
01298   Box& growLo (int idir,
01299                int n_cell=1);
01300 
01302 
01306   Box& growDir (int a_idir,
01307                 const Side::LoHiSide& a_sd,
01308                 int a_cell);
01309 
01311 
01320   Box& growHi (int idir,
01321                int n_cell=1);
01322 
01324 
01326 
01337   Box& refine (int refinement_ratio);
01338 
01340 
01352   friend Box refine (const Box& b,
01353                      int        refinement_ratio);
01354 
01356 
01367   Box& refine (const IntVect& refinement_ratio);
01368 
01370 
01382   friend Box refine (const Box&     b,
01383                      const IntVect& refinement_ratio);
01384 
01386 
01388 
01403   Box& coarsen (int refinement_ratio);
01404 
01406 
01421   friend Box coarsen (const Box& b,
01422                       int        refinement_ratio);
01423 
01425 
01439   Box& coarsen (const IntVect& refinement_ratio);
01440 
01442 
01457   friend Box coarsen (const Box&     b,
01458                       const IntVect& refinement_ratio);
01459 
01460   // next(...) is out of favor.  use BoxIterator.
01461   /*
01462     Step through the rectangle.  It is a runtime error to give
01463     a point not inside rectangle.  Iteration may not be efficient.
01464   */
01465   void next (IntVect &) const;
01466 
01467   /*
01468     Scan argument IntVect over object second arg is
01469     increment vector.  Runtime error if IntVect is not
01470     contained in object Box.  Iteration may not be efficient.
01471   */
01472   void next (IntVect&   p,
01473              const int* shv) const;
01474 
01475 
01477 
01479 
01492   Box chop (int dir,
01493             int chop_pnt);
01494 
01496 
01498 
01502   friend std::ostream& operator<< (std::ostream&   os,
01503                                    const Box& bx);
01504 
01506 
01510   friend std::istream& operator>> (std::istream& os,
01511                                    Box&     bx);
01512 
01513 
01515 
01518   void p() const;
01519 
01521 
01526   void dumpOn (std::ostream& strm) const;
01527 
01529 
01531 
01535   //static const Box Empty;
01536 
01537 
01538   // TheUnitBox is out of favor.
01539   /*
01540     This static member function returns a constant reference to 
01541     an object of type Box representing the unit box in
01542     BL\_SPACEDIM-dimensional space.
01543   */
01544 
01545   //static const Box& TheUnitBox ();
01546 
01547   //
01548   // Sets the 'len' element of the Box.  Aborts on integer overflow.
01549   //
01550   void computeBoxLen ();
01551   void computeBoxLenNotEmpty();
01552 
01553 protected:
01554   friend class HDF5Handle;
01555   //
01556   // A helper function for numPtsOK() and numPts().
01557   //
01558   bool numPtsOK (long& N) const;
01559   //
01560   // A helper function for volumeOK() and volume().
01561   //
01562   bool volumeOK (long& N) const;
01563 
01564   IntVect   smallend;
01565   IntVect   bigend;
01566   IntVect   len;
01567   IndexType btype;
01568 
01569 };
01570 
01571 // global function prototypes
01572 Box surroundingNodes (const Box& b,
01573                       int        dir);
01574 Box surroundingNodes (const Box& b);
01575 Box enclosedCells (const Box& b,
01576                    int        dir);
01577 Box enclosedCells (const Box& b);
01578 Box bdryBox(const Box& b,
01579             int        dir,
01580             Side::LoHiSide a_sd,
01581             int        len=1);
01582 Box bdryLo (const Box& b,
01583             int        dir,
01584             int        len=1);
01585 Box bdryHi (const Box& b,
01586             int        dir,
01587             int        len=1);
01588 Box adjCellLo (const Box& b,
01589                int        dir,
01590                int        len=1);
01591 Box adjCellHi (const Box& b,
01592                int        dir,
01593                int        len=1);
01594 Box minBox (const Box& b1,
01595             const Box& b2);
01596 //
01597 // Inlines. 
01598 //
01599 
01600 #ifndef WRAPPER
01601 
01602 inline
01603 Box::Box (const Box& b)
01604   : smallend(b.smallend),
01605     bigend(b.bigend),
01606     btype(b.btype)
01607 {
01608   D_EXPR(len[0] = b.len[0],
01609          len[1] = b.len[1],
01610          len[2] = b.len[2]);
01611 }
01612 
01613 inline
01614 Box&
01615 Box::operator= (const Box& b)
01616 {
01617   smallend = b.smallend;
01618   bigend = b.bigend;
01619   btype = b.btype;
01620   D_EXPR(len[0] = b.len[0],
01621          len[1] = b.len[1],
01622          len[2] = b.len[2]);
01623   return *this;
01624 }
01625 
01626 inline
01627 IntVect
01628 Box::sideEnd(Side::LoHiSide a_side) const
01629 {
01630   IntVect retval;
01631   if(a_side == Side::Lo)
01632     retval = smallEnd();
01633   else
01634     retval = bigEnd();
01635   return retval;
01636 }
01637 
01638 inline
01639 const IntVect&
01640 Box::smallEnd () const
01641 {
01642   return smallend;
01643 }
01644 
01645 inline
01646 int
01647 Box::smallEnd (int dir) const
01648 {
01649   return smallend[dir];
01650 }
01651 
01652 inline
01653 const IntVect&
01654 Box::bigEnd () const
01655 {
01656   return bigend;
01657 }
01658 
01659 inline
01660 int
01661 Box::bigEnd (int dir) const
01662 {
01663   return bigend[dir];
01664 }
01665 
01666 inline
01667 IndexType
01668 Box::ixType () const
01669 {
01670   return btype;
01671 }
01672 
01673 inline
01674 IntVect
01675 Box::type () const
01676 {
01677   return btype.ixType();
01678 }
01679 
01680 inline
01681 IndexType::CellIndex
01682 Box::type (int dir) const
01683 {
01684   return btype.ixType(dir);
01685 }
01686 
01687 inline
01688 const IntVect&
01689 Box::size () const
01690 {
01691   return len;
01692 }
01693 
01694 inline
01695 int
01696 Box::size (int dir) const
01697 {
01698   return len[dir];
01699 }
01700 
01701 inline
01702 const int*
01703 Box::loVect () const
01704 {
01705   return smallend.getVect();
01706 }
01707 
01708 inline
01709 const int*
01710 Box::hiVect () const
01711 {
01712   return bigend.getVect();
01713 }
01714 
01715 inline
01716 const int*
01717 Box::getVect () const
01718 {
01719   return smallend.getVect();
01720 }
01721 
01722 
01723 inline
01724 bool
01725 Box::numPtsOK () const
01726 {
01727   long ignore;
01728   return numPtsOK(ignore);
01729 }
01730 
01731 inline
01732 bool
01733 Box::isEmpty () const
01734 {
01735   //    return numPts() == 0;
01736   return (!(bigend >= smallend));
01737 }
01738 
01739 inline
01740 bool
01741 Box::contains (const IntVect& p) const
01742 {
01743 
01744   return ( !isEmpty() && (p >= smallend && p <= bigend) );
01745 }
01746 
01747 inline
01748 bool
01749 Box::sameType (const Box &b) const
01750 {
01751   return btype == b.btype;
01752 }
01753 
01754 inline
01755 bool
01756 Box::contains (const Box& b) const
01757 {
01758   assert(sameType(b));
01759   return ( !isEmpty() && !b.isEmpty() && 
01760            (b.smallend >= smallend && b.bigend <= bigend) );
01761 }
01762 
01763 inline
01764 bool
01765 Box::sameSize (const Box& b) const
01766 {
01767   assert(sameType(b));
01768   return D_TERM(len[0] == b.len[0],
01769                 && len[1]==b.len[1],
01770                 && len[2]==b.len[2]);
01771 }
01772 
01773 inline
01774 bool
01775 Box::operator== (const Box& b) const
01776 {
01777   return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01778 }
01779 
01780 inline
01781 bool
01782 Box::operator!= (const Box& b) const
01783 {
01784   return !operator==(b);
01785 }
01786 
01787 inline
01788 bool
01789 Box::cellCentered () const
01790 {
01791   return !btype.any();
01792 }
01793 
01794 inline
01795 bool
01796 Box::volumeOK () const
01797 {
01798   return numPtsOK();
01799 }
01800 
01801 inline
01802 long
01803 Box::index (const IntVect& v) const
01804 {
01805   long result = v.vect[0]-smallend.vect[0];
01806 #if   CH_SPACEDIM==2
01807   result += len[0]*(v.vect[1]-smallend.vect[1]);
01808 #elif CH_SPACEDIM==3
01809   result += len[0]*(v.vect[1]-smallend.vect[1]
01810                     +(v.vect[2]-smallend.vect[2])*len[1]);
01811 #endif
01812   return result;
01813 }
01814 
01815 inline
01816 void
01817 Box::computeBoxLen ()
01818 {
01819   if (isEmpty())
01820     {
01821       len = IntVect::Zero;
01822     }
01823   else
01824     {
01825       D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01826              len[1] = bigend[1]-smallend[1] + 1,
01827              len[2] = bigend[2]-smallend[2] + 1);
01828     }
01829 }
01830 
01831 inline
01832 void
01833 Box::computeBoxLenNotEmpty()
01834 {
01835   D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01836          len[1] = bigend[1]-smallend[1] + 1,
01837          len[2] = bigend[2]-smallend[2] + 1);
01838 }
01839 
01840 inline
01841 Box&
01842 Box::setSmall (const IntVect& sm)
01843 {
01844   assert (sm <= bigend);
01845 
01846   smallend = sm;
01847   computeBoxLen();
01848   return *this;
01849 }
01850 
01851 inline
01852 Box&
01853 Box::setSmall (int dir,
01854                int sm_index)
01855 {
01856   assert (sm_index <= bigend[dir]);
01857 
01858   smallend.setVal(dir,sm_index);
01859   computeBoxLen();
01860   return *this;
01861 }
01862 
01863 inline
01864 Box&
01865 Box::setBig (const IntVect& bg)
01866 {
01867   assert (bg >= smallend);
01868 
01869   bigend = bg;
01870   computeBoxLen();
01871   return *this;
01872 }
01873 
01874 inline
01875 Box&
01876 Box::setBig (int dir,
01877              int bg_index)
01878 {
01879   assert (bg_index >= smallend[dir]);
01880 
01881   bigend.setVal(dir,bg_index);
01882   computeBoxLen();
01883   return *this;
01884 }
01885 
01886 inline
01887 Box&
01888 Box::setRange (int dir,
01889                int sm_index,
01890                int n_cells)
01891 {
01892   assert (n_cells > 0);
01893 
01894   smallend.setVal(dir,sm_index);
01895   bigend.setVal(dir,sm_index+n_cells-1);
01896   computeBoxLen();
01897   return *this;
01898 }
01899 
01900 inline
01901 Box&
01902 Box::shift (int dir,
01903             int nzones)
01904 {
01905   if (!isEmpty())
01906     {
01907       smallend.shift(dir,nzones);
01908       bigend.shift(dir,nzones);
01909     }
01910   return *this;
01911 }
01912 
01913 inline
01914 Box&
01915 Box::shift (const IntVect& iv)
01916 {
01917   if (!isEmpty())
01918     {
01919       smallend.shift(iv);
01920       bigend.shift(iv);
01921     }
01922   return *this;
01923 }
01924 
01925 inline
01926 Box&
01927 Box::convert (const IntVect& typ)
01928 {
01929   assert(typ >= IntVect::TheZeroVector() && typ <= IntVect::TheUnitVector());
01930   if (!isEmpty())
01931     {
01932       IntVect shft(typ - btype.ixType());
01933       bigend += shft;
01934     }
01935   btype = IndexType(typ);
01936   computeBoxLen();
01937   return *this;
01938 }
01939 
01940 inline
01941 Box&
01942 Box::surroundingNodes (int dir)
01943 {
01944   if (!(btype[dir]))
01945     {
01946       if (!isEmpty())
01947         {
01948           bigend.shift(dir,1);
01949         }
01950       //
01951       // Set dir'th bit to 1 = IndexType::NODE.
01952       //
01953       btype.set(dir);
01954       computeBoxLen();
01955     }
01956   return *this;
01957 }
01958 
01959 inline
01960 Box&
01961 Box::enclosedCells (int dir)
01962 {
01963   if (btype[dir])
01964     {
01965       if (!isEmpty())
01966         {
01967           bigend.shift(dir,-1);
01968         }
01969       //
01970       // Set dir'th bit to 0 = IndexType::CELL.
01971       //
01972       btype.unset(dir);
01973       computeBoxLen();
01974     }
01975   return *this;
01976 }
01977 
01978 inline
01979 Box
01980 surroundingNodes (const Box& b,
01981                   int        dir)
01982 {
01983   Box bx(b);
01984   return bx.surroundingNodes(dir);
01985 }
01986 
01987 inline
01988 Box
01989 surroundingNodes (const Box& b)
01990 {
01991   Box bx(b);
01992   return bx.surroundingNodes();
01993 }
01994 
01995 inline
01996 Box
01997 enclosedCells (const Box& b,
01998                int        dir)
01999 {
02000   Box bx(b);
02001   return bx.enclosedCells(dir);
02002 }
02003 
02004 inline
02005 Box
02006 enclosedCells (const Box& b)
02007 {
02008   Box bx(b);
02009   return bx.enclosedCells();
02010 }
02011 
02012 inline
02013 Box&
02014 Box::operator+= (const IntVect& v)
02015 {
02016   if (!isEmpty())
02017     {
02018       smallend += v;
02019       bigend += v;
02020     }
02021   return *this;
02022 }
02023 
02024 inline
02025 Box
02026 Box::operator+  (const IntVect& v) const
02027 {
02028   if (isEmpty())
02029     {
02030       return(Box().convert(btype));
02031     }
02032   else
02033     {
02034       IntVect small(smallend);
02035       small += v;
02036       IntVect big(bigend);
02037       big += v;
02038       return Box(small,big,btype);
02039     }
02040 }
02041 
02042 inline
02043 Box&
02044 Box::operator-= (const IntVect& v)
02045 {
02046   if (!isEmpty())
02047     {
02048       smallend -= v;
02049       bigend -= v;
02050     }
02051   return *this;
02052 }
02053 
02054 inline
02055 bool 
02056 Box::operator < (const Box& rhs) const
02057 {
02058   return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02059 }
02060 
02061 inline
02062 Box
02063 Box::operator-  (const IntVect& v) const
02064 {
02065   if (isEmpty())
02066     {
02067       return(Box().convert(btype));
02068     }
02069   else
02070     {
02071       IntVect small = smallend;
02072       small -= v;
02073       IntVect big = bigend;
02074       big -= v;
02075       return Box(small,big,btype);
02076     }
02077 }
02078 
02079 inline
02080 Box&
02081 Box::grow (int i)
02082 {
02083   if (!isEmpty())
02084     {
02085       smallend.diagShift(-i);
02086       bigend.diagShift(i);
02087       if (!(bigend >= smallend)) *this = Box().convert(btype);
02088       computeBoxLen();
02089     }
02090   return *this;
02091 }
02092 
02093 inline
02094 Box
02095 grow (const Box& b,
02096       int        i)
02097 {
02098   if (b.isEmpty())
02099     {
02100       return (Box().convert(b.btype));
02101     }
02102   else
02103     {
02104       IntVect small = diagShift(b.smallend,-i);
02105       IntVect big   = diagShift(b.bigend,i);
02106       if (!(big >= small))
02107         {
02108           return(Box().convert(b.btype));
02109         }
02110       else
02111         {
02112           return Box(small,big,b.btype);
02113         }
02114     }
02115 }
02116 
02117 inline
02118 Box&
02119 Box::grow (const IntVect& v)
02120 {
02121   if (!isEmpty())
02122     {
02123       smallend -= v;
02124       bigend   += v;
02125       if (!(bigend >= smallend)) *this = Box().convert(btype);
02126       computeBoxLen();
02127     }
02128   return *this;
02129 }
02130 
02131 inline
02132 Box
02133 grow (const Box&     b,
02134       const IntVect& v)
02135 {
02136   if (b.isEmpty())
02137     {
02138       return(Box().convert(b.btype));
02139     }
02140   else
02141     {
02142       IntVect small = b.smallend - v;
02143       IntVect big   = b.bigend   + v;
02144       if (!(big >= small))
02145         {
02146           return(Box().convert(b.btype));
02147         }
02148       else
02149         {
02150           return Box(small,big,b.btype);
02151         }
02152     }
02153 }
02154 
02155 inline
02156 Box&
02157 Box::grow (int idir,
02158            int n_cell)
02159 {
02160   if (!isEmpty())
02161     {
02162       smallend.shift(idir, -n_cell);
02163       bigend.shift(idir, n_cell);
02164       if (!(bigend >= smallend)) *this = Box().convert(btype);
02165       computeBoxLen();
02166     }
02167   return *this;
02168 }
02169 
02170 inline
02171 Box&
02172 Box::growLo (int idir,
02173              int n_cell)
02174 {
02175   if (!isEmpty())
02176     {
02177       smallend.shift(idir, -n_cell);
02178       if (!(bigend >= smallend)) *this = Box().convert(btype);
02179       computeBoxLen();
02180     }
02181   return *this;
02182 }
02183 
02184 inline
02185 Box&
02186 Box::growDir (int idir,
02187               const Side::LoHiSide& a_sd,
02188               int n_cell)
02189 {
02190   if(a_sd == Side::Lo)
02191     {
02192       growLo(idir, n_cell);
02193     }
02194   else
02195     {
02196       growHi(idir, n_cell);
02197     }
02198   return *this;
02199 }
02200 
02201 inline
02202 Box&
02203 Box::growHi (int idir,
02204              int n_cell)
02205 {
02206   if (!isEmpty())
02207     {
02208       bigend.shift(idir,n_cell);
02209       if (!(bigend >= smallend)) *this = Box().convert(btype);
02210       computeBoxLen();
02211     }
02212   return *this;
02213 }
02214 
02215 
02216 inline
02217 Box
02218 Box::operator& (const Box& rhs) const
02219 {
02220   Box lhs(*this);
02221   return lhs &= rhs;
02222 }
02223 
02224 #endif /* WRAPPER */
02225 
02226 #endif /*CH_BOX_H*/

Generated on Thu Aug 29 11:05:44 2002 for Chombo&INS by doxygen1.2.16