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    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 #ifndef _BOX_H_
00053 #define _BOX_H_
00054 
00055 #ifdef NODEV
00056 #undef NODEV
00057 #endif
00058 
00059 #include "SPACE.H"
00060 
00061 #ifndef WRAPPER
00062 #include <iostream>
00063 
00064 #include "IntVect.H"
00065 #include "Misc.H"
00066 #include "LoHiSide.H"
00067 
00069 
00077 class IndexType
00078 {
00079 public:
00081 
00085   enum CellIndex { CELL = 0, NODE = 1 };
00086 
00088 
00092   IndexType ();
00093 
00095 
00099   IndexType (const IndexType& rhs);
00100 
00102 
00106   explicit IndexType (const IntVect& iv);
00107 
00109 
00113   IndexType& operator= (const IndexType& rhs);
00114 
00116 
00122   IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k));
00123 
00125 
00129   void set (int dir);
00130 
00132 
00136   void unset (int dir);
00137 
00139 
00143   bool test (int dir) const;
00144 
00146 
00150   void setall ();
00151 
00153 
00157   void clear ();
00158 
00160 
00164   bool any () const;
00165 
00167 
00171   bool ok () const;
00172 
00174 
00179   void flip (int i);
00180 
00182 
00186   bool operator== (const IndexType& t) const;
00187 
00189 
00193   bool operator!= (const IndexType& t) const;
00194 
00196 
00200   bool cellCentered () const;
00201 
00203 
00207   bool nodeCentered () const;
00208 
00210 
00214   void setType (int       dir,
00215                 CellIndex t);
00216 
00218 
00222   CellIndex ixType (int dir) const;
00223 
00225 
00229   int operator[] (int dir) const;
00230 
00232 
00237   IntVect ixType () const;
00238 
00240 
00247   static IndexType TheCellType ();
00248 
00250 
00257   static IndexType TheNodeType ();
00258 
00260 
00264   friend std::ostream& operator<< (std::ostream&         os,
00265                                    const IndexType& itype);
00266 
00268 
00272   friend std::istream& operator>> (std::istream&   is,
00273                                    IndexType& itype);
00274 private:
00275   //
00276   // Returns 1<<k.
00277   //
00278   static int mask (int k);
00279   //
00280   // An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1.
00281   //
00282   unsigned int itype;
00283 };
00284 
00285 //
00286 // Inlines.
00287 //
00288 
00289 inline
00290 int
00291 IndexType::mask (int k)
00292 {
00293   return 1<<k;
00294 }
00295 
00296 inline
00297 IndexType::IndexType ()
00298   :
00299   itype(0)
00300 {}
00301 
00302 inline
00303 IndexType::IndexType (const IndexType& bt)
00304   :
00305   itype(bt.itype)
00306 {}
00307 
00308 inline
00309 IndexType& IndexType::operator= (const IndexType& bt)
00310 {
00311   itype = bt.itype;
00312   return *this;
00313 }
00314 
00315 inline
00316 IndexType::IndexType (const IntVect& iv)
00317 {
00318   itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00319 }
00320 
00321 inline
00322 IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
00323 {
00324   itype = D_TERM(i, | (j<<1), | (k<<2));
00325 }
00326 
00327 inline
00328 void
00329 IndexType::set (int dir)
00330 {
00331   itype |= mask(dir);
00332 }
00333 
00334 inline
00335 void
00336 IndexType::unset (int dir)
00337 {
00338   itype &= ~mask(dir);
00339 }
00340 
00341 inline
00342 bool
00343 IndexType::test (int dir) const
00344 {
00345   return (itype & mask(dir)) != 0;
00346 }
00347 
00348 inline
00349 void
00350 IndexType::setall ()
00351 {
00352   itype = (1 << SpaceDim) - 1;
00353 }
00354 
00355 inline
00356 void
00357 IndexType::clear ()
00358 {
00359   itype = 0;
00360 }
00361 
00362 inline
00363 bool
00364 IndexType::any () const
00365 {
00366   return itype != 0;
00367 }
00368 
00369 inline
00370 bool
00371 IndexType::ok () const
00372 {
00373   return itype < (1 << SpaceDim);
00374 }
00375 
00376 inline
00377 void
00378 IndexType::flip (int i)
00379 {
00380   itype ^= mask(i);
00381 }
00382 
00383 inline
00384 bool
00385 IndexType::operator== (const IndexType& t) const
00386 {
00387   return t.itype == itype;
00388 }
00389 
00390 inline
00391 bool
00392 IndexType::operator!= (const IndexType& t) const
00393 {
00394   return t.itype != itype;
00395 }
00396 
00397 inline
00398 bool
00399 IndexType::cellCentered () const
00400 {
00401   return itype == 0;
00402 }
00403 
00404 inline
00405 bool
00406 IndexType::nodeCentered () const
00407 {
00408   return itype == (1<<SpaceDim)-1;
00409 }
00410 
00411 inline
00412 void
00413 IndexType::setType (int       dir,
00414                     CellIndex t)
00415 {
00416   t == CELL ? unset(dir) : set(dir);
00417 }
00418 
00419 inline
00420 IndexType::CellIndex
00421 IndexType::ixType (int dir) const
00422 {
00423   return (CellIndex) ((itype & (1<<dir)) >> dir);
00424 }
00425 
00426 inline
00427 int
00428 IndexType::operator[] (int dir) const
00429 {
00430   return test(dir);
00431 }
00432 
00433 inline
00434 IntVect
00435 IndexType::ixType () const
00436 {
00437   return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
00438 }
00439 
00440 #endif /* WRAPPER */
00441 
00442 //
00444 
00457 class Box
00458 {
00459 public:
00460 
00462 
00464 
00468   Box ();
00469 
00471 
00475   ~Box ()
00476   {}
00477 
00479 
00484   Box (const IntVect& small,
00485        const IntVect& big);
00486 
00488 
00493   void define(const IntVect& small, const IntVect& big);
00494 
00496 
00501   Box (const IntVect& small,
00502        const int*     vec_len);
00503 
00505 
00512   Box (const IntVect& small,
00513        const IntVect& big,
00514        const IntVect& typ);
00515 
00517 
00523   Box (const IntVect&   small,
00524        const IntVect&   big,
00525        const IndexType& t);
00526 
00528 
00532   Box (const Box& b);
00533 
00534   void define(const Box& b);
00535 
00536   Box copy() const {return *this;}
00537 
00539 
00541 
00545   const IntVect& smallEnd () const;
00546 
00548 
00552   IntVect sideEnd(Side::LoHiSide a_side) const;
00553 
00555 
00561   int smallEnd (int dir) const;
00562 
00564 
00568   const IntVect& bigEnd () const;
00569 
00571 
00577   int bigEnd (int dir) const;
00578 
00580 
00586   const int* loVect () const;
00587 
00589 
00595   const int* hiVect () const;
00596 
00598 
00604   const int* getVect () const;
00605 
00607 
00613   long index (const IntVect& v) const;
00614 
00616 
00618 
00622   IndexType ixType () const;
00623 
00625 
00629   IntVect type () const;
00630 
00632 
00638   IndexType::CellIndex type (int dir) const;
00639 
00641 
00643 
00648   const IntVect& size () const;
00649 
00651 
00657   int size (int dir) const;
00658 
00660 
00664   bool numPtsOK () const;
00665 
00667 
00673   long numPts () const;
00674 
00676 
00680   bool volumeOK () const;
00681 
00683 
00689   long volume () const;
00690 
00692 
00698   int longside (int& dir) const;
00699 
00701 
00705   int longside () const;
00706 
00708 
00714   int shortside (int& dir) const;
00715 
00717 
00721   int shortside () const;
00722 
00724 
00726 
00730   bool isEmpty () const;
00731 
00733 
00739   bool contains (const IntVect& p) const;
00740 
00742 
00748   bool contains (const Box& b) const;
00749 
00751 
00757   bool intersects (const Box& b) const;
00758 
00760 
00768   bool intersectsNotEmpty (const Box& b) const;
00769 
00771 
00776   bool sameSize (const Box& b) const;
00777 
00779 
00783   bool sameType (const Box &b) const;
00784 
00786 
00791   bool operator== (const Box& b) const;
00792 
00793   bool eq(const Box& b) const;
00795 
00799   bool operator!= (const Box& b) const;
00800 
00801   bool neq(const Box& b) const;
00803 
00808   bool cellCentered () const;
00809 
00810   // following operators added Sept. 14, 1999.  bvs
00812 
00820   bool operator < (const Box& rhs) const;
00821 
00822   bool lt(const Box& rhs) const;
00823 
00825 
00827 
00831   Box& operator= (const Box& b);
00832 
00834 
00840   Box& setSmall (const IntVect& sm);
00841 
00843 
00850   Box& setSmall (int dir,
00851                  int sm_index);
00852 
00854 
00860   Box& setBig (const IntVect& bg);
00861 
00863 
00870   Box& setBig (int dir,
00871                int bg_index);
00872 
00874 
00879   Box& setRange (int dir,
00880                  int sm_index,
00881                  int n_cells = 1);
00882 
00884 
00886 
00897   Box& convert (IndexType typ);
00898 
00900 
00909   Box& convert (const IntVect& typ);
00910 
00912 
00924   Box& convert (int                  dir,
00925                 IndexType::CellIndex typ);
00926 
00928 
00935   Box& surroundingNodes ();
00936 
00938 
00946   Box& surroundingNodes (int dir);
00947 
00948   Box& surroundingNodes_int(int dir);
00950 
00959   friend  Box surroundingNodes (const Box& b,
00960                                 int        dir);
00961 
00963 
00971   friend Box surroundingNodes (const Box& b);
00972 
00974 
00981   Box& enclosedCells ();
00982 
00984 
00992   Box& enclosedCells (int dir);
00993 
00994   Box& enclosedCells_int (int dir);
00995 
00997 
01006   friend Box enclosedCells (const Box& b,
01007                             int        dir);
01008 
01010 
01018   friend Box enclosedCells (const Box& b);
01019 
01021 
01023 
01030   Box& shift (int dir,
01031               int nzones);
01032 
01034 
01040   Box& shift (const IntVect& iv);
01041 
01042   Box& shift_intvect (const IntVect& iv);
01043 
01045 
01057   Box& shiftHalf (int dir,
01058                   int num_halfs);
01059 
01061 
01067   Box& shiftHalf (const IntVect& iv);
01068   Box& shiftHalf_intvect (const IntVect& iv);
01069 
01071 
01076   Box& operator+= (const IntVect& v);
01077 
01079 
01084   Box  operator+  (const IntVect& v) const;
01085 
01087 
01092   Box& operator-= (const IntVect& v);
01093 
01095 
01100   Box  operator-  (const IntVect& v) const;
01101 
01103 
01105   friend Box bdryBox(const Box& b,
01106                      int        dir,
01107                      Side::LoHiSide a_sd,
01108                      int        len);
01109 
01111 
01119   friend Box bdryLo (const Box& b,
01120                      int        dir,
01121                      int        len);
01122 
01124 
01132   friend Box bdryHi (const Box& b,
01133                      int        dir,
01134                      int        len);
01135 
01137 
01160   friend Box adjCellLo (const Box& b,
01161                         int        dir,
01162                         int        len);
01163 
01165 
01188   friend Box adjCellHi (const Box& b,
01189                         int        dir,
01190                         int        len);
01191 
01193 
01195 
01202   Box operator& (const Box&) const;
01203 
01205 
01211   Box& operator&= (const Box&);
01212 
01214   friend Box adjCellBox (const Box& b,
01215                          int        dir,
01216                          Side::LoHiSide a_side,
01217                          int        len);
01219 
01224   Box& minBox (const Box& b);
01225 
01227 
01232   friend Box minBox (const Box& b1,
01233                      const Box& b2);
01234 
01236 
01238 
01246   Box& grow (int i);
01247 
01249 
01257   friend Box grow (const Box& b,
01258                    int        i);
01259 
01261 
01269   Box& grow (const IntVect& v);
01270 
01272 
01280   friend  Box grow (const Box&     b,
01281                     const IntVect& v);
01282 
01284 
01293   Box& grow (int idir,
01294              int n_cell);
01295 
01297 
01306   Box& growLo (int idir,
01307                int n_cell=1);
01308 
01310 
01314   Box& growDir (int a_idir,
01315                 const Side::LoHiSide& a_sd,
01316                 int a_cell);
01317 
01319 
01328   Box& growHi (int idir,
01329                int n_cell=1);
01330 
01332 
01334 
01345   Box& refine (int refinement_ratio);
01346 
01348 
01360   friend Box refine (const Box& b,
01361                      int        refinement_ratio);
01362 
01364 
01375   Box& refine (const IntVect& refinement_ratio);
01376 
01378 
01390   friend Box refine (const Box&     b,
01391                      const IntVect& refinement_ratio);
01392 
01394 
01396 
01411   Box& coarsen (int refinement_ratio);
01412 
01414 
01429   friend Box coarsen (const Box& b,
01430                       int        refinement_ratio);
01431 
01433 
01447   Box& coarsen (const IntVect& refinement_ratio);
01448 
01450 
01465   friend Box coarsen (const Box&     b,
01466                       const IntVect& refinement_ratio);
01467 
01468   // next(...) is out of favor.  use BoxIterator.
01469   /*
01470     Step through the rectangle.  It is a runtime error to give
01471     a point not inside rectangle.  Iteration may not be efficient.
01472   */
01473   void next (IntVect &) const;
01474 
01475   /*
01476     Scan argument IntVect over object second arg is
01477     increment vector.  Runtime error if IntVect is not
01478     contained in object Box.  Iteration may not be efficient.
01479   */
01480   void next (IntVect&   p,
01481              const int* shv) const;
01482 
01484 
01486 
01499   Box chop (int dir,
01500             int chop_pnt);
01501 
01503 
01505 
01509   friend std::ostream& operator<< (std::ostream&   os,
01510                                    const Box& bx);
01511 
01513 
01517   friend std::istream& operator>> (std::istream& os,
01518                                    Box&     bx);
01519 
01521 
01524   void p() const;
01525 
01527 
01532   void dumpOn (std::ostream& strm) const;
01533 
01535 
01537 
01541   //static const Box Empty;
01542 
01543   // TheUnitBox is out of favor.
01544   /*
01545     This static member function returns a constant reference to
01546     an object of type Box representing the unit box in
01547     BL\_SPACEDIM-dimensional space.
01548   */
01549 
01550   //static const Box& TheUnitBox ();
01551 
01552   //
01553   // Sets the 'len' element of the Box.  Aborts on integer overflow.
01554   //
01555   void computeBoxLen ();
01556   void computeBoxLenNotEmpty();
01557 
01558 protected:
01559   friend class HDF5Handle;
01560   //
01561   // A helper function for numPtsOK() and numPts().
01562   //
01563   bool numPtsOK (long& N) const;
01564   //
01565   // A helper function for volumeOK() and volume().
01566   //
01567   bool volumeOK (long& N) const;
01568 
01569   IntVect   smallend;
01570   IntVect   bigend;
01571   IntVect   len;
01572   IndexType btype;
01573 
01574 };
01575 
01576 // global function prototypes
01577 Box surroundingNodes (const Box& b,
01578                       int        dir);
01579 Box surroundingNodes (const Box& b);
01580 Box enclosedCells (const Box& b,
01581                    int        dir);
01582 Box enclosedCells (const Box& b);
01583 Box bdryBox(const Box& b,
01584             int        dir,
01585             Side::LoHiSide a_sd,
01586             int        len=1);
01587 Box bdryLo (const Box& b,
01588             int        dir,
01589             int        len=1);
01590 Box bdryHi (const Box& b,
01591             int        dir,
01592             int        len=1);
01593 Box adjCellLo (const Box& b,
01594                int        dir,
01595                int        len=1);
01596 Box adjCellHi (const Box& b,
01597                int        dir,
01598                int        len=1);
01599 Box minBox (const Box& b1,
01600             const Box& b2);
01601 //
01602 // Inlines.
01603 //
01604 
01605 #ifndef WRAPPER
01606 
01607 inline
01608 Box::Box (const Box& b)
01609   : smallend(b.smallend),
01610     bigend(b.bigend),
01611     btype(b.btype)
01612 {
01613   D_EXPR(len[0] = b.len[0],
01614          len[1] = b.len[1],
01615          len[2] = b.len[2]);
01616 }
01617 
01618 inline
01619 Box&
01620 Box::operator= (const Box& b)
01621 {
01622   smallend = b.smallend;
01623   bigend = b.bigend;
01624   btype = b.btype;
01625   D_EXPR(len[0] = b.len[0],
01626          len[1] = b.len[1],
01627          len[2] = b.len[2]);
01628   return *this;
01629 }
01630 
01631 inline
01632 IntVect
01633 Box::sideEnd(Side::LoHiSide a_side) const
01634 {
01635   IntVect retval;
01636   if(a_side == Side::Lo)
01637     retval = smallEnd();
01638   else
01639     retval = bigEnd();
01640   return retval;
01641 }
01642 
01643 inline
01644 const IntVect&
01645 Box::smallEnd () const
01646 {
01647   return smallend;
01648 }
01649 
01650 inline
01651 int
01652 Box::smallEnd (int dir) const
01653 {
01654   return smallend[dir];
01655 }
01656 
01657 inline
01658 const IntVect&
01659 Box::bigEnd () const
01660 {
01661   return bigend;
01662 }
01663 
01664 inline
01665 int
01666 Box::bigEnd (int dir) const
01667 {
01668   return bigend[dir];
01669 }
01670 
01671 inline
01672 IndexType
01673 Box::ixType () const
01674 {
01675   return btype;
01676 }
01677 
01678 inline
01679 IntVect
01680 Box::type () const
01681 {
01682   return btype.ixType();
01683 }
01684 
01685 inline
01686 IndexType::CellIndex
01687 Box::type (int dir) const
01688 {
01689   return btype.ixType(dir);
01690 }
01691 
01692 inline
01693 const IntVect&
01694 Box::size () const
01695 {
01696   return len;
01697 }
01698 
01699 inline
01700 int
01701 Box::size (int dir) const
01702 {
01703   return len[dir];
01704 }
01705 
01706 inline
01707 const int*
01708 Box::loVect () const
01709 {
01710   return smallend.getVect();
01711 }
01712 
01713 inline
01714 const int*
01715 Box::hiVect () const
01716 {
01717   return bigend.getVect();
01718 }
01719 
01720 inline
01721 const int*
01722 Box::getVect () const
01723 {
01724   return smallend.getVect();
01725 }
01726 
01727 inline
01728 bool
01729 Box::numPtsOK () const
01730 {
01731   long ignore;
01732   return numPtsOK(ignore);
01733 }
01734 
01735 inline
01736 bool
01737 Box::isEmpty () const
01738 {
01739   //    return numPts() == 0;
01740   return (!(bigend >= smallend));
01741 }
01742 
01743 inline
01744 bool
01745 Box::contains (const IntVect& p) const
01746 {
01747 
01748   return ( !isEmpty() && (p >= smallend && p <= bigend) );
01749 }
01750 
01751 inline
01752 bool
01753 Box::sameType (const Box &b) const
01754 {
01755   return btype == b.btype;
01756 }
01757 
01758 inline
01759 bool
01760 Box::contains (const Box& b) const
01761 {
01762   assert(sameType(b));
01763   return ( b.isEmpty() ||
01764            (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
01765 }
01766 
01767 inline
01768 bool
01769 Box::sameSize (const Box& b) const
01770 {
01771   assert(sameType(b));
01772   return D_TERM(len[0] == b.len[0],
01773              && len[1] == b.len[1],
01774              && len[2] == b.len[2]);
01775 }
01776 
01777 inline
01778 bool
01779 Box::operator== (const Box& b) const
01780 {
01781   return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01782 }
01783 
01784 inline
01785 bool
01786 Box::operator!= (const Box& b) const
01787 {
01788   return !operator==(b);
01789 }
01790 
01791 inline
01792 bool
01793 Box::cellCentered () const
01794 {
01795   return !btype.any();
01796 }
01797 
01798 inline
01799 bool
01800 Box::volumeOK () const
01801 {
01802   return numPtsOK();
01803 }
01804 
01805 inline
01806 long
01807 Box::index (const IntVect& v) const
01808 {
01809   long result = v.vect[0]-smallend.vect[0];
01810 #if   CH_SPACEDIM==2
01811   result += len[0]*(v.vect[1]-smallend.vect[1]);
01812 #elif CH_SPACEDIM==3
01813   result += len[0]*(v.vect[1]-smallend.vect[1]
01814                     +(v.vect[2]-smallend.vect[2])*len[1]);
01815 #endif
01816   return result;
01817 }
01818 
01819 inline
01820 void
01821 Box::computeBoxLen ()
01822 {
01823   if (isEmpty())
01824     {
01825       len = IntVect::Zero;
01826     }
01827   else
01828     {
01829       D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01830              len[1] = bigend[1]-smallend[1] + 1,
01831              len[2] = bigend[2]-smallend[2] + 1);
01832     }
01833 }
01834 
01835 inline
01836 void
01837 Box::computeBoxLenNotEmpty()
01838 {
01839   D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01840          len[1] = bigend[1]-smallend[1] + 1,
01841          len[2] = bigend[2]-smallend[2] + 1);
01842 }
01843 
01844 inline
01845 Box&
01846 Box::setSmall (const IntVect& sm)
01847 {
01848   assert (sm <= bigend);
01849 
01850   smallend = sm;
01851   computeBoxLen();
01852   return *this;
01853 }
01854 
01855 inline
01856 Box&
01857 Box::setSmall (int dir,
01858                int sm_index)
01859 {
01860   assert (sm_index <= bigend[dir]);
01861 
01862   smallend.setVal(dir,sm_index);
01863   computeBoxLen();
01864   return *this;
01865 }
01866 
01867 inline
01868 Box&
01869 Box::setBig (const IntVect& bg)
01870 {
01871   assert (bg >= smallend);
01872 
01873   bigend = bg;
01874   computeBoxLen();
01875   return *this;
01876 }
01877 
01878 inline
01879 Box&
01880 Box::setBig (int dir,
01881              int bg_index)
01882 {
01883   assert (bg_index >= smallend[dir]);
01884 
01885   bigend.setVal(dir,bg_index);
01886   computeBoxLen();
01887   return *this;
01888 }
01889 
01890 inline
01891 Box&
01892 Box::setRange (int dir,
01893                int sm_index,
01894                int n_cells)
01895 {
01896   assert (n_cells > 0);
01897 
01898   smallend.setVal(dir,sm_index);
01899   bigend.setVal(dir,sm_index+n_cells-1);
01900   computeBoxLen();
01901   return *this;
01902 }
01903 
01904 inline
01905 Box&
01906 Box::shift (int dir,
01907             int nzones)
01908 {
01909   if (!isEmpty())
01910     {
01911       smallend.shift(dir,nzones);
01912       bigend.shift(dir,nzones);
01913     }
01914   return *this;
01915 }
01916 
01917 inline
01918 Box&
01919 Box::shift (const IntVect& iv)
01920 {
01921   if (!isEmpty())
01922     {
01923       smallend.shift(iv);
01924       bigend.shift(iv);
01925     }
01926   return *this;
01927 }
01928 
01929 inline
01930 Box&
01931 Box::convert (const IntVect& typ)
01932 {
01933   assert(typ >= IntVect::TheZeroVector() && typ <= IntVect::TheUnitVector());
01934   if (!isEmpty())
01935     {
01936       IntVect shft(typ - btype.ixType());
01937       bigend += shft;
01938     }
01939   btype = IndexType(typ);
01940   computeBoxLen();
01941   return *this;
01942 }
01943 
01944 inline
01945 Box&
01946 Box::surroundingNodes (int dir)
01947 {
01948   if (!(btype[dir]))
01949     {
01950       if (!isEmpty())
01951         {
01952           bigend.shift(dir,1);
01953         }
01954       //
01955       // Set dir'th bit to 1 = IndexType::NODE.
01956       //
01957       btype.set(dir);
01958       computeBoxLen();
01959     }
01960   return *this;
01961 }
01962 
01963 inline
01964 Box&
01965 Box::enclosedCells (int dir)
01966 {
01967   if (btype[dir])
01968     {
01969       if (!isEmpty())
01970         {
01971           bigend.shift(dir,-1);
01972         }
01973       //
01974       // Set dir'th bit to 0 = IndexType::CELL.
01975       //
01976       btype.unset(dir);
01977       computeBoxLen();
01978     }
01979   return *this;
01980 }
01981 
01982 inline
01983 Box
01984 surroundingNodes (const Box& b,
01985                   int        dir)
01986 {
01987   Box bx(b);
01988   return bx.surroundingNodes(dir);
01989 }
01990 
01991 inline
01992 Box
01993 surroundingNodes (const Box& b)
01994 {
01995   Box bx(b);
01996   return bx.surroundingNodes();
01997 }
01998 
01999 inline
02000 Box
02001 enclosedCells (const Box& b,
02002                int        dir)
02003 {
02004   Box bx(b);
02005   return bx.enclosedCells(dir);
02006 }
02007 
02008 inline
02009 Box
02010 enclosedCells (const Box& b)
02011 {
02012   Box bx(b);
02013   return bx.enclosedCells();
02014 }
02015 
02016 inline
02017 Box&
02018 Box::operator+= (const IntVect& v)
02019 {
02020   if (!isEmpty())
02021     {
02022       smallend += v;
02023       bigend += v;
02024     }
02025   return *this;
02026 }
02027 
02028 inline
02029 Box
02030 Box::operator+  (const IntVect& v) const
02031 {
02032   if (isEmpty())
02033     {
02034       return(Box().convert(btype));
02035     }
02036   else
02037     {
02038       IntVect small(smallend);
02039       small += v;
02040       IntVect big(bigend);
02041       big += v;
02042       return Box(small,big,btype);
02043     }
02044 }
02045 
02046 inline
02047 Box&
02048 Box::operator-= (const IntVect& v)
02049 {
02050   if (!isEmpty())
02051     {
02052       smallend -= v;
02053       bigend -= v;
02054     }
02055   return *this;
02056 }
02057 
02058 inline
02059 bool
02060 Box::operator < (const Box& rhs) const
02061 {
02062   return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02063 }
02064 
02065 inline
02066 Box
02067 Box::operator-  (const IntVect& v) const
02068 {
02069   if (isEmpty())
02070     {
02071       return(Box().convert(btype));
02072     }
02073   else
02074     {
02075       IntVect small = smallend;
02076       small -= v;
02077       IntVect big = bigend;
02078       big -= v;
02079       return Box(small,big,btype);
02080     }
02081 }
02082 
02083 inline
02084 Box&
02085 Box::grow (int i)
02086 {
02087   if (!isEmpty())
02088     {
02089       smallend.diagShift(-i);
02090       bigend.diagShift(i);
02091       if (!(bigend >= smallend)) *this = Box().convert(btype);
02092       computeBoxLen();
02093     }
02094   return *this;
02095 }
02096 
02097 inline
02098 Box
02099 grow (const Box& b,
02100       int        i)
02101 {
02102   if (b.isEmpty())
02103     {
02104       return (Box().convert(b.btype));
02105     }
02106   else
02107     {
02108       IntVect small = diagShift(b.smallend,-i);
02109       IntVect big   = diagShift(b.bigend,i);
02110       if (!(big >= small))
02111         {
02112           return(Box().convert(b.btype));
02113         }
02114       else
02115         {
02116           return Box(small,big,b.btype);
02117         }
02118     }
02119 }
02120 
02121 inline
02122 Box&
02123 Box::grow (const IntVect& v)
02124 {
02125   if (!isEmpty())
02126     {
02127       smallend -= v;
02128       bigend   += v;
02129       if (!(bigend >= smallend)) *this = Box().convert(btype);
02130       computeBoxLen();
02131     }
02132   return *this;
02133 }
02134 
02135 inline
02136 Box
02137 grow (const Box&     b,
02138       const IntVect& v)
02139 {
02140   if (b.isEmpty())
02141     {
02142       return(Box().convert(b.btype));
02143     }
02144   else
02145     {
02146       IntVect small = b.smallend - v;
02147       IntVect big   = b.bigend   + v;
02148       if (!(big >= small))
02149         {
02150           return(Box().convert(b.btype));
02151         }
02152       else
02153         {
02154           return Box(small,big,b.btype);
02155         }
02156     }
02157 }
02158 
02159 inline
02160 Box&
02161 Box::grow (int idir,
02162            int n_cell)
02163 {
02164   if (!isEmpty())
02165     {
02166       smallend.shift(idir, -n_cell);
02167       bigend.shift(idir, n_cell);
02168       if (!(bigend >= smallend)) *this = Box().convert(btype);
02169       computeBoxLen();
02170     }
02171   return *this;
02172 }
02173 
02174 inline
02175 Box&
02176 Box::growLo (int idir,
02177              int n_cell)
02178 {
02179   if (!isEmpty())
02180     {
02181       smallend.shift(idir, -n_cell);
02182       if (!(bigend >= smallend)) *this = Box().convert(btype);
02183       computeBoxLen();
02184     }
02185   return *this;
02186 }
02187 
02188 inline
02189 Box&
02190 Box::growDir (int idir,
02191               const Side::LoHiSide& a_sd,
02192               int n_cell)
02193 {
02194   if(a_sd == Side::Lo)
02195     {
02196       growLo(idir, n_cell);
02197     }
02198   else
02199     {
02200       growHi(idir, n_cell);
02201     }
02202   return *this;
02203 }
02204 
02205 inline
02206 Box&
02207 Box::growHi (int idir,
02208              int n_cell)
02209 {
02210   if (!isEmpty())
02211     {
02212       bigend.shift(idir,n_cell);
02213       if (!(bigend >= smallend)) *this = Box().convert(btype);
02214       computeBoxLen();
02215     }
02216   return *this;
02217 }
02218 
02219 inline
02220 Box
02221 Box::operator& (const Box& rhs) const
02222 {
02223   Box lhs(*this);
02224   return lhs &= rhs;
02225 }
02226 
02227 #endif /* WRAPPER */
02228 
02229 #endif /*CH_BOX_H*/

Generated on Wed Jan 19 17:51:22 2005 for Chombo&INSwithParticles by doxygen1.2.16