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