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 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 m_ghost = ghost;
00127
00128 #ifdef 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 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 assert(comps.size()>0);
00165
00166
00167 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 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(const Interval& srcComps,
00215 LevelData<T>& dest,
00216 const Interval& destComps) const
00217 {
00218 if(this == &dest){
00219 MayDay::Error("src == dest in copyTo function. Perhaps you want exchange ?");
00220 }
00221
00222 if(this->boxLayout() == dest.boxLayout() && dest.ghostVect() == IntVect::Zero)
00223 {
00224
00225 for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00226 {
00227 dest[it()].copy(this->box(it()),
00228 destComps,
00229 this->box(it()),
00230 this->operator[](it()),
00231 srcComps);
00232 }
00233 return;
00234 }
00235
00236 Copier copier(m_disjointBoxLayout, dest.getBoxes(), dest.m_ghost);
00237 copyTo(srcComps, dest, destComps, copier);
00238 }
00239
00240 template<class T>
00241 void LevelData<T>::copyTo(const Interval& srcComps,
00242 BoxLayoutData<T>& dest,
00243 const Interval& destComps,
00244 const Copier& copier) const
00245 {
00246
00247 makeItSo(srcComps, *this, dest, destComps, copier);
00248
00249 }
00250
00251 template<class T>
00252 void LevelData<T>::copyTo(const Interval& srcComps,
00253 LevelData<T>& dest,
00254 const Interval& destComps,
00255 const Copier& copier,
00256 const LDOperator<T>& a_op) const
00257 {
00258
00259 makeItSo(srcComps, *this, dest, destComps, copier, a_op);
00260
00261 }
00262
00263 template<class T>
00264 void LevelData<T>::exchange(const Interval& comps)
00265 {
00266
00267
00268
00269 Copier copier(m_disjointBoxLayout, m_disjointBoxLayout, m_ghost, true);
00270 exchange(comps, copier);
00271
00272
00273
00274
00275
00276
00277 }
00278
00279 template<class T>
00280 void LevelData<T>::exchange(const Interval& comps,
00281 const Copier& copier)
00282 {
00283 makeItSo(comps, *this, *this, comps, copier);
00284
00285 }
00286
00287 template<class T>
00288 void LevelData<T>::define(const BoxLayout& dp, int comps, const DataFactory<T>& a_factory)
00289 {
00290 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00291 }
00292
00293 template<class T>
00294 void LevelData<T>::define(const BoxLayout& dp)
00295 {
00296 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00297 }
00298
00299 template<class T>
00300 void LevelData<T>::define(const BoxLayoutData<T>& da, const DataFactory<T>& a_factory )
00301 {
00302 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00303 }
00304
00305 template<class T>
00306 void LevelData<T>::define(const BoxLayoutData<T>& da, const Interval& comps,
00307 const DataFactory<T>& a_factory)
00308 {
00309 MayDay::Error("LevelData<T>::define called with BoxLayout input");
00310 }
00311
00312 template<class T>
00313 void LevelData<T>::apply(void (*a_func)(const Box& box, int comps, T& t))
00314 {
00315 for(DataIterator it(this->dataIterator()); it.ok(); ++it)
00316 {
00317 unsigned int index = this->m_boxLayout.index(it());
00318 a_func(m_disjointBoxLayout.get(it()), this->m_comps, *(this->m_vector[index]));
00319 }
00320 }
00321
00322 #endif