00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011
00012
00013 #ifndef _BASEEBFACEFABI_H_
00014 #define _BASEEBFACEFABI_H_
00015
00016 #include "BoxIterator.H"
00017 #include "NamespaceHeader.H"
00018
00019
00020
00021 template <class T>
00022 void
00023 BaseEBFaceFAB<T>::setCoveredFaceVal(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& ivCell = bit();
00043 for(SideIterator sit; sit.ok(); ++sit)
00044 {
00045 const Vector< FaceIndex >& faces = m_ebisBox.getAllFaces(ivCell,m_iDir,sit());
00046 if( (faces.size()==0) || (faces.size()>1) )
00047 {
00048 const int& hilo = sign(sit());
00049 IntVect ivFace = ivCell;
00050 if(hilo == 1)
00051 {
00052 ivFace[m_iDir] += 1;
00053 }
00054 m_regFAB(ivFace,a_comp) = a_val;
00055 }
00056 }
00057 }
00058 }
00059 }
00060
00061
00062 template <class T>
00063 int
00064 BaseEBFaceFAB<T>::size(const Box& R, const Interval& comps) const
00065 {
00066
00067 Box RFace = surroundingNodes(R, m_iDir);
00068 int retval = m_regFAB.size(RFace, comps);
00069 retval += m_irrFAB.size(R, comps);
00070 return retval;
00071 }
00072
00073
00074 template <class T>
00075 void
00076 BaseEBFaceFAB<T>::linearOut(void* buf, const Box& R, const Interval& comps)
00077 const
00078 {
00079 Box RFace = surroundingNodes(R, m_iDir);
00080 unsigned char* buffer = (unsigned char*)buf;
00081 m_regFAB.linearOut(buffer, RFace, comps);
00082 buffer+= m_regFAB.size(RFace, comps);
00083 m_irrFAB.linearOut(buffer, R, comps);
00084 }
00085
00086 template <class T>
00087 void
00088 BaseEBFaceFAB<T>::linearIn(void* buf, const Box& R, const Interval& comps)
00089 {
00090 Box RFace = surroundingNodes(R, m_iDir);
00091 unsigned char* buffer = (unsigned char*)buf;
00092 m_regFAB.linearIn(buffer, RFace, comps);
00093 buffer+= m_regFAB.size(RFace, comps);
00094 m_irrFAB.linearIn(buffer, R, comps);
00095 }
00096
00097
00098 template <class T> inline
00099 const EBISBox&
00100 BaseEBFaceFAB<T>::getEBISBox() const
00101 {
00102 return m_ebisBox;
00103 }
00104
00105 template <class T>
00106 BaseEBFaceFAB<T>&
00107 BaseEBFaceFAB<T>::copy(const BaseEBFaceFAB<T>& a_src)
00108 {
00109 CH_assert(isDefined());
00110 CH_assert(a_src.isDefined());
00111
00112
00113
00114 if (!(m_ebisBox == a_src.m_ebisBox))
00115 {
00116
00117 CH_assert(m_region == a_src.m_region);
00118
00119 CH_assert(m_irrFAB.numFaces() == a_src.m_irrFAB.numFaces());
00120 }
00121
00122 CH_assert(m_nComp <= a_src.m_nComp);
00123 CH_assert(m_region.sameType(a_src.m_region));
00124
00125 Interval comps(0,m_nComp-1);
00126
00127 Box overlap(m_region);
00128 overlap &= a_src.m_region;
00129
00130 this->copy(overlap,comps,overlap,a_src,comps);
00131
00132 return *this;
00133 }
00134
00135
00136 template <class T>
00137 inline void
00138 BaseEBFaceFAB<T>::copy(const Box& a_regionFrom,
00139 const Interval& a_dstInt,
00140 const Box& a_regionTo,
00141 const BaseEBFaceFAB<T>& a_src,
00142 const Interval& a_srcInt)
00143 {
00144
00145 CH_assert(isDefined());
00146 CH_assert(a_dstInt.size()==a_srcInt.size());
00147 CH_assert(a_regionTo.cellCentered());
00148 CH_assert(a_src.m_iDir ==m_iDir);
00149 CH_assert(a_dstInt.begin()>=0);
00150 CH_assert(a_srcInt.begin()>=0);
00151 CH_assert(a_srcInt.end()< a_src.m_nComp);
00152 CH_assert(a_dstInt.end()< m_nComp);
00153 CH_assert(a_src.m_region.contains(a_regionFrom));
00154 CH_assert(m_region.contains(a_regionTo));
00155 Box RFromCell = a_regionFrom;
00156 Box RFromFace = surroundingNodes(RFromCell, m_iDir);
00157 Box RToCell = a_regionTo;
00158 Box RToFace = surroundingNodes(RToCell, m_iDir);
00159
00160 CH_assert(m_regionFace.contains(RToFace));
00161 CH_assert(a_src.m_regionFace.contains(RFromFace));
00162
00163
00164 m_regFAB.copy(RFromFace, a_dstInt, RToFace, a_src.m_regFAB, a_srcInt);
00165
00166
00167 m_irrFAB.copy(RFromCell, a_dstInt, RToCell, a_src.m_irrFAB, a_srcInt);
00168 }
00169
00170
00171 template <class T> inline
00172 BaseEBFaceFAB<T>::BaseEBFaceFAB()
00173 {
00174 setDefaultValues();
00175 }
00176
00177
00178
00179 template <class T> inline
00180 BaseEBFaceFAB<T>::BaseEBFaceFAB(const EBISBox& a_ebisBox,
00181 const Box& a_region,
00182 int a_iDir, int a_nComp)
00183 {
00184 setDefaultValues();
00185 define(a_ebisBox, a_region, a_iDir, a_nComp);
00186 }
00187
00188
00189
00190 template <class T> inline
00191 void
00192 BaseEBFaceFAB<T>::define(const EBISBox& a_ebisBox,
00193 const Box& a_region,
00194 int a_iDir, int a_nComp)
00195 {
00196 clear();
00197 m_isDefined = true;
00198 CH_assert(a_region.cellCentered());
00199 CH_assert(!a_region.isEmpty());
00200 CH_assert(a_nComp > 0);
00201 CH_assert((a_iDir >= 0) && (a_iDir < SpaceDim));
00202
00203 m_ebisBox = a_ebisBox;
00204 m_region = a_region;
00205 m_region &= a_ebisBox.getDomain().domainBox();
00206 CH_assert(!m_region.isEmpty());
00207
00208 CH_assert(a_ebisBox.getRegion().contains(m_region));
00209
00210 m_nComp = a_nComp;
00211 m_iDir = a_iDir;
00212 m_regionFace= surroundingNodes(m_region, a_iDir);
00213 Box grownRegion = m_region;
00214 grownRegion.grow(a_iDir, 1);
00215 grownRegion &= a_ebisBox.getDomain().domainBox();
00216
00217 CH_assert(a_ebisBox.getRegion().contains(grownRegion));
00218
00219 m_regFAB.resize(m_regionFace, m_nComp);
00220
00221 IntVectSet multiCells = m_ebisBox.getMultiCells(grownRegion);
00222
00223 m_irrFAB.define(multiCells, m_ebisBox.getEBGraph(), m_iDir, m_nComp);
00224 }
00225
00226
00227
00228 template <class T> inline
00229 const IntVectSet&
00230 BaseEBFaceFAB<T>::getMultiCells() const
00231 {
00232 CH_assert(isDefined());
00233 return(m_irrFAB.getIVS());
00234 }
00235
00236
00237 template <class T> inline
00238 BaseEBFaceFAB<T>::~BaseEBFaceFAB()
00239 {
00240 clear();
00241 }
00242
00243
00244
00245 template <class T> inline
00246 void
00247 BaseEBFaceFAB<T>::clear()
00248 {
00249 m_irrFAB.clear();
00250 m_regFAB.clear();
00251 m_isDefined = false;
00252 }
00253
00254
00255
00256 template <class T> inline
00257 void
00258 BaseEBFaceFAB<T>::setVal(const T& value)
00259 {
00260 m_irrFAB.setVal(value);
00261 m_regFAB.setVal(value);
00262 }
00263
00264
00265 template <class T> inline
00266 void
00267 BaseEBFaceFAB<T>::setVal(int ivar, const T& value)
00268 {
00269 m_irrFAB.setVal(ivar, value);
00270 m_regFAB.setVal(value, m_regFAB.box(), ivar, 1);
00271 }
00272
00273
00274
00275 template <class T> inline
00276 bool
00277 BaseEBFaceFAB<T>::isDefined() const
00278 {
00279 return (m_isDefined);
00280 }
00281
00282
00283
00284 template <class T> inline
00285 int
00286 BaseEBFaceFAB<T>::nComp() const
00287 {
00288 CH_assert(isDefined());
00289 return m_nComp;
00290 }
00291
00292
00293
00294 template <class T> inline
00295 const BaseIFFAB<T>&
00296 BaseEBFaceFAB<T>::getMultiValuedFAB() const
00297 {
00298 CH_assert(isDefined());
00299 return m_irrFAB;
00300 }
00301
00302
00303
00304 template <class T> inline
00305 BaseIFFAB<T>&
00306 BaseEBFaceFAB<T>::getMultiValuedFAB()
00307 {
00308 CH_assert(isDefined());
00309 return m_irrFAB;
00310 }
00311
00312
00313
00314 template <class T> inline
00315 const BaseFab<T>&
00316 BaseEBFaceFAB<T>::getSingleValuedFAB() const
00317 {
00318 CH_assert(isDefined());
00319 return m_regFAB;
00320 }
00321
00322
00323
00324 template <class T> inline
00325 BaseFab<T>&
00326 BaseEBFaceFAB<T>::getSingleValuedFAB()
00327 {
00328 CH_assert(isDefined());
00329 return m_regFAB;
00330 }
00331
00332
00333
00334 template <class T> inline
00335 int
00336 BaseEBFaceFAB<T>::direction() const
00337 {
00338 CH_assert(isDefined());
00339 return m_iDir;
00340 }
00341
00342
00343
00344 template <class T> inline
00345 const Box&
00346 BaseEBFaceFAB<T>::getRegion() const
00347 {
00348 CH_assert(isDefined());
00349 return m_regionFace;
00350 }
00351
00352
00353 template <class T> inline
00354 const Box&
00355 BaseEBFaceFAB<T>::getCellRegion() const
00356 {
00357 CH_assert(isDefined());
00358 return m_region;
00359 }
00360
00361
00362
00363 template <class T> inline
00364 T&
00365 BaseEBFaceFAB<T>::operator()(const FaceIndex& a_facein, int a_nCompLoc)
00366 {
00367 CH_assert(isDefined());
00368 CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
00369 const IntVect& ivlo = a_facein.gridIndex(Side::Lo);
00370 const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
00371 CH_assert(m_regionFace.contains(ivhi));
00372
00373 const IntVectSet& multiVals = getMultiCells();
00374 T* returnval;
00375 if(multiVals.contains(ivlo) || multiVals.contains(ivhi))
00376 {
00377 returnval = &m_irrFAB(a_facein, a_nCompLoc);
00378 }
00379 else
00380 {
00381 returnval = &m_regFAB(ivhi, a_nCompLoc);
00382 }
00383 return *returnval;
00384 }
00385
00386
00387
00388 template <class T> inline
00389 const T&
00390 BaseEBFaceFAB<T>::operator() (const FaceIndex& a_facein, int a_nCompLoc) const
00391 {
00392 CH_assert(isDefined());
00393 CH_assert((a_nCompLoc >= 0)&&(a_nCompLoc < m_nComp));
00394 const IntVect& ivlo = a_facein.gridIndex(Side::Lo);
00395 const IntVect& ivhi = a_facein.gridIndex(Side::Hi);
00396 CH_assert(m_regionFace.contains(ivhi));
00397
00398 const IntVectSet& multiVals = getMultiCells();
00399 const T* returnval;
00400 if(multiVals.contains(ivlo) || multiVals.contains(ivhi))
00401 {
00402 returnval = &m_irrFAB(a_facein, a_nCompLoc);
00403 }
00404 else
00405 {
00406 returnval = &m_regFAB(ivhi, a_nCompLoc);
00407 }
00408 return *returnval;
00409 }
00410
00411
00412
00413 template <class T> inline
00414 void
00415 BaseEBFaceFAB<T>::setDefaultValues()
00416 {
00417 m_isDefined = false;
00418 m_nComp = -1;
00419 m_iDir = -1;
00420 }
00421
00422 #include "NamespaceFooter.H"
00423 #endif