00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00049
00050
00051
00052
00053
00054
00055
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
00258
00259 static int mask (int k);
00260
00261
00262
00263 unsigned int itype;
00264 };
00265
00266
00267
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
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 class Box
00439 {
00440 public:
00441
00443
00445
00449 Box ();
00450
00452
00456 ~Box () {;}
00457
00458
00460
00465 Box (const IntVect& small,
00466 const IntVect& big);
00467
00469
00474 void define(const IntVect& small, const IntVect& big);
00475
00477
00482 Box (const IntVect& small,
00483 const int* vec_len);
00484
00486
00493 Box (const IntVect& small,
00494 const IntVect& big,
00495 const IntVect& typ);
00496
00498
00504 Box (const IntVect& small,
00505 const IntVect& big,
00506 const IndexType& t);
00507
00509
00513 Box (const Box& b);
00514
00515 void define(const Box& b);
00516
00517 Box copy() const {return *this;}
00518
00520
00522
00526 const IntVect& smallEnd () const;
00527
00529
00533 IntVect sideEnd(Side::LoHiSide a_side) const;
00534
00535
00537
00543 int smallEnd (int dir) const;
00544
00546
00550 const IntVect& bigEnd () const;
00551
00553
00559 int bigEnd (int dir) const;
00560
00562
00568 const int* loVect () const;
00569
00571
00577 const int* hiVect () const;
00578
00580
00586 const int* getVect () const;
00587
00589
00595 long index (const IntVect& v) const;
00596
00598
00600
00604 IndexType ixType () const;
00605
00607
00611 IntVect type () const;
00612
00614
00620 IndexType::CellIndex type (int dir) const;
00621
00623
00625
00630 const IntVect& size () const;
00631
00633
00639 int size (int dir) const;
00640
00642
00646 bool numPtsOK () const;
00647
00649
00655 long numPts () const;
00656
00658
00662 bool volumeOK () const;
00663
00665
00671 long volume () const;
00672
00674
00680 int longside (int& dir) const;
00681
00683
00687 int longside () const;
00688
00690
00696 int shortside (int& dir) const;
00697
00699
00703 int shortside () const;
00704
00705
00707
00709
00713 bool isEmpty () const;
00714
00716
00722 bool contains (const IntVect& p) const;
00723
00725
00731 bool contains (const Box& b) const;
00732
00734
00740 bool intersects (const Box& b) const;
00741
00743
00751 bool intersectsNotEmpty (const Box& b) const;
00752
00754
00759 bool sameSize (const Box& b) const;
00760
00762
00766 bool sameType (const Box &b) const;
00767
00769
00774 bool operator== (const Box& b) const;
00775
00776 bool eq(const Box& b) const;
00778
00782 bool operator!= (const Box& b) const;
00783
00784 bool neq(const Box& b) const;
00786
00791 bool cellCentered () const;
00792
00793
00795
00803 bool operator < (const Box& rhs) const;
00804
00805 bool lt(const Box& rhs) const;
00806
00807
00809
00811
00815 Box& operator= (const Box& b);
00816
00818
00824 Box& setSmall (const IntVect& sm);
00825
00827
00834 Box& setSmall (int dir,
00835 int sm_index);
00836
00838
00844 Box& setBig (const IntVect& bg);
00845
00847
00854 Box& setBig (int dir,
00855 int bg_index);
00856
00858
00863 Box& setRange (int dir,
00864 int sm_index,
00865 int n_cells = 1);
00866
00868
00870
00881 Box& convert (IndexType typ);
00882
00884
00893 Box& convert (const IntVect& typ);
00894
00896
00908 Box& convert (int dir,
00909 IndexType::CellIndex typ);
00910
00912
00919 Box& surroundingNodes ();
00920
00922
00930 Box& surroundingNodes (int dir);
00931
00932 Box& surroundingNodes_int(int dir);
00934
00943 friend Box surroundingNodes (const Box& b,
00944 int dir);
00945
00946
00948
00956 friend Box surroundingNodes (const Box& b);
00957
00959
00966 Box& enclosedCells ();
00967
00969
00977 Box& enclosedCells (int dir);
00978
00979 Box& enclosedCells_int (int dir);
00980
00982
00991 friend Box enclosedCells (const Box& b,
00992 int dir);
00993
00995
01003 friend Box enclosedCells (const Box& b);
01004
01006
01008
01015 Box& shift (int dir,
01016 int nzones);
01017
01019
01025 Box& shift (const IntVect& iv);
01026
01027 Box& shift_intvect (const IntVect& iv);
01028
01030
01042 Box& shiftHalf (int dir,
01043 int num_halfs);
01044
01046
01052 Box& shiftHalf (const IntVect& iv);
01053 Box& shiftHalf_intvect (const IntVect& iv);
01054
01056
01061 Box& operator+= (const IntVect& v);
01062
01064
01069 Box operator+ (const IntVect& v) const;
01070
01072
01077 Box& operator-= (const IntVect& v);
01078
01080
01085 Box operator- (const IntVect& v) const;
01086
01088
01090 friend Box bdryBox(const Box& b,
01091 int dir,
01092 Side::LoHiSide a_sd,
01093 int len);
01094
01095
01097
01105 friend Box bdryLo (const Box& b,
01106 int dir,
01107 int len);
01108
01110
01118 friend Box bdryHi (const Box& b,
01119 int dir,
01120 int len);
01121
01123
01146 friend Box adjCellLo (const Box& b,
01147 int dir,
01148 int len);
01149
01151
01174 friend Box adjCellHi (const Box& b,
01175 int dir,
01176 int len);
01177
01178
01180
01182
01189 Box operator& (const Box&) const;
01190
01192
01198 Box& operator&= (const Box&);
01199
01200
01202 friend Box adjCellBox (const Box& b,
01203 int dir,
01204 Side::LoHiSide a_side,
01205 int len);
01207
01212 Box& minBox (const Box& b);
01213
01215
01220 friend Box minBox (const Box& b1,
01221 const Box& b2);
01222
01224
01226
01234 Box& grow (int i);
01235
01237
01245 friend Box grow (const Box& b,
01246 int i);
01247
01249
01257 Box& grow (const IntVect& v);
01258
01260
01268 friend Box grow (const Box& b,
01269 const IntVect& v);
01270
01272
01281 Box& grow (int idir,
01282 int n_cell);
01283
01285
01294 Box& growLo (int idir,
01295 int n_cell=1);
01296
01298
01302 Box& growDir (int a_idir,
01303 const Side::LoHiSide& a_sd,
01304 int a_cell);
01305
01307
01316 Box& growHi (int idir,
01317 int n_cell=1);
01318
01320
01322
01333 Box& refine (int refinement_ratio);
01334
01336
01348 friend Box refine (const Box& b,
01349 int refinement_ratio);
01350
01352
01363 Box& refine (const IntVect& refinement_ratio);
01364
01366
01378 friend Box refine (const Box& b,
01379 const IntVect& refinement_ratio);
01380
01382
01384
01399 Box& coarsen (int refinement_ratio);
01400
01402
01417 friend Box coarsen (const Box& b,
01418 int refinement_ratio);
01419
01421
01435 Box& coarsen (const IntVect& refinement_ratio);
01436
01438
01453 friend Box coarsen (const Box& b,
01454 const IntVect& refinement_ratio);
01455
01456
01457
01458
01459
01460
01461 void next (IntVect &) const;
01462
01463
01464
01465
01466
01467
01468 void next (IntVect& p,
01469 const int* shv) const;
01470
01471
01473
01475
01488 Box chop (int dir,
01489 int chop_pnt);
01490
01492
01494
01498 friend std::ostream& operator<< (std::ostream& os,
01499 const Box& bx);
01500
01502
01506 friend std::istream& operator>> (std::istream& os,
01507 Box& bx);
01508
01509
01511
01514 void p() const;
01515
01517
01522 void dumpOn (std::ostream& strm) const;
01523
01525
01527
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546 void computeBoxLen ();
01547 void computeBoxLenNotEmpty();
01548
01549 protected:
01550 friend class HDF5Handle;
01551
01552
01553
01554 bool numPtsOK (long& N) const;
01555
01556
01557
01558 bool volumeOK (long& N) const;
01559
01560 IntVect smallend;
01561 IntVect bigend;
01562 IntVect len;
01563 IndexType btype;
01564
01565 };
01566
01567
01568 Box surroundingNodes (const Box& b,
01569 int dir);
01570 Box surroundingNodes (const Box& b);
01571 Box enclosedCells (const Box& b,
01572 int dir);
01573 Box enclosedCells (const Box& b);
01574 Box bdryBox(const Box& b,
01575 int dir,
01576 Side::LoHiSide a_sd,
01577 int len=1);
01578 Box bdryLo (const Box& b,
01579 int dir,
01580 int len=1);
01581 Box bdryHi (const Box& b,
01582 int dir,
01583 int len=1);
01584 Box adjCellLo (const Box& b,
01585 int dir,
01586 int len=1);
01587 Box adjCellHi (const Box& b,
01588 int dir,
01589 int len=1);
01590 Box minBox (const Box& b1,
01591 const Box& b2);
01592
01593
01594
01595
01596 #ifndef WRAPPER
01597
01598 inline
01599 Box::Box (const Box& b)
01600 : smallend(b.smallend),
01601 bigend(b.bigend),
01602 btype(b.btype)
01603 {
01604 D_EXPR(len[0] = b.len[0],
01605 len[1] = b.len[1],
01606 len[2] = b.len[2]);
01607 }
01608
01609 inline
01610 Box&
01611 Box::operator= (const Box& b)
01612 {
01613 smallend = b.smallend;
01614 bigend = b.bigend;
01615 btype = b.btype;
01616 D_EXPR(len[0] = b.len[0],
01617 len[1] = b.len[1],
01618 len[2] = b.len[2]);
01619 return *this;
01620 }
01621
01622 inline
01623 IntVect
01624 Box::sideEnd(Side::LoHiSide a_side) const
01625 {
01626 IntVect retval;
01627 if(a_side == Side::Lo)
01628 retval = smallEnd();
01629 else
01630 retval = bigEnd();
01631 return retval;
01632 }
01633
01634 inline
01635 const IntVect&
01636 Box::smallEnd () const
01637 {
01638 return smallend;
01639 }
01640
01641 inline
01642 int
01643 Box::smallEnd (int dir) const
01644 {
01645 return smallend[dir];
01646 }
01647
01648 inline
01649 const IntVect&
01650 Box::bigEnd () const
01651 {
01652 return bigend;
01653 }
01654
01655 inline
01656 int
01657 Box::bigEnd (int dir) const
01658 {
01659 return bigend[dir];
01660 }
01661
01662 inline
01663 IndexType
01664 Box::ixType () const
01665 {
01666 return btype;
01667 }
01668
01669 inline
01670 IntVect
01671 Box::type () const
01672 {
01673 return btype.ixType();
01674 }
01675
01676 inline
01677 IndexType::CellIndex
01678 Box::type (int dir) const
01679 {
01680 return btype.ixType(dir);
01681 }
01682
01683 inline
01684 const IntVect&
01685 Box::size () const
01686 {
01687 return len;
01688 }
01689
01690 inline
01691 int
01692 Box::size (int dir) const
01693 {
01694 return len[dir];
01695 }
01696
01697 inline
01698 const int*
01699 Box::loVect () const
01700 {
01701 return smallend.getVect();
01702 }
01703
01704 inline
01705 const int*
01706 Box::hiVect () const
01707 {
01708 return bigend.getVect();
01709 }
01710
01711 inline
01712 const int*
01713 Box::getVect () const
01714 {
01715 return smallend.getVect();
01716 }
01717
01718
01719 inline
01720 bool
01721 Box::numPtsOK () const
01722 {
01723 long ignore;
01724 return numPtsOK(ignore);
01725 }
01726
01727 inline
01728 bool
01729 Box::isEmpty () const
01730 {
01731
01732 return (!(bigend >= smallend));
01733 }
01734
01735 inline
01736 bool
01737 Box::contains (const IntVect& p) const
01738 {
01739
01740 return ( !isEmpty() && (p >= smallend && p <= bigend) );
01741 }
01742
01743 inline
01744 bool
01745 Box::sameType (const Box &b) const
01746 {
01747 return btype == b.btype;
01748 }
01749
01750 inline
01751 bool
01752 Box::contains (const Box& b) const
01753 {
01754 assert(sameType(b));
01755 return ( !isEmpty() && !b.isEmpty() &&
01756 (b.smallend >= smallend && b.bigend <= bigend) );
01757 }
01758
01759 inline
01760 bool
01761 Box::sameSize (const Box& b) const
01762 {
01763 assert(sameType(b));
01764 return D_TERM(len[0] == b.len[0],
01765 && len[1]==b.len[1],
01766 && len[2]==b.len[2]);
01767 }
01768
01769 inline
01770 bool
01771 Box::operator== (const Box& b) const
01772 {
01773 return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01774 }
01775
01776 inline
01777 bool
01778 Box::operator!= (const Box& b) const
01779 {
01780 return !operator==(b);
01781 }
01782
01783 inline
01784 bool
01785 Box::cellCentered () const
01786 {
01787 return !btype.any();
01788 }
01789
01790 inline
01791 bool
01792 Box::volumeOK () const
01793 {
01794 return numPtsOK();
01795 }
01796
01797 inline
01798 long
01799 Box::index (const IntVect& v) const
01800 {
01801 long result = v.vect[0]-smallend.vect[0];
01802 #if CH_SPACEDIM==2
01803 result += len[0]*(v.vect[1]-smallend.vect[1]);
01804 #elif CH_SPACEDIM==3
01805 result += len[0]*(v.vect[1]-smallend.vect[1]
01806 +(v.vect[2]-smallend.vect[2])*len[1]);
01807 #endif
01808 return result;
01809 }
01810
01811 inline
01812 void
01813 Box::computeBoxLen ()
01814 {
01815 if (isEmpty())
01816 {
01817 len = IntVect::Zero;
01818 }
01819 else
01820 {
01821 D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01822 len[1] = bigend[1]-smallend[1] + 1,
01823 len[2] = bigend[2]-smallend[2] + 1);
01824 }
01825 }
01826
01827 inline
01828 void
01829 Box::computeBoxLenNotEmpty()
01830 {
01831 D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
01832 len[1] = bigend[1]-smallend[1] + 1,
01833 len[2] = bigend[2]-smallend[2] + 1);
01834 }
01835
01836 inline
01837 Box&
01838 Box::setSmall (const IntVect& sm)
01839 {
01840 assert (sm <= bigend);
01841
01842 smallend = sm;
01843 computeBoxLen();
01844 return *this;
01845 }
01846
01847 inline
01848 Box&
01849 Box::setSmall (int dir,
01850 int sm_index)
01851 {
01852 assert (sm_index <= bigend[dir]);
01853
01854 smallend.setVal(dir,sm_index);
01855 computeBoxLen();
01856 return *this;
01857 }
01858
01859 inline
01860 Box&
01861 Box::setBig (const IntVect& bg)
01862 {
01863 assert (bg >= smallend);
01864
01865 bigend = bg;
01866 computeBoxLen();
01867 return *this;
01868 }
01869
01870 inline
01871 Box&
01872 Box::setBig (int dir,
01873 int bg_index)
01874 {
01875 assert (bg_index >= smallend[dir]);
01876
01877 bigend.setVal(dir,bg_index);
01878 computeBoxLen();
01879 return *this;
01880 }
01881
01882 inline
01883 Box&
01884 Box::setRange (int dir,
01885 int sm_index,
01886 int n_cells)
01887 {
01888 assert (n_cells > 0);
01889
01890 smallend.setVal(dir,sm_index);
01891 bigend.setVal(dir,sm_index+n_cells-1);
01892 computeBoxLen();
01893 return *this;
01894 }
01895
01896 inline
01897 Box&
01898 Box::shift (int dir,
01899 int nzones)
01900 {
01901 if (!isEmpty())
01902 {
01903 smallend.shift(dir,nzones);
01904 bigend.shift(dir,nzones);
01905 }
01906 return *this;
01907 }
01908
01909 inline
01910 Box&
01911 Box::shift (const IntVect& iv)
01912 {
01913 if (!isEmpty())
01914 {
01915 smallend.shift(iv);
01916 bigend.shift(iv);
01917 }
01918 return *this;
01919 }
01920
01921 inline
01922 Box&
01923 Box::convert (const IntVect& typ)
01924 {
01925 assert(typ >= IntVect::TheZeroVector() && typ <= IntVect::TheUnitVector());
01926 if (!isEmpty())
01927 {
01928 IntVect shft(typ - btype.ixType());
01929 bigend += shft;
01930 }
01931 btype = IndexType(typ);
01932 computeBoxLen();
01933 return *this;
01934 }
01935
01936 inline
01937 Box&
01938 Box::surroundingNodes (int dir)
01939 {
01940 if (!(btype[dir]))
01941 {
01942 if (!isEmpty())
01943 {
01944 bigend.shift(dir,1);
01945 }
01946
01947
01948
01949 btype.set(dir);
01950 computeBoxLen();
01951 }
01952 return *this;
01953 }
01954
01955 inline
01956 Box&
01957 Box::enclosedCells (int dir)
01958 {
01959 if (btype[dir])
01960 {
01961 if (!isEmpty())
01962 {
01963 bigend.shift(dir,-1);
01964 }
01965
01966
01967
01968 btype.unset(dir);
01969 computeBoxLen();
01970 }
01971 return *this;
01972 }
01973
01974 inline
01975 Box
01976 surroundingNodes (const Box& b,
01977 int dir)
01978 {
01979 Box bx(b);
01980 return bx.surroundingNodes(dir);
01981 }
01982
01983 inline
01984 Box
01985 surroundingNodes (const Box& b)
01986 {
01987 Box bx(b);
01988 return bx.surroundingNodes();
01989 }
01990
01991 inline
01992 Box
01993 enclosedCells (const Box& b,
01994 int dir)
01995 {
01996 Box bx(b);
01997 return bx.enclosedCells(dir);
01998 }
01999
02000 inline
02001 Box
02002 enclosedCells (const Box& b)
02003 {
02004 Box bx(b);
02005 return bx.enclosedCells();
02006 }
02007
02008 inline
02009 Box&
02010 Box::operator+= (const IntVect& v)
02011 {
02012 if (!isEmpty())
02013 {
02014 smallend += v;
02015 bigend += v;
02016 }
02017 return *this;
02018 }
02019
02020 inline
02021 Box
02022 Box::operator+ (const IntVect& v) const
02023 {
02024 if (isEmpty())
02025 {
02026 return(Box().convert(btype));
02027 }
02028 else
02029 {
02030 IntVect small(smallend);
02031 small += v;
02032 IntVect big(bigend);
02033 big += v;
02034 return Box(small,big,btype);
02035 }
02036 }
02037
02038 inline
02039 Box&
02040 Box::operator-= (const IntVect& v)
02041 {
02042 if (!isEmpty())
02043 {
02044 smallend -= v;
02045 bigend -= v;
02046 }
02047 return *this;
02048 }
02049
02050 inline
02051 bool
02052 Box::operator < (const Box& rhs) const
02053 {
02054 return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02055 }
02056
02057 inline
02058 Box
02059 Box::operator- (const IntVect& v) const
02060 {
02061 if (isEmpty())
02062 {
02063 return(Box().convert(btype));
02064 }
02065 else
02066 {
02067 IntVect small = smallend;
02068 small -= v;
02069 IntVect big = bigend;
02070 big -= v;
02071 return Box(small,big,btype);
02072 }
02073 }
02074
02075 inline
02076 Box&
02077 Box::grow (int i)
02078 {
02079 if (!isEmpty())
02080 {
02081 smallend.diagShift(-i);
02082 bigend.diagShift(i);
02083 if (!(bigend >= smallend)) *this = Box().convert(btype);
02084 computeBoxLen();
02085 }
02086 return *this;
02087 }
02088
02089 inline
02090 Box
02091 grow (const Box& b,
02092 int i)
02093 {
02094 if (b.isEmpty())
02095 {
02096 return (Box().convert(b.btype));
02097 }
02098 else
02099 {
02100 IntVect small = diagShift(b.smallend,-i);
02101 IntVect big = diagShift(b.bigend,i);
02102 if (!(big >= small))
02103 {
02104 return(Box().convert(b.btype));
02105 }
02106 else
02107 {
02108 return Box(small,big,b.btype);
02109 }
02110 }
02111 }
02112
02113 inline
02114 Box&
02115 Box::grow (const IntVect& v)
02116 {
02117 if (!isEmpty())
02118 {
02119 smallend -= v;
02120 bigend += v;
02121 if (!(bigend >= smallend)) *this = Box().convert(btype);
02122 computeBoxLen();
02123 }
02124 return *this;
02125 }
02126
02127 inline
02128 Box
02129 grow (const Box& b,
02130 const IntVect& v)
02131 {
02132 if (b.isEmpty())
02133 {
02134 return(Box().convert(b.btype));
02135 }
02136 else
02137 {
02138 IntVect small = b.smallend - v;
02139 IntVect big = b.bigend + v;
02140 if (!(big >= small))
02141 {
02142 return(Box().convert(b.btype));
02143 }
02144 else
02145 {
02146 return Box(small,big,b.btype);
02147 }
02148 }
02149 }
02150
02151 inline
02152 Box&
02153 Box::grow (int idir,
02154 int n_cell)
02155 {
02156 if (!isEmpty())
02157 {
02158 smallend.shift(idir, -n_cell);
02159 bigend.shift(idir, n_cell);
02160 if (!(bigend >= smallend)) *this = Box().convert(btype);
02161 computeBoxLen();
02162 }
02163 return *this;
02164 }
02165
02166 inline
02167 Box&
02168 Box::growLo (int idir,
02169 int n_cell)
02170 {
02171 if (!isEmpty())
02172 {
02173 smallend.shift(idir, -n_cell);
02174 if (!(bigend >= smallend)) *this = Box().convert(btype);
02175 computeBoxLen();
02176 }
02177 return *this;
02178 }
02179
02180 inline
02181 Box&
02182 Box::growDir (int idir,
02183 const Side::LoHiSide& a_sd,
02184 int n_cell)
02185 {
02186 if(a_sd == Side::Lo)
02187 {
02188 growLo(idir, n_cell);
02189 }
02190 else
02191 {
02192 growHi(idir, n_cell);
02193 }
02194 return *this;
02195 }
02196
02197 inline
02198 Box&
02199 Box::growHi (int idir,
02200 int n_cell)
02201 {
02202 if (!isEmpty())
02203 {
02204 bigend.shift(idir,n_cell);
02205 if (!(bigend >= smallend)) *this = Box().convert(btype);
02206 computeBoxLen();
02207 }
02208 return *this;
02209 }
02210
02211
02212 inline
02213 Box
02214 Box::operator& (const Box& rhs) const
02215 {
02216 Box lhs(*this);
02217 return lhs &= rhs;
02218 }
02219
02220 #endif
02221
02222 #endif