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