00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _BASEIVFABI_H_
00012 #define _BASEIVFABI_H_
00013 #include "MayDay.H"
00014 #include "IntVectSet.H"
00015 #include "VoFIterator.H"
00016 #include "parstream.H"
00017 #include "SPMD.H"
00018 #include "DebugOut.H"
00019 #include "EBDebugOut.H"
00020 #include "SPMD.H"
00021 #include "NamespaceHeader.H"
00022
00023 template <class T>
00024 bool BaseIVFAB<T>::s_verbose = false;
00025
00026 template <class T>
00027 void
00028 BaseIVFAB<T>::setVerbose(bool a_verbose)
00029 {
00030 s_verbose = a_verbose;
00031 }
00032 template <class T>
00033 bool BaseIVFAB<T>::s_verboseDebug = false;
00034
00035 template <class T>
00036 void
00037 BaseIVFAB<T>::setVerboseDebug(bool a_verboseDebug)
00038 {
00039 s_verboseDebug = a_verboseDebug;
00040 }
00041
00042 template <class T> inline
00043 const EBGraph&
00044 BaseIVFAB<T>::getEBGraph() const
00045 {
00046 return m_ebgraph;
00047 }
00048
00049 template <class T> inline
00050 const IntVectSet&
00051 BaseIVFAB<T>::getIVS() const
00052 {
00053 return m_ivs;
00054 }
00055
00056 template <class T> inline
00057 BaseIVFAB<T>::BaseIVFAB()
00058 {
00059 setDefaultValues();
00060 }
00061
00062 template <class T> inline
00063 BaseIVFAB<T>::~BaseIVFAB()
00064 {
00065 clear();
00066 }
00067
00068 template <class T> inline
00069 BaseIVFAB<T>::BaseIVFAB(const IntVectSet& a_ivsin,
00070 const EBGraph& a_ebgraph,
00071 const int& a_nvarin)
00072 {
00073 setDefaultValues();
00074 define(a_ivsin, a_ebgraph, a_nvarin);
00075 }
00076
00077 template <class T> inline
00078 void
00079 BaseIVFAB<T>::define(const IntVectSet& a_ivsin,
00080 const EBGraph& a_ebGraph,
00081 const int& a_nvarin)
00082 {
00083 clear();
00084 m_isDefined = true;
00085 CH_assert(a_nvarin > 0);
00086
00087 m_ivs = a_ivsin;
00088 m_nComp = a_nvarin;
00089 m_ebgraph = a_ebGraph;
00090 m_nVoFs = 0;
00091
00092 if (!a_ivsin.isEmpty())
00093 {
00094 Box minbox = a_ivsin.minBox();
00095 m_fab.resize(minbox, 1);
00096 m_fab.setVal(NULL);
00097
00098
00099 IVSIterator ivsit(m_ivs);
00100 for (ivsit.reset(); ivsit.ok(); ++ivsit)
00101 {
00102 m_nVoFs += m_ebgraph.numVoFs(ivsit());
00103 }
00104
00105
00106
00107 if (m_nVoFs > 0)
00108 {
00109
00110
00111 m_data.resize(m_nVoFs*m_nComp);
00112 T* currentLoc = &m_data[0];
00113 for (ivsit.reset(); ivsit.ok(); ++ivsit)
00114 {
00115 int numVoFs = m_ebgraph.numVoFs(ivsit());
00116 m_fab(ivsit(), 0) = currentLoc;
00117 currentLoc += numVoFs;
00118 }
00119 }
00120 }
00121 }
00122
00123 template <class T> inline
00124 void
00125 BaseIVFAB<T>::setVal(const T& a_value)
00126 {
00127 for (int ivec = 0; ivec < m_nVoFs*m_nComp; ivec++)
00128 {
00129 m_data[ivec] = a_value;
00130 }
00131 }
00132
00133
00134 template <class T> inline
00135 void
00136 BaseIVFAB<T>::setVal(int ivar, const T& a_value)
00137 {
00138 CH_assert(isDefined());
00139 CH_assert(ivar >= 0);
00140 CH_assert(ivar < m_nComp);
00141 int ioffset = ivar*m_nVoFs;
00142 for (int ivec = 0; ivec < m_nVoFs; ivec ++)
00143 {
00144 m_data[ivec+ioffset] = a_value;
00145 }
00146 }
00147
00148 template <class T> inline
00149 void
00150 BaseIVFAB<T>::setVal(const T& a_value,
00151 const Box& a_box,
00152 int a_nstart,
00153 int a_numcomp)
00154
00155 {
00156 CH_assert(isDefined());
00157
00158 if ( !m_ivs.isEmpty() )
00159 {
00160 IntVectSet ivsIntersect = m_ivs;
00161 ivsIntersect &= a_box;
00162 BaseIVFAB<T>& thisFAB = *this;
00163 for (VoFIterator vofit(ivsIntersect, m_ebgraph); vofit.ok(); ++vofit)
00164 {
00165 const VolIndex& vof = vofit();
00166 for (int icomp = a_nstart; icomp < a_numcomp; icomp++)
00167 {
00168 thisFAB(vof, icomp) = a_value;
00169 }
00170 }
00171 }
00172 }
00173
00174 template <class T> inline
00175 void
00176 BaseIVFAB<T>::copy(const Box& a_fromBox,
00177 const Interval& a_dstInterval,
00178 const Box& a_toBox,
00179 const BaseIVFAB<T>& a_src,
00180 const Interval& a_srcInterval)
00181 {
00182 CH_assert(isDefined());
00183 CH_assert(a_src.isDefined());
00184 CH_assert(a_srcInterval.size() == a_dstInterval.size());
00185 CH_assert(a_dstInterval.begin() >= 0);
00186 CH_assert(a_srcInterval.begin() >= 0);
00187 CH_assert(a_dstInterval.end() < m_nComp);
00188 CH_assert(a_srcInterval.end() < a_src.m_nComp);
00189
00190 if ((!m_ivs.isEmpty()) && (!a_src.m_ivs.isEmpty()))
00191 {
00192 CH_assert( (a_fromBox == a_toBox) || m_ebgraph.getDomain().isPeriodic() );
00193 Box intBox = a_fromBox;
00194 IntVectSet ivsIntersect = m_ivs;
00195 ivsIntersect &= a_src.m_ivs;
00196 ivsIntersect &= intBox;
00197 BaseIVFAB<T>& thisFAB = *this;
00198 int compSize = a_srcInterval.size();
00199 for (VoFIterator vofit(ivsIntersect, m_ebgraph); vofit.ok(); ++vofit)
00200 {
00201 const VolIndex& vof = vofit();
00202 for (int icomp = 0; icomp < compSize; icomp++)
00203 {
00204 int isrccomp = a_srcInterval.begin() + icomp;
00205 int idstcomp = a_dstInterval.begin() + icomp;
00206 thisFAB(vof, idstcomp) = a_src(vof, isrccomp);
00207 }
00208 }
00209 }
00210 }
00211
00212 template <class T> inline
00213 int BaseIVFAB<T>::size(const Box& a_region,
00214 const Interval& a_comps) const
00215 {
00216 CH_assert(isDefined());
00217
00218
00219
00220 IntVectSet subIVS = m_ivs;
00221 subIVS &= a_region;
00222
00223 VoFIterator vofit(subIVS, m_ebgraph);
00224
00225 const Vector<VolIndex>& vofs = vofit.getVector();
00226
00227 int vofsize = linearListSize(vofs);
00228
00229
00230 int datasize = 0;
00231 for (int ivof = 0; ivof < vofs.size(); ivof++)
00232 {
00233 if (s_verboseDebug)
00234 {
00235 IntVect iv = vofs[ivof].gridIndex();
00236 pout() << "BaseIVFAB::size vof " << vofs[ivof] << " Is irregular? " << m_ebgraph.isIrregular(iv) << endl;
00237 }
00238 for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00239 {
00240 const T& dataPt = (*this)(vofs[ivof], icomp);
00241 int pointsize = CH_XD::linearSize(dataPt);
00242 datasize += pointsize;
00243 }
00244
00245 }
00246
00247 int retval = vofsize + datasize;
00248 if (s_verboseDebug)
00249 {
00250 pout() << "BaseIVFAB::size " << retval << endl;
00251 }
00252 return retval;
00253 }
00254
00255 template <class T> inline
00256 void BaseIVFAB<T>::linearOut(void* a_buf,
00257 const Box& a_region,
00258 const Interval& a_comps) const
00259 {
00260 CH_assert(isDefined());
00261
00262 if (s_verboseDebug)
00263 {
00264 pout() << "" << endl;
00265 pout() << "BaseIVFAB<T>::linearOut " << " for box " << a_region << endl;
00266 }
00267
00268
00269 IntVectSet subIVS = m_ivs;
00270 subIVS &= a_region;
00271
00272 VoFIterator vofit(subIVS, m_ebgraph);
00273 const Vector<VolIndex>& vofs = vofit.getVector();
00274
00275 unsigned char* charbuffer = (unsigned char *) a_buf;
00276 linearListOut(charbuffer, vofs);
00277 charbuffer += linearListSize(vofs);
00278
00279
00280 for (int ivof = 0; ivof < vofs.size(); ivof++)
00281 {
00282 const VolIndex& vof = vofs[ivof];
00283 if (s_verboseDebug)
00284 {
00285 pout() << "vof " << vof << endl;
00286 }
00287 for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00288 {
00289 const T& dataPt = (*this)(vof, icomp);
00290 CH_XD::linearOut(charbuffer, dataPt);
00291
00292 charbuffer += linearSize(dataPt);
00293 }
00294 }
00295 }
00296
00297 template <class T> inline
00298 void BaseIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00299 {
00300 CH_assert(isDefined());
00301
00302
00303 if (s_verboseDebug)
00304 {
00305 pout() << "" << endl;
00306 pout() << "BaseIVFAB<T>::linearIn " << " for box " << a_region << endl;
00307 }
00308 Vector<VolIndex> vofs;
00309 unsigned char* charbuffer = (unsigned char *) a_buf;
00310 linearListIn(vofs, charbuffer);
00311 charbuffer += linearListSize(vofs);
00312
00313
00314 for (int ivof = 0; ivof < vofs.size(); ivof++)
00315 {
00316 const VolIndex& vof = vofs[ivof];
00317 if (s_verboseDebug)
00318 {
00319 pout() << "vof " << vof << endl;
00320 }
00321 for (int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00322 {
00323 T& dataPt = (*this)(vof, icomp);
00324 CH_XD::linearIn(dataPt, charbuffer) ;
00325
00326 charbuffer += linearSize(dataPt);
00327 }
00328 }
00329 }
00330
00331 template <class T> inline
00332 T*
00333 BaseIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
00334 {
00335 CH_assert(isDefined());
00336 CH_assert(m_ivs.contains(a_vof.gridIndex()));
00337 CH_assert((a_comp >= 0) && (a_comp < m_nComp));
00338
00339 T* dataPtr = (T*)(m_fab(a_vof.gridIndex(), 0));
00340 dataPtr += a_vof.cellIndex();
00341 dataPtr += a_comp*m_nVoFs;
00342 return dataPtr;
00343 }
00344
00345 template <class T> inline
00346 void
00347 BaseIVFAB<T>::clear()
00348 {
00349 m_nComp = 0;
00350 m_nVoFs = 0;
00351 m_ivs.makeEmpty();
00352 m_fab.clear();
00353
00354
00355
00356
00357
00358 m_isDefined = false;
00359 }
00360
00361 template <class T> inline
00362 bool
00363 BaseIVFAB<T>::isDefined() const
00364 {
00365 return (m_isDefined);
00366 }
00367
00368 template <class T> inline
00369 int
00370 BaseIVFAB<T>::numVoFs() const
00371 {
00372 return m_nVoFs;
00373 }
00374
00375 template <class T> inline
00376 T*
00377 BaseIVFAB<T>::dataPtr(const int& a_comp)
00378 {
00379 CH_assert(a_comp >= 0);
00380 CH_assert(a_comp <= m_nComp);
00381 static T* dummy = NULL;
00382 if (m_nVoFs == 0) return dummy;
00383
00384 T* retval = &(m_data[a_comp*m_nVoFs]);
00385 return retval;
00386 }
00387
00388 template <class T> inline
00389 const T*
00390 BaseIVFAB<T>::dataPtr(const int& a_comp) const
00391 {
00392 CH_assert(a_comp >= 0);
00393 CH_assert(a_comp <= m_nComp);
00394 static T* dummy = NULL;
00395 if (m_nVoFs == 0) return dummy;
00396 const T* retval = &(m_data[a_comp*m_nVoFs]);
00397
00398 return retval;
00399 }
00400
00401 template <class T> inline
00402 int
00403 BaseIVFAB<T>::nComp() const
00404 {
00405 return m_nComp;
00406 }
00407
00408 template <class T> inline
00409 T&
00410 BaseIVFAB<T>::operator() (const VolIndex& a_ndin,
00411 const int& a_comp)
00412 {
00413 CH_assert(isDefined());
00414 CH_assert(a_comp >= 0);
00415 CH_assert(a_comp < m_nComp);
00416 T* dataPtr = getIndex(a_ndin, a_comp);
00417 return(*dataPtr);
00418 }
00419
00420 template <class T> inline
00421 const T&
00422 BaseIVFAB<T>::operator() (const VolIndex& a_ndin,
00423 const int& a_comp) const
00424 {
00425 CH_assert(isDefined());
00426 CH_assert(a_comp >= 0);
00427 CH_assert(a_comp < m_nComp);
00428
00429 T* dataPtr = getIndex(a_ndin, a_comp);
00430 return(*dataPtr);
00431 }
00432
00433 template <class T> inline
00434 void
00435 BaseIVFAB<T>::setDefaultValues()
00436 {
00437 m_isDefined = false;
00438 m_nVoFs = 0;
00439 m_nComp = 0;
00440
00441 m_data.resize(0);
00442 }
00443
00444 #include "NamespaceFooter.H"
00445 #endif
00446