Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

ProblemDomain.H

Go to the documentation of this file.
00001 /*   _______              __
00002     / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
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   // Constructors
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   //  Accessors
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   //  Modification Functions
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   // Intersection functions
00524 
00526 
00533   Box operator& (const Box& a_b) const;
00534 
00535   // refinement
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   // coarsening
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   // I/O Functions
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 // Inlines.
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   // default is a non-periodic domain
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   // boy is this ugly!
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   // boy is this ugly!
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 /*WRAPPER*/
00933 
00934 #endif

Generated on Wed Oct 5 13:52:09 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1