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