Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Copier.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef COPIER_H
00029 #define COPIER_H
00030 
00031 #include "DisjointBoxLayout.H"
00032 #include "Pool.H"
00033 #include "Vector.H"
00034 #include "ProblemDomain.H"
00035 
00036 class MotionItem;
00037 
00038 class CopyIterator;
00039 
00040 
00042 
00063 class Copier
00064 {
00065 public:
00066 
00068   Copier(){;}
00070   Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest);
00071 
00073   Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00074          const ProblemDomain& a_domain);
00075 
00077   Copier(const DisjointBoxLayout& a_level, 
00078          const BoxLayout& a_dest, 
00079          const IntVect& a_destGhost);
00080 
00082   Copier(const DisjointBoxLayout& a_level, 
00083          const BoxLayout& a_dest, 
00084          const ProblemDomain& a_domain,
00085          const IntVect& a_destGhost);
00086 
00088   virtual ~Copier();
00089 
00091   virtual void define(const DisjointBoxLayout& a_level, const BoxLayout& a_dest);
00092 
00093 
00095   virtual void define(const DisjointBoxLayout& a_level, 
00096                       const BoxLayout& a_dest,
00097                       const ProblemDomain& a_domain);
00098 
00100   virtual void define(const DisjointBoxLayout& a_level, 
00101                       const BoxLayout& a_dest,
00102                       const IntVect& a_destGhost);
00103 
00105   virtual void define(const DisjointBoxLayout& a_level, 
00106                       const BoxLayout& a_dest,
00107                       const ProblemDomain& a_domain,
00108                       const IntVect& a_destGhost);
00109 
00111   virtual void clear();
00112 
00114   bool check(const DisjointBoxLayout& from, const BoxLayout& to) const;
00115 
00116   int print() const;
00117 
00118 protected:
00119 
00120   friend class CopyIterator;
00121 
00122   Vector<MotionItem*> m_localMotionPlan;
00123   Vector<MotionItem*> m_fromMotionPlan;
00124   Vector<MotionItem*> m_toMotionPlan;
00125 
00126   friend void dumpmemoryatexit();
00127   static Pool s_motionItemPool;
00128 
00129 private:
00130 
00131   // keep a refcounted reference around for debugging purposes, we can
00132   // decide afterwards if we want to eliminate it.
00133   DisjointBoxLayout m_originPlan;
00134   BoxLayout  m_dest;
00135 
00136 };
00137 
00138 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00139 
00140 //===========================================================================
00141 // end of public interface for Copier.  
00142 //===========================================================================
00143 
00144 
00145 //  These classes are public because I can't find a nice
00146 //  way to make a class a friend of all the instantiations
00147 //  of a template class.  These classes are not part of
00148 //  the public interface for the Array API.  
00149 //
00150 //  Later, if MotionItem shows up in the profiler, we
00151 //  can start using a pool allocation scheme and placement new
00152 
00153 class MotionItem{
00154 public:
00155   DataIndex fromIndex, toIndex;
00156   Box fromRegion;
00157   Box toRegion;
00158   int procID;
00159   // this constructor will probably eventually go away
00160   MotionItem(const DataIndex& a_from, 
00161              const DataIndex& a_to,
00162              const Box&       a_region);
00163   MotionItem(const DataIndex& a_from, 
00164              const DataIndex& a_to,
00165              const Box&       a_fromRegion,
00166              const Box&       a_toRegion);
00167 };
00168 
00169 inline MotionItem::MotionItem(const DataIndex& a_from, 
00170                               const DataIndex& a_to,
00171                               const Box&       a_region)
00172   :fromIndex(a_from), toIndex(a_to), fromRegion(a_region), 
00173   toRegion(a_region), procID(-1)
00174 {;}
00175 
00176 inline MotionItem::MotionItem(const DataIndex& a_from, 
00177                               const DataIndex& a_to,
00178                               const Box&       a_fromRegion,
00179                               const Box&       a_toRegion)
00180   :fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion), 
00181   toRegion(a_toRegion), procID(-1)
00182 {;}
00183 
00184 
00185 
00186 class CopyIterator
00187 {
00188 public:
00189   enum local_from_to {LOCAL, FROM, TO};
00190 
00191   inline CopyIterator(const Copier& a_copier, local_from_to);
00192 
00193   inline const MotionItem& operator()() const;
00194 
00195   inline void operator++();
00196 
00197   inline bool ok() const;
00198 
00199   inline void reset();
00200 private:
00201   const Vector<MotionItem*>* m_motionplanPtr;
00202   unsigned int  m_current;
00203 };
00204 
00205 //====== inlined functions====================================
00206 
00207 inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
00208   :m_current(0)
00209 {
00210   switch(type){
00211   case LOCAL:
00212     m_motionplanPtr = &(a_copier.m_localMotionPlan);
00213     break;
00214   case FROM:
00215     m_motionplanPtr = &(a_copier.m_fromMotionPlan);
00216     break;
00217   case TO:
00218     m_motionplanPtr = &(a_copier.m_toMotionPlan);
00219     break;
00220   default:
00221     MayDay::Error("illegal local_from_to option for CopyIterator");
00222   }
00223 }
00224 
00225 inline const MotionItem& CopyIterator::operator()() const
00226 {
00227   assert(m_current < m_motionplanPtr->size());
00228   return *(m_motionplanPtr->operator[](m_current));
00229 }
00230 
00231 inline void CopyIterator::operator++() {++m_current;}
00232 
00233 inline bool CopyIterator::ok() const
00234 {
00235   return m_current < m_motionplanPtr->size();
00236 }
00237 
00238 inline void CopyIterator::reset()
00239 {
00240   m_current = 0;
00241 }
00242 
00243 
00244 
00245 
00246 #endif 

Generated on Tue Jul 2 10:42:19 2002 for Chombo by doxygen1.2.16