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