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_PROBDOMAIN_H
00029 #define CH_PROBDOMAIN_H
00030
00031 #ifndef WRAPPER
00032 #include <iostream>
00033
00034 #include "Vector.H"
00035 #include "IntVect.H"
00036 #include "Box.H"
00037 #include "Misc.H"
00038 #endif
00039
00040 #include "SPACE.H"
00041
00043
00049 class ShiftIterator
00050 {
00051 public:
00053 ShiftIterator();
00054
00056 ShiftIterator(const bool* a_isPeriodic);
00057
00059 ShiftIterator(const ShiftIterator& a_shiftIt);
00060
00062 ~ShiftIterator();
00063
00065 ShiftIterator& operator=(const ShiftIterator& a_src);
00066
00068 void computeShifts(const bool* a_isPeriodic);
00069
00071 inline IntVect operator()() const;
00072 IntVect i() const {return this->operator()();}
00073
00075 inline void operator++();
00076 void incr(){++(*this);}
00077
00079 inline bool ok() const;
00080
00082 inline void reset();
00083
00085 inline void begin();
00086
00088
00091 void end();
00092
00093 private:
00094
00095 unsigned int m_index;
00096
00097 Vector<IntVect> m_shift_vectors;
00098
00099 };
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 class ProblemDomain
00128 {
00129 public:
00130
00132
00134
00138 ProblemDomain ();
00139
00141
00145 ProblemDomain(const Box& a_domBox);
00146
00148
00153 ProblemDomain(const Box& a_domBox, const bool* a_isPeriodic);
00154
00156
00161 ProblemDomain (const IntVect& small,
00162 const IntVect& big);
00163
00164
00166
00173 ProblemDomain (const IntVect& small,
00174 const IntVect& big,
00175 const bool* a_isPeriodic);
00176
00177
00179
00184 ProblemDomain (const IntVect& small,
00185 const int* vec_len);
00186
00187
00189
00196 ProblemDomain (const IntVect& small,
00197 const int* vec_len,
00198 const bool* a_isPeriodic);
00199
00200
00202
00206 ProblemDomain (const ProblemDomain& a_src);
00207
00209
00211
00214 const Box& domainBox() const;
00215
00216
00218
00221 bool isPeriodic(int a_dir) const;
00222
00224
00227 bool isPeriodic() const;
00228
00229
00231
00234 ShiftIterator shiftIterator() const;
00235
00236
00238
00241 bool isEmpty () const;
00242
00244
00249 bool contains (const IntVect& p) const;
00251
00256 bool image (IntVect& p) const;
00257
00259
00264 bool contains (const Box& b) const;
00265 bool contains_box(const Box& b) const {return contains(b);}
00266
00268
00276 bool intersects (const Box& a_box) const;
00277
00279
00288 bool intersectsNotEmpty (const Box& a_box) const;
00289
00290
00292
00295 bool intersects(const Box& box1, const Box& box2) const;
00296
00298
00301 friend void operator &=(Box& a_box, const ProblemDomain& a_probomain);
00302
00304
00307 friend Box operator & (const Box& a_box, const ProblemDomain& a_probdomain);
00308
00310
00312
00316 ProblemDomain& operator= (const ProblemDomain& b);
00317
00319
00322 void setPeriodic(int a_dir, bool a_isPeriodic);
00323
00325
00327 inline ProblemDomain& grow (int i);
00328
00330
00332 friend inline ProblemDomain grow(const ProblemDomain& pd,
00333 int i);
00334
00336
00340 inline ProblemDomain& grow(const IntVect& v);
00341
00343
00347 friend inline ProblemDomain grow (const ProblemDomain& pd,
00348 const IntVect& v);
00349
00351
00354 inline ProblemDomain& grow(int idir, int n_cell);
00355
00357
00360 inline ProblemDomain& growLo(int idir, int n_cell=1);
00361
00363
00366 inline ProblemDomain& growHi(int idir, int n_cell=1);
00367
00368
00369
00371
00380 friend Box bdryLo (const ProblemDomain& a_pd,
00381 int a_dir,
00382 int a_len=1);
00383
00385
00394 friend Box bdryHi (const ProblemDomain& a_pd,
00395 int a_dir,
00396 int a_len=1);
00397
00399
00423 friend Box adjCellLo (const ProblemDomain& a_pd,
00424 int a_dir,
00425 int a_len=1);
00426
00428
00452 friend Box adjCellHi (const ProblemDomain& a_pd,
00453 int a_dir,
00454 int a_len=1);
00455
00456
00458
00460
00468 Box operator& (const Box& a_b) const;
00469
00470
00471
00472
00474
00476
00481 ProblemDomain& refine (int a_refinement_ratio);
00482
00484
00490 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00491 int a_refinement_ratio);
00492
00494
00498 ProblemDomain& refine (const IntVect& a_refinement_ratio);
00499
00501
00507 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00508 const IntVect& a_refinement_ratio);
00509
00511
00513
00519 ProblemDomain& coarsen (int a_refinement_ratio);
00520
00522
00528 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00529 int a_refinement_ratio);
00530
00532
00536 ProblemDomain& coarsen (const IntVect& refinement_ratio);
00537
00539
00545 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00546 const IntVect& a_refinement_ratio);
00547
00548
00549
00551
00553
00557 friend std::ostream& operator<< (std::ostream& os,
00558 const ProblemDomain& bx);
00559
00561
00565 friend std::istream& operator>> (std::istream& is,
00566 ProblemDomain& bx);
00567
00569
00574 void dumpOn (std::ostream& strm) const;
00575
00576
00577 protected:
00578 friend class HDF5Handle;
00579
00580 bool m_isPeriodic[SpaceDim];
00581
00582 Box m_domainBox;
00583
00584 ShiftIterator m_shiftIt;
00585
00586
00587
00588 };
00589
00590
00591
00592
00593 #ifndef WRAPPER
00594
00595 inline
00596 ShiftIterator::ShiftIterator()
00597 : m_index(100), m_shift_vectors()
00598 {
00599 }
00600
00601 inline
00602 ShiftIterator::ShiftIterator(const ShiftIterator& a_src)
00603 {
00604 m_index = a_src.m_index;
00605 m_shift_vectors = a_src.m_shift_vectors;
00606 }
00607
00608 inline
00609 ShiftIterator&
00610 ShiftIterator::operator=(const ShiftIterator& a_src)
00611 {
00612 m_index = a_src.m_index;
00613 m_shift_vectors = a_src.m_shift_vectors;
00614 return *this;
00615 }
00616
00617 inline
00618 IntVect
00619 ShiftIterator::operator()() const
00620 {
00621 assert(ok());
00622 return m_shift_vectors[m_index];
00623 }
00624
00625 inline
00626 void
00627 ShiftIterator::operator++()
00628 {
00629 m_index++;
00630 }
00631
00632 inline
00633 bool
00634 ShiftIterator::ok() const
00635 {
00636 return (m_index < m_shift_vectors.size());
00637 }
00638
00639 inline
00640 void
00641 ShiftIterator::reset()
00642 {
00643 m_index = 0;
00644 }
00645
00646 inline
00647 void
00648 ShiftIterator::begin()
00649 {
00650 m_index = 0;
00651 }
00652
00653 inline
00654 void
00655 ShiftIterator::end()
00656 {
00657 m_index = m_shift_vectors.size();
00658 }
00659
00660 inline
00661 ProblemDomain::ProblemDomain ()
00662 {
00663
00664 for (int dir=0; dir<SpaceDim; dir++)
00665 {
00666 m_isPeriodic[dir] = false;
00667 }
00668
00669 }
00670
00671 inline
00672 ProblemDomain::ProblemDomain (const ProblemDomain& b)
00673 : m_domainBox(b.m_domainBox), m_shiftIt(b.m_shiftIt)
00674 {
00675 for (int dir=0; dir<SpaceDim; dir++)
00676 {
00677 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00678 }
00679 }
00680
00681
00682 inline
00683 ProblemDomain&
00684 ProblemDomain::operator= (const ProblemDomain& b)
00685 {
00686 m_domainBox = b.m_domainBox;
00687 for (int dir=0; dir<SpaceDim; dir++)
00688 {
00689 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00690 }
00691 m_shiftIt = b.m_shiftIt;
00692 return *this;
00693 }
00694
00695 inline
00696 const Box&
00697 ProblemDomain::domainBox() const
00698 {
00699 return m_domainBox;
00700 }
00701
00702 inline
00703 bool
00704 ProblemDomain::isPeriodic(int a_dir) const
00705 {
00706 return m_isPeriodic[a_dir];
00707 }
00708
00709 inline
00710 bool
00711 ProblemDomain::isPeriodic() const
00712 {
00713 return D_TERM(m_isPeriodic[0],
00714 || m_isPeriodic[1],
00715 || m_isPeriodic[2]);
00716 }
00717
00718 inline
00719 ProblemDomain&
00720 ProblemDomain::grow(int i)
00721 {
00722 m_domainBox.grow(i);
00723 return *this;
00724 }
00725
00726 inline
00727 ProblemDomain
00728 grow(const ProblemDomain& pd, int i)
00729 {
00730 ProblemDomain newPd(pd);
00731 newPd.grow(i);
00732 return newPd;
00733 }
00734
00735 inline
00736 ProblemDomain&
00737 ProblemDomain::grow(const IntVect& v)
00738 {
00739 m_domainBox.grow(v);
00740 return *this;
00741 }
00742
00743 inline
00744 ProblemDomain
00745 grow(const ProblemDomain& pd, const IntVect& v)
00746 {
00747 ProblemDomain newPd(pd);
00748 newPd.grow(v);
00749 return newPd;
00750 }
00751
00752 inline
00753 ProblemDomain&
00754 ProblemDomain::grow(int idir, int n_cell)
00755 {
00756 m_domainBox.grow(idir, n_cell);
00757 return *this;
00758 }
00759
00760 inline
00761 ProblemDomain&
00762 ProblemDomain::growLo(int idir, int n_cell)
00763 {
00764 m_domainBox.growLo(idir, n_cell);
00765 return *this;
00766 }
00767
00768 inline
00769 ProblemDomain&
00770 ProblemDomain::growHi(int idir, int n_cell)
00771 {
00772 m_domainBox.growHi(idir, n_cell);
00773 return *this;
00774 }
00775
00776 inline
00777 ShiftIterator
00778 ProblemDomain::shiftIterator() const
00779 {
00780 return m_shiftIt;
00781 }
00782
00783 inline
00784 bool
00785 ProblemDomain::isEmpty () const
00786 {
00787 return (m_domainBox.isEmpty());
00788 }
00789
00790 inline
00791 bool
00792 ProblemDomain::contains (const IntVect& p) const
00793 {
00794
00795
00796 return ( !isEmpty() &&
00797 (D_TERM((m_isPeriodic[0]
00798 || (p[0]>m_domainBox.smallEnd(0)
00799 && p[0]<m_domainBox.bigEnd(0))),
00800 && (m_isPeriodic[1]
00801 || (p[1]>m_domainBox.smallEnd(1)
00802 && p[1]<m_domainBox.bigEnd(1))),
00803 && (m_isPeriodic[2]
00804 || (p[2]>m_domainBox.smallEnd(2)
00805 && p[2]<m_domainBox.bigEnd(2))))));
00806 }
00807
00808 inline
00809 bool
00810 ProblemDomain::image(IntVect& p) const
00811 {
00812 if(m_domainBox.contains(p)) return true;
00813 if(!contains(p)) return false;
00814
00815 if(m_isPeriodic[0]){
00816 if(p[0]<m_domainBox.smallEnd(0)) p[0]+= m_domainBox.size(0);
00817 else if(p[0]>m_domainBox.bigEnd(0)) p[0]-= m_domainBox.size(0);
00818 }
00819 if(m_isPeriodic[1]){
00820 if(p[1]<m_domainBox.smallEnd(1)) p[1]+= m_domainBox.size(1);
00821 else if(p[1]>m_domainBox.bigEnd(1)) p[1]-= m_domainBox.size(1);
00822 }
00823
00824 #if (CH_SPACEDIM == 3)
00825 if(m_isPeriodic[2]){
00826 if(p[2]<m_domainBox.smallEnd(2)) p[2]+= m_domainBox.size(2);
00827 else if(p[2]>m_domainBox.bigEnd(2)) p[2]-= m_domainBox.size(2);
00828 }
00829 #endif
00830 return true;
00831 }
00832
00833
00834 inline
00835 bool
00836 ProblemDomain::contains (const Box& b) const
00837 {
00838
00839 return ( !isEmpty() &&
00840 (D_TERM((m_isPeriodic[0]
00841 || (b.smallEnd(0)>=m_domainBox.smallEnd(0)
00842 && b.bigEnd(0)<=m_domainBox.bigEnd(0))),
00843 && (m_isPeriodic[1]
00844 || (b.smallEnd(1)>=m_domainBox.smallEnd(1)
00845 && b.bigEnd(1)<=m_domainBox.bigEnd(1))),
00846 && (m_isPeriodic[2]
00847 || (b.smallEnd(2)>=m_domainBox.smallEnd(2)
00848 && b.bigEnd(2)<=m_domainBox.bigEnd(2))))));
00849
00850 }
00851
00852 #endif
00853
00854
00855 #endif