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 #ifndef CH_BINFABIMPLEM_H
00029 #define CH_BINFABIMPLEM_H
00030
00031 #include "BoxIterator.H"
00032 #include "List.H"
00033
00034
00035
00036
00037
00038
00039 template <class T>
00040 BinFab<T>::BinFab()
00041 : BaseFab<List<T> >(),
00042 m_origin(D_DECL(1.0e8, 1.0e8, 1.0e8)),
00043 m_mesh_spacing(D_DECL(0,0,0))
00044 {
00045 }
00046
00047 template <class T>
00048 BinFab<T>::BinFab(const Box& a_domain, const RealVect& a_mesh_spacing,
00049 const RealVect& a_origin,
00050 const ProblemDomain& a_probdomain)
00051 {
00052 define(a_domain, a_mesh_spacing, a_origin, a_probdomain);
00053 }
00054
00055 template <class T>
00056 BinFab<T>::BinFab(const BinFab& a_binfab)
00057 {
00058 define(a_binfab.domain, a_binfab.m_mesh_spacing, a_binfab.m_origin,
00059 a_binfab.m_probdomain);
00060 copy(a_binfab);
00061 }
00062
00063
00064 template <class T>
00065 BinFab<T>::~BinFab()
00066 {
00067 undefine();
00068 }
00069
00070 template <class T>
00071 void
00072 BinFab<T>::define(const Box& a_domain, const RealVect& a_mesh_spacing,
00073 const RealVect& a_origin, const ProblemDomain& a_probdomain)
00074 {
00075 domain = a_domain;
00076 nvar = 1;
00077 numpts = domain.numPts();
00078
00079 BaseFab<List<T> >::define();
00080
00081 m_mesh_spacing = a_mesh_spacing;
00082 m_origin = a_origin;
00083
00084 assert (!a_probdomain.isPeriodic());
00085 m_probdomain = a_probdomain;
00086 }
00087
00088
00089 template <class T>
00090 void
00091 BinFab<T>::reBin()
00092 {
00093
00094
00095 BoxIterator bit(domain);
00096 int comp = 0;
00097
00098 for (bit.begin(); bit.ok(); ++bit)
00099 {
00100 const IntVect thisIV = bit();
00101 List<T>& thisList = operator()(thisIV,comp);
00102
00103 if (thisList.length() > 0)
00104 {
00105
00106
00107 ListIterator<T> thisLit(thisList);
00108
00109 IntVect binLoc;
00110
00111
00112 for (thisLit.rewind(); thisLit; ++thisLit)
00113 {
00114 T& thisItem = thisList[thisLit];
00115
00116 #if 0
00117
00118 thisPos = thisItem.position();
00119 thisPos -= m_origin;
00120 thisPos /= m_mesh_spacing;
00121 D_TERM( binLoc[0] = (int) thisPos[0]; ,
00122 binLoc[1] = (int) thisPos[1]; ,
00123 binLoc[2] = (int) thisPos[2]; );
00124 #endif
00125
00126 binLoc = locateBin(thisItem);
00127
00128 if (binLoc != thisIV)
00129 {
00130
00131
00132
00133 if (domain.contains(binLoc))
00134 operator()(binLoc,comp).append(thisItem);
00135
00136 thisList.remove(thisLit);
00137 }
00138
00139
00140 }
00141 }
00142
00143 }
00144 }
00145
00146 template <class T>
00147 void
00148 BinFab<T>::addItem(const T& a_item)
00149 {
00150 int comp = 0 ;
00151 IntVect binLoc = locateBin(a_item) ;
00152 if (domain.contains(binLoc))
00153 operator()(binLoc,comp).append(a_item) ;
00154 }
00155
00156 template <class T>
00157 void
00158 BinFab<T>::addItems(const List<T>& a_List)
00159 {
00160
00161 ListIterator<T> lit(a_List);
00162
00163 int comp = 0;
00164 IntVect binLoc;
00165
00166
00167 if (a_List.length() > 0)
00168 {
00169 for (lit.rewind(); lit; ++lit)
00170 {
00171
00172
00173 const T& thisItem = a_List[lit];
00174 #if 0
00175
00176 thisPos = thisItem.position();
00177 thisPos -= m_origin;
00178 thisPos /= m_mesh_spacing;
00179
00180 D_TERM( binLoc[0] = (int) thisPos[0]; ,
00181 binLoc[1] = (int) thisPos[1]; ,
00182 binLoc[2] = (int) thisPos[2]; );
00183 #endif
00184 binLoc = locateBin(thisItem);
00185
00186 if (domain.contains(binLoc))
00187 operator()(binLoc,comp).append(thisItem);
00188 }
00189 }
00190 }
00191
00192 template <class T>
00193 void
00194 BinFab<T>::addItemsDestructive(List<T>& a_List)
00195 {
00196
00197
00198 ListIterator<T> lit(a_List);
00199 int comp = 0;
00200 IntVect binLoc;
00201
00202 if (a_List.length() > 0)
00203 {
00204 for (lit.rewind(); lit; ++lit)
00205 {
00206 const T& thisItem = a_List[lit];
00207 binLoc = locateBin(thisItem);
00208 if (domain.contains(binLoc))
00209 {
00210 operator()(binLoc,comp).append(thisItem);
00211 a_List.remove(lit);
00212 }
00213 }
00214 }
00215 }
00216
00217 template <class T>
00218 void
00219 BinFab<T>::clear()
00220 {
00221 undefine();
00222
00223 domain = Box();
00224 nvar = 0;
00225 numpts = 0;
00226 m_origin = RealVect(D_DECL(1.0e8, 1.0e8, 1.0e8));
00227 m_mesh_spacing = RealVect(D_DECL(1.0e8, 1.0e8, 1.0e8));
00228
00229 }
00230
00231 template <class T>
00232 int
00233 BinFab<T>::size(const Box& box, const Interval& comps) const
00234 {
00235 int totalSize=0;
00236 BoxIterator bit(box);
00237
00238
00239 bit.begin();
00240 const List<T>& thisList = operator()(bit(), comps.begin());
00241 int sizeOfT = thisList.firstElement().size();
00242
00243 for (int comp=comps.begin(); comp<= comps.end(); comp++)
00244 {
00245 for (bit.begin(); bit.ok(); ++bit)
00246 {
00247 const List<T>& thisList = operator()(bit(), comp);
00248 totalSize += thisList.length();
00249 }
00250 }
00251
00252
00253 totalSize *= sizeOfT;
00254
00255
00256
00257
00258
00259
00260 int numBins = box.numPts();
00261 totalSize += numBins*sizeof(int);
00262
00263 return totalSize;
00264
00265 }
00266
00267 template <class T>
00268 void
00269 BinFab<T>::linearOut(void* buf, const Box& R, const Interval& comps) const
00270 {
00271
00272
00273 BoxIterator bit(R);
00274 for (int comp=comps.begin(); comp<= comps.end(); ++comp)
00275 {
00276 for (bit.begin(); bit.ok(); ++bit)
00277 {
00278 const List<T>& thisList = operator()(bit(), comp);
00279 int* intBuffer = (int*)buf;
00280 *intBuffer = thisList.length();
00281
00282
00283 ListIterator<T> lit(thisList);
00284 for (lit.rewind(); lit; ++lit)
00285 {
00286 thisList[lit].linearOut(buf);
00287 }
00288 }
00289 }
00290 }
00291
00292 template <class T>
00293 void
00294 BinFab<T>::linearIn(void* buf, const Box& R, const Interval& comps)
00295 {
00296
00297 BoxIterator bit(R);
00298 for (int comp= comps.begin(); comp<= comps.end(); ++comp)
00299 {
00300 for (bit.begin(); bit.ok(); ++bit)
00301 {
00302 List<T>& thisList = operator()(bit(), comp);
00303 int* intBuffer = (int*)buf;
00304 int numItems = *intBuffer;
00305 for (int n=0; n<numItems; ++n)
00306 {
00307 T thisBinItem;
00308 thisBinItem.linearIn(buf);
00309 thisList.append(thisBinItem);
00310 }
00311 }
00312 }
00313
00314 }
00315
00316 template <class T>
00317 IntVect
00318 BinFab<T>::locateBin(const T& a_binItem) const
00319 {
00320 IntVect binLoc;
00321 RealVect thisPos = a_binItem.position();
00322 thisPos -= m_origin;
00323 thisPos /= m_mesh_spacing;
00324
00325 D_TERM( binLoc[0] = (int) thisPos[0]; ,
00326 binLoc[1] = (int) thisPos[1]; ,
00327 binLoc[2] = (int) thisPos[2]; );
00328
00329 return binLoc;
00330 }
00331
00332
00333
00334 #endif