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