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                  bool a_exchange = false);
00072 
00074   Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00075          const ProblemDomain& a_domain,
00076                  bool  a_exchange  = false);
00077 
00079   Copier(const DisjointBoxLayout& a_level, 
00080          const BoxLayout& a_dest, 
00081          const IntVect& a_destGhost,
00082                  bool  a_exchange = false);
00083 
00085   Copier(const DisjointBoxLayout& a_level, 
00086          const BoxLayout& a_dest, 
00087          const ProblemDomain& a_domain,
00088          const IntVect& a_destGhost,
00089                  bool  a_exchange = false);
00090 
00092   virtual ~Copier();
00093 
00095   virtual void define(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00096                                           bool  a_exchange = false);
00097 
00098 
00100   virtual void define(const DisjointBoxLayout& a_level, 
00101                       const BoxLayout& a_dest,
00102                       const ProblemDomain& a_domain,
00103                                           bool  a_exchange = false);
00104 
00106   virtual void define(const DisjointBoxLayout& a_level, 
00107                       const BoxLayout& a_dest,
00108                       const IntVect& a_destGhost,
00109                                           bool  a_exchange = false);
00110 
00112   virtual void define(const DisjointBoxLayout& a_level, 
00113                       const BoxLayout& a_dest,
00114                       const ProblemDomain& a_domain,
00115                       const IntVect& a_destGhost,
00116                                           bool  a_exchange = false);
00117 
00119 
00123   void ghostDefine(const DisjointBoxLayout& a_src,
00124                                    const DisjointBoxLayout& a_dest,
00125                                    const ProblemDomain& a_domain,
00126                                    const IntVect& a_srcGhost);
00128   virtual void clear();
00129 
00131   bool check(const DisjointBoxLayout& from, const BoxLayout& to) const;
00132 
00133   int print() const;
00134 
00135   bool bufferAllocated() const;
00136   void setBufferAllocated(bool arg) const;
00137 
00138 protected:
00139 
00140   friend class CopyIterator;
00141 
00142   Vector<MotionItem*> m_localMotionPlan;
00143   Vector<MotionItem*> m_fromMotionPlan;
00144   Vector<MotionItem*> m_toMotionPlan;
00145 
00146   friend void dumpmemoryatexit();
00147   static Pool s_motionItemPool;
00148   mutable bool buffersAllocated;
00149 private:
00150 
00151   // keep a refcounted reference around for debugging purposes, we can
00152   // decide afterwards if we want to eliminate it.
00153   DisjointBoxLayout m_originPlan;
00154   BoxLayout  m_dest;
00155 
00156 };
00157 
00158 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00159 
00160 //===========================================================================
00161 // end of public interface for Copier.  
00162 //===========================================================================
00163 
00164 
00165 //  These classes are public because I can't find a nice
00166 //  way to make a class a friend of all the instantiations
00167 //  of a template class.  These classes are not part of
00168 //  the public interface for the Array API.  
00169 //
00170 //  Later, if MotionItem shows up in the profiler, we
00171 //  can start using a pool allocation scheme and placement new
00172 
00173 class MotionItem{
00174 public:
00175   DataIndex fromIndex, toIndex;
00176   Box fromRegion;
00177   Box toRegion;
00178   int procID;
00179   // this constructor will probably eventually go away
00180   MotionItem(const DataIndex& a_from, 
00181              const DataIndex& a_to,
00182              const Box&       a_region);
00183   MotionItem(const DataIndex& a_from, 
00184              const DataIndex& a_to,
00185              const Box&       a_fromRegion,
00186              const Box&       a_toRegion);
00187   void reverse();
00188 
00189 };
00190 
00191 inline MotionItem::MotionItem(const DataIndex& a_from, 
00192                               const DataIndex& a_to,
00193                               const Box&       a_region)
00194   :fromIndex(a_from), toIndex(a_to), fromRegion(a_region), 
00195   toRegion(a_region), procID(-1)
00196 {;}
00197 
00198 inline MotionItem::MotionItem(const DataIndex& a_from, 
00199                               const DataIndex& a_to,
00200                               const Box&       a_fromRegion,
00201                               const Box&       a_toRegion)
00202   :fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion), 
00203   toRegion(a_toRegion), procID(-1)
00204 {;}
00205 
00206 inline 
00207 void  MotionItem::reverse()
00208 {
00209   Box tmp(fromRegion);
00210   fromRegion=toRegion;
00211   toRegion=tmp;
00212   DataIndex tmpIndex(fromIndex);
00213   fromIndex = toIndex;
00214   toIndex = tmpIndex;
00215 }
00216 
00217 
00218 class CopyIterator
00219 {
00220 public:
00221   enum local_from_to {LOCAL, FROM, TO};
00222 
00223   inline CopyIterator(const Copier& a_copier, local_from_to);
00224 
00225   inline const MotionItem& operator()() const;
00226 
00227   inline void operator++();
00228 
00229   inline bool ok() const;
00230 
00231   inline void reset();
00232 private:
00233   const Vector<MotionItem*>* m_motionplanPtr;
00234   unsigned int  m_current;
00235 };
00236 
00237 //====== inlined functions====================================
00238 
00239 inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
00240   :m_current(0)
00241 {
00242   switch(type){
00243   case LOCAL:
00244     m_motionplanPtr = &(a_copier.m_localMotionPlan);
00245     break;
00246   case FROM:
00247     m_motionplanPtr = &(a_copier.m_fromMotionPlan);
00248     break;
00249   case TO:
00250     m_motionplanPtr = &(a_copier.m_toMotionPlan);
00251     break;
00252   default:
00253     MayDay::Error("illegal local_from_to option for CopyIterator");
00254   }
00255 }
00256 
00257 inline const MotionItem& CopyIterator::operator()() const
00258 {
00259   assert(m_current < m_motionplanPtr->size());
00260   return *(m_motionplanPtr->operator[](m_current));
00261 }
00262 
00263 inline void CopyIterator::operator++() {++m_current;}
00264 
00265 inline bool CopyIterator::ok() const
00266 {
00267   return m_current < m_motionplanPtr->size();
00268 }
00269 
00270 inline void CopyIterator::reset()
00271 {
00272   m_current = 0;
00273 }
00274 
00275 
00276 
00277 
00278 #endif 

Generated on Wed Jun 2 13:53:32 2004 for Chombo&INSwithParticles by doxygen 1.3.2