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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _COPIER_H_
00053 #define _COPIER_H_
00054
00055 #include "DisjointBoxLayout.H"
00056 #include "Pool.H"
00057 #include "Vector.H"
00058 #include "ProblemDomain.H"
00059
00060 class MotionItem;
00061 class CopyIterator;
00062
00064
00085 class Copier
00086 {
00087 public:
00088
00090 Copier()
00091 {}
00092
00094 Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00095 bool a_exchange = false);
00096
00098 Copier(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00099 const ProblemDomain& a_domain,
00100 bool a_exchange = false);
00101
00103 Copier(const DisjointBoxLayout& a_level,
00104 const BoxLayout& a_dest,
00105 const IntVect& a_destGhost,
00106 bool a_exchange = false);
00107
00109 Copier(const DisjointBoxLayout& a_level,
00110 const BoxLayout& a_dest,
00111 const ProblemDomain& a_domain,
00112 const IntVect& a_destGhost,
00113 bool a_exchange = false);
00114
00116 virtual ~Copier();
00117
00119 virtual void define(const DisjointBoxLayout& a_level, const BoxLayout& a_dest,
00120 bool a_exchange = false);
00121
00123 virtual void define(const DisjointBoxLayout& a_level,
00124 const BoxLayout& a_dest,
00125 const ProblemDomain& a_domain,
00126 bool a_exchange = false);
00127
00129 virtual void define(const DisjointBoxLayout& a_level,
00130 const BoxLayout& a_dest,
00131 const IntVect& a_destGhost,
00132 bool a_exchange = false);
00133
00135 virtual void define(const BoxLayout& a_level,
00136 const BoxLayout& a_dest,
00137 const ProblemDomain& a_domain,
00138 const IntVect& a_destGhost,
00139 bool a_exchange = false);
00140
00142
00146 void ghostDefine(const DisjointBoxLayout& a_src,
00147 const DisjointBoxLayout& a_dest,
00148 const ProblemDomain& a_domain,
00149 const IntVect& a_srcGhost);
00151 virtual void clear();
00152
00154 bool check(const DisjointBoxLayout& from, const BoxLayout& to) const;
00155
00156 int print() const;
00157
00158 bool bufferAllocated() const;
00159 void setBufferAllocated(bool arg) const;
00160
00161 int numLocalCellsToCopy() const;
00162 int numFromCellsToCopy() const;
00163 int numToCellsToCopy() const;
00164
00165
00166 protected:
00167
00168 friend class CopyIterator;
00169
00170 Vector<MotionItem*> m_localMotionPlan;
00171 Vector<MotionItem*> m_fromMotionPlan;
00172 Vector<MotionItem*> m_toMotionPlan;
00173
00174 friend void dumpmemoryatexit();
00175 static Pool s_motionItemPool;
00176 mutable bool buffersAllocated;
00177 private:
00178
00179
00180
00181 DisjointBoxLayout m_originPlan;
00182 BoxLayout m_dest;
00183
00184 };
00185
00186 std::ostream& operator<<(std::ostream& os, const Copier& copier);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 class MotionItem{
00201 public:
00202 DataIndex fromIndex, toIndex;
00203 Box fromRegion;
00204 Box toRegion;
00205 int procID;
00206
00207 MotionItem(const DataIndex& a_from,
00208 const DataIndex& a_to,
00209 const Box& a_region);
00210 MotionItem(const DataIndex& a_from,
00211 const DataIndex& a_to,
00212 const Box& a_fromRegion,
00213 const Box& a_toRegion);
00214 void reverse();
00215
00216 };
00217
00218 inline MotionItem::MotionItem(const DataIndex& a_from,
00219 const DataIndex& a_to,
00220 const Box& a_region)
00221 :fromIndex(a_from), toIndex(a_to), fromRegion(a_region),
00222 toRegion(a_region), procID(-1)
00223 {}
00224
00225 inline MotionItem::MotionItem(const DataIndex& a_from,
00226 const DataIndex& a_to,
00227 const Box& a_fromRegion,
00228 const Box& a_toRegion)
00229 :fromIndex(a_from), toIndex(a_to), fromRegion(a_fromRegion),
00230 toRegion(a_toRegion), procID(-1)
00231 {}
00232
00233 inline
00234 void MotionItem::reverse()
00235 {
00236 Box tmp(fromRegion);
00237 fromRegion=toRegion;
00238 toRegion=tmp;
00239 DataIndex tmpIndex(fromIndex);
00240 fromIndex = toIndex;
00241 toIndex = tmpIndex;
00242 }
00243
00244 class CopyIterator
00245 {
00246 public:
00247 enum local_from_to {LOCAL, FROM, TO};
00248
00249 inline CopyIterator(const Copier& a_copier, local_from_to);
00250
00251 inline const MotionItem& operator()() const;
00252
00253 inline void operator++();
00254
00255 inline bool ok() const;
00256
00257 inline void reset();
00258 private:
00259 const Vector<MotionItem*>* m_motionplanPtr;
00260 unsigned int m_current;
00261 };
00262
00263
00264
00265 inline CopyIterator::CopyIterator(const Copier& a_copier, local_from_to type)
00266 :m_current(0)
00267 {
00268 switch(type){
00269 case LOCAL:
00270 m_motionplanPtr = &(a_copier.m_localMotionPlan);
00271 break;
00272 case FROM:
00273 m_motionplanPtr = &(a_copier.m_fromMotionPlan);
00274 break;
00275 case TO:
00276 m_motionplanPtr = &(a_copier.m_toMotionPlan);
00277 break;
00278 default:
00279 MayDay::Error("illegal local_from_to option for CopyIterator");
00280 }
00281 }
00282
00283 inline const MotionItem& CopyIterator::operator()() const
00284 {
00285 CH_assert(m_current < m_motionplanPtr->size());
00286 return *(m_motionplanPtr->operator[](m_current));
00287 }
00288
00289 inline void CopyIterator::operator++() {++m_current;}
00290
00291 inline bool CopyIterator::ok() const
00292 {
00293 return m_current < m_motionplanPtr->size();
00294 }
00295
00296 inline void CopyIterator::reset()
00297 {
00298 m_current = 0;
00299 }
00300
00301 #endif