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 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
00132
00133 DisjointBoxLayout m_originPlan;
00134 BoxLayout m_dest;
00135
00136 };
00137
00138 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 class MotionItem{
00154 public:
00155 DataIndex fromIndex, toIndex;
00156 Box fromRegion;
00157 Box toRegion;
00158 int procID;
00159
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
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