00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef BL_BOX_H
00024 #define BL_BOX_H
00025
00026
00027
00028 #ifdef NODEV
00029 #undef NODEV
00030 #endif
00031
00032 #include <iosfwd>
00033
00034 #include <ccse-mpi.H>
00035 #include <IntVect.H>
00036 #include <IndexType.H>
00037 #include <Orientation.H>
00038 #include <SPACE.H>
00039
00040
00041
00042 class Box;
00043
00044 namespace BoxLib
00045 {
00049 Box grow (const Box& b, int i);
00050
00052
00053 Box grow (const Box& b, const IntVect& v);
00054
00063 Box coarsen (const Box& b, int refinement_ratio);
00064
00073 Box coarsen (const Box& b, const IntVect& refinement_ratio);
00074
00081 Box refine (const Box& b, int refinement_ratio);
00082
00089 Box refine (const Box& b, const IntVect& refinement_ratio);
00090
00095 Box surroundingNodes (const Box& b, int dir);
00096
00100 Box surroundingNodes (const Box& b);
00101
00107 Box enclosedCells (const Box& b, int dir);
00108
00112 Box enclosedCells (const Box& b);
00113
00117 Box bdryLo (const Box& b, int dir, int len=1);
00118
00122 Box bdryHi (const Box& b, int dir, int len=1);
00123
00127 Box bdryNode (const Box& b, const Orientation& face, int len=1);
00128
00140 Box adjCellLo (const Box& b, int dir, int len=1);
00141
00144 Box adjCellHi (const Box& b, int dir, int len=1);
00145
00148 Box adjCell (const Box& b, const Orientation& face, int len=1);
00149
00154 Box minBox (const Box& b1, const Box& b2);
00155 }
00156
00157
00159
00160 std::ostream& operator<< (std::ostream& os, const Box& bx);
00161
00163
00164 std::istream& operator>> (std::istream& os, Box& bx);
00165
00166
00167
00169
00183 class Box
00184 {
00185 friend MPI_Datatype ParallelDescriptor::Mpi_typemap<Box>::type();
00186 public:
00187
00191 Box ();
00192
00194
00195 Box (const IntVect& small,
00196 const IntVect& big);
00197
00199
00200 Box (const IntVect& small,
00201 const int* vec_len);
00202
00206 Box (const IntVect& small,
00207 const IntVect& big,
00208 const IntVect& typ);
00209
00211
00212 Box (const IntVect& small,
00213 const IntVect& big,
00214 const IndexType& t);
00215
00217
00218 const IntVect& smallEnd () const;
00219
00221
00222 int smallEnd (int dir) const;
00223
00225
00226 const IntVect& bigEnd () const;
00227
00229
00230 int bigEnd (int dir) const;
00231
00233
00234 IndexType ixType () const;
00235
00237
00238 IntVect type () const;
00239
00241
00242 IndexType::CellIndex type (int dir) const;
00243
00245
00246 const IntVect& length () const;
00247
00249
00250 int length (int dir) const;
00251
00255 const int* loVect () const;
00256
00260 const int* hiVect () const;
00261
00265 const int* getVect () const;
00266
00268
00269 int operator[] (const Orientation& face) const;
00270
00272
00273 bool isEmpty () const;
00274
00276
00277 bool ok () const;
00278
00280
00281 bool contains (const IntVect& p) const;
00282
00286 bool contains (const Box& b) const;
00287
00291 bool intersects (const Box& b) const;
00292
00296 bool sameSize (const Box& b) const;
00297
00299
00300 bool sameType (const Box &b) const;
00301
00303
00304 bool operator== (const Box& b) const;
00305
00307
00308 bool operator!= (const Box& b) const;
00309
00311
00312 bool cellCentered () const;
00313
00315
00316 bool numPtsOK () const;
00317
00321 long numPts () const;
00322
00324
00325 bool volumeOK () const;
00326
00335 long volume () const;
00336
00340 int longside (int& dir) const;
00341
00343
00344 int longside () const;
00345
00349 int shortside (int& dir) const;
00350
00352
00353 int shortside () const;
00354
00359 long index (const IntVect& v) const;
00360
00362
00363 Box& setSmall (const IntVect& sm);
00364
00366
00367 Box& setSmall (int dir,
00368 int sm_index);
00369
00371
00372 Box& setBig (const IntVect& bg);
00373
00375
00376 Box& setBig (int dir,
00377 int bg_index);
00378
00383 Box& setRange (int dir,
00384 int sm_index,
00385 int n_cells = 1);
00386
00390 Box& shift (int dir,
00391 int nzones);
00392
00394
00395 Box& shift (const IntVect& iv);
00396
00405 Box& shiftHalf (int dir,
00406 int num_halfs);
00407
00409
00410 Box& shiftHalf (const IntVect& iv);
00411
00418 Box& convert (IndexType typ);
00419
00426 Box& convert (const IntVect& typ);
00427
00429
00430 Box& surroundingNodes ();
00431
00433
00434 Box& surroundingNodes (int dir);
00435
00437
00438 Box& enclosedCells ();
00439
00441
00442 Box& enclosedCells (int dir);
00443
00447 Box operator& (const Box&) const;
00448
00452 Box& operator&= (const Box&);
00453
00458 Box& minBox (const Box &);
00459
00461
00462 Box& operator+= (const IntVect& v);
00463
00465
00466 Box operator+ (const IntVect& v) const;
00467
00469
00470 Box& operator-= (const IntVect& v);
00471
00473
00474 Box operator- (const IntVect& v) const;
00475
00487 Box chop (int dir,
00488 int chop_pnt);
00489
00493 Box& grow (int i);
00494
00496
00497 Box& grow (const IntVect& v);
00498
00502 Box& grow (int idir,
00503 int n_cell);
00504
00509 Box& growLo (int idir,
00510 int n_cell=1);
00511
00516 Box& growHi (int idir,
00517 int n_cell=1);
00518
00520
00521 Box& grow (const Orientation& face,
00522 int n_cell=1);
00523
00530 Box& refine (int refinement_ratio);
00531
00538 Box& refine (const IntVect& refinement_ratio);
00539
00548 Box& coarsen (int refinement_ratio);
00549
00558 Box& coarsen (const IntVect& refinement_ratio);
00559
00563 void next (IntVect &) const;
00564
00569 void next (IntVect& p,
00570 const int* shv) const;
00571
00576 static const Box& TheUnitBox ();
00577
00578 protected:
00579
00580
00581
00582 bool numPtsOK (long& N) const;
00583
00584
00585
00586 bool volumeOK (long& N) const;
00587
00588 IntVect smallend;
00589 IntVect bigend;
00590 mutable IntVect len;
00591 IndexType btype;
00592 };
00593
00594 inline
00595 const IntVect&
00596 Box::smallEnd () const
00597 {
00598 return smallend;
00599 }
00600
00601 inline
00602 int
00603 Box::smallEnd (int dir) const
00604 {
00605 return smallend[dir];
00606 }
00607
00608 inline
00609 const IntVect&
00610 Box::bigEnd () const
00611 {
00612 return bigend;
00613 }
00614
00615 inline
00616 int
00617 Box::bigEnd (int dir) const
00618 {
00619 return bigend[dir];
00620 }
00621
00622 inline
00623 IndexType
00624 Box::ixType () const
00625 {
00626 return btype;
00627 }
00628
00629 inline
00630 IntVect
00631 Box::type () const
00632 {
00633 return btype.ixType();
00634 }
00635
00636 inline
00637 IndexType::CellIndex
00638 Box::type (int dir) const
00639 {
00640 return btype.ixType(dir);
00641 }
00642
00643 inline
00644 int
00645 Box::length (int dir) const
00646 {
00647 return bigend[dir] - smallend[dir] + 1;
00648 }
00649
00650 inline
00651 const int*
00652 Box::loVect () const
00653 {
00654 return smallend.getVect();
00655 }
00656
00657 inline
00658 const int*
00659 Box::hiVect () const
00660 {
00661 return bigend.getVect();
00662 }
00663
00664 inline
00665 const int*
00666 Box::getVect () const
00667 {
00668 return smallend.getVect();
00669 }
00670
00671 inline
00672 int
00673 Box::operator[] (const Orientation& face) const
00674 {
00675 const int dir = face.coordDir();
00676 return face.isLow() ? smallend[dir] : bigend[dir];
00677 }
00678
00679 inline
00680 bool
00681 Box::numPtsOK () const
00682 {
00683 long ignore;
00684 return numPtsOK(ignore);
00685 }
00686
00687 inline
00688 bool
00689 Box::isEmpty () const
00690 {
00691 return numPts() == 0;
00692 }
00693
00694 inline
00695 bool
00696 Box::sameType (const Box &b) const
00697 {
00698 return btype == b.btype;
00699 }
00700
00701 inline
00702 bool
00703 Box::contains (const IntVect& p) const
00704 {
00705 return p >= smallend && p <= bigend;
00706 }
00707
00708 inline
00709 bool
00710 Box::contains (const Box& b) const
00711 {
00712 BL_ASSERT(sameType(b));
00713 return b.smallend >= smallend && b.bigend <= bigend;
00714 }
00715
00716 inline
00717 bool
00718 Box::sameSize (const Box& b) const
00719 {
00720 BL_ASSERT(sameType(b));
00721 return D_TERM(length(0) == b.length(0),
00722 && length(1)==b.length(1),
00723 && length(2)==b.length(2));
00724 }
00725
00726 inline
00727 bool
00728 Box::operator== (const Box& b) const
00729 {
00730 return smallend == b.smallend && bigend == b.bigend && b.btype == btype;
00731 }
00732
00733 inline
00734 bool
00735 Box::operator!= (const Box& b) const
00736 {
00737 return !operator==(b);
00738 }
00739
00740 inline
00741 bool
00742 Box::cellCentered () const
00743 {
00744 return !btype.any();
00745 }
00746
00747 inline
00748 bool
00749 Box::ok () const
00750 {
00751 return (bigend >= smallend) && btype.ok();
00752 }
00753
00754 inline
00755 const IntVect&
00756 Box::length () const
00757 {
00758 D_EXPR(len[0] = bigend[0]-smallend[0] + 1,
00759 len[1] = bigend[1]-smallend[1] + 1,
00760 len[2] = bigend[2]-smallend[2] + 1);
00761
00762 return len;
00763 }
00764
00765 #endif