00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _BOXLAYOUTDATA_H_
00012 #define _BOXLAYOUTDATA_H_
00013
00014 #include "LayoutData.H"
00015 #include "Interval.H"
00016 #include "FArrayBox.H"
00017 #include "DisjointBoxLayout.H"
00018 #include "Copier.H"
00019 #include "SPMD.H"
00020 #include "memtrack.H"
00021 #include "NamespaceHeader.H"
00022
00023
00024 extern int LinearizationTest;
00025
00027 template <class T> class DataFactory
00028 {
00029 public:
00030
00031 virtual ~DataFactory(){;}
00033
00035 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const=0;
00036
00037 virtual bool callDelete() const {return true;}
00038 };
00039
00041
00055 template <class T> class DefaultDataFactory : public DataFactory<T>
00056 {
00057 public:
00059
00061 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00062
00063 };
00064
00065 class FABAliasDataFactory : public DataFactory<FArrayBox>
00066 {
00067 public:
00068 virtual ~FABAliasDataFactory()
00069 {}
00070
00071 FABAliasDataFactory(const LayoutData<Real*>& aliases);
00072 void define(const LayoutData<Real*>& aliases);
00074
00076 virtual FArrayBox* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00077
00078 protected:
00079 LayoutData<Real*> aliasPtrs;
00080 };
00081
00082 template<class T> class BoxLayoutData;
00083
00084 template <class T>
00085 class AliasDataFactory : public DataFactory<T>
00086 {
00087 public:
00088 virtual ~AliasDataFactory()
00089 {}
00090
00091 AliasDataFactory(BoxLayoutData<T>* a_original, const Interval& interval);
00092 void define(BoxLayoutData<T>* a_original, const Interval& interval);
00095 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00096
00097 protected:
00098 BoxLayoutData<T>* m_origPointer;
00099 Interval m_interval;
00100 };
00101
00102 template<class T> class LevelData;
00103
00104 template <class T>
00105 class LDOperator
00106 {
00107 public:
00108 virtual ~LDOperator(){}
00109
00110 virtual int size(const T& arg, const Box& b, const Interval& comps) const
00111 {
00112 return arg.size(b, comps);
00113 }
00114 virtual void linearOut(const T& arg, void* buf, const Box& R,
00115 const Interval& comps) const
00116 {
00117 arg.linearOut(buf, R, comps);
00118 }
00119 virtual void linearIn(T& arg, void* buf, const Box& R,
00120 const Interval& comps)const
00121 {
00122 arg.linearIn(buf, R, comps);
00123 }
00124 virtual void op(T& dest,
00125 const Box& RegionFrom,
00126 const Interval& Cdest,
00127 const Box& RegionTo,
00128 const T& src,
00129 const Interval& Csrc) const
00130 {
00131 if(LinearizationTest == 0){
00132 dest.copy(RegionFrom, Cdest,RegionTo, src, Csrc);
00133 } else {
00134 int sizeSource = size(src, RegionFrom, Csrc);
00135 int sizeDest = size(dest, RegionTo, Cdest);
00136
00137 if(T::preAllocatable() == 0 || T::preAllocatable() == 1){
00138 if(sizeSource != sizeDest)
00139 {
00140 MayDay::Abort("LinearizationTest failure: dest and source have different sizes");
00141 }
00142 }
00143 Vector<char> buffer(sizeSource);
00144 void* b = (void*)&(buffer[0]);
00145 linearOut(src, b, RegionFrom, Csrc);
00146 linearIn(dest, b, RegionTo, Cdest);
00147 }
00148 }
00149 };
00150
00152
00186 template<class T>
00187 class BoxLayoutData : public LayoutData<T>
00188 {
00189 public:
00191 BoxLayoutData();
00192
00193 virtual ~BoxLayoutData();
00195 BoxLayoutData(const BoxLayout& boxes, int comps,
00196 const DataFactory<T>& factory = DefaultDataFactory<T>());
00197
00199 virtual void define(const BoxLayout& boxes, int comps,
00200 const DataFactory<T>& factory = DefaultDataFactory<T>());
00201
00203 virtual void define(const BoxLayoutData<T>& da,
00204 const DataFactory<T>& factory = DefaultDataFactory<T>());
00205
00207
00210 virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
00211 const DataFactory<T>& factory = DefaultDataFactory<T>());
00212
00214 virtual void define(const BoxLayout& boxes);
00215
00217 int nComp() const { return m_comps;}
00218
00220 Interval interval() const
00221 {
00222 Interval outint(0, m_comps-1);
00223 return(outint);
00224 }
00225
00227
00235 void generalCopyTo(const BoxLayout& a_destGrids,
00236 LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00237 const Interval& a_interval,
00238 const ProblemDomain& a_domain,
00239 const DataFactory<T>& factory = DefaultDataFactory<T>()) const ;
00240
00242 void generalCopyTo(const BoxLayout& a_destGrids,
00243 LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00244 const Interval& a_interval,
00245 const ProblemDomain& a_domain,
00246 const Copier& a_copier,
00247 const DataFactory<T>& factory = DefaultDataFactory<T>()) const ;
00248
00249
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 virtual void apply(void (*a_Function)(const Box& box, int comps, T& t));
00263
00265 virtual bool isDefined() const;
00266
00267 virtual void clear() ;
00268
00269 static int s_verbosity;
00270
00271 protected:
00272 int m_comps;
00273 bool m_isdefined;
00274
00275 friend class LevelData<T>;
00276
00277 void setVector(const BoxLayoutData<T>& da,
00278 const Interval& srcComps,
00279 const Interval& destComps);
00280
00281 void allocateGhostVector(const DataFactory<T>& factory,
00282 const IntVect& ghost = IntVect::Zero);
00283
00284 void makeItSo(const Interval& a_srcComps,
00285 const BoxLayoutData<T>& a_src,
00286 BoxLayoutData<T>& a_dest,
00287 const Interval& a_destComps,
00288 const Copier& a_copier,
00289 const LDOperator<T>& a_op = LDOperator<T>()) const;
00290 void makeItSoBegin(
00291 const Interval& a_srcComps,
00292 const BoxLayoutData<T>& a_src,
00293 BoxLayoutData<T>& a_dest,
00294 const Interval& a_destComps,
00295 const Copier& a_copier,
00296 const LDOperator<T>& a_op = LDOperator<T>()) const;
00297 void makeItSoLocalCopy(
00298 const Interval& a_srcComps,
00299 const BoxLayoutData<T>& a_src,
00300 BoxLayoutData<T>& a_dest,
00301 const Interval& a_destComps,
00302 const Copier& a_copier,
00303 const LDOperator<T>& a_op = LDOperator<T>()) const;
00304 void makeItSoEnd(
00305 BoxLayoutData<T>& a_dest,
00306 const Interval& a_destComps,
00307 const LDOperator<T>& a_op = LDOperator<T>()) const;
00308
00309
00310
00311
00312
00313
00314
00315 void completePendingSends() const;
00316
00317 void allocateBuffers(const BoxLayoutData<T>& a_src,
00318 const Interval& a_srcComps,
00319 const BoxLayoutData<T>& a_dest,
00320 const Interval& a_destComps,
00321 const Copier& a_copier,
00322 const LDOperator<T>& a_op) const;
00323
00324 void writeSendDataFromMeIntoBuffers(const BoxLayoutData<T>& a_src,
00325 const Interval& a_srcComps,
00326 const LDOperator<T>& a_op) const;
00327
00328 void postSendsFromMe() const ;
00329
00330 void postReceivesToMe() const ;
00331
00332 void unpackReceivesToMe(BoxLayoutData<T>& a_dest,
00333 const Interval& a_destComps,
00334 const LDOperator<T>& a_op) const ;
00335
00336 void unpackReceivesToMe_append(LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00337 const Interval& a_destComps,
00338 int ncomp,
00339 const DataFactory<T>& factory,
00340 const LDOperator<T>& a_op) const;
00341
00344
00345
00346
00347
00348
00349
00350 mutable CopierBuffer* m_buff;
00351 #ifdef CH_MPI
00352
00353 #ifndef DOXYGEN
00354
00355
00356 #endif
00357
00358
00359
00360
00361 mutable Vector<MPI_Request> m_sendRequests, m_receiveRequests;
00362 mutable Vector<MPI_Status> m_receiveStatus, m_sendStatus;
00363 mutable int numSends, numReceives;
00364 #endif
00365
00366 };
00367
00369
00388 Real norm(const BoxLayoutData<FArrayBox>& A,
00389 const Interval& interval,
00390 const int& p = 2);
00391
00392
00393 template < >
00394 BaseFab<int>* DefaultDataFactory<BaseFab<int> >::create(const Box& box,
00395 int ncomps,
00396 const DataIndex& a_datInd) const;
00397
00398 template < >
00399 FArrayBox* DefaultDataFactory<FArrayBox>::create(const Box& box,
00400 int ncomps,
00401 const DataIndex& a_datInd) const;
00402
00403
00404 #include "NamespaceFooter.H"
00405 #include "BoxLayoutDataI.H"
00406
00407 #endif //BOXLAYOUTDATA