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 #ifndef _BaseEBCellFABI_H_
00030 #define _BaseEBCellFABI_H_
00031
00032 #include "BoxIterator.H"
00033
00034
00035 template <class T>
00036 void
00037 BaseEBCellFAB<T>::setCoveredCellVal(const T& a_val,
00038 const int& a_comp)
00039 {
00040 assert(a_comp >= 0);
00041 assert(a_comp < m_nComp);
00042
00043 if(m_ebisBox.isAllRegular())
00044 {
00045 return;
00046 }
00047 else if(m_ebisBox.isAllCovered())
00048 {
00049 m_regFAB.setVal(a_val, a_comp);
00050 }
00051 else
00052 {
00053 for(BoxIterator bit(m_region); bit.ok(); ++bit)
00054 {
00055 const IntVect& iv = bit();
00056 if(m_ebisBox.isCovered(iv))
00057 {
00058 m_regFAB(iv, a_comp) = a_val;
00059 }
00060 }
00061
00062 for(IVSIterator ivsit(getMultiCells());
00063 ivsit.ok(); ++ivsit)
00064 {
00065 const IntVect& iv = ivsit();
00066 m_regFAB(iv, a_comp) = a_val;
00067 }
00068
00069 }
00070 }
00071
00072
00073 template <class T>
00074 void
00075 BaseEBCellFAB<T>::copy(const Box& a_RegionFrom,
00076 const Interval& a_dstInt,
00077 const Box& a_RegionTo,
00078 const BaseEBCellFAB<T>& a_src,
00079 const Interval& a_srcInt)
00080 {
00081 assert(a_RegionFrom == a_RegionTo);
00082 assert(isDefined());
00083 assert(a_dstInt.size()==a_srcInt.size());
00084 assert(a_dstInt.begin()>=0);
00085 assert(a_srcInt.begin()>=0);
00086 assert(a_srcInt.end()< a_src.m_nComp);
00087 assert(a_dstInt.end()< m_nComp);
00088 Box domain = m_ebisBox.getDomain();
00089
00090 Box rboxFrom = a_RegionFrom & domain;
00091 Box rboxTo = a_RegionTo & domain;
00092
00093 if(!rboxFrom.isEmpty() && !rboxTo.isEmpty())
00094 {
00095 assert(a_src.m_region.contains(rboxFrom));
00096 assert(m_region.contains(rboxTo));
00097
00098 m_regFAB.copy(rboxFrom, a_dstInt,rboxTo, a_src.m_regFAB, a_srcInt);
00099 m_irrFAB.copy(rboxFrom, a_dstInt,rboxTo, a_src.m_irrFAB, a_srcInt);
00100 }
00101 }
00102
00103
00104
00105
00106
00107 template <class T>
00108 int
00109 BaseEBCellFAB<T>::size(const Box& R, const Interval& comps) const
00110 {
00111 int retval = regSize(R, comps);
00112 retval += m_irrFAB.size(R, comps);
00113 return retval;
00114 }
00115
00116
00117
00118 template <class T>
00119 int
00120 BaseEBCellFAB<T>::regSize(const Box& R, const Interval& comps) const
00121 {
00122 Box subbox = R & m_region;
00123 int retval= sizeof(Real)*subbox.numPts()*comps.size();
00124 return retval;
00125 }
00126
00127
00128
00129
00130 template <class T>
00131 void
00132 BaseEBCellFAB<T>::regLinearOut(void* buf, const Box& R, const Interval& comps)
00133 const
00134 {
00135 Box subbox = R & m_region;
00136 Real* dataOut = (Real*) buf;
00137 int idataOut = 0;
00138 int irealsize = regSize(R,comps)/sizeof(Real);
00139
00140 for(BoxIterator bit(subbox); bit.ok(); ++bit)
00141 {
00142 const IntVect& iv = bit();
00143 for(int ivar = comps.begin(); ivar <= comps.end(); ++ivar)
00144 {
00145 assert(idataOut < irealsize);
00146 dataOut[idataOut] = m_regFAB(iv, ivar);
00147 idataOut++;
00148 }
00149 }
00150 }
00151
00152
00153 template <class T>
00154 void
00155 BaseEBCellFAB<T>::regLinearIn(void* buf, const Box& R, const Interval& comps)
00156 {
00157 const Real* dataIn = (const Real*) buf;
00158 int idataIn = 0;
00159 int irealsize = regSize(R,comps)/sizeof(Real);
00160 Box subbox = R & m_region;
00161
00162 for(BoxIterator bit(subbox); bit.ok(); ++bit)
00163 {
00164 const IntVect& iv = bit();
00165 for(int ivar = comps.begin(); ivar <= comps.end(); ++ivar)
00166 {
00167 assert(idataIn < irealsize);
00168 Real inputVal = dataIn[idataIn] ;
00169 m_regFAB(iv, ivar) = inputVal;
00170 idataIn++;
00171 }
00172 }
00173 }
00174
00175
00176 template <class T>
00177 void
00178 BaseEBCellFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
00179 const
00180 {
00181 regLinearOut(buf, R, comps);
00182 unsigned char* buffer = (unsigned char*)buf;
00183 buffer+= regSize(R, comps);
00184 m_irrFAB.linearOut(buffer, R, comps);
00185 }
00186
00187
00188 template <class T>
00189 void
00190 BaseEBCellFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
00191 {
00192 regLinearIn(buf, R, comps);
00193 unsigned char* buffer = (unsigned char*)buf;
00194 buffer+= regSize(R, comps);
00195 m_irrFAB.linearIn(buffer, R, comps);
00196 }
00197
00198
00199
00200
00201 template <class T>
00202 const IntVectSet&
00203 BaseEBCellFAB<T>::getMultiCells() const
00204 {
00205 assert(isDefined());
00206 return m_irrFAB.getIVS();
00207 }
00208
00209
00210
00211 template <class T>
00212 BaseEBCellFAB<T>::BaseEBCellFAB()
00213 {
00214 setDefaultValues();
00215 }
00216
00217
00218
00219 template <class T>
00220 BaseEBCellFAB<T>::BaseEBCellFAB(const EBISBox& a_ebisBox,
00221 const Box& a_region, int a_nVar)
00222 {
00223 setDefaultValues();
00224 define(a_ebisBox, a_region, a_nVar);
00225 }
00226
00227
00228
00229 template <class T>
00230 void
00231 BaseEBCellFAB<T>::define(const EBISBox& a_ebisBox,
00232 const Box& a_region, int a_nVar)
00233 {
00234 clear();
00235 m_isDefined = true;
00236 assert(a_region.cellCentered());
00237 assert(a_nVar > 0);
00238 assert(!a_region.isEmpty());
00239 m_region = a_region & a_ebisBox.getRegion();
00240 assert(!m_region.isEmpty());
00241 m_nComp = a_nVar;
00242 m_ebisBox = a_ebisBox;
00243
00244 m_regFAB.resize(m_region, m_nComp);
00245 m_isMultiValued.resize(m_region, 1);
00246 m_isMultiValued.setVal(false);
00247
00248
00249 IntVectSet multiCells =
00250 m_ebisBox.getMultiCells(m_region);
00251
00252 for(IVSIterator ivsit(multiCells); ivsit.ok(); ++ivsit)
00253 m_isMultiValued(ivsit(), 0) = true;
00254
00255
00256 m_irrFAB.define(multiCells, m_ebisBox.getEBGraph(), m_nComp);
00257 }
00258
00259
00260
00261 template <class T>
00262
00263 BaseEBCellFAB<T>::~BaseEBCellFAB()
00264 {
00265 clear();
00266 }
00267
00268
00269
00270 template <class T>
00271 void
00272 BaseEBCellFAB<T>::clear()
00273 {
00274 m_irrFAB.clear();
00275 m_regFAB.clear();
00276 m_isMultiValued.clear();
00277 m_nComp = 0;
00278 m_isDefined = false;
00279 }
00280
00281
00282 template <class T>
00283 void
00284 BaseEBCellFAB<T>::setVal(T value)
00285 {
00286 m_irrFAB.setVal(value);
00287 m_regFAB.setVal(value);
00288 }
00289
00290
00291
00292 template <class T>
00293 bool
00294 BaseEBCellFAB<T>::isDefined() const
00295 {
00296 return (m_isDefined);
00297 }
00298
00299
00300 template <class T>
00301 int
00302 BaseEBCellFAB<T>::nComp() const
00303 {
00304 assert(isDefined());
00305 return m_nComp;
00306 }
00307
00308
00309 template <class T>
00310 const Box&
00311 BaseEBCellFAB<T>::getRegion() const
00312 {
00313 assert(isDefined());
00314 return m_region;
00315 }
00316
00317
00318 template <class T>
00319 const Box&
00320 BaseEBCellFAB<T>::box() const
00321 {
00322 return getRegion();
00323 }
00324
00325
00326
00327
00328 template <class T>
00329 const BaseIVFAB<T>&
00330 BaseEBCellFAB<T>::getMultiValuedFAB() const
00331 {
00332 assert(isDefined());
00333 return m_irrFAB;
00334 }
00335
00336
00337
00338
00339 template <class T>
00340 BaseIVFAB<T>&
00341 BaseEBCellFAB<T>::getMultiValuedFAB()
00342 {
00343 assert(isDefined());
00344 return m_irrFAB;
00345 }
00346
00347
00348
00349 template <class T>
00350 const BaseFab<T>&
00351 BaseEBCellFAB<T>::getSingleValuedFAB() const
00352 {
00353 assert(isDefined());
00354 return m_regFAB;
00355 }
00356
00357
00358
00359
00360 template <class T>
00361 BaseFab<T>&
00362 BaseEBCellFAB<T>::getSingleValuedFAB()
00363 {
00364 assert(isDefined());
00365 return m_regFAB;
00366 }
00367
00368
00369 template <class T>
00370 const T&
00371 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc) const
00372 {
00373 assert(isDefined());
00374 assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00375 assert(m_region.contains(a_ndin.gridIndex()));
00376 assert((a_nVarLoc >= 0)&&(a_nVarLoc < m_nComp));
00377
00378 const T* returnval = NULL;
00379 if(m_isMultiValued(a_ndin.gridIndex()))
00380 {
00381 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00382 }
00383 else
00384 {
00385 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00386 }
00387 return *returnval;
00388 }
00389
00390
00391 template <class T>
00392 T&
00393 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc)
00394 {
00395 assert(isDefined());
00396 assert(m_region.contains(a_ndin.gridIndex()));
00397 assert((a_nVarLoc >= 0)&&(a_nVarLoc < m_nComp));
00398 assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00399
00400 T* returnval = NULL;
00401 if(m_isMultiValued(a_ndin.gridIndex()))
00402 {
00403 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00404 }
00405 else
00406 {
00407 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00408 }
00409 return *returnval;
00410 }
00411
00412
00413 template <class T>
00414 void
00415 BaseEBCellFAB<T>:: setDefaultValues()
00416 {
00417 m_isDefined = false;
00418 m_nComp = 0;
00419 }
00420
00421
00422 template <class T>
00423 const EBISBox&
00424 BaseEBCellFAB<T>::getEBISBox() const
00425 {
00426 return m_ebisBox;
00427 }
00428
00429 #endif
00430