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 _LEVELDATA_H_
00029 #define _LEVELDATA_H_
00030
00031 #include "IntVect.H"
00032 #include "BoxLayoutData.H"
00033 #include "DisjointBoxLayout.H"
00034 #include "Copier.H"
00035 #include "SPMD.H"
00036
00037 template <class T>
00038 class LDOperator
00039 {
00040 public:
00041 virtual int size(const T& arg, const Box& b, const Interval& comps) const
00042 {
00043 return arg.size(b, comps);
00044 }
00045 virtual void linearOut(const T& arg, void* buf, const Box& R,
00046 const Interval& comps) const
00047 {
00048 arg.linearOut(buf, R, comps);
00049 }
00050 virtual void linearIn(T& arg, void* buf, const Box& R,
00051 const Interval& comps)const
00052 {
00053 arg.linearIn(buf, R, comps);
00054 }
00055 virtual void op(T& dest,
00056 const Box& RegionFrom,
00057 const Interval& Cdest,
00058 const Box& RegionTo,
00059 const T& src,
00060 const Interval& Csrc) const
00061 {
00062 dest.copy(RegionFrom, Cdest,RegionTo, src, Csrc);
00063 }
00064 };
00065
00067
00080 template<class T> class LevelData : public BoxLayoutData<T>
00081 {
00082 public:
00083
00085 LevelData();
00086
00088 LevelData(const DisjointBoxLayout& dp, int comps,
00089 const IntVect& ghost = IntVect::TheZeroVector(),
00090 const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00091
00093 virtual ~LevelData();
00094
00095
00097 virtual void define(const DisjointBoxLayout& dp, int comps,
00098 const IntVect& ghost = IntVect::TheZeroVector(),
00099 const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00100
00101
00103
00106 virtual void define(const LevelData<T>& da,
00107 const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00108
00110
00115 virtual void define(const LevelData<T>& da, const Interval& comps,
00116 const DataFactory<T>& a_factory = DefaultDataFactory<T>());
00117
00119 virtual void copyTo(const Interval& srcComps,
00120 BoxLayoutData<T>& dest,
00121 const Interval& destComps) const;
00122
00124 virtual void copyTo(const Interval& srcComps,
00125 BoxLayoutData<T>& dest,
00126 const Interval& destComps,
00127 const Copier& copier) const;
00129
00131 virtual void copyTo(const Interval& srcComps,
00132 LevelData<T>& dest,
00133 const Interval& destComps) const;
00134
00136
00139 virtual void copyTo(const Interval& srcComps,
00140 LevelData<T>& dest,
00141 const Interval& destComps,
00142 const Copier& copier,
00143 const LDOperator<T>& a_op = LDOperator<T>()) const;
00144
00146 virtual void exchange(const Interval& comps);
00147
00149 virtual void exchange(const Interval& comps,
00150 const Copier& copier);
00151
00153 const IntVect& ghostVect() const { return m_ghost;}
00154
00168 virtual void define(const BoxLayout& dp, int comps,
00169 const DataFactory<T>& factory);
00170
00172 virtual void define(const BoxLayoutData<T>& da,
00173 const DataFactory<T>& factory = DefaultDataFactory<T>());
00174
00176 virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
00177 const DataFactory<T>& factory = DefaultDataFactory<T>());
00178
00179 virtual void define(const BoxLayout& deadFunction);
00182
00183 const DisjointBoxLayout& getBoxes() const
00184 {
00185 return m_disjointBoxLayout;
00186 }
00187
00189 const DisjointBoxLayout& disjointBoxLayout() const
00190 {
00191 return m_disjointBoxLayout;
00192 }
00193
00195
00219 virtual void apply(void (*a_Function)(const Box& box, int comps, T& t));
00220
00221 protected:
00222
00223 void makeItSo(const Interval& a_srcComps,
00224 const LevelData<T>& a_src,
00225 BoxLayoutData<T>& a_dest,
00226 const Interval& a_destComps,
00227 const Copier& a_copier,
00228 const LDOperator<T>& a_op = LDOperator<T>()) const;
00229
00230 DisjointBoxLayout m_disjointBoxLayout;
00231
00232 IntVect m_ghost;
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 void completePendingSends() const;
00244
00245 void allocateBuffers(const LevelData<T>& a_src,
00246 const Interval& a_srcComps,
00247 const BoxLayoutData<T>& a_dest,
00248 const Interval& a_destComps,
00249 const Copier& a_copier,
00250 const LDOperator<T>& a_op) const;
00251
00252 void writeSendDataFromMeIntoBuffers(const LevelData<T>& a_src,
00253 const Interval& a_srcComps,
00254 const LDOperator<T>& a_op) const;
00255
00256 void postSendsFromMe() const ;
00257
00258 void postReceivesToMe() const ;
00259
00260 void unpackReceivesToMe(BoxLayoutData<T>& a_dest,
00261 const Interval& a_destComps,
00262 const LDOperator<T>& a_op) const ;
00263
00266 mutable void* m_sendbuffer;
00267
00268 mutable size_t m_sendcapacity;
00269 mutable void* m_recbuffer;
00270
00271 mutable size_t m_reccapacity;
00272
00273 #ifdef MPI
00274
00275 #ifndef DOXYGEN
00276
00277 struct bufEntry
00278 {
00279 void* bufPtr;
00280 size_t size;
00281 const MotionItem* item;
00282 unsigned int procID;
00283 bool operator < (const bufEntry& rhs) const
00284 {
00285 if(procID == rhs.procID)
00286 {
00287 const Box& left = item->toRegion;
00288 const Box& right= rhs.item->toRegion;
00289 if(left.smallEnd() == right.smallEnd())
00290 {
00291 return left.bigEnd().lexLT(right.bigEnd());
00292 }
00293 else
00294 {
00295 return item->toRegion < rhs.item->toRegion;
00296 }
00297 }
00298
00299 return procID < rhs.procID;
00300 }
00301 };
00302
00303 #endif
00304 mutable std::vector<bufEntry> m_fromMe;
00305 mutable std::vector<bufEntry> m_toMe;
00306
00307 mutable MPI_Request *m_sendRequests, *m_receiveRequests;
00308 mutable MPI_Status *m_sendStatus, *m_receiveStatus;
00309 mutable int numSends, numReceives;
00310
00311 #endif
00312
00314 #ifdef DOXYGEN
00315 friend void aliasLevelData<T>(LevelData<T>& a_alias,
00316 LevelData<T>* a_original,
00317 const Interval& a_interval);
00318 #endif
00319
00320 };
00321
00323
00350 template <class T>
00351 void aliasLevelData(LevelData<T>& a_alias, LevelData<T>* a_original,
00352 const Interval& a_interval)
00353 {
00354 AliasDataFactory<T> factory(a_original, a_interval);
00355 a_alias.define(a_original->disjointBoxLayout(), a_interval.size(), a_original->ghostVect(), factory);
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365 #include "LevelDataI.H"
00366
00367
00368
00369 #endif