00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _BOX_H_
00012 #define _BOX_H_
00013
00014 #ifdef NODEV
00015 #undef NODEV
00016 #endif
00017
00018 #include "SPACE.H"
00019
00020 #ifndef WRAPPER
00021 #include <iostream>
00022
00023 #include "IntVect.H"
00024 #include "Misc.H"
00025 #include "LoHiSide.H"
00026 #include "Vector.H"
00027 #include "SPMD.H"
00028 #include "NamespaceHeader.H"
00029
00030 class SliceSpec;
00031
00033
00041 class IndexType
00042 {
00043 public:
00045
00049 enum CellIndex { CELL = 0, NODE = 1 };
00050
00052
00056 IndexType ();
00057
00059
00063 IndexType (const IndexType& rhs);
00064
00066
00070 explicit IndexType (const IntVect& iv);
00071
00073
00077 IndexType& operator= (const IndexType& rhs);
00078
00080
00084 IndexType& operator= (const IntVect& iv);
00085
00087
00093 IndexType (D_DECL6(CellIndex i, CellIndex j, CellIndex k,
00094 CellIndex l, CellIndex m, CellIndex n));
00095
00097
00101 void set (int dir);
00102
00104
00108 void unset (int dir);
00109
00111
00115 bool test (int dir) const;
00116
00118
00122 void setall ();
00123
00125
00129 void clear ();
00130
00132
00136 bool any () const;
00137
00139
00143 bool ok () const;
00144
00146
00151 void flip (int i);
00152
00154
00158 bool operator== (const IndexType& t) const;
00159
00161
00164 bool operator<(const IndexType& t) const;
00165
00167
00171 bool operator!= (const IndexType& t) const;
00172
00174
00178 bool cellCentered () const;
00179
00181
00185 bool nodeCentered () const;
00186
00188
00192 void setType (int dir,
00193 CellIndex t);
00194
00196
00200 CellIndex ixType (int dir) const;
00201
00203
00207 int operator[] (int dir) const;
00208
00210
00215 IntVect ixType () const;
00216
00218
00225 static IndexType TheCellType ();
00226
00228
00235 static IndexType TheNodeType ();
00236
00238
00242 friend std::ostream& operator<< (std::ostream& os,
00243 const IndexType& itype);
00244
00246
00250 friend std::istream& operator>> (std::istream& is,
00251 IndexType& itype);
00252 private:
00253
00254
00255
00256
00257 static unsigned char mask (int k);
00258
00259
00260
00261
00262 unsigned char itype;
00263 };
00264
00265
00266
00267
00268
00269
00270 inline
00271 unsigned char
00272 IndexType::mask (int k)
00273 {
00274 return 1<<k;
00275 }
00276
00277 inline
00278 IndexType::IndexType ()
00279 :
00280 itype(0)
00281 {}
00282
00283 inline
00284 IndexType::IndexType (const IndexType& bt)
00285 :
00286 itype(bt.itype)
00287 {}
00288
00289 inline
00290 IndexType& IndexType::operator= (const IndexType& bt)
00291 {
00292 itype = bt.itype;
00293 return *this;
00294 }
00295
00296 inline
00297 IndexType::IndexType (const IntVect& iv)
00298 {
00299 itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
00300 | (iv[3]?1:0), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
00301 }
00302
00303 inline
00304 IndexType& IndexType::operator= (const IntVect& iv)
00305 {
00306 itype = D_TERM6((iv[0]?1:0), | ((iv[1]?1:0)<<1), | ((iv[2]?1:0)<<2),
00307 | (iv[3]?1:0), | ((iv[4]?1:0)<<1), | ((iv[5]?1:0)<<2));
00308 return *this;
00309 }
00310
00311 inline
00312 IndexType::IndexType (D_DECL6(CellIndex i, CellIndex j, CellIndex k,
00313 CellIndex l, CellIndex m, CellIndex n))
00314 {
00315 itype = D_TERM6(i, | (j<<1), | (k<<2),
00316 | (l<<3), | (m<<4), | (n<<5));
00317 }
00318
00319 inline
00320 void
00321 IndexType::set (int dir)
00322 {
00323 itype |= mask(dir);
00324 }
00325
00326 inline
00327 void
00328 IndexType::unset (int dir)
00329 {
00330 itype &= ~mask(dir);
00331 }
00332
00333 inline
00334 bool
00335 IndexType::test (int dir) const
00336 {
00337 return (itype & mask(dir)) != 0;
00338 }
00339
00340 inline
00341 void
00342 IndexType::setall ()
00343 {
00344 itype = (1 << CH_SPACEDIM) - 1;
00345 }
00346
00347 inline
00348 void
00349 IndexType::clear ()
00350 {
00351 itype = 0;
00352 }
00353
00354 inline
00355 bool
00356 IndexType::any () const
00357 {
00358 return itype != 0;
00359 }
00360
00361 inline
00362 bool
00363 IndexType::ok () const
00364 {
00365 return itype < (1 << CH_SPACEDIM);
00366 }
00367
00368 inline
00369 void
00370 IndexType::flip (int i)
00371 {
00372 itype ^= mask(i);
00373 }
00374
00375 inline
00376 bool
00377 IndexType::operator== (const IndexType& t) const
00378 {
00379 return t.itype == itype;
00380 }
00381
00382 inline
00383 bool
00384 IndexType::operator< (const IndexType& t) const
00385 {
00386 return itype < t.itype;
00387 }
00388
00389 inline
00390 bool
00391 IndexType::operator!= (const IndexType& t) const
00392 {
00393 return t.itype != itype;
00394 }
00395
00396 inline
00397 bool
00398 IndexType::cellCentered () const
00399 {
00400 return itype == 0;
00401 }
00402
00403 inline
00404 bool
00405 IndexType::nodeCentered () const
00406 {
00407 return itype == (1<<CH_SPACEDIM)-1;
00408 }
00409
00410 inline
00411 void
00412 IndexType::setType (int dir,
00413 CellIndex t)
00414 {
00415 t == CELL ? unset(dir) : set(dir);
00416 }
00417
00418 inline
00419 IndexType::CellIndex
00420 IndexType::ixType (int dir) const
00421 {
00422 return (CellIndex) ((itype & (1<<dir)) >> dir);
00423 }
00424
00425 inline
00426 int
00427 IndexType::operator[] (int dir) const
00428 {
00429 return test(dir);
00430 }
00431
00432 inline
00433 IntVect
00434 IndexType::ixType () const
00435 {
00436 return IntVect(D_DECL6(itype&1, (itype>>1)&1, (itype>>2)&1,
00437 (itype>>3)&1, (itype>>4)&1, (itype>>5)&1));
00438 }
00439
00440 #endif
00441
00442
00444
00459 class Box
00460 {
00461 public:
00462
00464
00466
00470 Box ();
00471
00473
00477 ~Box ()
00478 {}
00479
00481
00486 Box (const IntVect& small,
00487 const IntVect& big);
00488
00490
00495 void define(const IntVect& small, const IntVect& big);
00496
00498
00503 Box (const IntVect& small,
00504 const int* vec_len);
00505
00507
00514 Box (const IntVect& small,
00515 const IntVect& big,
00516 const IntVect& typ);
00517
00519
00526 void define(const IntVect& small,
00527 const IntVect& big,
00528 const IntVect& typ);
00529
00531
00537 Box (const IntVect& small,
00538 const IntVect& big,
00539 const IndexType& t);
00540
00542
00548 void define(const IntVect& small,
00549 const IntVect& big,
00550 const IndexType& t);
00551
00553
00557 Box (const Box& b);
00558
00559 void define(const Box& b);
00560
00561 Box copy() const {return *this;}
00562
00564
00566
00570 const IntVect& smallEnd () const;
00571
00573
00577 IntVect sideEnd(Side::LoHiSide a_side) const;
00578
00580
00586 int smallEnd (int dir) const;
00587
00589
00593 const IntVect& bigEnd () const;
00594
00596
00602 int bigEnd (int dir) const;
00603
00605
00611 const int* loVect () const;
00612
00614
00620 const int* hiVect () const;
00621
00623
00629 const int* getVect () const;
00630
00632
00638 long index (const IntVect& v) const;
00639
00641
00643
00647 IndexType ixType () const;
00648
00650
00654 IntVect type () const;
00655
00657
00663 IndexType::CellIndex type (int dir) const;
00664
00666
00668
00673 inline
00674 IntVect size () const;
00675
00677
00683 int size (int dir) const;
00684
00686
00690 bool numPtsOK () const;
00691
00693
00699 long numPts () const;
00700
00702
00706 bool volumeOK () const;
00707
00709
00715 long volume () const;
00716
00718
00724 int longside (int& dir) const;
00725
00727
00731 int longside () const;
00732
00734
00740 int shortside (int& dir) const;
00741
00743
00747 int shortside () const;
00748
00750
00752
00756 bool isEmpty () const;
00757
00759
00763 bool ok() const;
00764
00766
00772 bool contains (const IntVect& p) const;
00773
00775
00781 bool contains (const Box& b) const;
00782
00784
00790 bool intersects (const Box& b) const;
00791
00793
00801 bool intersectsNotEmpty (const Box& b) const;
00802
00804
00809 bool sameSize (const Box& b) const;
00810
00812
00816 bool sameType (const Box &b) const;
00817
00819
00824 bool operator== (const Box& b) const;
00825
00826 bool eq(const Box& b) const;
00828
00832 bool operator!= (const Box& b) const;
00833
00834 bool neq(const Box& b) const;
00836
00841 bool cellCentered () const;
00842
00843
00845
00853 bool operator < (const Box& rhs) const;
00854
00855 bool lt(const Box& rhs) const;
00856
00858
00860
00864 Box& operator= (const Box& b);
00865
00867
00873 Box& setSmall (const IntVect& sm);
00874
00876
00883 Box& setSmall (int dir,
00884 int sm_index);
00885
00887
00893 Box& setBig (const IntVect& bg);
00894
00896
00903 Box& setBig (int dir,
00904 int bg_index);
00905
00907
00912 Box& setRange (int dir,
00913 int sm_index,
00914 int n_cells = 1);
00915
00917
00919
00930 Box& convert (IndexType typ);
00931
00933
00942 Box& convert (const IntVect& typ);
00943
00945
00957 Box& convert (int dir,
00958 IndexType::CellIndex typ);
00959
00961
00968 Box& surroundingNodes ();
00969
00971
00979 Box& surroundingNodes (int dir);
00980
00981 Box& surroundingNodes_int(int dir);
00983
00992 friend Box surroundingNodes (const Box& b,
00993 int dir);
00994
00996
01004 friend Box surroundingNodes (const Box& b);
01005
01007
01014 Box& enclosedCells ();
01015
01017
01025 Box& enclosedCells (int dir);
01026
01027 Box& enclosedCells_int (int dir);
01028
01030
01039 friend Box enclosedCells (const Box& b,
01040 int dir);
01041
01043
01051 friend Box enclosedCells (const Box& b);
01052
01054
01056
01063 Box& shift (int dir,
01064 int nzones);
01065
01067
01073 Box& shift (const IntVect& iv);
01074
01075 Box& shift_intvect (const IntVect& iv);
01076
01078
01090 Box& shiftHalf (int dir,
01091 int num_halfs);
01092
01094
01100 Box& shiftHalf (const IntVect& iv);
01101 Box& shiftHalf_intvect (const IntVect& iv);
01102
01104
01109 Box& operator+= (const IntVect& v);
01110
01112
01117 Box operator+ (const IntVect& v) const;
01118
01120
01125 Box& operator-= (const IntVect& v);
01126
01128
01133 Box operator- (const IntVect& v) const;
01134
01136
01138 friend Box bdryBox(const Box& b,
01139 int dir,
01140 Side::LoHiSide a_sd,
01141 int len);
01142
01144
01152 friend Box bdryLo (const Box& b,
01153 int dir,
01154 int len);
01155
01157
01165 friend Box bdryHi (const Box& b,
01166 int dir,
01167 int len);
01168
01170
01193 friend Box adjCellLo (const Box& b,
01194 int dir,
01195 int len);
01196
01198
01221 friend Box adjCellHi (const Box& b,
01222 int dir,
01223 int len);
01224
01226
01228
01235 Box operator& (const Box&) const;
01236
01238
01244 Box& operator&= (const Box&);
01245
01247 friend Box adjCellBox (const Box& b,
01248 int dir,
01249 Side::LoHiSide a_side,
01250 int len);
01252
01257 Box& minBox (const Box& b);
01258
01260
01265 friend Box minBox (const Box& b1,
01266 const Box& b2);
01267
01269
01271
01279 Box& grow (int i);
01280
01282
01290 friend Box grow (const Box& b,
01291 int i);
01292
01294
01302 Box& grow (const IntVect& v);
01303
01305
01313 friend Box grow (const Box& b,
01314 const IntVect& v);
01315
01317
01326 Box& grow (int idir,
01327 int n_cell);
01328
01330
01339 Box& growLo (int idir,
01340 int n_cell=1);
01341
01343
01347 Box& growDir (int a_idir,
01348 const Side::LoHiSide& a_sd,
01349 int a_cell);
01350
01352
01361 Box& growHi (int idir,
01362 int n_cell=1);
01363
01365
01367
01378 Box& refine (int refinement_ratio);
01379
01381
01393 friend Box refine (const Box& b,
01394 int refinement_ratio);
01395
01397
01408 Box& refine (const IntVect& refinement_ratio);
01409
01411
01423 friend Box refine (const Box& b,
01424 const IntVect& refinement_ratio);
01425
01427
01429
01444 Box& coarsen (int refinement_ratio);
01445
01447
01462 friend Box coarsen (const Box& b,
01463 int refinement_ratio);
01464
01466
01480 Box& coarsen (const IntVect& refinement_ratio);
01481
01483
01498 friend Box coarsen (const Box& b,
01499 const IntVect& refinement_ratio);
01500
01501
01502
01503
01504
01505
01506 void next (IntVect &) const;
01507
01508
01509
01510
01511
01512
01513 void next (IntVect& p,
01514 const int* shv) const;
01515
01517
01519
01532 Box chop (int dir,
01533 int chop_pnt);
01534
01548 void degenerate( Box& a_to, const SliceSpec& a_sliceSpec,
01549 bool* a_outofbounds=0 ) const;
01550
01552
01554
01558 friend std::ostream& operator<< (std::ostream& os,
01559 const Box& bx);
01560
01562
01566 friend std::istream& operator>> (std::istream& os,
01567 Box& bx);
01568
01570
01573 void p() const;
01574
01576
01581 void dumpOn (std::ostream& strm) const;
01582
01584
01586
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604 void computeBoxLen ();
01605 void computeBoxLenNotEmpty();
01606
01608 static void setTempestOutputFormat( bool );
01609
01610 protected:
01611 friend class HDF5Handle;
01612
01613
01614
01615 bool numPtsOK (long& N) const;
01616
01617
01618
01619 bool volumeOK (long& N) const;
01620
01621 IntVect smallend;
01622 IntVect bigend;
01623
01624 IndexType btype;
01625
01626 static bool s_tempestOutputFormat;
01627 };
01628
01629 #include "NamespaceFooter.H"
01630
01631 #include "BaseNamespaceHeader.H"
01632
01633 #include "NamespaceVar.H"
01634
01635
01636 template < >
01637 int linearSize(const CH_XDIR::Box& a_input);
01638
01639
01640 template < >
01641 void linearIn(CH_XDIR::Box& a_outputT, const void* const a_inBuf);
01642
01643
01644 template < >
01645 void linearOut(void* const a_outBuf, const CH_XDIR::Box& a_inputT);
01646
01647
01648
01649 template < >
01650 int linearSize(const Vector<CH_XDIR::Box>& a_input);
01651 template < >
01652 void linearIn(Vector<CH_XDIR::Box>& a_outputT, const void* const inBuf);
01653 template < >
01654 void linearOut(void* const a_outBuf, const Vector<CH_XDIR::Box>& a_inputT);
01655
01656
01657 template < >
01658 int linearSize(const Vector<Vector<CH_XDIR::Box> >& a_input);
01659 template < >
01660 void linearIn(Vector<Vector<CH_XDIR::Box> >& a_outputT, const void* const inBuf);
01661 template < >
01662 void linearOut(void* const a_outBuf, const Vector<Vector<CH_XDIR::Box> >& a_inputT);
01663
01664 #include "BaseNamespaceFooter.H"
01665 #include "NamespaceHeader.H"
01666
01667
01668 Box surroundingNodes (const Box& b,
01669 int dir);
01670 Box surroundingNodes (const Box& b);
01671 Box enclosedCells (const Box& b,
01672 int dir);
01673 Box enclosedCells (const Box& b);
01674 Box bdryBox(const Box& b,
01675 int dir,
01676 Side::LoHiSide a_sd,
01677 int len=1);
01678 Box bdryLo (const Box& b,
01679 int dir,
01680 int len=1);
01681 Box bdryHi (const Box& b,
01682 int dir,
01683 int len=1);
01684 Box adjCellLo (const Box& b,
01685 int dir,
01686 int len=1);
01687 Box adjCellHi (const Box& b,
01688 int dir,
01689 int len=1);
01690 Box minBox (const Box& b1,
01691 const Box& b2);
01692 Box coarsen (const Box& b,
01693 const IntVect& refinement_ratio);
01694 Box coarsen (const Box& b,
01695 int refinement_ratio);
01696 Box refine (const Box& b,
01697 const IntVect& refinement_ratio);
01698 Box refine (const Box& b,
01699 int refinement_ratio);
01700
01701
01702
01703
01704
01705 #ifndef WRAPPER
01706
01707 inline
01708 Box::Box (const Box& b)
01709 : smallend(b.smallend),
01710 bigend(b.bigend),
01711 btype(b.btype)
01712 {
01713
01714
01715
01716 }
01717
01718 inline
01719 Box&
01720 Box::operator= (const Box& b)
01721 {
01722 smallend = b.smallend;
01723 bigend = b.bigend;
01724 btype = b.btype;
01725
01726
01727
01728 return *this;
01729 }
01730
01731 inline
01732 IntVect
01733 Box::sideEnd(Side::LoHiSide a_side) const
01734 {
01735 IntVect retval;
01736 if(a_side == Side::Lo)
01737 retval = smallEnd();
01738 else
01739 retval = bigEnd();
01740 return retval;
01741 }
01742
01743 inline
01744 const IntVect&
01745 Box::smallEnd () const
01746 {
01747 return smallend;
01748 }
01749
01750 inline
01751 int
01752 Box::smallEnd (int dir) const
01753 {
01754 return smallend[dir];
01755 }
01756
01757 inline
01758 const IntVect&
01759 Box::bigEnd () const
01760 {
01761 return bigend;
01762 }
01763
01764 inline
01765 int
01766 Box::bigEnd (int dir) const
01767 {
01768 return bigend[dir];
01769 }
01770
01771 inline
01772 IndexType
01773 Box::ixType () const
01774 {
01775 return btype;
01776 }
01777
01778 inline
01779 IntVect
01780 Box::type () const
01781 {
01782 return btype.ixType();
01783 }
01784
01785 inline
01786 IndexType::CellIndex
01787 Box::type (int dir) const
01788 {
01789 return btype.ixType(dir);
01790 }
01791
01792 inline
01793 IntVect
01794 Box::size () const
01795 {
01796 return IntVect(D_DECL6(bigend[0]-smallend[0]+1,
01797 bigend[1]-smallend[1]+1,
01798 bigend[2]-smallend[2]+1,
01799 bigend[3]-smallend[3]+1,
01800 bigend[4]-smallend[4]+1,
01801 bigend[5]-smallend[5]+1));
01802 }
01803
01804 inline
01805 int
01806 Box::size (int dir) const
01807 {
01808
01809 return bigend[dir]-smallend[dir]+1;
01810 }
01811
01812 inline
01813 const int*
01814 Box::loVect () const
01815 {
01816 return smallend.getVect();
01817 }
01818
01819 inline
01820 const int*
01821 Box::hiVect () const
01822 {
01823 return bigend.getVect();
01824 }
01825
01826 inline
01827 const int*
01828 Box::getVect () const
01829 {
01830 return smallend.getVect();
01831 }
01832
01833 inline
01834 bool
01835 Box::numPtsOK () const
01836 {
01837 long ignore;
01838 return numPtsOK(ignore);
01839 }
01840
01841 inline
01842 bool
01843 Box::isEmpty () const
01844 {
01845
01846 return D_TERM6((bigend[0] < smallend[0]),
01847 || (bigend[1] < smallend[1]),
01848 || (bigend[2] < smallend[2]),
01849 || (bigend[3] < smallend[3]),
01850 || (bigend[4] < smallend[4]),
01851 || (bigend[5] < smallend[5]) );
01852 }
01853
01854 inline
01855 bool
01856 Box::ok () const
01857 {
01858
01859
01860
01861
01862
01863 return (bigend >= smallend);
01864 }
01865
01866 inline
01867 bool
01868 Box::contains (const IntVect& p) const
01869 {
01870
01871
01872 return (p >= smallend && p <= bigend);
01873 }
01874
01875 inline
01876 bool
01877 Box::sameType (const Box &b) const
01878 {
01879 return btype == b.btype;
01880 }
01881
01882 inline
01883 bool
01884 Box::contains (const Box& b) const
01885 {
01886 CH_assert(sameType(b));
01887 return ( b.isEmpty() ||
01888 (!isEmpty() && b.smallend >= smallend && b.bigend <= bigend) );
01889 }
01890
01891 inline
01892 bool
01893 Box::sameSize (const Box& b) const
01894 {
01895 CH_assert(sameType(b));
01896 return D_TERM6(bigend[0] -smallend[0] == b.bigend[0]-b.smallend[0],
01897 && bigend[1] -smallend[1] == b.bigend[1]-b.smallend[1],
01898 && bigend[2] -smallend[2] == b.bigend[2]-b.smallend[2],
01899 && bigend[3] -smallend[3] == b.bigend[3]-b.smallend[3],
01900 && bigend[4] -smallend[4] == b.bigend[4]-b.smallend[4],
01901 && bigend[5] -smallend[5] == b.bigend[5]-b.smallend[5]);
01902 }
01903
01904 inline
01905 bool
01906 Box::operator== (const Box& b) const
01907 {
01908 return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
01909 }
01910
01911 inline
01912 bool
01913 Box::operator!= (const Box& b) const
01914 {
01915 return !operator==(b);
01916 }
01917
01918 inline
01919 bool
01920 Box::cellCentered () const
01921 {
01922 return !btype.any();
01923 }
01924
01925 inline
01926 bool
01927 Box::volumeOK () const
01928 {
01929 return numPtsOK();
01930 }
01931
01932 inline
01933 long
01934 Box::index (const IntVect& v) const
01935 {
01936 long result = v.vect[0]-smallend.vect[0];
01937 #if CH_SPACEDIM == 1
01938
01939 #elif CH_SPACEDIM==2
01940 int len0=(bigend[0]-smallend[0]+1);
01941 result += len0*(v.vect[1]-smallend.vect[1]);
01942 #elif CH_SPACEDIM==3
01943 int len0=(bigend[0]-smallend[0]+1);
01944 int len1=(bigend[1]-smallend[1]+1);
01945 result += len0*(v.vect[1]-smallend.vect[1]
01946 +(v.vect[2]-smallend.vect[2])*len1);
01947 #elif CH_SPACEDIM==4
01948 int len0=(bigend[0]-smallend[0]+1);
01949 int len1=(bigend[1]-smallend[1]+1);
01950 int len2=(bigend[2]-smallend[2]+1);
01951 result += len0*((v.vect[1]-smallend.vect[1])
01952 +len1*((v.vect[2]-smallend.vect[2])
01953 +len2*(v.vect[3]-smallend[3])));
01954 #elif CH_SPACEDIM==5
01955 int len0=(bigend[0]-smallend[0]+1);
01956 int len1=(bigend[1]-smallend[1]+1);
01957 int len2=(bigend[2]-smallend[2]+1);
01958 int len3=(bigend[3]-smallend[3]+1);
01959 result += len0*(v.vect[1]-smallend.vect[1]
01960 +len1*(v.vect[2]-smallend.vect[2]
01961 +len2*(v.vect[3]-smallend[3]
01962 +len3*(v.vect[4]-smallend[4]))));
01963 #elif CH_SPACEDIM==6
01964 int len0=(bigend[0]-smallend[0]+1);
01965 int len1=(bigend[1]-smallend[1]+1);
01966 int len2=(bigend[2]-smallend[2]+1);
01967 int len3=(bigend[3]-smallend[3]+1);
01968 int len4=(bigend[4]-smallend[4]+1);
01969 result += len0*(v.vect[1]-smallend.vect[1]
01970 +len1*(v.vect[2]-smallend.vect[2]
01971 +len2*(v.vect[3]-smallend[3]
01972 +len3*(v.vect[4]-smallend[4]
01973 +len4*(v.vect[5]-smallend[5])))));
01974
01975 #else
01976 DIM > 6 undefined!
01977 #endif
01978 return result;
01979 }
01980
01981 inline
01982 void
01983 Box::computeBoxLen ()
01984 {
01985
01986
01987
01988
01989
01990
01991
01992
01993
01994
01995 }
01996
01997 inline
01998 void
01999 Box::computeBoxLenNotEmpty()
02000 {
02001
02002
02003
02004 }
02005
02006 inline
02007 Box&
02008 Box::setSmall (const IntVect& sm)
02009 {
02010 CH_assert (sm <= bigend);
02011
02012 smallend = sm;
02013 computeBoxLen();
02014 return *this;
02015 }
02016
02017 inline
02018 Box&
02019 Box::setSmall (int dir,
02020 int sm_index)
02021 {
02022 CH_assert (sm_index <= bigend[dir]);
02023
02024 smallend.setVal(dir,sm_index);
02025 computeBoxLen();
02026 return *this;
02027 }
02028
02029 inline
02030 Box&
02031 Box::setBig (const IntVect& bg)
02032 {
02033 CH_assert (bg >= smallend);
02034
02035 bigend = bg;
02036 computeBoxLen();
02037 return *this;
02038 }
02039
02040 inline
02041 Box&
02042 Box::setBig (int dir,
02043 int bg_index)
02044 {
02045 CH_assert (bg_index >= smallend[dir]);
02046
02047 bigend.setVal(dir,bg_index);
02048 computeBoxLen();
02049 return *this;
02050 }
02051
02052 inline
02053 Box&
02054 Box::setRange (int dir,
02055 int sm_index,
02056 int n_cells)
02057 {
02058 CH_assert (n_cells > 0);
02059
02060 smallend.setVal(dir,sm_index);
02061 bigend.setVal(dir,sm_index+n_cells-1);
02062 computeBoxLen();
02063 return *this;
02064 }
02065
02066 inline
02067 Box&
02068 Box::shift (int dir,
02069 int nzones)
02070 {
02071 if (!isEmpty())
02072 {
02073 smallend.shift(dir,nzones);
02074 bigend.shift(dir,nzones);
02075 }
02076 return *this;
02077 }
02078
02079 inline
02080 Box&
02081 Box::shift (const IntVect& iv)
02082 {
02083 if (!isEmpty())
02084 {
02085 smallend.shift(iv);
02086 bigend.shift(iv);
02087 }
02088 return *this;
02089 }
02090
02091 inline
02092 Box&
02093 Box::convert (const IntVect& typ)
02094 {
02095 CH_assert(typ >= IntVect::Zero && typ <= IntVect::Unit);
02096 if (!isEmpty())
02097 {
02098 IntVect shft(typ - btype.ixType());
02099 bigend += shft;
02100 }
02101 btype = IndexType(typ);
02102 computeBoxLen();
02103 return *this;
02104 }
02105
02106 inline
02107 Box&
02108 Box::surroundingNodes (int dir)
02109 {
02110 if (!(btype[dir]))
02111 {
02112 if (!isEmpty())
02113 {
02114 bigend.shift(dir,1);
02115 }
02116
02117
02118
02119 btype.set(dir);
02120 computeBoxLen();
02121 }
02122 return *this;
02123 }
02124
02125 inline
02126 Box&
02127 Box::enclosedCells (int dir)
02128 {
02129 if (btype[dir])
02130 {
02131 if (!isEmpty())
02132 {
02133 bigend.shift(dir,-1);
02134 }
02135
02136
02137
02138 btype.unset(dir);
02139 computeBoxLen();
02140 }
02141 return *this;
02142 }
02143
02144 inline
02145 Box
02146 surroundingNodes (const Box& b,
02147 int dir)
02148 {
02149 Box bx(b);
02150 return bx.surroundingNodes(dir);
02151 }
02152
02153 inline
02154 Box
02155 surroundingNodes (const Box& b)
02156 {
02157 Box bx(b);
02158 return bx.surroundingNodes();
02159 }
02160
02161 inline
02162 Box
02163 enclosedCells (const Box& b,
02164 int dir)
02165 {
02166 Box bx(b);
02167 return bx.enclosedCells(dir);
02168 }
02169
02170 inline
02171 Box
02172 enclosedCells (const Box& b)
02173 {
02174 Box bx(b);
02175 return bx.enclosedCells();
02176 }
02177
02178 inline
02179 Box&
02180 Box::operator+= (const IntVect& v)
02181 {
02182 if (!isEmpty())
02183 {
02184 smallend += v;
02185 bigend += v;
02186 }
02187 return *this;
02188 }
02189
02190 inline
02191 Box
02192 Box::operator+ (const IntVect& v) const
02193 {
02194 if (isEmpty())
02195 {
02196 return(Box().convert(btype));
02197 }
02198 else
02199 {
02200 IntVect small(smallend);
02201 small += v;
02202 IntVect big(bigend);
02203 big += v;
02204 return Box(small,big,btype);
02205 }
02206 }
02207
02208 inline
02209 Box&
02210 Box::operator-= (const IntVect& v)
02211 {
02212 if (!isEmpty())
02213 {
02214 smallend -= v;
02215 bigend -= v;
02216 }
02217 return *this;
02218 }
02219
02220 inline
02221 bool
02222 Box::operator < (const Box& rhs) const
02223 {
02224 if(smallend == rhs.smallend) return bigend.lexLT(rhs.bigend);
02225 return(!isEmpty() && (rhs.isEmpty() || smallend.lexLT(rhs.smallend)));
02226 }
02227
02228 inline
02229 Box
02230 Box::operator- (const IntVect& v) const
02231 {
02232 if (isEmpty())
02233 {
02234 return(Box().convert(btype));
02235 }
02236 else
02237 {
02238 IntVect small = smallend;
02239 small -= v;
02240 IntVect big = bigend;
02241 big -= v;
02242 return Box(small,big,btype);
02243 }
02244 }
02245
02246 inline
02247 Box&
02248 Box::grow (int i)
02249 {
02250 if (!isEmpty())
02251 {
02252 smallend.diagShift(-i);
02253 bigend.diagShift(i);
02254 if (!(bigend >= smallend)) *this = Box().convert(btype);
02255 computeBoxLen();
02256 }
02257 return *this;
02258 }
02259
02260 inline
02261 Box
02262 grow (const Box& b,
02263 int i)
02264 {
02265 if (b.isEmpty())
02266 {
02267 return Box().convert(b.btype);
02268 }
02269
02270 IntVect small = diagShift(b.smallend,-i);
02271 IntVect big = diagShift(b.bigend,i);
02272 if (!(big >= small))
02273 {
02274 return Box().convert(b.btype);
02275 }
02276 return Box(small,big,b.btype);
02277 }
02278
02279 inline
02280 Box&
02281 Box::grow (const IntVect& v)
02282 {
02283 if (!isEmpty())
02284 {
02285 smallend -= v;
02286 bigend += v;
02287 if (!(bigend >= smallend)) *this = Box().convert(btype);
02288 computeBoxLen();
02289 }
02290 return *this;
02291 }
02292
02293 inline
02294 Box
02295 grow (const Box& b,
02296 const IntVect& v)
02297 {
02298 if (b.isEmpty())
02299 {
02300 return Box().convert(b.btype);
02301 }
02302 else
02303 {
02304 IntVect small = b.smallend - v;
02305 IntVect big = b.bigend + v;
02306 if (!(big >= small))
02307 {
02308 return Box().convert(b.btype);
02309 }
02310 else
02311 {
02312 return Box(small,big,b.btype);
02313 }
02314 }
02315 }
02316
02317 inline
02318 Box&
02319 Box::grow (int idir,
02320 int n_cell)
02321 {
02322 if (!isEmpty())
02323 {
02324 smallend.shift(idir, -n_cell);
02325 bigend.shift(idir, n_cell);
02326 if (!(bigend >= smallend)) *this = Box().convert(btype);
02327 computeBoxLen();
02328 }
02329 return *this;
02330 }
02331
02332 inline
02333 Box&
02334 Box::growLo (int idir,
02335 int n_cell)
02336 {
02337 if (!isEmpty())
02338 {
02339 smallend.shift(idir, -n_cell);
02340 if (!(bigend >= smallend)) *this = Box().convert(btype);
02341 computeBoxLen();
02342 }
02343 return *this;
02344 }
02345
02346 inline
02347 Box&
02348 Box::growDir (int idir,
02349 const Side::LoHiSide& a_sd,
02350 int n_cell)
02351 {
02352 if(a_sd == Side::Lo)
02353 {
02354 growLo(idir, n_cell);
02355 }
02356 else
02357 {
02358 growHi(idir, n_cell);
02359 }
02360 return *this;
02361 }
02362
02363 inline
02364 Box&
02365 Box::growHi (int idir,
02366 int n_cell)
02367 {
02368 if (!isEmpty())
02369 {
02370 bigend.shift(idir,n_cell);
02371 if (!(bigend >= smallend)) *this = Box().convert(btype);
02372 computeBoxLen();
02373 }
02374 return *this;
02375 }
02376
02377 inline
02378 Box
02379 Box::operator& (const Box& rhs) const
02380 {
02381 Box lhs(*this);
02382 return lhs &= rhs;
02383 }
02384
02385 #endif
02386
02387 #include "NamespaceFooter.H"
02388 #endif