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 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
00152
00153 DisjointBoxLayout m_originPlan;
00154 BoxLayout m_dest;
00155
00156 };
00157
00158 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 class MotionItem{
00174 public:
00175 DataIndex fromIndex, toIndex;
00176 Box fromRegion;
00177 Box toRegion;
00178 int procID;
00179
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
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