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