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
00025 class FluxBox;
00026
00027 extern int LinearizationTest;
00028
00029
00030 template <class T> class DataFactory
00031 {
00032 public:
00033
00034 virtual ~DataFactory()
00035 {
00036 }
00037
00038
00039
00040
00041 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const=0;
00042
00043 virtual bool callDelete() const
00044 {
00045 return true;
00046 }
00047
00048
00049 virtual bool threadSafe() const
00050 {
00051 return true;
00052 }
00053 };
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 template <class T> class DefaultDataFactory : public DataFactory<T>
00071 {
00072 public:
00073
00074
00075
00076 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00077
00078 };
00079
00080 class FABAliasDataFactory : public DataFactory<FArrayBox>
00081 {
00082 public:
00083 virtual ~FABAliasDataFactory()
00084 {}
00085
00086 FABAliasDataFactory(const LayoutData<Real*>& aliases);
00087 void define(const LayoutData<Real*>& aliases);
00088
00089
00090
00091 virtual FArrayBox* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00092
00093 protected:
00094 LayoutData<Real*> aliasPtrs;
00095 };
00096
00097 template<class T> class BoxLayoutData;
00098
00099 template <class T>
00100 class AliasDataFactory : public DataFactory<T>
00101 {
00102 public:
00103 virtual ~AliasDataFactory()
00104 {}
00105
00106 AliasDataFactory(BoxLayoutData<T>* a_original, const Interval& interval);
00107 void define(BoxLayoutData<T>* a_original, const Interval& interval);
00108
00109
00110 virtual T* create(const Box& box, int ncomps, const DataIndex& a_datInd) const;
00111
00112
00113 virtual bool threadSafe() const
00114 {
00115 return m_origPointer->threadSafe();
00116 }
00117 protected:
00118 BoxLayoutData<T>* m_origPointer;
00119 Interval m_interval;
00120 };
00121
00122
00123
00124 class FABAliasFlBxDataFactory : public DataFactory<FArrayBox>
00125 {
00126 public:
00127 virtual ~FABAliasFlBxDataFactory()
00128 {}
00129
00130 FABAliasFlBxDataFactory(BoxLayoutData<FluxBox>* a_original,
00131 const Interval& a_interval,
00132 const int a_dir);
00133 void define(BoxLayoutData<FluxBox>* a_original,
00134 const Interval& a_interval,
00135 const int a_dir);
00136
00137
00138 virtual FArrayBox* create(const Box& a_box,
00139 int a_ncomps,
00140 const DataIndex& a_datInd) const;
00141 protected:
00142 BoxLayoutData<FluxBox> *m_origPointer;
00143 Interval m_interval;
00144 int m_dir;
00145 };
00146
00147
00148
00149
00150 class FaceFabDataFactory : public DataFactory<FArrayBox>
00151 {
00152 public:
00153 virtual ~FaceFabDataFactory()
00154 {}
00155
00156 FaceFabDataFactory(const int a_dir);
00157
00158 void define(const int a_dir);
00159
00160
00161
00162 virtual FArrayBox* create(const Box & a_box ,
00163 int a_ncomps,
00164 const DataIndex& a_datInd) const;
00165 protected:
00166 int m_dir;
00167 };
00168
00169
00170 template<class T> class LevelData;
00171
00172 template <class T>
00173 class LDOperator
00174 {
00175 public:
00176
00177 virtual ~LDOperator()
00178 {
00179 }
00180 virtual int size(const T& arg, const Box& b, const Interval& comps) const
00181 {
00182 return arg.size(b, comps);
00183 }
00184 virtual void linearOut(const T& arg, void* buf, const Box& R,
00185 const Interval& comps) const
00186 {
00187 arg.linearOut(buf, R, comps);
00188 }
00189 virtual void linearIn(T& arg, void* buf, const Box& R,
00190 const Interval& comps)const
00191 {
00192 arg.linearIn(buf, R, comps);
00193 }
00194
00195
00196
00197
00198
00199
00200 virtual bool threadSafe() const
00201 {
00202 return true;
00203 }
00204 virtual void op(T& dest,
00205 const Box& RegionFrom,
00206 const Interval& Cdest,
00207 const Box& RegionTo,
00208 const T& src,
00209 const Interval& Csrc) const
00210 {
00211 if (LinearizationTest == 0)
00212 {
00213 dest.copy(RegionFrom, Cdest,RegionTo, src, Csrc);
00214 }
00215 else
00216 {
00217 int sizeSource = size(src, RegionFrom, Csrc);
00218 int sizeDest = size(dest, RegionTo, Cdest);
00219
00220 if (T::preAllocatable() == 0 || T::preAllocatable() == 1)
00221 {
00222 if (sizeSource != sizeDest)
00223 {
00224 MayDay::Abort("LinearizationTest failure: dest and source have different sizes");
00225 }
00226 }
00227 Vector<char> buffer(sizeSource);
00228 void* b = (void*)&(buffer[0]);
00229 linearOut(src, b, RegionFrom, Csrc);
00230 linearIn(dest, b, RegionTo, Cdest);
00231 }
00232 }
00233 };
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 template<class T>
00272 class BoxLayoutData : public LayoutData<T>
00273 {
00274 public:
00275
00276 BoxLayoutData();
00277
00278 virtual ~BoxLayoutData();
00279
00280 BoxLayoutData(const BoxLayout& boxes, int comps,
00281 const DataFactory<T>& factory = DefaultDataFactory<T>());
00282
00283
00284 virtual void define(const BoxLayout& boxes, int comps,
00285 const DataFactory<T>& factory = DefaultDataFactory<T>());
00286
00287
00288 virtual void define(const BoxLayoutData<T>& da,
00289 const DataFactory<T>& factory = DefaultDataFactory<T>());
00290
00291
00292
00293
00294
00295 virtual void define(const BoxLayoutData<T>& da, const Interval& comps,
00296 const DataFactory<T>& factory = DefaultDataFactory<T>());
00297
00298
00299 virtual void define(const BoxLayout& boxes);
00300
00301 virtual bool threadSafe() const
00302 {
00303 return m_threadSafe;
00304 }
00305
00306 int nComp() const
00307 {
00308 return m_comps;
00309 }
00310
00311
00312 Interval interval() const
00313 {
00314 Interval outint(0, m_comps-1);
00315 return(outint);
00316 }
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 void generalCopyTo(const BoxLayout& a_destGrids,
00328 LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00329 const Interval& a_interval,
00330 const ProblemDomain& a_domain,
00331 const DataFactory<T>& factory = DefaultDataFactory<T>()) const ;
00332
00333
00334 void generalCopyTo(const BoxLayout& a_destGrids,
00335 LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00336 const Interval& a_interval,
00337 const ProblemDomain& a_domain,
00338 const Copier& a_copier,
00339 const DataFactory<T>& factory = DefaultDataFactory<T>()) const ;
00340
00341
00342
00343
00344
00345
00346 void addTo(const Interval& a_srcComps,
00347 BoxLayoutData<T>& a_dest,
00348 const Interval& a_destComps,
00349 const ProblemDomain& a_domain) const;
00350
00351
00352
00353
00354
00355
00356 void addTo(const Interval& a_srcComps,
00357 BoxLayoutData<T>& a_dest,
00358 const Interval& a_destComps,
00359 const ProblemDomain& a_domain,
00360 const Copier& a_copier) const;
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377 virtual void apply(void (*a_Function)(const Box& box, int comps, T& t));
00378
00379
00380 virtual bool isDefined() const;
00381
00382 virtual void clear() ;
00383
00384 static int s_verbosity;
00385
00386 protected:
00387 int m_comps;
00388 bool m_threadSafe;
00389 bool m_isdefined;
00390
00391 friend class LevelData<T>;
00392
00393 void setVector(const BoxLayoutData<T>& da,
00394 const Interval& srcComps,
00395 const Interval& destComps);
00396
00397 void allocateGhostVector(const DataFactory<T>& factory,
00398 const IntVect& ghost = IntVect::Zero);
00399
00400 void makeItSo(const Interval& a_srcComps,
00401 const BoxLayoutData<T>& a_src,
00402 BoxLayoutData<T>& a_dest,
00403 const Interval& a_destComps,
00404 const Copier& a_copier,
00405 const LDOperator<T>& a_op = LDOperator<T>()) const;
00406 void makeItSoBegin(
00407 const Interval& a_srcComps,
00408 const BoxLayoutData<T>& a_src,
00409 BoxLayoutData<T>& a_dest,
00410 const Interval& a_destComps,
00411 const Copier& a_copier,
00412 const LDOperator<T>& a_op = LDOperator<T>()) const;
00413 void makeItSoLocalCopy(
00414 const Interval& a_srcComps,
00415 const BoxLayoutData<T>& a_src,
00416 BoxLayoutData<T>& a_dest,
00417 const Interval& a_destComps,
00418 const Copier& a_copier,
00419 const LDOperator<T>& a_op = LDOperator<T>()) const;
00420 void makeItSoEnd(
00421 BoxLayoutData<T>& a_dest,
00422 const Interval& a_destComps,
00423 const LDOperator<T>& a_op = LDOperator<T>()) const;
00424
00425
00426
00427
00428
00429
00430
00431 void completePendingSends() const;
00432
00433 void allocateBuffers(const BoxLayoutData<T>& a_src,
00434 const Interval& a_srcComps,
00435 const BoxLayoutData<T>& a_dest,
00436 const Interval& a_destComps,
00437 const Copier& a_copier,
00438 const LDOperator<T>& a_op) const;
00439
00440 void writeSendDataFromMeIntoBuffers(const BoxLayoutData<T>& a_src,
00441 const Interval& a_srcComps,
00442 const LDOperator<T>& a_op) const;
00443
00444 void postSendsFromMe() const ;
00445
00446 void postReceivesToMe() const ;
00447
00448 void unpackReceivesToMe(BoxLayoutData<T>& a_dest,
00449 const Interval& a_destComps,
00450 const LDOperator<T>& a_op) const ;
00451
00452 void unpackReceivesToMe_append(LayoutData<Vector<RefCountedPtr<T> > >& a_dest,
00453 const Interval& a_destComps,
00454 int ncomp,
00455 const DataFactory<T>& factory,
00456 const LDOperator<T>& a_op) const;
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 mutable CopierBuffer* m_buff;
00467 #ifdef CH_MPI
00468
00469 #ifndef DOXYGEN
00470
00471 #endif
00472
00473
00474
00475 mutable Vector<MPI_Request> m_sendRequests, m_receiveRequests;
00476 mutable Vector<MPI_Status> m_receiveStatus, m_sendStatus;
00477 mutable int numSends, numReceives;
00478 #endif
00479
00480 };
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502 Real norm(const BoxLayoutData<FArrayBox>& A,
00503 const Interval& interval,
00504 const int& p = 2);
00505
00506
00507 template < >
00508 BaseFab<int>* DefaultDataFactory<BaseFab<int> >::create(const Box& box,
00509 int ncomps,
00510 const DataIndex& a_datInd) const;
00511
00512 template < >
00513 FArrayBox* DefaultDataFactory<FArrayBox>::create(const Box& box,
00514 int ncomps,
00515 const DataIndex& a_datInd) const;
00516
00517 #include "NamespaceFooter.H"
00518 #include "BoxLayoutDataI.H"
00519
00520 #endif //BOXLAYOUTDATA