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