Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class 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 
00120   IndexType& operator= (const IntVect& iv);
00121 
00123 
00129   IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k));
00130 
00132 
00136   void set (int dir);
00137 
00139 
00143   void unset (int dir);
00144 
00146 
00150   bool test (int dir) const;
00151 
00153 
00157   void setall ();
00158 
00160 
00164   void clear ();
00165 
00167 
00171   bool any () const;
00172 
00174 
00178   bool ok () const;
00179 
00181 
00186   void flip (int i);
00187 
00189 
00193   bool operator== (const IndexType& t) const;
00194 
00196 
00199   bool operator<(const IndexType& t) const;
00200 
00202 
00206   bool operator!= (const IndexType& t) const;
00207 
00209 
00213   bool cellCentered () const;
00214 
00216 
00220   bool nodeCentered () const;
00221 
00223 
00227   void setType (int       dir,
00228                 CellIndex t);
00229 
00231 
00235   CellIndex ixType (int dir) const;
00236 
00238 
00242   int operator[] (int dir) const;
00243 
00245 
00250   IntVect ixType () const;
00251 
00253 
00260   static IndexType TheCellType ();
00261 
00263 
00270   static IndexType TheNodeType ();
00271 
00273 
00277   friend std::ostream& operator<< (std::ostream&         os,
00278                                    const IndexType& itype);
00279 
00281 
00285   friend std::istream& operator>> (std::istream&   is,
00286                                    IndexType& itype);
00287 private:
00288   //
00289   // Returns 1<<k.
00290   //
00291   static int mask (int k);
00292   //
00293   // An integer holding the CellIndex in bits 0 - BL\_SPACEDIM-1.
00294   //
00295   unsigned int itype;
00296 };
00297 
00298 //
00299 // Inlines.
00300 //
00301 
00302 inline
00303 int
00304 IndexType::mask (int k)
00305 {
00306   return 1<<k;
00307 }
00308 
00309 inline
00310 IndexType::IndexType ()
00311   :
00312   itype(0)
00313 {}
00314 
00315 inline
00316 IndexType::IndexType (const IndexType& bt)
00317   :
00318   itype(bt.itype)
00319 {}
00320 
00321 inline
00322 IndexType& IndexType::operator= (const IndexType& bt)
00323 {
00324   itype = bt.itype;
00325   return *this;
00326 }
00327 
00328 inline
00329 IndexType::IndexType (const IntVect& iv)
00330 {
00331   itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00332 }
00333 
00334 inline
00335 IndexType& IndexType::operator= (const IntVect& iv)
00336 {
00337   itype = D_TERM((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2));
00338   return *this;
00339 }
00340 
00341 inline
00342 IndexType::IndexType (D_DECL(CellIndex i, CellIndex j, CellIndex k))
00343 {
00344   itype = D_TERM(i, | (j<<1), | (k<<2));
00345 }
00346 
00347 inline
00348 void
00349 IndexType::set (int dir)
00350 {
00351   itype |= mask(dir);
00352 }
00353 
00354 inline
00355 void
00356 IndexType::unset (int dir)
00357 {
00358   itype &= ~mask(dir);
00359 }
00360 
00361 inline
00362 bool
00363 IndexType::test (int dir) const
00364 {
00365   return (itype & mask(dir)) != 0;
00366 }
00367 
00368 inline
00369 void
00370 IndexType::setall ()
00371 {
00372   itype = (1 << SpaceDim) - 1;
00373 }
00374 
00375 inline
00376 void
00377 IndexType::clear ()
00378 {
00379   itype = 0;
00380 }
00381 
00382 inline
00383 bool
00384 IndexType::any () const
00385 {
00386   return itype != 0;
00387 }
00388 
00389 inline
00390 bool
00391 IndexType::ok () const
00392 {
00393   return itype < (1 << SpaceDim);
00394 }
00395 
00396 inline
00397 void
00398 IndexType::flip (int i)
00399 {
00400   itype ^= mask(i);
00401 }
00402 
00403 inline
00404 bool
00405 IndexType::operator== (const IndexType& t) const
00406 {
00407   return t.itype == itype;
00408 }
00409 
00410 inline
00411 bool
00412 IndexType::operator< (const IndexType& t) const
00413 {
00414   return itype < t.itype;
00415 }
00416 
00417 inline
00418 bool
00419 IndexType::operator!= (const IndexType& t) const
00420 {
00421   return t.itype != itype;
00422 }
00423 
00424 inline
00425 bool
00426 IndexType::cellCentered () const
00427 {
00428   return itype == 0;
00429 }
00430 
00431 inline
00432 bool
00433 IndexType::nodeCentered () const
00434 {
00435   return itype == (1<<SpaceDim)-1;
00436 }
00437 
00438 inline
00439 void
00440 IndexType::setType (int       dir,
00441                     CellIndex t)
00442 {
00443   t == CELL ? unset(dir) : set(dir);
00444 }
00445 
00446 inline
00447 IndexType::CellIndex
00448 IndexType::ixType (int dir) const
00449 {
00450   return (CellIndex) ((itype & (1<<dir)) >> dir);
00451 }
00452 
00453 inline
00454 int
00455 IndexType::operator[] (int dir) const
00456 {
00457   return test(dir);
00458 }
00459 
00460 inline
00461 IntVect
00462 IndexType::ixType () const
00463 {
00464   return IntVect(D_DECL(itype&1, (itype>>1)&1, (itype>>2)&1));
00465 }
00466 
00467 #endif /* WRAPPER */
00468 
00469 //
00471 
00486 class Box
00487 {
00488 public:
00489 
00491 
00493 
00497   Box ();
00498 
00500 
00504   ~Box ()
00505   {}
00506 
00508 
00513   Box (const IntVect& small,
00514        const IntVect& big);
00515 
00517 
00522   void define(const IntVect& small, const IntVect& big);
00523 
00525 
00530   Box (const IntVect& small,
00531        const int*     vec_len);
00532 
00534 
00541   Box (const IntVect& small,
00542        const IntVect& big,
00543        const IntVect& typ);
00544 
00546 
00553   void define(const IntVect& small,
00554               const IntVect& big,
00555               const IntVect& typ);
00556 
00558 
00564   Box (const IntVect&   small,
00565        const IntVect&   big,
00566        const IndexType& t);
00567 
00569 
00575   void define(const IntVect&   small,
00576               const IntVect&   big,
00577               const IndexType& t);
00578 
00580 
00584   Box (const Box& b);
00585 
00586   void define(const Box& b);
00587 
00588   Box copy() const {return *this;}
00589 
00591 
00593 
00597   const IntVect& smallEnd () const;
00598 
00600 
00604   IntVect sideEnd(Side::LoHiSide a_side) const;
00605 
00607 
00613   int smallEnd (int dir) const;
00614 
00616 
00620   const IntVect& bigEnd () const;
00621 
00623 
00629   int bigEnd (int dir) const;
00630 
00632 
00638   const int* loVect () const;
00639 
00641 
00647   const int* hiVect () const;
00648 
00650 
00656   const int* getVect () const;
00657 
00659 
00665   long index (const IntVect& v) const;
00666 
00668 
00670 
00674   IndexType ixType () const;
00675 
00677 
00681   IntVect type () const;
00682 
00684 
00690   IndexType::CellIndex type (int dir) const;
00691 
00693 
00695 
00700   const IntVect& size () const;
00701 
00703 
00709   int size (int dir) const;
00710 
00712 
00716   bool numPtsOK () const;
00717 
00719 
00725   long numPts () const;
00726 
00728 
00732   bool volumeOK () const;
00733 
00735 
00741   long volume () const;
00742 
00744 
00750   int longside (int& dir) const;
00751 
00753 
00757   int longside () const;
00758 
00760 
00766   int shortside (int& dir) const;
00767 
00769 
00773   int shortside () const;
00774 
00776 
00778 
00782   bool isEmpty () const;
00783 
00785 
00791   bool contains (const IntVect& p) const;
00792 
00794 
00800   bool contains (const Box& b) const;
00801 
00803 
00809   bool intersects (const Box& b) const;
00810 
00812 
00820   bool intersectsNotEmpty (const Box& b) const;
00821 
00823 
00828   bool sameSize (const Box& b) const;
00829 
00831 
00835   bool sameType (const Box &b) const;
00836 
00838 
00843   bool operator== (const Box& b) const;
00844 
00845   bool eq(const Box& b) const;
00847 
00851   bool operator!= (const Box& b) const;
00852 
00853   bool neq(const Box& b) const;
00855 
00860   bool cellCentered () const;
00861 
00862   // following operators added Sept. 14, 1999.  bvs
00864 
00872   bool operator < (const Box& rhs) const;
00873 
00874   bool lt(const Box& rhs) const;
00875 
00877 
00879 
00883   Box& operator= (const Box& b);
00884 
00886 
00892   Box& setSmall (const IntVect& sm);
00893 
00895 
00902   Box& setSmall (int dir,
00903                  int sm_index);
00904 
00906 
00912   Box& setBig (const IntVect& bg);
00913 
00915 
00922   Box& setBig (int dir,
00923                int bg_index);
00924 
00926 
00931   Box& setRange (int dir,
00932                  int sm_index,
00933                  int n_cells = 1);
00934 
00936 
00938 
00949   Box& convert (IndexType typ);
00950 
00952 
00961   Box& convert (const IntVect& typ);
00962 
00964 
00976   Box& convert (int                  dir,
00977                 IndexType::CellIndex typ);
00978 
00980 
00987   Box& surroundingNodes ();
00988 
00990 
00998   Box& surroundingNodes (int dir);
00999 
01000   Box& surroundingNodes_int(int dir);
01002 
01011   friend  Box surroundingNodes (const Box& b,
01012                                 int        dir);
01013 
01015 
01023   friend Box surroundingNodes (const Box& b);
01024 
01026 
01033   Box& enclosedCells ();
01034 
01036 
01044   Box& enclosedCells (int dir);
01045 
01046   Box& enclosedCells_int (int dir);
01047 
01049 
01058   friend Box enclosedCells (const Box& b,
01059                             int        dir);
01060 
01062 
01070   friend Box enclosedCells (const Box& b);
01071 
01073 
01075 
01082   Box& shift (int dir,
01083               int nzones);
01084 
01086 
01092   Box& shift (const IntVect& iv);
01093 
01094   Box& shift_intvect (const IntVect& iv);
01095 
01097 
01109   Box& shiftHalf (int dir,
01110                   int num_halfs);
01111 
01113 
01119   Box& shiftHalf (const IntVect& iv);
01120   Box& shiftHalf_intvect (const IntVect& iv);
01121 
01123 
01128   Box& operator+= (const IntVect& v);
01129 
01131 
01136   Box  operator+  (const IntVect& v) const;
01137 
01139 
01144   Box& operator-= (const IntVect& v);
01145 
01147 
01152   Box  operator-  (const IntVect& v) const;
01153 
01155 
01157   friend Box bdryBox(const Box& b,
01158                      int        dir,
01159                      Side::LoHiSide a_sd,
01160                      int        len);
01161 
01163 
01171   friend Box bdryLo (const Box& b,
01172                      int        dir,
01173                      int        len);
01174 
01176 
01184   friend Box bdryHi (const Box& b,
01185                      int        dir,
01186                      int        len);
01187 
01189 
01212   friend Box adjCellLo (const Box& b,
01213                         int        dir,
01214                         int        len);
01215 
01217 
01240   friend Box adjCellHi (const Box& b,
01241                         int        dir,
01242                         int        len);
01243 
01245 
01247 
01254   Box operator& (const Box&) const;
01255 
01257 
01263   Box& operator&= (const Box&);
01264 
01266   friend Box adjCellBox (const Box& b,
01267                          int        dir,
01268                          Side::LoHiSide a_side,
01269                          int        len);
01271 
01276   Box& minBox (const Box& b);
01277 
01279 
01284   friend Box minBox (const Box& b1,
01285                      const Box& b2);
01286 
01288 
01290 
01298   Box& grow (int i);
01299 
01301 
01309   friend Box grow (const Box& b,
01310                    int        i);
01311 
01313 
01321   Box& grow (const IntVect& v);
01322 
01324 
01332   friend  Box grow (const Box&     b,
01333                     const IntVect& v);
01334 
01336 
01345   Box& grow (int idir,
01346              int n_cell);
01347 
01349 
01358   Box& growLo (int idir,
01359                int n_cell=1);
01360 
01362 
01366   Box& growDir (int a_idir,
01367                 const Side::LoHiSide& a_sd,
01368                 int a_cell);
01369 
01371 
01380   Box& growHi (int idir,
01381                int n_cell=1);
01382 
01384 
01386 
01397   Box& refine (int refinement_ratio);
01398 
01400 
01412   friend Box refine (const Box& b,
01413                      int        refinement_ratio);
01414 
01416 
01427   Box& refine (const IntVect& refinement_ratio);
01428 
01430 
01442   friend Box refine (const Box&     b,
01443                      const IntVect& refinement_ratio);
01444 
01446 
01448 
01463   Box& coarsen (int refinement_ratio);
01464 
01466 
01481   friend Box coarsen (const Box& b,
01482                       int        refinement_ratio);
01483 
01485 
01499   Box& coarsen (const IntVect& refinement_ratio);
01500 
01502 
01517   friend Box coarsen (const Box&     b,
01518                       const IntVect& refinement_ratio);
01519 
01520   // next(...) is out of favor.  use BoxIterator.
01521   /*
01522     Step through the rectangle.  It is a runtime error to give
01523     a point not inside rectangle.  Iteration may not be efficient.
01524   */
01525   void next (IntVect &) const;
01526 
01527   /*
01528     Scan argument IntVect over object second arg is
01529     increment vector.  Runtime error if IntVect is not
01530     contained in object Box.  Iteration may not be efficient.
01531   */
01532   void next (IntVect&   p,
01533              const int* shv) const;
01534 
01536 
01538 
01551   Box chop (int dir,
01552             int chop_pnt);
01553 
01555 
01557 
01561   friend std::ostream& operator<< (std::ostream&   os,
01562                                    const Box& bx);
01563 
01565 
01569   friend std::istream& operator>> (std::istream& os,
01570                                    Box&     bx);
01571 
01573 
01576   void p() const;
01577 
01579 
01584   void dumpOn (std::ostream& strm) const;
01585 
01587 
01589 
01593   //static const Box Empty;
01594 
01595   // TheUnitBox is out of favor.
01596   /*
01597     This static member function returns a constant reference to
01598     an object of type Box representing the unit box in
01599     BL\_SPACEDIM-dimensional space.
01600   */
01601 
01602   //static const Box& TheUnitBox ();
01603 
01604   //
01605   // Sets the 'len' element of the Box.  Aborts on integer overflow.
01606   //
01607   void computeBoxLen ();
01608   void computeBoxLenNotEmpty();
01609 
01610 protected:
01611   friend class HDF5Handle;
01612   //
01613   // A helper function for numPtsOK() and numPts().
01614   //
01615   bool numPtsOK (long& N) const;
01616   //
01617   // A helper function for volumeOK() and volume().
01618   //
01619   bool volumeOK (long& N) const;
01620 
01621   IntVect   smallend;
01622   IntVect   bigend;
01623   IntVect   len;
01624   IndexType btype;
01625 
01626 };
01627 
01628 // global function prototypes
01629 Box surroundingNodes (const Box& b,
01630                       int        dir);
01631 Box surroundingNodes (const Box& b);
01632 Box enclosedCells (const Box& b,
01633                    int        dir);
01634 Box enclosedCells (const Box& b);
01635 Box bdryBox(const Box& b,
01636             int        dir,
01637             Side::LoHiSide a_sd,
01638             int        len=1);
01639 Box bdryLo (const Box& b,
01640             int        dir,
01641             int        len=1);
01642 Box bdryHi (const Box& b,
01643             int        dir,
01644             int        len=1);
01645 Box adjCellLo (const Box& b,
01646                int        dir,
01647                int        len=1);
01648 Box adjCellHi (const Box& b,
01649                int        dir,
01650                int        len=1);
01651 Box minBox (const Box& b1,
01652             const Box& b2);
01653 Box coarsen (const Box&     b,
01654              const IntVect& refinement_ratio);
01655 Box coarsen (const Box&     b,
01656              int refinement_ratio);
01657 Box refine  (const Box&     b,
01658              const IntVect& refinement_ratio);
01659 Box refine  (const Box&     b,
01660              int refinement_ratio);
01661 
01662 //
01663 // Inlines.
01664 //
01665 
01666 #ifndef WRAPPER
01667 
01668 inline
01669 Box::Box (const Box& b)
01670   : smallend(b.smallend),
01671     bigend(b.bigend),
01672     btype(b.btype)
01673 {
01674   D_EXPR(len[0] = b.len[0],
01675          len[1] = b.len[1],
01676          len[2] = b.len[2]);
01677 }
01678 
01679 inline
01680 Box&
01681 Box::operator= (const Box& b)
01682 {
01683   smallend = b.smallend;
01684   bigend = b.bigend;
01685   btype = b.btype;
01686   D_EXPR(len[0] = b.len[0],
01687          len[1] = b.len[1],
01688          len[2] = b.len[2]);
01689   return *this;
01690 }
01691 
01692 inline
01693 IntVect
01694 Box::sideEnd(Side::LoHiSide a_side) const
01695 {
01696   IntVect retval;
01697   if(a_side == Side::Lo)
01698     retval = smallEnd();
01699   else
01700     retval = bigEnd();
01701   return retval;
01702 }
01703 
01704 inline
01705 const IntVect&
01706 Box::smallEnd () const
01707 {
01708   return smallend;
01709 }
01710 
01711 inline
01712 int
01713 Box::smallEnd (int dir) const
01714 {
01715   return smallend[dir];
01716 }
01717 
01718 inline
01719 const IntVect&
01720 Box::bigEnd () const
01721 {
01722   return bigend;
01723 }
01724 
01725 inline
01726 int
01727 Box::bigEnd (int dir) const
01728 {
01729   return bigend[dir];
01730 }
01731 
01732 inline
01733 IndexType
01734 Box::ixType () const
01735 {
01736   return btype;
01737 }
01738 
01739 inline
01740 IntVect
01741 Box::type () const
01742 {
01743   return btype.ixType();
01744 }
01745 
01746 inline
01747 IndexType::CellIndex
01748 Box::type (int dir) const
01749 {
01750   return btype.ixType(dir);
01751 }
01752 
01753 inline
01754 const IntVect&
01755 Box::size () const
01756 {
01757   return len;
01758 }
01759 
01760 inline
01761 int
01762 Box::size (int dir) const
01763 {
01764   return len[dir];
01765 }
01766 
01767 inline
01768 const int*
01769 Box::loVect () const
01770 {
01771   return smallend.getVect();
01772 }
01773 
01774 inline
01775 const int*
01776 Box::hiVect () const
01777 {
01778   return bigend.getVect();
01779 }
01780 
01781 inline
01782 const int*
01783 Box::getVect () const
01784 {
01785   return smallend.getVect();
01786 }
01787 
01788 inline
01789 bool
01790 Box::numPtsOK () const
01791 {
01792   long ignore;
01793   return numPtsOK(ignore);
01794 }
01795 
01796 inline
01797 bool
01798 Box::isEmpty () const
01799 {
01800   //    return numPts() == 0;
01801   return (bigend[0] < smallend[0]);
01802 }
01803 
01804 inline
01805 bool
01806 Box::contains (const IntVect& p) const
01807 {
01808 
01809   //return ( !isEmpty() && (p >= smallend && p <= bigend) );
01810   return (p >= smallend && p <= bigend);
01811 }
01812 
01813 inline
01814 bool
01815 Box::sameType (const Box &b) const
01816 {
01817   return btype == b.btype;
01818 }
01819 
01820 inline
01821 bool
01822 Box::contains (const Box& b) const
01823 {
01824  CH_assert(sameType(b));
01825   return ( b.isEmpty() ||
01826            (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
01827 }
01828 
01829 inline
01830 bool
01831 Box::sameSize (const Box& b) const
01832 {
01833  CH_assert(sameType(b));
01834   return D_TERM(len[0] == b.len[0],
01835              && len[1] == b.len[1],
01836              && len[2] == b.len[2]);
01837 }
01838 
01839 inline
01840 bool
01841 Box::operator== (const Box& b) const
01842 {
01843   return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01844 }
01845 
01846 inline
01847 bool
01848 Box::operator!= (const Box& b) const
01849 {
01850   return !operator==(b);
01851 }
01852 
01853 inline
01854 bool
01855 Box::cellCentered () const
01856 {
01857   return !btype.any();
01858 }
01859 
01860 inline
01861 bool
01862 Box::volumeOK () const
01863 {
01864   return numPtsOK();
01865 }
01866 
01867 inline
01868 long
01869 Box::index (const IntVect& v) const
01870 {
01871   long result = v.vect[0]-smallend.vect[0];
01872 #if   CH_SPACEDIM==2
01873   result += len[0]*(v.vect[1]-smallend.vect[1]);
01874 #elif CH_SPACEDIM==3
01875   result += len[0]*(v.vect[1]-smallend.vect[1]
01876                     +(v.vect[2]-smallend.vect[2])*len[1]);
01877 #endif
01878   return result;
01879 }
01880 
01881 inline
01882 void
01883 Box::computeBoxLen ()
01884 {
01885   if (isEmpty())
01886     {
01887       len = IntVect::Zero;
01888     }
01889   else
01890     {
01891       D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01892              len[1] = bigend[1]-smallend[1] + 1,
01893              len[2] = bigend[2]-smallend[2] + 1);
01894     }
01895 }
01896 
01897 inline
01898 void
01899 Box::computeBoxLenNotEmpty()
01900 {
01901   D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01902          len[1] = bigend[1]-smallend[1] + 1,
01903          len[2] = bigend[2]-smallend[2] + 1);
01904 }
01905 
01906 inline
01907 Box&
01908 Box::setSmall (const IntVect& sm)
01909 {
01910  CH_assert (sm <= bigend);
01911 
01912   smallend = sm;
01913   computeBoxLen();
01914   return *this;
01915 }
01916 
01917 inline
01918 Box&
01919 Box::setSmall (int dir,
01920                int sm_index)
01921 {
01922  CH_assert (sm_index <= bigend[dir]);
01923 
01924   smallend.setVal(dir,sm_index);
01925   computeBoxLen();
01926   return *this;
01927 }
01928 
01929 inline
01930 Box&
01931 Box::setBig (const IntVect& bg)
01932 {
01933  CH_assert (bg >= smallend);
01934 
01935   bigend = bg;
01936   computeBoxLen();
01937   return *this;
01938 }
01939 
01940 inline
01941 Box&
01942 Box::setBig (int dir,
01943              int bg_index)
01944 {
01945  CH_assert (bg_index >= smallend[dir]);
01946 
01947   bigend.setVal(dir,bg_index);
01948   computeBoxLen();
01949   return *this;
01950 }
01951 
01952 inline
01953 Box&
01954 Box::setRange (int dir,
01955                int sm_index,
01956                int n_cells)
01957 {
01958  CH_assert (n_cells > 0);
01959 
01960   smallend.setVal(dir,sm_index);
01961   bigend.setVal(dir,sm_index+n_cells-1);
01962   computeBoxLen();
01963   return *this;
01964 }
01965 
01966 inline
01967 Box&
01968 Box::shift (int dir,
01969             int nzones)
01970 {
01971   if (!isEmpty())
01972     {
01973       smallend.shift(dir,nzones);
01974       bigend.shift(dir,nzones);
01975     }
01976   return *this;
01977 }
01978 
01979 inline
01980 Box&
01981 Box::shift (const IntVect& iv)
01982 {
01983   if (!isEmpty())
01984     {
01985       smallend.shift(iv);
01986       bigend.shift(iv);
01987     }
01988   return *this;
01989 }
01990 
01991 inline
01992 Box&
01993 Box::convert (const IntVect& typ)
01994 {
01995  CH_assert(typ >= IntVect::Zero && typ <= IntVect::Unit);
01996   if (!isEmpty())
01997     {
01998       IntVect shft(typ - btype.ixType());
01999       bigend += shft;
02000     }
02001   btype = IndexType(typ);
02002   computeBoxLen();
02003   return *this;
02004 }
02005 
02006 inline
02007 Box&
02008 Box::surroundingNodes (int dir)
02009 {
02010   if (!(btype[dir]))
02011     {
02012       if (!isEmpty())
02013         {
02014           bigend.shift(dir,1);
02015         }
02016       //
02017       // Set dir'th bit to 1 = IndexType::NODE.
02018       //
02019       btype.set(dir);
02020       computeBoxLen();
02021     }
02022   return *this;
02023 }
02024 
02025 inline
02026 Box&
02027 Box::enclosedCells (int dir)
02028 {
02029   if (btype[dir])
02030     {
02031       if (!isEmpty())
02032         {
02033           bigend.shift(dir,-1);
02034         }
02035       //
02036       // Set dir'th bit to 0 = IndexType::CELL.
02037       //
02038       btype.unset(dir);
02039       computeBoxLen();
02040     }
02041   return *this;
02042 }
02043 
02044 inline
02045 Box
02046 surroundingNodes (const Box& b,
02047                   int        dir)
02048 {
02049   Box bx(b);
02050   return bx.surroundingNodes(dir);
02051 }
02052 
02053 inline
02054 Box
02055 surroundingNodes (const Box& b)
02056 {
02057   Box bx(b);
02058   return bx.surroundingNodes();
02059 }
02060 
02061 inline
02062 Box
02063 enclosedCells (const Box& b,
02064                int        dir)
02065 {
02066   Box bx(b);
02067   return bx.enclosedCells(dir);
02068 }
02069 
02070 inline
02071 Box
02072 enclosedCells (const Box& b)
02073 {
02074   Box bx(b);
02075   return bx.enclosedCells();
02076 }
02077 
02078 inline
02079 Box&
02080 Box::operator+= (const IntVect& v)
02081 {
02082   if (!isEmpty())
02083     {
02084       smallend += v;
02085       bigend += v;
02086     }
02087   return *this;
02088 }
02089 
02090 inline
02091 Box
02092 Box::operator+  (const IntVect& v) const
02093 {
02094   if (isEmpty())
02095     {
02096       return(Box().convert(btype));
02097     }
02098   else
02099     {
02100       IntVect small(smallend);
02101       small += v;
02102       IntVect big(bigend);
02103       big += v;
02104       return Box(small,big,btype);
02105     }
02106 }
02107 
02108 inline
02109 Box&
02110 Box::operator-= (const IntVect& v)
02111 {
02112   if (!isEmpty())
02113     {
02114       smallend -= v;
02115       bigend -= v;
02116     }
02117   return *this;
02118 }
02119 
02120 inline
02121 bool
02122 Box::operator < (const Box& rhs) const
02123 {
02124   return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02125 }
02126 
02127 inline
02128 Box
02129 Box::operator-  (const IntVect& v) const
02130 {
02131   if (isEmpty())
02132     {
02133       return(Box().convert(btype));
02134     }
02135   else
02136     {
02137       IntVect small = smallend;
02138       small -= v;
02139       IntVect big = bigend;
02140       big -= v;
02141       return Box(small,big,btype);
02142     }
02143 }
02144 
02145 inline
02146 Box&
02147 Box::grow (int i)
02148 {
02149   if (!isEmpty())
02150     {
02151       smallend.diagShift(-i);
02152       bigend.diagShift(i);
02153       if (!(bigend >= smallend)) *this = Box().convert(btype);
02154       computeBoxLen();
02155     }
02156   return *this;
02157 }
02158 
02159 inline
02160 Box
02161 grow (const Box& b,
02162       int        i)
02163 {
02164   if (b.isEmpty())
02165     {
02166       return Box().convert(b.btype);
02167     }
02168   else
02169     {
02170       IntVect small = diagShift(b.smallend,-i);
02171       IntVect big   = diagShift(b.bigend,i);
02172       if (!(big >= small))
02173         {
02174           return Box().convert(b.btype);
02175         }
02176       else
02177         {
02178           return Box(small,big,b.btype);
02179         }
02180     }
02181 }
02182 
02183 inline
02184 Box&
02185 Box::grow (const IntVect& v)
02186 {
02187   if (!isEmpty())
02188     {
02189       smallend -= v;
02190       bigend   += v;
02191       if (!(bigend >= smallend)) *this = Box().convert(btype);
02192       computeBoxLen();
02193     }
02194   return *this;
02195 }
02196 
02197 inline
02198 Box
02199 grow (const Box&     b,
02200       const IntVect& v)
02201 {
02202   if (b.isEmpty())
02203     {
02204       return Box().convert(b.btype);
02205     }
02206   else
02207     {
02208       IntVect small = b.smallend - v;
02209       IntVect big   = b.bigend   + v;
02210       if (!(big >= small))
02211         {
02212           return Box().convert(b.btype);
02213         }
02214       else
02215         {
02216           return Box(small,big,b.btype);
02217         }
02218     }
02219 }
02220 
02221 inline
02222 Box&
02223 Box::grow (int idir,
02224            int n_cell)
02225 {
02226   if (!isEmpty())
02227     {
02228       smallend.shift(idir, -n_cell);
02229       bigend.shift(idir, n_cell);
02230       if (!(bigend >= smallend)) *this = Box().convert(btype);
02231       computeBoxLen();
02232     }
02233   return *this;
02234 }
02235 
02236 inline
02237 Box&
02238 Box::growLo (int idir,
02239              int n_cell)
02240 {
02241   if (!isEmpty())
02242     {
02243       smallend.shift(idir, -n_cell);
02244       if (!(bigend >= smallend)) *this = Box().convert(btype);
02245       computeBoxLen();
02246     }
02247   return *this;
02248 }
02249 
02250 inline
02251 Box&
02252 Box::growDir (int idir,
02253               const Side::LoHiSide& a_sd,
02254               int n_cell)
02255 {
02256   if(a_sd == Side::Lo)
02257     {
02258       growLo(idir, n_cell);
02259     }
02260   else
02261     {
02262       growHi(idir, n_cell);
02263     }
02264   return *this;
02265 }
02266 
02267 inline
02268 Box&
02269 Box::growHi (int idir,
02270              int n_cell)
02271 {
02272   if (!isEmpty())
02273     {
02274       bigend.shift(idir,n_cell);
02275       if (!(bigend >= smallend)) *this = Box().convert(btype);
02276       computeBoxLen();
02277     }
02278   return *this;
02279 }
02280 
02281 inline
02282 Box
02283 Box::operator& (const Box& rhs) const
02284 {
02285   Box lhs(*this);
02286   return lhs &= rhs;
02287 }
02288 
02289 #endif /* WRAPPER */
02290 
02291 #endif /*CH_BOX_H*/

Generated on Wed Oct 5 13:52:08 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1