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

IVSFABI.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 _IVSFABI_H_
00029 #define _IVSFABI_H_
00030 #include "MayDay.H"
00031 #include "IntVectSet.H"
00032 #include "parstream.H"
00033 #include "SPMD.H"
00034 #include "DebugOut.H"
00035 #include "SPMD.H"
00036 
00037 template <class T> 
00038 bool IVSFAB<T>::s_verbose = false;
00039 
00040 template <class T> 
00041 void 
00042 IVSFAB<T>::setVerbose(bool a_verbose) 
00043 {
00044   s_verbose = a_verbose;
00045 }
00046 /*************/
00047 template <class T> inline
00048 const IntVectSet& 
00049 IVSFAB<T>::getIVS() const
00050 {
00051   return m_ivs;
00052 }
00053 /******************/
00054 template <class T> inline 
00055 IVSFAB<T>::IVSFAB()
00056 {
00057   setDefaultValues();
00058 }
00059 /******************/
00060 template <class T> inline 
00061 IVSFAB<T>::~IVSFAB()
00062 {
00063   clear();
00064 }
00065 /******************/
00066 template <class T> inline 
00067 IVSFAB<T>::IVSFAB(const IntVectSet& a_ivsin, 
00068                         const int&        a_nvarin)
00069 {
00070   setDefaultValues();
00071   define(a_ivsin, a_nvarin);
00072 }
00073 /******************/
00074 template <class T> inline 
00075 void
00076 IVSFAB<T>::define(const IntVectSet& a_ivsin, 
00077                      const int& a_nvarin)
00078 {
00079   clear();
00080   m_isDefined = true;
00081   assert(a_nvarin > 0);
00082   m_ivs = a_ivsin;
00083   m_nComp = a_nvarin;
00084   m_nIvs = 0;
00085   if(!a_ivsin.isEmpty())
00086     {
00087       Box minbox = a_ivsin.minBox();
00088       m_ivmap.resize(minbox, 1);
00089       IVSIterator ivsit(a_ivsin);
00090       for(ivsit.reset(); ivsit.ok(); ++ivsit)
00091         {
00092           const IntVect& iv = ivsit();
00093           m_ivmap(iv,0) = m_nIvs;
00094           m_nIvs++;
00095         }
00096 
00097       if( (m_nIvs > 0) && m_nComp > 0)
00098         {
00099           m_dataPtr = new T[m_nComp*m_nIvs];
00100         }
00101       else
00102         {
00103           m_dataPtr = NULL;
00104         }
00105     }
00106   else
00107     {
00108       m_dataPtr = NULL;
00109     }
00110   if(m_nIvs > 0)
00111     {
00112       //set up face low and high vectors
00113       for (int dir = 0; dir < CH_SPACEDIM; ++dir)
00114         {
00115           m_loVect[dir] = 1;
00116           m_hiVect[dir] = 1;
00117         }
00118       m_hiVect[0] = m_nIvs;
00119 
00120     }
00121   else
00122     {
00123       m_loVect = IntVect::Unit;
00124       m_hiVect = IntVect::Zero;
00125       m_dataPtr = NULL;
00126     }
00127 
00128 }
00129 /******************/
00130 template <class T> inline 
00131 void
00132 IVSFAB<T>::setVal(const T& a_value)
00133 {
00134   assert(isDefined());
00135   for(int ivec = 0; ivec < m_nIvs*m_nComp; ivec++)
00136     m_dataPtr[ivec] = a_value;
00137 }
00138 /******************/
00139 template <class T> inline 
00140 void
00141 IVSFAB<T>::copy(const Box& a_fromBox, 
00142                    const Interval& a_dstInterval,
00143                    const Box& a_toBox,
00144                    const IVSFAB<T>& a_src, 
00145                    const Interval& a_srcInterval)
00146 {
00147   assert(a_fromBox == a_toBox);
00148   assert(isDefined());
00149   assert(a_src.isDefined());
00150   assert(a_srcInterval.size() == a_dstInterval.size());
00151   assert(a_dstInterval.begin() >= 0);
00152   assert(a_srcInterval.begin() >= 0);
00153   assert(a_dstInterval.end()   < m_nComp);
00154   assert(a_srcInterval.end()   < a_src.m_nComp);
00155 
00156   if((!m_ivs.isEmpty()) && (!a_src.m_ivs.isEmpty()))
00157     {
00158       Box intBox = a_fromBox;
00159       IntVectSet ivsIntersect = m_ivs;
00160       ivsIntersect &= a_src.m_ivs; //how did this ever work without this line?
00161       ivsIntersect &= intBox;  // 
00162       IVSFAB<T>& thisFAB = *this;
00163       int compSize = a_srcInterval.size();
00164       for(IVSIterator ivit(ivsIntersect); ivit.ok(); ++ivit)
00165         {
00166           const IntVect& iv = ivit();
00167           for(int icomp = 0; icomp < compSize; icomp++)
00168             {
00169               int isrccomp = a_srcInterval.begin() + icomp;
00170               int idstcomp = a_dstInterval.begin() + icomp;
00171               thisFAB(iv, idstcomp) = a_src(iv, isrccomp);
00172             }
00173         }
00174     }
00175 }
00176 /******************/
00177 template <class T> inline 
00178 int IVSFAB<T>::size(const Box& a_region, 
00179                        const Interval& a_comps) const
00180 {
00181   MayDay::Error();
00182   return 0; // to prevent compiler error, but function should prolly be void?
00183 }
00184 /********************/
00185 template <class T> inline 
00186 void IVSFAB<T>::linearOut(void* a_buf, 
00187                              const Box& a_region, 
00188                              const Interval& a_comps) const
00189 {
00190   MayDay::Error();
00191 }
00192 /********************/
00193 template <class T> inline 
00194 void IVSFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00195 {
00196   MayDay::Error();
00197 }
00198 
00199 template <class T> inline 
00200 int
00201 IVSFAB<T>::getIndex(const IntVect& a_iv, const int& a_comp) const
00202 {
00203   assert(isDefined());
00204   assert(m_ivs.contains(a_iv));
00205   assert((a_comp >= 0) && (a_comp < m_nComp));
00206 
00207   int ioffset = m_ivmap(a_iv, 0);
00208   assert(ioffset >= 0);
00209   assert(ioffset < m_nIvs);
00210   //now add offset from componentnitude
00211   ioffset += m_nIvs*a_comp;
00212   return ioffset;
00213 }
00214 /********************/
00215 template <class T> inline 
00216 void
00217 IVSFAB<T>::clear()
00218 {
00219   m_nComp = 0;
00220   m_nIvs = 0;
00221   m_ivs.makeEmpty();
00222   m_ivmap.clear();
00223   if(m_dataPtr != NULL)
00224     {
00225       delete[] m_dataPtr;
00226       m_dataPtr = NULL;
00227     }
00228   m_isDefined = false;
00229 }
00230 /*************************/
00231 template <class T> inline 
00232 bool 
00233 IVSFAB<T>::isDefined() const
00234 {
00235   return (m_isDefined);
00236 }
00237 /*************************/
00238 template <class T> inline 
00239 int
00240 IVSFAB<T>::numIvs() const 
00241 {
00242   return m_nIvs;
00243 }
00244 /*************************/
00245 template <class T> inline 
00246 int
00247 IVSFAB<T>::nComp() const 
00248 {
00249   return m_nComp;
00250 }
00251 /*************************/
00252 template <class T> inline 
00253 T&
00254 IVSFAB<T>::operator() (const IntVect& a_ndin,
00255                        const int& a_comp)
00256 { 
00257   assert(isDefined());
00258   assert(a_comp >= 0);
00259   assert(a_comp < m_nComp);
00260   int iloc = getIndex(a_ndin, a_comp);
00261   return(m_dataPtr[iloc]);
00262 }
00263 /**************************/
00264 template <class T> inline 
00265 const T&
00266 IVSFAB<T>::operator() (const IntVect& a_ndin,
00267                        const int& a_comp) const
00268 { 
00269   assert(isDefined());
00270   assert(a_comp >= 0);
00271   assert(a_comp < m_nComp);
00272   int iloc = getIndex(a_ndin, a_comp);
00273   return(m_dataPtr[iloc]);
00274 }
00275 /******************/
00276 template <class T> inline 
00277 const T*
00278 IVSFAB<T>::dataPtr(const int& a_comp) const
00279 {
00280   assert(isDefined());
00281   assert(a_comp >= 0);
00282   assert(a_comp < m_nComp);
00283   return m_dataPtr + a_comp*m_nIvs;
00284 }
00285 /******************/
00286 template <class T> inline 
00287 T* 
00288 IVSFAB<T>::dataPtr(const int& a_comp) 
00289 {
00290   assert(isDefined());
00291   assert(a_comp >= 0);
00292   assert(a_comp < m_nComp);
00293   return m_dataPtr + a_comp*m_nIvs;
00294 }
00295 /******************/
00296 template <class T> inline 
00297 const int*
00298 IVSFAB<T>::loVect() const 
00299 {
00300   return m_loVect.getVect();
00301 }
00302 /******************/
00303 template <class T> inline 
00304 const int*
00305 IVSFAB<T>::hiVect() const 
00306 {
00307   return m_hiVect.getVect();
00308 }
00309 /******************/
00310 template <class T> inline 
00311 void
00312 IVSFAB<T>::setDefaultValues()
00313 {
00314   m_isDefined = false;
00315   m_dataPtr = NULL;
00316   m_nIvs = 0;
00317   m_nComp = 0;
00318   m_loVect = IntVect::Unit;
00319   m_hiVect = IntVect::Zero;
00320 }
00321 /******************/
00322 template <class T> inline 
00323 IVSFAB<T>& 
00324 IVSFAB<T>::operator= (const IVSFAB<T>& a_input)
00325 {
00326   MayDay::Error("IVSFAB operator = not defined");
00327   return *this;
00328 }
00329 /******************/
00330 template <class T> inline 
00331 IVSFAB<T>::IVSFAB (const IVSFAB<T>& a_input)
00332 {
00333   MayDay::Error("IVSFAB copy constructor not defined");
00334 }
00335 
00336 #endif
00337 

Generated on Wed Jun 2 13:53:33 2004 for Chombo&INSwithParticles by doxygen 1.3.2