Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BaseIVFABI.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef _BASEIVFABI_H_
00029 #define _BASEIVFABI_H_
00030 #include "MayDay.H"
00031 #include "IntVectSet.H"
00032 #include "VoFIterator.H"
00033 /******************/
00034 template <class T> inline 
00035 const EBGraph& 
00036 BaseIVFAB<T>::getEBGraph() const
00037 {
00038   return m_ebgraph;
00039 }
00040 /*************/
00041 template <class T> inline
00042 const IntVectSet& 
00043 BaseIVFAB<T>::getIVS() const
00044 {
00045   return m_ivs;
00046 }
00047 /******************/
00048 template <class T> inline 
00049 BaseIVFAB<T>::BaseIVFAB()
00050 {
00051   setDefaultValues();
00052 }
00053 /******************/
00054 template <class T> inline 
00055 BaseIVFAB<T>::~BaseIVFAB()
00056 {
00057   clear();
00058 }
00059 /******************/
00060 template <class T> inline 
00061 BaseIVFAB<T>::BaseIVFAB(const IntVectSet& a_ivsin, 
00062                         const EBGraph&    a_ebgraph,
00063                         const int&        a_nvarin)
00064 {
00065   setDefaultValues();
00066   define(a_ivsin, a_ebgraph, a_nvarin);
00067 }
00068 /******************/
00069 template <class T> inline 
00070 void
00071 BaseIVFAB<T>::define(const IntVectSet& a_ivsin, 
00072                      const EBGraph& a_ebGraph,
00073                      const int& a_nvarin)
00074 {
00075   clear();
00076   m_isDefined = true;
00077   assert(a_nvarin > 0);
00078   m_ivs = a_ivsin;
00079   m_nComp = a_nvarin;
00080   m_ebgraph = a_ebGraph;
00081   m_nVoFs = 0;
00082   if(!a_ivsin.isEmpty())
00083     {
00084       Box minbox = a_ivsin.minBox();
00085       m_ivmap.resize(minbox, 1);
00086       IVSIterator ivsit(a_ivsin);
00087       for(ivsit.reset(); ivsit.ok(); ++ivsit)
00088         {
00089           const IntVect& iv = ivsit();
00090           Vector<VolIndex> vofs = m_ebgraph.getVoFs(iv);
00091           int numvofs = vofs.size();
00092           Vector<int>& vIndex = m_ivmap(iv, 0);
00093           vIndex.resize(numvofs);
00094           for(int ivof = 0; ivof < numvofs; ivof++)
00095             {
00096               vIndex[ivof] = m_nVoFs;
00097               m_nVoFs++;
00098             }
00099         }
00100 
00101       if( (m_nVoFs > 0) && m_nComp > 0)
00102         {
00103           m_dataPtr = new T[m_nComp*m_nVoFs];
00104         }
00105       else
00106         {
00107           m_dataPtr = NULL;
00108         }
00109     }
00110   else
00111     {
00112       m_dataPtr = NULL;
00113     }
00114   if(m_nVoFs > 0)
00115     {
00116       //set up face low and high vectors
00117       for (int dir = 0; dir < CH_SPACEDIM; ++dir)
00118         {
00119           m_loVect[dir] = 1;
00120           m_hiVect[dir] = 1;
00121         }
00122       m_hiVect[0] = m_nVoFs;
00123 
00124     }
00125   else
00126     {
00127       m_loVect = IntVect::Unit;
00128       m_hiVect = IntVect::Zero;
00129       m_dataPtr = NULL;
00130     }
00131 
00132 }
00133 /******************/
00134 template <class T> inline 
00135 void
00136 BaseIVFAB<T>::setVal(const T& a_value)
00137 {
00138   assert(isDefined());
00139   for(int ivec = 0; ivec < m_nVoFs*m_nComp; ivec++)
00140     m_dataPtr[ivec] = a_value;
00141 }
00142 /******************/
00143 template <class T> inline 
00144 void
00145 BaseIVFAB<T>::copy(const Box& a_fromBox, 
00146                    const Interval& a_dstInterval,
00147                    const Box& a_toBox,
00148                    const BaseIVFAB<T>& a_src, 
00149                    const Interval& a_srcInterval)
00150 {
00151   assert(a_fromBox == a_toBox);
00152   assert(isDefined());
00153   assert(a_src.isDefined());
00154   assert(a_srcInterval.size() == a_dstInterval.size());
00155   assert(a_dstInterval.begin() >= 0);
00156   assert(a_srcInterval.begin() >= 0);
00157   assert(a_dstInterval.end()   < m_nComp);
00158   assert(a_srcInterval.end()   < a_src.m_nComp);
00159 
00160   Box intBox = a_fromBox;
00161   IntVectSet ivsIntersect = m_ivs;
00162   ivsIntersect &= intBox;  // 
00163   BaseIVFAB<T>& thisFAB = *this;
00164   int compSize = a_srcInterval.size();
00165   for(VoFIterator vofit(ivsIntersect, m_ebgraph); vofit.ok(); ++vofit)
00166     {
00167       const VolIndex& vof = vofit();
00168       for(int icomp = 0; icomp < compSize; icomp++)
00169         {
00170           int isrccomp = a_srcInterval.begin() + icomp;
00171           int idstcomp = a_dstInterval.begin() + icomp;
00172           thisFAB(vof, idstcomp) = a_src(vof, isrccomp);
00173         }
00174     }
00175 }
00176 /******************/
00177 template <class T> inline 
00178 int BaseIVFAB<T>::size(const Box& a_region, 
00179                        const Interval& a_comps) const
00180 {
00181   assert(isDefined());
00182   //create set of cells in fab that are also in the input region
00183   IntVectSet subIVS = m_ivs;
00184   subIVS &= a_region;
00185 
00186   //account for number of points in the intersection
00187   int retval = 0;
00188   for(VoFIterator vofit(subIVS, m_ebgraph); vofit.ok(); ++vofit)
00189     {
00190       retval++;
00191     }
00192 
00193   //account for number of components
00194   retval *= a_comps.size();
00195   //account for the size of the template object
00196   retval *= sizeof(T);
00197   return retval;
00198 }
00199 /********************/
00200 template <class T> inline 
00201 void BaseIVFAB<T>::linearOut(void* a_buf, 
00202                              const Box& a_region, 
00203                              const Interval& a_comps) const
00204 {
00205   //cast buffer into a pointer of the correct type
00206   //this way incrementing the pointer goes by the correct amount
00207   T* buffer = (T*)a_buf;
00208   //create set of cells in fab that are also in the input region
00209   IntVectSet subIVS = m_ivs;
00210   subIVS &= a_region;
00211   const BaseIVFAB<T>& thisFAB = *this;
00212   for(VoFIterator vofit(subIVS, m_ebgraph); vofit.ok(); ++vofit)
00213     {
00214       const VolIndex& vof = vofit();
00215       for(int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00216         {
00217           *buffer = thisFAB(vof, icomp);
00218           //increment the buffer offset
00219           ++buffer;
00220         }
00221     }
00222 }
00223 /********************/
00224 template <class T> inline 
00225 void BaseIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00226 {
00227   //cast buffer into a pointer of the correct type
00228   //this way incrementing the pointer goes by the correct amount
00229   T* buffer = (T*)a_buf;
00230   //create set of cells in fab that are also in the input region
00231   IntVectSet subIVS = m_ivs;
00232   subIVS &= a_region;
00233 
00234   BaseIVFAB<T>& thisFAB = *this;
00235   for(VoFIterator vofit(subIVS, m_ebgraph); vofit.ok(); ++vofit)
00236     {
00237       const VolIndex& vof = vofit();
00238       for(int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00239         {
00240           thisFAB(vof, icomp) = *buffer;
00241           //increment the buffer offset
00242           ++buffer;
00243         }
00244     }
00245 }
00246 /********************/
00247 template <class T> inline 
00248 int
00249 BaseIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
00250 {
00251   assert(isDefined());
00252   assert(m_ivs.contains(a_vof.gridIndex()));
00253   assert((a_comp >= 0) && (a_comp < m_nComp));
00254 
00255   const Vector<int>& vecOffset = m_ivmap(a_vof.gridIndex(), 0);
00256   //this checks whether the volindex is defined 
00257   assert(a_vof.cellIndex() >= 0);
00258   //if this fails on a size() thing, then the
00259   //basefab<vector<int> > was constructed incorrectly
00260   //(the assert should catch wheter the vof is outside the orig ivs)
00261   int ioffset = vecOffset[a_vof.cellIndex()];
00262   //need these because we are indexing into a straight
00263   //pointer (no vector bounds checking).
00264   assert(ioffset >= 0);
00265   assert(ioffset < m_nVoFs);
00266   //now add offset from componentnitude
00267   ioffset += m_nVoFs*a_comp;
00268   return ioffset;
00269 }
00270 /********************/
00271 template <class T> inline 
00272 void
00273 BaseIVFAB<T>::clear()
00274 {
00275   m_nComp = 0;
00276   m_nVoFs = 0;
00277   m_ivs.makeEmpty();
00278   m_ivmap.clear();
00279   if(m_dataPtr != NULL)
00280     {
00281       delete[] m_dataPtr;
00282       m_dataPtr = NULL;
00283     }
00284   m_isDefined = false;
00285 }
00286 /*************************/
00287 template <class T> inline 
00288 bool 
00289 BaseIVFAB<T>::isDefined() const
00290 {
00291   return (m_isDefined);
00292 }
00293 /*************************/
00294 template <class T> inline 
00295 int
00296 BaseIVFAB<T>::numVoFs() const 
00297 {
00298   return m_nVoFs;
00299 }
00300 /*************************/
00301 template <class T> inline 
00302 int
00303 BaseIVFAB<T>::nComp() const 
00304 {
00305   return m_nComp;
00306 }
00307 /*************************/
00308 template <class T> inline 
00309 T&
00310 BaseIVFAB<T>::operator() (const VolIndex& a_ndin,
00311                           const int& a_comp)
00312 { 
00313   assert(isDefined());
00314   assert(a_comp >= 0);
00315   assert(a_comp < m_nComp);
00316   int iloc = getIndex(a_ndin, a_comp);
00317   return(m_dataPtr[iloc]);
00318 }
00319 /**************************/
00320 template <class T> inline 
00321 const T&
00322 BaseIVFAB<T>::operator() (const VolIndex& a_ndin,
00323                           const int& a_comp) const
00324 { 
00325   assert(isDefined());
00326   assert(a_comp >= 0);
00327   assert(a_comp < m_nComp);
00328   int iloc = getIndex(a_ndin, a_comp);
00329   return(m_dataPtr[iloc]);
00330 }
00331 /******************/
00332 template <class T> inline 
00333 const T*
00334 BaseIVFAB<T>::dataPtr(const int& a_comp) const
00335 {
00336   assert(isDefined());
00337   assert(a_comp >= 0);
00338   assert(a_comp < m_nComp);
00339   return m_dataPtr + a_comp*m_nVoFs;
00340 }
00341 /******************/
00342 template <class T> inline 
00343 T* 
00344 BaseIVFAB<T>::dataPtr(const int& a_comp) 
00345 {
00346   assert(isDefined());
00347   assert(a_comp >= 0);
00348   assert(a_comp < m_nComp);
00349   return m_dataPtr + a_comp*m_nVoFs;
00350 }
00351 /******************/
00352 template <class T> inline 
00353 const int*
00354 BaseIVFAB<T>::loVect() const 
00355 {
00356   return lo_vect.getVect();
00357 }
00358 /******************/
00359 template <class T> inline 
00360 const int*
00361 BaseIVFAB<T>::hiVect() const 
00362 {
00363   return m_hiVect.getVect();
00364 }
00365 /******************/
00366 template <class T> inline 
00367 void
00368 BaseIVFAB<T>::setDefaultValues()
00369 {
00370   m_isDefined = false;
00371   m_dataPtr = NULL;
00372   m_nVoFs = 0;
00373   m_nComp = 0;
00374   m_loVect = IntVect::Unit;
00375   m_hiVect = IntVect::Zero;
00376 }
00377 /******************/
00378 template <class T> inline 
00379 BaseIVFAB<T>& 
00380 BaseIVFAB<T>::operator= (const BaseIVFAB<T>& a_input)
00381 {
00382   MayDay::Error("BaseIVFAB operator = not defined");
00383   return *this;
00384 }
00385 /******************/
00386 template <class T> inline 
00387 BaseIVFAB<T>::BaseIVFAB (const BaseIVFAB<T>& a_input)
00388 {
00389   MayDay::Error("BaseIVFAB copy constructor not defined");
00390 }
00391 
00392 #endif
00393 

Generated on Wed Apr 16 14:31:03 2003 for EBChombo by doxygen1.2.16