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
00060 ShiftIterator(const bool* a_isPeriodic);
00061
00063 ShiftIterator(const ShiftIterator& a_shiftIt);
00064
00066 ~ShiftIterator();
00067
00069 ShiftIterator& operator=(const ShiftIterator& a_src);
00070
00072 void computeShifts(const bool* a_isPeriodic);
00073
00075 inline IntVect operator()() const;
00076
00078 IntVect i() const {return this->operator()();}
00079
00081 inline void operator++();
00082
00084 void incr(){++(*this);}
00085
00087 inline bool ok() const;
00088
00090 inline void reset();
00091
00093 inline void begin();
00094
00096
00099 void end();
00100
00101 private:
00102
00103 unsigned int m_index;
00104
00105 Vector<IntVect> m_shift_vectors;
00106
00107 };
00108
00109
00110
00111
00113
00134 class ProblemDomain
00135 {
00136 public:
00137
00138
00139
00141
00143 ProblemDomain ();
00144
00146
00149 ProblemDomain(const Box& a_domBox);
00150
00152
00157 ProblemDomain(const Box& a_domBox, const bool* a_isPeriodic);
00158
00160
00164 ProblemDomain (const IntVect& small,
00165 const IntVect& big);
00166
00167
00169
00175 ProblemDomain (const IntVect& small,
00176 const IntVect& big,
00177 const bool* a_isPeriodic);
00178
00179
00181
00185 ProblemDomain (const IntVect& small,
00186 const int* vec_len);
00187
00188
00190
00196 ProblemDomain (const IntVect& small,
00197 const int* vec_len,
00198 const bool* a_isPeriodic);
00199
00200
00202
00204 ProblemDomain (const ProblemDomain& a_src);
00205
00206
00207
00209
00211 const Box& domainBox() const;
00212
00213
00215
00217 bool isPeriodic(int a_dir) const;
00218
00220
00222 bool isPeriodic() const;
00223
00224
00226
00230 ShiftIterator shiftIterator() const;
00231
00232
00234
00236 bool isEmpty () const;
00237
00239
00245 bool contains (const IntVect& p) const;
00246
00248
00252 bool image (IntVect& p) const;
00253
00255
00260 bool contains (const Box& b) const;
00261
00263 bool contains_box(const Box& b) const {return contains(b);}
00264
00266
00273 bool intersects (const Box& a_box) const;
00274
00276
00284 bool intersectsNotEmpty (const Box& a_box) const;
00285
00286
00288
00291 bool intersects(const Box& box1, const Box& box2) const;
00292
00294
00296 friend void operator &=(Box& a_box, const ProblemDomain& a_probdomain);
00297
00299
00301 friend Box operator & (const Box& a_box, const ProblemDomain& a_probdomain);
00302
00303
00304
00306
00308 ProblemDomain& operator= (const ProblemDomain& b);
00309
00311
00313 void setPeriodic(int a_dir, bool a_isPeriodic);
00314
00316
00318 inline ProblemDomain& grow (int i);
00319
00321
00323 friend inline ProblemDomain grow(const ProblemDomain& pd,
00324 int i);
00325
00327
00331 inline ProblemDomain& grow(const IntVect& v);
00332
00334
00338 friend inline ProblemDomain grow (const ProblemDomain& pd,
00339 const IntVect& v);
00340
00342
00346 inline ProblemDomain& grow(int idir, int n_cell);
00347
00349
00353 inline ProblemDomain& growLo(int idir, int n_cell=1);
00354
00356
00359 inline ProblemDomain& growHi(int idir, int n_cell=1);
00360
00361
00362
00364
00372 friend Box bdryLo (const ProblemDomain& a_pd,
00373 int a_dir,
00374 int a_len=1);
00375
00377
00385 friend Box bdryHi (const ProblemDomain& a_pd,
00386 int a_dir,
00387 int a_len=1);
00388
00390
00416 friend Box adjCellLo (const ProblemDomain& a_pd,
00417 int a_dir,
00418 int a_len=1);
00419
00421
00447 friend Box adjCellHi (const ProblemDomain& a_pd,
00448 int a_dir,
00449 int a_len=1);
00450
00451
00452
00453
00455
00462 Box operator& (const Box& a_b) const;
00463
00464
00465
00466
00467
00468
00470
00474 ProblemDomain& refine (int a_refinement_ratio);
00475
00477
00482 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00483 int a_refinement_ratio);
00484
00486
00490 ProblemDomain& refine (const IntVect& a_refinement_ratio);
00491
00493
00499 friend ProblemDomain refine (const ProblemDomain& a_probdomain,
00500 const IntVect& a_refinement_ratio);
00501
00502
00503
00505
00511 ProblemDomain& coarsen (int a_refinement_ratio);
00512
00514
00519 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00520 int a_refinement_ratio);
00521
00523
00527 ProblemDomain& coarsen (const IntVect& refinement_ratio);
00528
00530
00536 friend ProblemDomain coarsen (const ProblemDomain& a_probdomain,
00537 const IntVect& a_refinement_ratio);
00538
00539
00540
00541
00542
00544
00546 friend std::ostream& operator<< (std::ostream& os,
00547 const ProblemDomain& bx);
00548
00550
00552 friend std::istream& operator>> (std::istream& is,
00553 ProblemDomain& bx);
00554
00556
00559 void dumpOn (std::ostream& strm) const;
00560
00561
00562 protected:
00563 friend class HDF5Handle;
00564
00568 bool m_isPeriodic[SpaceDim];
00569
00573 Box m_domainBox;
00574
00578 ShiftIterator m_shiftIt;
00579
00580
00581
00582 };
00583
00584
00585
00586
00587 #ifndef WRAPPER
00588
00589 inline
00590 ShiftIterator::ShiftIterator()
00591 : m_index(100), m_shift_vectors()
00592 {
00593 }
00594
00595 inline
00596 ShiftIterator::ShiftIterator(const ShiftIterator& a_src)
00597 {
00598 m_index = a_src.m_index;
00599 m_shift_vectors = a_src.m_shift_vectors;
00600 }
00601
00602 inline
00603 ShiftIterator&
00604 ShiftIterator::operator=(const ShiftIterator& a_src)
00605 {
00606 m_index = a_src.m_index;
00607 m_shift_vectors = a_src.m_shift_vectors;
00608 return *this;
00609 }
00610
00611 inline
00612 IntVect
00613 ShiftIterator::operator()() const
00614 {
00615 assert(ok());
00616 return m_shift_vectors[m_index];
00617 }
00618
00619 inline
00620 void
00621 ShiftIterator::operator++()
00622 {
00623 m_index++;
00624 }
00625
00626 inline
00627 bool
00628 ShiftIterator::ok() const
00629 {
00630 return (m_index < m_shift_vectors.size());
00631 }
00632
00633 inline
00634 void
00635 ShiftIterator::reset()
00636 {
00637 m_index = 0;
00638 }
00639
00640 inline
00641 void
00642 ShiftIterator::begin()
00643 {
00644 m_index = 0;
00645 }
00646
00647 inline
00648 void
00649 ShiftIterator::end()
00650 {
00651 m_index = m_shift_vectors.size();
00652 }
00653
00654 inline
00655 ProblemDomain::ProblemDomain ()
00656 {
00657
00658 for (int dir=0; dir<SpaceDim; dir++)
00659 {
00660 m_isPeriodic[dir] = false;
00661 }
00662
00663 }
00664
00665 inline
00666 ProblemDomain::ProblemDomain (const ProblemDomain& b)
00667 : m_domainBox(b.m_domainBox), m_shiftIt(b.m_shiftIt)
00668 {
00669 for (int dir=0; dir<SpaceDim; dir++)
00670 {
00671 m_isPeriodic[dir] = b.m_isPeriodic[dir];
00672 }
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
00828 inline
00829 bool
00830 ProblemDomain::contains (const Box& b) const
00831 {
00832
00833 return ( !isEmpty() &&
00834 (D_TERM((m_isPeriodic[0]
00835 || (b.smallEnd(0)>=m_domainBox.smallEnd(0)
00836 && b.bigEnd(0)<=m_domainBox.bigEnd(0))),
00837 && (m_isPeriodic[1]
00838 || (b.smallEnd(1)>=m_domainBox.smallEnd(1)
00839 && b.bigEnd(1)<=m_domainBox.bigEnd(1))),
00840 && (m_isPeriodic[2]
00841 || (b.smallEnd(2)>=m_domainBox.smallEnd(2)
00842 && b.bigEnd(2)<=m_domainBox.bigEnd(2))))));
00843
00844 }
00845
00846 #endif
00847
00848
00849 #endif