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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _PROBLEMDOMAIN_H_
00053 #define _PROBLEMDOMAIN_H_
00054
00055 #ifndef WRAPPER
00056 #include <iostream>
00057
00058 #include "Vector.H"
00059 #include "IntVect.H"
00060 #include "Box.H"
00061 #include "Misc.H"
00062 #endif
00063
00064 #include "SPACE.H"
00065
00067
00073 class ShiftIterator
00074 {
00075 public:
00077 ShiftIterator();
00078
00080
00084 ShiftIterator(const bool* a_isPeriodic);
00085
00087 ShiftIterator(const ShiftIterator& a_shiftIt);
00088
00090 ~ShiftIterator();
00091
00093 ShiftIterator& operator=(const ShiftIterator& a_src);
00094
00096 void computeShifts(const bool* a_isPeriodic);
00097
00099 inline IntVect operator()() const;
00100
00102 IntVect i() const {return this->operator()();}
00103
00105 inline void operator++();
00106
00108 void incr(){++(*this);}
00109
00111 inline bool ok() const;
00112
00114 inline void reset();
00115
00117 inline void begin();
00118
00120
00123 void end();
00124
00125 private:
00126
00127 unsigned int m_index;
00128
00129 Vector<IntVect> m_shift_vectors;
00130
00131 };
00132
00134
00155 class ProblemDomain
00156 {
00157 public:
00158
00159
00160
00162
00164 ProblemDomain ();
00165
00167
00170 ProblemDomain(const Box& a_domBox);
00171
00173
00178 ProblemDomain(const Box& a_domBox, const bool* a_isPeriodic);
00179
00181
00185 ProblemDomain (const IntVect& small,
00186 const IntVect& big);
00187
00189
00195 ProblemDomain (const IntVect& small,
00196 const IntVect& big,
00197 const bool* a_isPeriodic);
00198
00200
00204 ProblemDomain (const IntVect& small,
00205 const int* vec_len);
00206
00208
00214 ProblemDomain (const IntVect& small,
00215 const int* vec_len,
00216 const bool* a_isPeriodic);
00217
00219
00221 ProblemDomain (const ProblemDomain& a_src);
00222
00223
00224
00226
00228 const Box& domainBox() const;
00229
00231
00233 bool isPeriodic(int a_dir) const;
00234
00236
00238 bool isPeriodic() const;
00239
00241
00245 ShiftIterator shiftIterator() const;
00246
00248
00250 bool isEmpty () const;
00251
00253
00259 bool contains (const IntVect& p) const;
00260
00262
00266 bool image (IntVect& p) const;
00267
00269
00274 bool contains (const Box& b) const;
00275
00277 bool contains_box(const Box& b) const {return contains(b);}
00278
00280
00287 bool intersects (const Box& a_box) const;
00288
00290
00298 bool intersectsNotEmpty (const Box& a_box) const;
00299
00301
00304 bool intersects(const Box& box1, const Box& box2) const;
00305
00307
00309 friend void operator &=(Box& a_box, const ProblemDomain& a_probdomain);
00310
00312
00314 friend Box operator & (const Box& a_box, const ProblemDomain& a_probdomain);
00315
00316
00317
00319
00321 ProblemDomain& operator= (const ProblemDomain& b);
00322
00324
00326 void setPeriodic(int a_dir, bool a_isPeriodic);
00327
00329
00331 inline ProblemDomain& grow (int i);
00332
00334
00336 friend inline ProblemDomain grow(const ProblemDomain& pd,
00337 int i);
00338
00340
00344 inline ProblemDomain& grow(const IntVect& v);
00345
00347
00351 friend inline ProblemDomain grow (const ProblemDomain& pd,
00352 const IntVect& v);
00353
00355
00359 inline ProblemDomain& grow(int idir, int n_cell);
00360
00362
00366 inline ProblemDomain& growLo(int idir, int n_cell=1);
00367
00369
00372 inline ProblemDomain& growHi(int idir, int n_cell=1);
00373
00375
00383 friend Box bdryLo (const ProblemDomain& a_pd,
00384 int a_dir,
00385 int a_len=1);
00386
00388
00396 friend Box bdryHi (const ProblemDomain& a_pd,
00397 int a_dir,
00398 int a_len=1);
00399
00401
00426 friend Box adjCellLo (const ProblemDomain& a_pd,
00427 int a_dir,
00428 int a_len=1);
00429
00431
00457 friend Box adjCellHi (const ProblemDomain& a_pd,
00458 int a_dir,
00459 int a_len=1);
00460
00461
00462
00464
00471 Box operator& (const Box& a_b) const;
00472
00473
00474
00476
00480 ProblemDomain& refine (int a_refinement_ratio);
00481
00483
00488 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00489 int a_refinement_ratio);
00490
00492
00496 ProblemDomain& refine (const IntVect& a_refinement_ratio);
00497
00499
00505 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00506 const IntVect& a_refinement_ratio);
00507
00508
00509
00511
00517 ProblemDomain& coarsen (int a_refinement_ratio);
00518
00520
00525 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00526 int a_refinement_ratio);
00527
00529
00533 ProblemDomain& coarsen (const IntVect& refinement_ratio);
00534
00536
00542 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00543 const IntVect& a_refinement_ratio);
00544
00545
00546
00548
00550 friend std::ostream& operator<< (std::ostream& os,
00551 const ProblemDomain& bx);
00552
00554
00556 friend std::istream& operator>> (std::istream& is,
00557 ProblemDomain& bx);
00558
00560
00563 void dumpOn (std::ostream& strm) const;
00564
00565
00566 protected:
00567 friend class HDF5Handle;
00568
00572 bool m_isPeriodic[SpaceDim];
00573
00577 Box m_domainBox;
00578
00582 ShiftIterator m_shiftIt;
00583 };
00584
00585
00586
00587
00588 #ifndef WRAPPER
00589
00590 inline
00591 ShiftIterator::ShiftIterator()
00592 : m_index(100), m_shift_vectors()
00593 {
00594 }
00595
00596 inline
00597 ShiftIterator::ShiftIterator(const ShiftIterator& a_src)
00598 {
00599 m_index = a_src.m_index;
00600 m_shift_vectors = a_src.m_shift_vectors;
00601 }
00602
00603 inline
00604 ShiftIterator&
00605 ShiftIterator::operator=(const ShiftIterator& a_src)
00606 {
00607 m_index = a_src.m_index;
00608 m_shift_vectors = a_src.m_shift_vectors;
00609 return *this;
00610 }
00611
00612 inline
00613 IntVect
00614 ShiftIterator::operator()() const
00615 {
00616 assert(ok());
00617 return m_shift_vectors[m_index];
00618 }
00619
00620 inline
00621 void
00622 ShiftIterator::operator++()
00623 {
00624 m_index++;
00625 }
00626
00627 inline
00628 bool
00629 ShiftIterator::ok() const
00630 {
00631 return (m_index < m_shift_vectors.size());
00632 }
00633
00634 inline
00635 void
00636 ShiftIterator::reset()
00637 {
00638 m_index = 0;
00639 }
00640
00641 inline
00642 void
00643 ShiftIterator::begin()
00644 {
00645 m_index = 0;
00646 }
00647
00648 inline
00649 void
00650 ShiftIterator::end()
00651 {
00652 m_index = m_shift_vectors.size();
00653 }
00654
00655 inline
00656 ProblemDomain::ProblemDomain ()
00657 {
00658
00659 for (int dir=0; dir<SpaceDim; dir++)
00660 {
00661 m_isPeriodic[dir] = false;
00662 }
00663
00664 }
00665
00666 inline
00667 ProblemDomain::ProblemDomain (const ProblemDomain& b)
00668 : m_domainBox(b.m_domainBox), m_shiftIt(b.m_shiftIt)
00669 {
00670 for (int dir=0; dir<SpaceDim; dir++)
00671 {
00672 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00673 }
00674 }
00675
00676 inline
00677 ProblemDomain&
00678 ProblemDomain::operator= (const ProblemDomain& b)
00679 {
00680 m_domainBox = b.m_domainBox;
00681 for (int dir=0; dir<SpaceDim; dir++)
00682 {
00683 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00684 }
00685 m_shiftIt = b.m_shiftIt;
00686 return *this;
00687 }
00688
00689 inline
00690 const Box&
00691 ProblemDomain::domainBox() const
00692 {
00693 return m_domainBox;
00694 }
00695
00696 inline
00697 bool
00698 ProblemDomain::isPeriodic(int a_dir) const
00699 {
00700 return m_isPeriodic[a_dir];
00701 }
00702
00703 inline
00704 bool
00705 ProblemDomain::isPeriodic() const
00706 {
00707 return D_TERM(m_isPeriodic[0],
00708 || m_isPeriodic[1],
00709 || m_isPeriodic[2]);
00710 }
00711
00712 inline
00713 ProblemDomain&
00714 ProblemDomain::grow(int i)
00715 {
00716 m_domainBox.grow(i);
00717 return *this;
00718 }
00719
00720 inline
00721 ProblemDomain
00722 grow(const ProblemDomain& pd, int i)
00723 {
00724 ProblemDomain newPd(pd);
00725 newPd.grow(i);
00726 return newPd;
00727 }
00728
00729 inline
00730 ProblemDomain&
00731 ProblemDomain::grow(const IntVect& v)
00732 {
00733 m_domainBox.grow(v);
00734 return *this;
00735 }
00736
00737 inline
00738 ProblemDomain
00739 grow(const ProblemDomain& pd, const IntVect& v)
00740 {
00741 ProblemDomain newPd(pd);
00742 newPd.grow(v);
00743 return newPd;
00744 }
00745
00746 inline
00747 ProblemDomain&
00748 ProblemDomain::grow(int idir, int n_cell)
00749 {
00750 m_domainBox.grow(idir, n_cell);
00751 return *this;
00752 }
00753
00754 inline
00755 ProblemDomain&
00756 ProblemDomain::growLo(int idir, int n_cell)
00757 {
00758 m_domainBox.growLo(idir, n_cell);
00759 return *this;
00760 }
00761
00762 inline
00763 ProblemDomain&
00764 ProblemDomain::growHi(int idir, int n_cell)
00765 {
00766 m_domainBox.growHi(idir, n_cell);
00767 return *this;
00768 }
00769
00770 inline
00771 ShiftIterator
00772 ProblemDomain::shiftIterator() const
00773 {
00774 return m_shiftIt;
00775 }
00776
00777 inline
00778 bool
00779 ProblemDomain::isEmpty () const
00780 {
00781 return (m_domainBox.isEmpty());
00782 }
00783
00784 inline
00785 bool
00786 ProblemDomain::contains (const IntVect& p) const
00787 {
00788
00789
00790 return ( !isEmpty() &&
00791 (D_TERM((m_isPeriodic[0]
00792 || (p[0]>m_domainBox.smallEnd(0)
00793 && p[0]<m_domainBox.bigEnd(0))),
00794 && (m_isPeriodic[1]
00795 || (p[1]>m_domainBox.smallEnd(1)
00796 && p[1]<m_domainBox.bigEnd(1))),
00797 && (m_isPeriodic[2]
00798 || (p[2]>m_domainBox.smallEnd(2)
00799 && p[2]<m_domainBox.bigEnd(2))))));
00800 }
00801
00802 inline
00803 bool
00804 ProblemDomain::image(IntVect& p) const
00805 {
00806 if(m_domainBox.contains(p)) return true;
00807 if(!contains(p)) return false;
00808
00809 if(m_isPeriodic[0]){
00810 if(p[0]<m_domainBox.smallEnd(0)) p[0]+= m_domainBox.size(0);
00811 else if(p[0]>m_domainBox.bigEnd(0)) p[0]-= m_domainBox.size(0);
00812 }
00813 if(m_isPeriodic[1]){
00814 if(p[1]<m_domainBox.smallEnd(1)) p[1]+= m_domainBox.size(1);
00815 else if(p[1]>m_domainBox.bigEnd(1)) p[1]-= m_domainBox.size(1);
00816 }
00817
00818 #if (CH_SPACEDIM == 3)
00819 if(m_isPeriodic[2]){
00820 if(p[2]<m_domainBox.smallEnd(2)) p[2]+= m_domainBox.size(2);
00821 else if(p[2]>m_domainBox.bigEnd(2)) p[2]-= m_domainBox.size(2);
00822 }
00823 #endif
00824 return true;
00825 }
00826
00827 inline
00828 bool
00829 ProblemDomain::contains (const Box& b) const
00830 {
00831
00832 return ( !isEmpty() &&
00833 (D_TERM((m_isPeriodic[0]
00834 || (b.smallEnd(0)>=m_domainBox.smallEnd(0)
00835 && b.bigEnd(0)<=m_domainBox.bigEnd(0))),
00836 && (m_isPeriodic[1]
00837 || (b.smallEnd(1)>=m_domainBox.smallEnd(1)
00838 && b.bigEnd(1)<=m_domainBox.bigEnd(1))),
00839 && (m_isPeriodic[2]
00840 || (b.smallEnd(2)>=m_domainBox.smallEnd(2)
00841 && b.bigEnd(2)<=m_domainBox.bigEnd(2))))));
00842
00843 }
00844
00845 #endif
00846
00847 #endif