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
00224
00227 void define(const Box& a_domBox);
00228
00230
00235 void define(const Box& a_domBox, const bool* a_isPeriodic);
00236
00238
00242 void define (const IntVect& small,
00243 const IntVect& big);
00244
00246
00252 void define (const IntVect& small,
00253 const IntVect& big,
00254 const bool* a_isPeriodic);
00255
00257
00261 void define (const IntVect& small,
00262 const int* vec_len);
00263
00265
00271 void define (const IntVect& small,
00272 const int* vec_len,
00273 const bool* a_isPeriodic);
00274
00276
00278 void define (const ProblemDomain& a_src);
00279
00280
00281
00283
00285 const Box& domainBox() const;
00286
00288
00290 bool isPeriodic(int a_dir) const;
00291
00293
00295 bool isPeriodic() const;
00296
00298
00302 ShiftIterator shiftIterator() const;
00303
00305
00307 bool isEmpty () const;
00308
00310
00316 bool contains (const IntVect& p) const;
00317
00319
00323 bool image (IntVect& p) const;
00324
00326
00331 bool contains (const Box& b) const;
00332
00334 bool contains_box(const Box& b) const {return contains(b);}
00335
00337
00344 bool intersects (const Box& a_box) const;
00345
00347
00355 bool intersectsNotEmpty (const Box& a_box) const;
00356
00358
00361 bool intersects(const Box& box1, const Box& box2) const;
00362
00364
00366 bool operator== (const ProblemDomain& a_otherDomain);
00367
00369
00371 friend void operator &=(Box& a_box, const ProblemDomain& a_probdomain);
00372
00374
00376 friend Box operator & (const Box& a_box, const ProblemDomain& a_probdomain);
00377
00378
00379
00381
00383 ProblemDomain& operator= (const ProblemDomain& b);
00384
00386
00388 void setPeriodic(int a_dir, bool a_isPeriodic);
00389
00391
00393 inline ProblemDomain& grow (int i);
00394
00396
00398 friend inline ProblemDomain grow(const ProblemDomain& pd,
00399 int i);
00400
00402
00406 inline ProblemDomain& grow(const IntVect& v);
00407
00409
00413 friend inline ProblemDomain grow (const ProblemDomain& pd,
00414 const IntVect& v);
00415
00417
00421 inline ProblemDomain& grow(int idir, int n_cell);
00422
00424
00428 inline ProblemDomain& growLo(int idir, int n_cell=1);
00429
00431
00434 inline ProblemDomain& growHi(int idir, int n_cell=1);
00435
00437
00445 friend Box bdryLo (const ProblemDomain& a_pd,
00446 int a_dir,
00447 int a_len=1);
00448
00450
00458 friend Box bdryHi (const ProblemDomain& a_pd,
00459 int a_dir,
00460 int a_len=1);
00461
00463
00488 friend Box adjCellLo (const ProblemDomain& a_pd,
00489 int a_dir,
00490 int a_len=1);
00491
00493
00519 friend Box adjCellHi (const ProblemDomain& a_pd,
00520 int a_dir,
00521 int a_len=1);
00522
00523
00524
00526
00533 Box operator& (const Box& a_b) const;
00534
00535
00536
00538
00542 ProblemDomain& refine (int a_refinement_ratio);
00543
00545
00550 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00551 int a_refinement_ratio);
00552
00554
00558 ProblemDomain& refine (const IntVect& a_refinement_ratio);
00559
00561
00567 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00568 const IntVect& a_refinement_ratio);
00569
00570
00571
00573
00579 ProblemDomain& coarsen (int a_refinement_ratio);
00580
00582
00587 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00588 int a_refinement_ratio);
00589
00591
00595 ProblemDomain& coarsen (const IntVect& refinement_ratio);
00596
00598
00604 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00605 const IntVect& a_refinement_ratio);
00606
00607
00608
00610
00612 friend std::ostream& operator<< (std::ostream& os,
00613 const ProblemDomain& bx);
00614
00616
00618 friend std::istream& operator>> (std::istream& is,
00619 ProblemDomain& bx);
00620
00622
00625 void dumpOn (std::ostream& strm) const;
00626
00627
00628 protected:
00629 friend class HDF5Handle;
00630
00634 bool m_isPeriodic[SpaceDim];
00635
00639 Box m_domainBox;
00640
00644 ShiftIterator m_shiftIt;
00645 };
00646
00647
00648
00649
00650 #ifndef WRAPPER
00651
00652 inline
00653 ShiftIterator::ShiftIterator()
00654 : m_index(100), m_shift_vectors()
00655 {
00656 }
00657
00658 inline
00659 ShiftIterator::ShiftIterator(const ShiftIterator& a_src)
00660 {
00661 m_index = a_src.m_index;
00662 m_shift_vectors = a_src.m_shift_vectors;
00663 }
00664
00665 inline
00666 ShiftIterator&
00667 ShiftIterator::operator=(const ShiftIterator& a_src)
00668 {
00669 m_index = a_src.m_index;
00670 m_shift_vectors = a_src.m_shift_vectors;
00671 return *this;
00672 }
00673
00674 inline
00675 IntVect
00676 ShiftIterator::operator()() const
00677 {
00678 CH_assert(ok());
00679 return m_shift_vectors[m_index];
00680 }
00681
00682 inline
00683 void
00684 ShiftIterator::operator++()
00685 {
00686 m_index++;
00687 }
00688
00689 inline
00690 bool
00691 ShiftIterator::ok() const
00692 {
00693 return (m_index < m_shift_vectors.size());
00694 }
00695
00696 inline
00697 void
00698 ShiftIterator::reset()
00699 {
00700 m_index = 0;
00701 }
00702
00703 inline
00704 void
00705 ShiftIterator::begin()
00706 {
00707 m_index = 0;
00708 }
00709
00710 inline
00711 void
00712 ShiftIterator::end()
00713 {
00714 m_index = m_shift_vectors.size();
00715 }
00716
00717 inline
00718 ProblemDomain::ProblemDomain ()
00719 {
00720
00721 for (int dir=0; dir<SpaceDim; dir++)
00722 {
00723 m_isPeriodic[dir] = false;
00724 }
00725
00726 }
00727
00728 inline
00729 ProblemDomain::ProblemDomain (const ProblemDomain& b)
00730 : m_domainBox(b.m_domainBox), m_shiftIt(b.m_shiftIt)
00731 {
00732 for (int dir=0; dir<SpaceDim; dir++)
00733 {
00734 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00735 }
00736 }
00737
00738 inline
00739 bool
00740 ProblemDomain::operator== (const ProblemDomain& a_otherDomain)
00741 {
00742 bool result = true;
00743
00744 if (m_domainBox != a_otherDomain.m_domainBox)
00745 {
00746 result = false;
00747 }
00748 else
00749 {
00750 for (int dir=0; dir<SpaceDim; dir++)
00751 {
00752 if (m_isPeriodic[dir] != a_otherDomain.m_isPeriodic[dir])
00753 {
00754 result = false;
00755 break;
00756 }
00757 }
00758 }
00759
00760 return result;
00761 }
00762
00763 inline
00764 ProblemDomain&
00765 ProblemDomain::operator= (const ProblemDomain& b)
00766 {
00767 m_domainBox = b.m_domainBox;
00768 for (int dir=0; dir<SpaceDim; dir++)
00769 {
00770 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00771 }
00772 m_shiftIt = b.m_shiftIt;
00773 return *this;
00774 }
00775
00776 inline
00777 const Box&
00778 ProblemDomain::domainBox() const
00779 {
00780 return m_domainBox;
00781 }
00782
00783 inline
00784 bool
00785 ProblemDomain::isPeriodic(int a_dir) const
00786 {
00787 return m_isPeriodic[a_dir];
00788 }
00789
00790 inline
00791 bool
00792 ProblemDomain::isPeriodic() const
00793 {
00794 return D_TERM(m_isPeriodic[0],
00795 || m_isPeriodic[1],
00796 || m_isPeriodic[2]);
00797 }
00798
00799 inline
00800 ProblemDomain&
00801 ProblemDomain::grow(int i)
00802 {
00803 m_domainBox.grow(i);
00804 return *this;
00805 }
00806
00807 inline
00808 ProblemDomain
00809 grow(const ProblemDomain& pd, int i)
00810 {
00811 ProblemDomain newPd(pd);
00812 newPd.grow(i);
00813 return newPd;
00814 }
00815
00816 inline
00817 ProblemDomain&
00818 ProblemDomain::grow(const IntVect& v)
00819 {
00820 m_domainBox.grow(v);
00821 return *this;
00822 }
00823
00824 inline
00825 ProblemDomain
00826 grow(const ProblemDomain& pd, const IntVect& v)
00827 {
00828 ProblemDomain newPd(pd);
00829 newPd.grow(v);
00830 return newPd;
00831 }
00832
00833 inline
00834 ProblemDomain&
00835 ProblemDomain::grow(int idir, int n_cell)
00836 {
00837 m_domainBox.grow(idir, n_cell);
00838 return *this;
00839 }
00840
00841 inline
00842 ProblemDomain&
00843 ProblemDomain::growLo(int idir, int n_cell)
00844 {
00845 m_domainBox.growLo(idir, n_cell);
00846 return *this;
00847 }
00848
00849 inline
00850 ProblemDomain&
00851 ProblemDomain::growHi(int idir, int n_cell)
00852 {
00853 m_domainBox.growHi(idir, n_cell);
00854 return *this;
00855 }
00856
00857 inline
00858 ShiftIterator
00859 ProblemDomain::shiftIterator() const
00860 {
00861 return m_shiftIt;
00862 }
00863
00864 inline
00865 bool
00866 ProblemDomain::isEmpty () const
00867 {
00868 return (m_domainBox.isEmpty());
00869 }
00870
00871 inline
00872 bool
00873 ProblemDomain::contains (const IntVect& p) const
00874 {
00875
00876
00877 return ( !isEmpty() &&
00878 (D_TERM((m_isPeriodic[0]
00879 || (p[0]>=m_domainBox.smallEnd(0)
00880 && p[0]<=m_domainBox.bigEnd(0))),
00881 && (m_isPeriodic[1]
00882 || (p[1]>=m_domainBox.smallEnd(1)
00883 && p[1]<=m_domainBox.bigEnd(1))),
00884 && (m_isPeriodic[2]
00885 || (p[2]>=m_domainBox.smallEnd(2)
00886 && p[2]<=m_domainBox.bigEnd(2))))));
00887 }
00888
00889 inline
00890 bool
00891 ProblemDomain::image(IntVect& p) const
00892 {
00893 if(m_domainBox.contains(p)) return true;
00894 if(!contains(p)) return false;
00895
00896 if(m_isPeriodic[0]){
00897 if(p[0]<m_domainBox.smallEnd(0)) p[0]+= m_domainBox.size(0);
00898 else if(p[0]>m_domainBox.bigEnd(0)) p[0]-= m_domainBox.size(0);
00899 }
00900 if(m_isPeriodic[1]){
00901 if(p[1]<m_domainBox.smallEnd(1)) p[1]+= m_domainBox.size(1);
00902 else if(p[1]>m_domainBox.bigEnd(1)) p[1]-= m_domainBox.size(1);
00903 }
00904
00905 #if (CH_SPACEDIM == 3)
00906 if(m_isPeriodic[2]){
00907 if(p[2]<m_domainBox.smallEnd(2)) p[2]+= m_domainBox.size(2);
00908 else if(p[2]>m_domainBox.bigEnd(2)) p[2]-= m_domainBox.size(2);
00909 }
00910 #endif
00911 return true;
00912 }
00913
00914 inline
00915 bool
00916 ProblemDomain::contains (const Box& b) const
00917 {
00918
00919 return ( !isEmpty() &&
00920 (D_TERM((m_isPeriodic[0]
00921 || (b.smallEnd(0)>=m_domainBox.smallEnd(0)
00922 && b.bigEnd(0)<=m_domainBox.bigEnd(0))),
00923 && (m_isPeriodic[1]
00924 || (b.smallEnd(1)>=m_domainBox.smallEnd(1)
00925 && b.bigEnd(1)<=m_domainBox.bigEnd(1))),
00926 && (m_isPeriodic[2]
00927 || (b.smallEnd(2)>=m_domainBox.smallEnd(2)
00928 && b.bigEnd(2)<=m_domainBox.bigEnd(2))))));
00929
00930 }
00931
00932 #endif
00933
00934 #endif