00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _LEVELDATAI_H_
00012 #define _LEVELDATAI_H_
00013
00014 #include <cstdlib>
00015 #include <algorithm>
00016 using std::sort;
00017
00018 #include "parstream.H"
00019 #include "CH_Timer.H"
00020 #include <float.h>
00021 #include "NamespaceHeader.H"
00022
00023
00024 template<class T>
00025 LevelData<T>::LevelData()
00026 {
00027 }
00028
00029
00030
00031 template<class T>
00032 LevelData<T>::~LevelData()
00033 {
00034 CH_TIME("~LevelData");
00035 }
00036
00037
00038
00039 template<class T>
00040 LevelData<T>::LevelData(const DisjointBoxLayout& dp, int comps, const IntVect& ghost,
00041 const DataFactory<T>& a_factory)
00042 : m_disjointBoxLayout(dp), m_ghost(ghost)
00043 {
00044 #ifdef CH_MPI
00045 this->numSends = 0;
00046 this->numReceives = 0;
00047 #endif
00048 this->m_boxLayout = dp;
00049 this->m_comps = comps;
00050 this->m_isdefined = true;
00051
00052 if (!dp.isClosed())
00053 {
00054 MayDay::Error("non-disjoint DisjointBoxLayout: LevelData<T>::LevelData(const DisjointBoxLayout& dp, int comps)");
00055 }
00056
00057 Interval interval(0, comps-1);
00058 this->allocateGhostVector(a_factory, ghost);
00059 this->setVector(*this, interval, interval);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069 template<class T>
00070 void LevelData<T>::define(const DisjointBoxLayout& dp, int comps, const IntVect& ghost,
00071 const DataFactory<T> & a_factory)
00072 {
00073 CH_TIME("LevelData<T>::define(dbl,comps,ghost,factory)");
00074
00075 if (this->m_isdefined)
00076 {
00077 m_exchangeCopier.clear();
00078 }
00079
00080 this->m_isdefined = true;
00081 if (!dp.isClosed())
00082 {
00083 MayDay::Error("non-disjoint DisjointBoxLayout: LevelData<T>::define(const DisjointBoxLayout& dp,....)");
00084 }
00085 if (comps<=0)
00086 {
00087 MayDay::Error("LevelData::LevelData(const BoxLayout& dp, int comps) comps<=0");
00088 }
00089 this->m_comps = comps;
00090 this->m_boxLayout = dp;
00091
00092 m_disjointBoxLayout = dp;
00093 m_ghost = ghost;
00094
00095
00096 this->allocateGhostVector(a_factory, ghost);
00097
00098 }
00099
00100
00101
00102 template<class T>
00103 void LevelData<T>::define(const LevelData<T>& da, const DataFactory<T> & a_factory)
00104 {
00105 CH_TIME("LevelData<T>::define(LevelData<T>,factory)");
00106
00107 if (this->m_isdefined)
00108 {
00109 m_exchangeCopier.clear();
00110 }
00111 this->m_isdefined = true;
00112 if (this == &da) return;
00113 m_disjointBoxLayout = da.m_disjointBoxLayout;
00114 this->m_boxLayout = da.m_disjointBoxLayout;
00115 this->m_comps = da.m_comps;
00116 m_ghost = da.m_ghost;
00117
00118 Interval srcAnddest(0, this->m_comps-1);
00119
00120 this->allocateGhostVector(a_factory, m_ghost);
00121 da.copyTo(*this);
00122 }
00123
00124
00125
00126 template<class T>
00127 void LevelData<T>::define(const LevelData<T>& da, const Interval& comps,
00128 const DataFactory<T>& a_factory)
00129 {
00130 CH_TIME("LevelData<T>::define(LevelData<T>,comps,factory)");
00131
00132 if (this->m_isdefined)
00133 {
00134 m_exchangeCopier.clear();
00135 }
00136 this->m_isdefined = true;
00137 if (this == &da)
00138 {
00139 MayDay::Error(" LevelData<T>::define(const LevelData<T>& da, const Interval& comps) called with 'this'");
00140 }
00141 CH_assert(comps.size()>0);
00142
00143
00144 CH_assert(comps.begin()>=0);
00145
00146 m_disjointBoxLayout = da.m_disjointBoxLayout;
00147 this->m_boxLayout = da.m_disjointBoxLayout;
00148
00149 this->m_comps = comps.size();
00150
00151 m_ghost = da.m_ghost;
00152
00153 Interval dest(0, this->m_comps-1);
00154
00155 this->allocateGhostVector(a_factory, m_ghost);
00156
00157 this->setVector(da, comps, dest);
00158
00159 }
00160
00161
00162
00163 template<class T>
00164 void LevelData<T>::copyTo(const Interval& srcComps,
00165 BoxLayoutData<T>& dest,
00166 const Interval& destComps) const
00167 {
00168 if ((BoxLayoutData<T>*)this == &dest) return;
00169
00170 if (this->boxLayout() == dest.boxLayout())
00171 {
00172
00173 for (DataIterator it(this->dataIterator()); it.ok(); ++it)
00174 {
00175 dest[it()].copy(this->box(it()),
00176 destComps,
00177 this->box(it()),
00178 this->operator[](it()),
00179 srcComps);
00180 }
00181 return;
00182 }
00183
00184 Copier copier(m_disjointBoxLayout, dest.boxLayout());
00185 copyTo(srcComps, dest, destComps, copier);
00186 }
00187
00188
00189
00190 template<class T>
00191 void LevelData<T>::copyTo(BoxLayoutData<T>& dest) const
00192 {
00193 CH_assert(this->nComp() == dest.nComp());
00194 this->copyTo(this->interval(), dest, dest.interval());
00195 }
00196
00197
00198
00199 template<class T>
00200 void LevelData<T>::copyTo(const Interval& srcComps,
00201 LevelData<T>& dest,
00202 const Interval& destComps) const
00203 {
00204 if (this == &dest)
00205 {
00206 MayDay::Error("src == dest in copyTo function. Perhaps you want exchange ?");
00207 }
00208
00209 if (this->boxLayout() == dest.boxLayout() && dest.ghostVect() == IntVect::Zero)
00210 {
00211
00212 for (DataIterator it(this->dataIterator()); it.ok(); ++it)
00213 {
00214 dest[it()].copy(this->box(it()),
00215 destComps,
00216 this->box(it()),
00217 this->operator[](it()),
00218 srcComps);
00219 }
00220 return;
00221 }
00222
00223 Copier copier(m_disjointBoxLayout, dest.getBoxes(), dest.m_ghost);
00224 copyTo(srcComps, dest, destComps, copier);
00225 }
00226
00227
00228
00229 template<class T>
00230 void LevelData<T>::copyTo(LevelData<T>& dest) const
00231 {
00232 CH_assert(this->nComp() == dest.nComp());
00233 this->copyTo(this->interval(), dest, dest.interval());
00234 }
00235
00236
00237
00238 template<class T>
00239 void LevelData<T>::copyTo(const Interval& srcComps,
00240 BoxLayoutData<T>& dest,
00241 const Interval& destComps,
00242 const Copier& copier,
00243 const LDOperator<T>& a_op) const
00244 {
00245 CH_TIME("copyTo");
00246 #ifdef CH_MPI
00247 {
00248
00249
00250 }
00251 #endif
00252
00253 this->makeItSo(srcComps, *this, dest, destComps, copier, a_op);
00254 }
00255
00256
00257
00258 template<class T>
00259 void LevelData<T>::copyTo(BoxLayoutData<T>& dest,
00260 const Copier& copier,
00261 const LDOperator<T>& a_op) const
00262 {
00263 CH_assert(this->nComp() == dest.nComp());
00264 this->copyTo(this->interval(), dest, dest.interval(), copier, a_op);
00265 }
00266
00267
00268
00269
00270 template<class T>
00271 void LevelData<T>::copyTo(const Interval& srcComps,
00272 LevelData<T>& dest,
00273 const Interval& destComps,
00274 const Copier& copier,
00275 const LDOperator<T>& a_op) const
00276 {
00277 CH_TIME("copyTo");
00278 #ifdef CH_MPI
00279 {
00280
00281
00282 }
00283 #endif
00284 this->makeItSo(srcComps, *this, dest, destComps, copier, a_op);
00285 }
00286
00287
00288
00289 template<class T>
00290 void LevelData<T>::copyTo(LevelData<T>& dest,
00291 const Copier& copier,
00292 const LDOperator<T>& a_op) const
00293 {
00294 CH_assert(this->nComp() == dest.nComp());
00295 this->copyTo(this->interval(), dest, dest.interval(), copier, a_op);
00296 }
00297
00298
00299
00300
00301 template<class T>
00302 void LevelData<T>::exchange(const Interval& comps)
00303 {
00304 CH_TIME("exchange+copier");
00305
00306
00307
00308 if (!m_exchangeCopier.isDefined())
00309 {
00310 m_exchangeCopier.define(m_disjointBoxLayout, m_disjointBoxLayout, m_ghost, true);
00311 }
00312 exchange(comps, m_exchangeCopier);
00313
00314
00315
00316
00317
00318
00319 }
00320
00321
00322
00323 template<class T>
00324 void LevelData<T>::exchange(void)
00325 {
00326 exchange(this->interval());
00327 }
00328
00329
00330
00331 template<class T>
00332 void LevelData<T>::exchange(const Interval& comps,
00333 const Copier& copier)
00334 {
00335 CH_TIME("exchange");
00336 #ifdef CH_MPI
00337 {
00338
00339
00340 }
00341 #endif
00342 this->makeItSo(comps, *this, *this, comps, copier);
00343 }
00344
00345
00346
00347 template<class T>
00348 void LevelData<T>::exchange(const Copier& copier)
00349 {
00350 exchange(this->interval(), copier);
00351 }
00352
00353
00354
00355 template<class T>
00356 void LevelData<T>::exchangeNoOverlap(const Copier& copier)
00357 {
00358 CH_TIME("exchangeNoOverlap");
00359 this->makeItSoBegin(this->interval(), *this, *this, this->interval(), copier);
00360 this->makeItSoEnd(*this, this->interval());
00361 this->makeItSoLocalCopy(this->interval(), *this, *this, this->interval(), copier);
00362 }
00363
00364
00365
00366
00367 template<class T>
00368 void LevelData<T>::exchangeBegin(const Copier& copier)
00369 {
00370 CH_TIME("exchangeBegin");
00371 this->makeItSoBegin(this->interval(), *this, *this, this->interval(), copier);
00372 this->makeItSoLocalCopy(this->interval(), *this, *this, this->interval(), copier);
00373 }
00374
00375
00376
00377 template<class T>
00378 void LevelData<T>::exchangeEnd()
00379 {
00380 CH_TIME("exchangeEnd");
00381 this->makeItSoEnd(*this, this->interval());
00382 }
00383
00384
00385
00386
00387 template<class T>
00388 void LevelData<T>::define(const BoxLayout& dp, int comps, const DataFactory<T>& a_factory)
00389 {
00390 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00391 }
00392
00393
00394
00395 template<class T>
00396 void LevelData<T>::define(const BoxLayout& dp)
00397 {
00398 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00399 }
00400
00401
00402
00403 template<class T>
00404 void LevelData<T>::define(const BoxLayoutData<T>& da, const DataFactory<T>& a_factory )
00405 {
00406 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00407 }
00408
00409
00410
00411 template<class T>
00412 void LevelData<T>::define(const BoxLayoutData<T>& da, const Interval& comps,
00413 const DataFactory<T>& a_factory)
00414 {
00415 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00416 }
00417
00418
00419
00420
00421 template<class T>
00422 void LevelData<T>::apply( void (*a_Function)(const Box& box, int comps, T& t) )
00423 {
00424 for (DataIterator it(this->dataIterator()); it.ok(); ++it)
00425 {
00426 a_Function(m_disjointBoxLayout.get(it()), this->m_comps, *(this->m_vector[it().datInd()]));
00427 }
00428 }
00429
00430
00431
00432 template<class T>
00433 void LevelData<T>::apply( const ApplyFunctor & f )
00434 {
00435 for (DataIterator it(this->dataIterator()); it.ok(); ++it)
00436 {
00437
00438 f(m_disjointBoxLayout.get(it()), this->m_comps, *(this->m_vector[it().datInd()]));
00439 }
00440 }
00441
00442
00443
00444 template<class T> void
00445 LevelData<T>::degenerate( LevelData<T>& a_to,
00446 const SliceSpec& a_sliceSpec ) const
00447 {
00448 DisjointBoxLayout toDBL;
00449 m_disjointBoxLayout.degenerate( toDBL, a_sliceSpec );
00450 IntVect toGhost;
00451 for ( int i=0;i<CH_SPACEDIM;++i )
00452 {
00453 if ( i != a_sliceSpec.direction )
00454 {
00455 toGhost[i] = m_ghost[i];
00456 } else
00457 {
00458 toGhost[i] = 0;
00459 }
00460 }
00461 a_to.define( toDBL, this->nComp(), toGhost );
00462 copyTo( a_to );
00463 }
00464
00465
00466 #include "NamespaceFooter.H"
00467 #endif