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   bool bufferAllocated() const;
00119   void setBufferAllocated(bool arg) const;
00120 
00121 protected:
00122 
00123   friend class CopyIterator;
00124 
00125   Vector<MotionItem*> m_localMotionPlan;
00126   Vector<MotionItem*> m_fromMotionPlan;
00127   Vector<MotionItem*> m_toMotionPlan;
00128 
00129   friend void dumpmemoryatexit();
00130   static Pool s_motionItemPool;
00131   mutable bool buffersAllocated;
00132 private:
00133 
00134   // keep a refcounted reference around for debugging purposes, we can
00135   // decide afterwards if we want to eliminate it.
00136   DisjointBoxLayout m_originPlan;
00137   BoxLayout  m_dest;
00138 
00139 };
00140 
00141 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00142 
00143 //===========================================================================
00144 // end of public interface for Copier.  
00145 //===========================================================================
00146 
00147 
00148 //  These classes are public because I can't find a nice
00149 //  way to make a class a friend of all the instantiations
00150 //  of a template class.  These classes are not part of
00151 //  the public interface for the Array API.  
00152 //
00153 //  Later, if MotionItem shows up in the profiler, we
00154 //  can start using a pool allocation scheme and placement new
00155 
00156 class MotionItem{
00157 public:
00158   DataIndex fromIndex, toIndex;
00159   Box fromRegion;
00160   Box toRegion;
00161   int procID;
00162   // this constructor will probably eventually go away
00163   MotionItem(const DataIndex& a_from, 
00164              const DataIndex& a_to,
00165              const Box&       a_region);
00166   MotionItem(const DataIndex& a_from, 
00167              const DataIndex& a_to,
00168              const Box&       a_fromRegion,
00169              const Box&       a_toRegion);
00170 };
00171 
00172 inline MotionItem::MotionItem(const DataIndex& a_from, 
00173                               const DataIndex& a_to,
00174                               const Box&       a_region)
00175   :fromIndex(a_from), toIndex(a_to), fromRegion(a_region), 
00176   toRegion(a_region), procID(-1)
00177 {;}
00178 
00179 inline MotionItem::MotionItem(const DataIndex& a_from, 
00180                               const DataIndex& a_to,
00181                               const Box&       a_fromRegion,
00182                               const Box&       a_toRegion)
00183   :fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion), 
00184   toRegion(a_toRegion), procID(-1)
00185 {;}
00186 
00187 
00188 
00189 class CopyIterator
00190 {
00191 public:
00192   enum local_from_to {LOCAL, FROM, TO};
00193 
00194   inline CopyIterator(const Copier& a_copier, local_from_to);
00195 
00196   inline const MotionItem& operator()() const;
00197 
00198   inline void operator++();
00199 
00200   inline bool ok() const;
00201 
00202   inline void reset();
00203 private:
00204   const Vector<MotionItem*>* m_motionplanPtr;
00205   unsigned int  m_current;
00206 };
00207 
00208 //====== inlined functions====================================
00209 
00210 inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
00211   :m_current(0)
00212 {
00213   switch(type){
00214   case LOCAL:
00215     m_motionplanPtr = &(a_copier.m_localMotionPlan);
00216     break;
00217   case FROM:
00218     m_motionplanPtr = &(a_copier.m_fromMotionPlan);
00219     break;
00220   case TO:
00221     m_motionplanPtr = &(a_copier.m_toMotionPlan);
00222     break;
00223   default:
00224     MayDay::Error("illegal local_from_to option for CopyIterator");
00225   }
00226 }
00227 
00228 inline const MotionItem& CopyIterator::operator()() const
00229 {
00230   assert(m_current < m_motionplanPtr->size());
00231   return *(m_motionplanPtr->operator[](m_current));
00232 }
00233 
00234 inline void CopyIterator::operator++() {++m_current;}
00235 
00236 inline bool CopyIterator::ok() const
00237 {
00238   return m_current < m_motionplanPtr->size();
00239 }
00240 
00241 inline void CopyIterator::reset()
00242 {
00243   m_current = 0;
00244 }
00245 
00246 
00247 
00248 
00249 #endif 

Generated on Wed Apr 16 14:31:04 2003 for EBChombo by doxygen1.2.16