00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013 #ifndef _BASEEBCELLFABI_H_
00014 #define _BASEEBCELLFABI_H_
00015
00016 #include "BoxIterator.H"
00017 #include "CH_Timer.H"
00018 #include "NamespaceHeader.H"
00019
00020
00021 template <class T>
00022 void
00023 BaseEBCellFAB<T>::setCoveredCellVal(const T& a_val,
00024 const int& a_comp,
00025 const bool& a_doMulti)
00026 {
00027 CH_assert(a_comp >= 0);
00028 CH_assert(a_comp < m_nComp);
00029
00030 if(m_ebisBox.isAllRegular())
00031 {
00032 return;
00033 }
00034 else if(m_ebisBox.isAllCovered())
00035 {
00036 m_regFAB.setVal(a_val, a_comp);
00037 }
00038 else
00039 {
00040 for(BoxIterator bit(m_region); bit.ok(); ++bit)
00041 {
00042 const IntVect& iv = bit();
00043 if(m_ebisBox.isCovered(iv))
00044 {
00045 m_regFAB(iv, a_comp) = a_val;
00046 }
00047 }
00048 if(a_doMulti)
00049 {
00050
00051 for(IVSIterator ivsit(getMultiCells());ivsit.ok(); ++ivsit)
00052 {
00053 const IntVect& iv = ivsit();
00054 m_regFAB(iv, a_comp) = a_val;
00055 }
00056 }
00057 }
00058 }
00059
00060
00061 template <class T>
00062 BaseEBCellFAB<T>&
00063 BaseEBCellFAB<T>::copy(const BaseEBCellFAB<T>& a_src)
00064 {
00065 CH_TIMERS("BaseEBCellFAB::copy");
00066 CH_TIMER("sameregion_copy", t1);
00067 CH_TIMER("overlap_copy", t2);
00068 CH_assert(isDefined());
00069 CH_assert(a_src.isDefined());
00070
00071 CH_assert(m_nComp <= a_src.m_nComp);
00072 CH_assert(m_region.sameType(a_src.m_region));
00073
00074 Interval comps(0,m_nComp-1);
00075
00076 if(m_region == a_src.m_region)
00077 {
00078 CH_START(t1);
00079 m_regFAB.copy(a_src.m_regFAB);
00080
00081 if(m_hasMultiCells)
00082 {
00083 const T* src = a_src.m_irrFAB.dataPtr(0);
00084 T* dest = m_irrFAB.dataPtr(0);
00085 T* end = dest + m_irrFAB.numVoFs()*m_nComp;
00086 for(; dest<end ; src++, dest++)
00087 {
00088 *dest = *src;
00089 }
00090 }
00091 CH_STOP(t1);
00092 }
00093 else
00094 {
00095 CH_START(t2);
00096 Box overlap(m_region);
00097 overlap &= a_src.m_region;
00098
00099 this->copy(overlap,comps,overlap,a_src,comps);
00100 CH_STOP(t2);
00101 }
00102
00103 return *this;
00104 }
00105
00106
00107
00108 template <class T>
00109 void
00110 BaseEBCellFAB<T>::copy(const Box& a_RegionFrom,
00111 const Interval& a_dstInt,
00112 const Box& a_RegionTo,
00113 const BaseEBCellFAB<T>& a_src,
00114 const Interval& a_srcInt)
00115 {
00116 CH_TIMERS("BaseEBCellFAB::copy2");
00117 CH_TIMER("regular_copy", t1);
00118 CH_TIMER("irregular_copy", t2);
00119 CH_TIMER("box_intersections", t3);
00120
00121 CH_assert(isDefined());
00122 CH_assert(a_dstInt.size()==a_srcInt.size());
00123 CH_assert(a_dstInt.begin()>=0);
00124 CH_assert(a_srcInt.begin()>=0);
00125 CH_assert(a_srcInt.end()< a_src.m_nComp);
00126 CH_assert(a_dstInt.end()< m_nComp);
00127 ProblemDomain domain = m_ebisBox.getDomain();
00128 if(!domain.isPeriodic())
00129 {
00130 CH_assert(a_RegionFrom == a_RegionTo);
00131 }
00132
00133
00134
00135
00136
00137
00138 CH_START(t1);
00139 m_regFAB.copy(a_RegionFrom, a_dstInt, a_RegionTo, a_src.m_regFAB, a_srcInt);
00140 CH_STOP(t1);
00141
00142 if(m_hasMultiCells)
00143 {
00144 CH_START(t3);
00145 Box rboxFrom = a_RegionFrom & domain;
00146 Box rboxTo = a_RegionTo & domain;
00147 bool doSomething = (!rboxFrom.isEmpty() && !rboxTo.isEmpty());
00148 CH_STOP(t3);
00149 if(doSomething)
00150 {
00151
00152 CH_START(t2);
00153 m_irrFAB.copy(rboxFrom, a_dstInt,rboxTo, a_src.m_irrFAB, a_srcInt);
00154 CH_STOP(t2);
00155 }
00156 }
00157 }
00158
00159
00160
00161 template <class T>
00162 int
00163 BaseEBCellFAB<T>::size(const Box& R, const Interval& comps) const
00164 {
00165 int retval = m_regFAB.size(R, comps);
00166 retval += m_irrFAB.size(R, comps);
00167 return retval;
00168 }
00169
00170
00171 template <class T>
00172 void
00173 BaseEBCellFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
00174 const
00175 {
00176 unsigned char* buffer = (unsigned char*)buf;
00177 m_regFAB.linearOut(buffer, R, comps);
00178 buffer+= m_regFAB.size(R, comps);
00179 m_irrFAB.linearOut(buffer, R, comps);
00180 }
00181
00182
00183 template <class T>
00184 void
00185 BaseEBCellFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
00186 {
00187 unsigned char* buffer = (unsigned char*)buf;
00188 m_regFAB.linearIn(buffer, R, comps);
00189 buffer+= m_regFAB.size(R, comps);
00190 m_irrFAB.linearIn(buffer, R, comps);
00191 }
00192
00193
00194
00195 template <class T>
00196 const IntVectSet&
00197 BaseEBCellFAB<T>::getMultiCells() const
00198 {
00199 CH_assert(isDefined());
00200 return m_irrFAB.getIVS();
00201 }
00202
00203
00204
00205 template <class T>
00206 BaseEBCellFAB<T>::BaseEBCellFAB()
00207 {
00208 setDefaultValues();
00209 }
00210
00211
00212
00213 template <class T>
00214 BaseEBCellFAB<T>::BaseEBCellFAB(const EBISBox& a_ebisBox,
00215 const Box& a_region, int a_nVar)
00216 {
00217 setDefaultValues();
00218 define(a_ebisBox, a_region, a_nVar);
00219 }
00220
00221
00222
00223 template <class T>
00224 void
00225 BaseEBCellFAB<T>::define(const EBISBox& a_ebisBox,
00226 const Box& a_region, int a_nVar)
00227 {
00228 clear();
00229 m_isDefined = true;
00230 CH_assert(a_region.cellCentered());
00231 CH_assert(a_nVar > 0);
00232 CH_assert(!a_region.isEmpty());
00233 m_region = a_region & a_ebisBox.getRegion();
00234 CH_assert(!m_region.isEmpty());
00235 m_nComp = a_nVar;
00236 m_ebisBox = a_ebisBox;
00237
00238
00239
00240 m_regFAB.resize(a_region, m_nComp);
00241
00242
00243 m_multiCells =
00244 m_ebisBox.getMultiCells(m_region);
00245
00246 m_hasMultiCells = !m_multiCells.isEmpty();
00247
00248
00249 m_irrFAB.define(m_multiCells, m_ebisBox.getEBGraph(), m_nComp);
00250 }
00251
00252
00253
00254 template <class T>
00255 BaseEBCellFAB<T>::
00256 ~BaseEBCellFAB()
00257 {
00258 clear();
00259 }
00260
00261
00262
00263 template <class T>
00264 void
00265 BaseEBCellFAB<T>::clear()
00266 {
00267 m_irrFAB.clear();
00268 m_regFAB.clear();
00269 m_multiCells.makeEmpty();
00270 m_nComp = 0;
00271 m_isDefined = false;
00272 }
00273
00274
00275 template <class T>
00276 void
00277 BaseEBCellFAB<T>::setVal(const T& value)
00278 {
00279 m_irrFAB.setVal(value);
00280 m_regFAB.setVal(value);
00281 }
00282
00283
00284 template <class T>
00285 void
00286 BaseEBCellFAB<T>::setVal(int ivar,const T& value)
00287 {
00288 m_irrFAB.setVal(ivar, value);
00289 m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
00290 }
00291
00292 template <class T>
00293 void
00294 BaseEBCellFAB<T>::setVal(const T& a_value,
00295 const Box& a_box,
00296 int a_nstart,
00297 int a_numcomp)
00298 {
00299 CH_assert(isDefined());
00300 if(!a_box.isEmpty())
00301 {
00302 m_irrFAB.setVal(a_value,a_box,a_nstart,a_numcomp);
00303 m_regFAB.setVal(a_value,a_box,a_nstart,a_numcomp);
00304 }
00305 }
00306
00307
00308
00309 template <class T>
00310 bool
00311 BaseEBCellFAB<T>::isDefined() const
00312 {
00313 return (m_isDefined);
00314 }
00315
00316
00317 template <class T>
00318 int
00319 BaseEBCellFAB<T>::nComp() const
00320 {
00321 CH_assert(isDefined());
00322 return m_nComp;
00323 }
00324
00325
00326 template <class T>
00327 const Box&
00328 BaseEBCellFAB<T>::getRegion() const
00329 {
00330 CH_assert(isDefined());
00331 return m_region;
00332 }
00333
00334
00335 template <class T>
00336 const Box&
00337 BaseEBCellFAB<T>::box() const
00338 {
00339 return getRegion();
00340 }
00341
00342
00343
00344 template <class T>
00345 const BaseIVFAB<T>&
00346 BaseEBCellFAB<T>::getMultiValuedFAB() const
00347 {
00348 CH_assert(isDefined());
00349 return m_irrFAB;
00350 }
00351
00352
00353
00354
00355 template <class T>
00356 BaseIVFAB<T>&
00357 BaseEBCellFAB<T>::getMultiValuedFAB()
00358 {
00359 CH_assert(isDefined());
00360 return m_irrFAB;
00361 }
00362
00363
00364
00365 template <class T>
00366 const BaseFab<T>&
00367 BaseEBCellFAB<T>::getSingleValuedFAB() const
00368 {
00369 CH_assert(isDefined());
00370 return m_regFAB;
00371 }
00372
00373
00374
00375
00376 template <class T>
00377 BaseFab<T>&
00378 BaseEBCellFAB<T>::getSingleValuedFAB()
00379 {
00380 CH_assert(isDefined());
00381 return m_regFAB;
00382 }
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 template <class T>
00393 const T&
00394 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc,
00395 int a_isKnownMultiValued ) const
00396 {
00397 CH_assert(isDefined());
00398 CH_assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00399
00400 CH_assert((a_nVarLoc >= 0)&&(a_nVarLoc < m_nComp));
00401 CH_assert( (a_isKnownMultiValued == -1)
00402 || (a_isKnownMultiValued == 0)
00403 || (a_isKnownMultiValued == +1) );
00404
00405 const T* returnval = NULL;
00406
00407 switch( a_isKnownMultiValued )
00408 {
00409 case -1:
00410 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00411 break;
00412 case +1:
00413 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00414 break;
00415 case 0:
00416 {
00417 if( m_multiCells.contains(a_ndin.gridIndex()) )
00418 {
00419 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00420 } else
00421 {
00422 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00423 }
00424 }
00425 }
00426
00427 return *returnval;
00428
00429 }
00430
00431
00432
00433
00434 template <class T>
00435 T&
00436 BaseEBCellFAB<T>::operator()(const VolIndex& a_ndin,int a_nVarLoc,
00437 int a_isKnownMultiValued )
00438 {
00439 CH_assert(isDefined());
00440 CH_assert(m_region.contains(a_ndin.gridIndex()));
00441 CH_assert((a_nVarLoc >= 0)&&(a_nVarLoc < m_nComp));
00442 CH_assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00443 CH_assert( (a_isKnownMultiValued == -1)
00444 || (a_isKnownMultiValued == 0)
00445 || (a_isKnownMultiValued == +1) );
00446
00447 T* returnval = NULL;
00448
00449 if( (a_isKnownMultiValued == -1) || m_multiCells.isEmpty())
00450 {
00451 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00452 }
00453 else if (a_isKnownMultiValued == 1)
00454 {
00455 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00456 }
00457 else if (a_isKnownMultiValued == 0)
00458 {
00459 if( m_multiCells.contains(a_ndin.gridIndex()) )
00460 {
00461 returnval = &(m_irrFAB(a_ndin,a_nVarLoc));
00462 }
00463 else
00464 {
00465 returnval = &(m_regFAB(a_ndin.gridIndex(), a_nVarLoc));
00466 }
00467 }
00468 else
00469 {
00470 MayDay::Error("bogus a_isKnownMultiValued input");
00471 }
00472
00473 return *returnval;
00474 }
00475
00476
00477 template <class T>
00478 void
00479 BaseEBCellFAB<T>::fill(T* array, const VolIndex& a_ndin, const Interval& a_comps) const
00480 {
00481 CH_assert(isDefined());
00482 CH_assert(m_region.contains(a_ndin.gridIndex()));
00483 CH_assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00484
00485 if(m_multiCells.contains(a_ndin.gridIndex()))
00486 {
00487 const T* val = &(m_irrFAB(a_ndin,a_comps.begin()));
00488 for(int i=0; i<a_comps.size(); i++)
00489 {
00490 array[i] = val[i];
00491 }
00492
00493 }
00494 else
00495 {
00496 const T* val = &(m_regFAB(a_ndin.gridIndex(), a_comps.begin()));
00497 int numPts = m_regFAB.box().numPts();
00498 for(int i=0; i<a_comps.size(); i++){
00499 array[i] = val[i*numPts];
00500 }
00501
00502 }
00503
00504 }
00505
00506 template <class T>
00507 void
00508 BaseEBCellFAB<T>::assign(const T* array,
00509 const VolIndex& a_ndin,
00510 const Interval& a_comps)
00511 {
00512 CH_assert(isDefined());
00513 CH_assert(m_region.contains(a_ndin.gridIndex()));
00514 CH_assert(!m_ebisBox.isCovered(a_ndin.gridIndex()));
00515
00516 if(m_multiCells.contains(a_ndin.gridIndex()))
00517 {
00518 T* val = &(m_irrFAB(a_ndin,a_comps.begin()));
00519 for(int i=0; i<a_comps.size(); i++)
00520 {
00521 val[i] = array[i];
00522 }
00523
00524 }
00525 else
00526 {
00527 T* val = &(m_regFAB(a_ndin.gridIndex(), a_comps.begin()));
00528 int numPts = m_regFAB.box().numPts();
00529 for(int i=0; i<a_comps.size(); i++){
00530 val[i*numPts] = array[i];
00531 }
00532
00533 }
00534
00535 }
00536
00537
00538
00539 template <class T>
00540 void
00541 BaseEBCellFAB<T>:: setDefaultValues()
00542 {
00543 m_isDefined = false;
00544 m_nComp = 0;
00545 }
00546
00547
00548 template <class T>
00549 const EBISBox&
00550 BaseEBCellFAB<T>::getEBISBox() const
00551 {
00552 return m_ebisBox;
00553 }
00554
00555 #include "NamespaceFooter.H"
00556 #endif