Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

IVSFABI.H

Go to the documentation of this file.
00001 /*   _______              __
00002     / ___/ /  ___  __ _  / /  ___
00003    / /__/ _ \/ _ \/  V \/ _ \/ _ \
00004    \___/_//_/\___/_/_/_/_.__/\___/
00005 */
00006 // CHOMBO Copyright (c) 2000-2004, The Regents of the University of
00007 // California, through Lawrence Berkeley National Laboratory (subject to
00008 // receipt of any required approvals from U.S. Dept. of Energy).  All
00009 // rights reserved.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are met:
00013 //
00014 // (1) Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 // (2) Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in the
00018 // documentation and/or other materials provided with the distribution.
00019 // (3) Neither the name of Lawrence Berkeley National Laboratory, U.S.
00020 // Dept. of Energy nor the names of its contributors may be used to endorse
00021 // or promote products derived from this software without specific prior
00022 // written permission.
00023 //
00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035 //
00036 // You are under no obligation whatsoever to provide any bug fixes,
00037 // patches, or upgrades to the features, functionality or performance of
00038 // the source code ("Enhancements") to anyone; however, if you choose to
00039 // make your Enhancements available either publicly, or directly to
00040 // Lawrence Berkeley National Laboratory, without imposing a separate
00041 // written license agreement for such Enhancements, then you hereby grant
00042 // the following license: a non-exclusive, royalty-free perpetual license
00043 // to install, use, modify, prepare derivative works, incorporate into
00044 // other computer software, distribute, and sublicense such Enhancements or
00045 // derivative works thereof, in binary and source code form.
00046 //
00047 // TRADEMARKS. Product and company names mentioned herein may be the
00048 // trademarks of their respective owners.  Any rights not expressly granted
00049 // herein are reserved.
00050 //
00051 
00052 #ifndef _IVSFABI_H_
00053 #define _IVSFABI_H_
00054 
00055 #include "MayDay.H"
00056 #include "IntVectSet.H"
00057 #include "parstream.H"
00058 #include "SPMD.H"
00059 #include "DebugOut.H"
00060 #include "SPMD.H"
00061 
00062 template <class T>
00063 bool IVSFAB<T>::s_verbose = false;
00064 
00065 template <class T>
00066 void
00067 IVSFAB<T>::setVerbose(bool a_verbose)
00068 {
00069   s_verbose = a_verbose;
00070 }
00071 /*************/
00072 template <class T> inline
00073 const IntVectSet&
00074 IVSFAB<T>::getIVS() const
00075 {
00076   return m_ivs;
00077 }
00078 /******************/
00079 template <class T> inline
00080 IVSFAB<T>::IVSFAB()
00081 {
00082   setDefaultValues();
00083 }
00084 /******************/
00085 template <class T> inline
00086 IVSFAB<T>::~IVSFAB()
00087 {
00088   clear();
00089 }
00090 /******************/
00091 template <class T> inline
00092 IVSFAB<T>::IVSFAB(const IntVectSet& a_ivsin,
00093                         const int&        a_nvarin)
00094 {
00095   setDefaultValues();
00096   define(a_ivsin, a_nvarin);
00097 }
00098 /******************/
00099 template <class T> inline
00100 void
00101 IVSFAB<T>::define(const IntVectSet& a_ivsin,
00102                      const int& a_nvarin)
00103 {
00104   clear();
00105   m_isDefined = true;
00106  CH_assert(a_nvarin > 0);
00107   m_ivs = a_ivsin;
00108   m_nComp = a_nvarin;
00109   m_nIvs = 0;
00110   if(!a_ivsin.isEmpty())
00111     {
00112       Box minbox = a_ivsin.minBox();
00113       m_ivmap.resize(minbox, 1);
00114       IVSIterator ivsit(a_ivsin);
00115       for(ivsit.reset(); ivsit.ok(); ++ivsit)
00116         {
00117           const IntVect& iv = ivsit();
00118           m_ivmap(iv,0) = m_nIvs;
00119           m_nIvs++;
00120         }
00121 
00122       if( (m_nIvs > 0) && m_nComp > 0)
00123         {
00124           m_dataPtr = new T[m_nComp*m_nIvs];
00125         }
00126       else
00127         {
00128           m_dataPtr = NULL;
00129         }
00130     }
00131   else
00132     {
00133       m_dataPtr = NULL;
00134     }
00135   if(m_nIvs > 0)
00136     {
00137       //set up face low and high vectors
00138       for (int dir = 0; dir < CH_SPACEDIM; ++dir)
00139         {
00140           m_loVect[dir] = 1;
00141           m_hiVect[dir] = 1;
00142         }
00143       m_hiVect[0] = m_nIvs;
00144 
00145     }
00146   else
00147     {
00148       m_loVect = IntVect::Unit;
00149       m_hiVect = IntVect::Zero;
00150       m_dataPtr = NULL;
00151     }
00152 
00153 }
00154 /******************/
00155 template <class T> inline
00156 void
00157 IVSFAB<T>::setVal(const T& a_value)
00158 {
00159  CH_assert(isDefined());
00160   for(int ivec = 0; ivec < m_nIvs*m_nComp; ivec++)
00161     m_dataPtr[ivec] = a_value;
00162 }
00163 /******************/
00164 template <class T> inline
00165 void
00166 IVSFAB<T>::copy(const Box& a_fromBox,
00167                    const Interval& a_dstInterval,
00168                    const Box& a_toBox,
00169                    const IVSFAB<T>& a_src,
00170                    const Interval& a_srcInterval)
00171 {
00172  CH_assert(a_fromBox == a_toBox);
00173  CH_assert(isDefined());
00174  CH_assert(a_src.isDefined());
00175  CH_assert(a_srcInterval.size() == a_dstInterval.size());
00176  CH_assert(a_dstInterval.begin() >= 0);
00177  CH_assert(a_srcInterval.begin() >= 0);
00178  CH_assert(a_dstInterval.end()   < m_nComp);
00179  CH_assert(a_srcInterval.end()   < a_src.m_nComp);
00180 
00181   if((!m_ivs.isEmpty()) && (!a_src.m_ivs.isEmpty()))
00182     {
00183       Box intBox = a_fromBox;
00184       IntVectSet ivsIntersect = m_ivs;
00185       ivsIntersect &= a_src.m_ivs; //how did this ever work without this line?
00186       ivsIntersect &= intBox;  //
00187       IVSFAB<T>& thisFAB = *this;
00188       int compSize = a_srcInterval.size();
00189       for(IVSIterator ivit(ivsIntersect); ivit.ok(); ++ivit)
00190         {
00191           const IntVect& iv = ivit();
00192           for(int icomp = 0; icomp < compSize; icomp++)
00193             {
00194               int isrccomp = a_srcInterval.begin() + icomp;
00195               int idstcomp = a_dstInterval.begin() + icomp;
00196               thisFAB(iv, idstcomp) = a_src(iv, isrccomp);
00197             }
00198         }
00199     }
00200 }
00201 /******************/
00202 template <class T> inline
00203 int IVSFAB<T>::size(const Box& a_region,
00204                        const Interval& a_comps) const
00205 {
00206   MayDay::Error();
00207   return 0; // to prevent compiler error, but function should prolly be void?
00208 }
00209 /********************/
00210 template <class T> inline
00211 void IVSFAB<T>::linearOut(void* a_buf,
00212                              const Box& a_region,
00213                              const Interval& a_comps) const
00214 {
00215   MayDay::Error();
00216 }
00217 /********************/
00218 template <class T> inline
00219 void IVSFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00220 {
00221   MayDay::Error();
00222 }
00223 
00224 template <class T> inline
00225 int
00226 IVSFAB<T>::getIndex(const IntVect& a_iv, const int& a_comp) const
00227 {
00228  CH_assert(isDefined());
00229  CH_assert(m_ivs.contains(a_iv));
00230  CH_assert((a_comp >= 0) && (a_comp < m_nComp));
00231 
00232   int ioffset = m_ivmap(a_iv, 0);
00233  CH_assert(ioffset >= 0);
00234  CH_assert(ioffset < m_nIvs);
00235   //now add offset from componentnitude
00236   ioffset += m_nIvs*a_comp;
00237   return ioffset;
00238 }
00239 /********************/
00240 template <class T> inline
00241 void
00242 IVSFAB<T>::clear()
00243 {
00244   m_nComp = 0;
00245   m_nIvs = 0;
00246   m_ivs.makeEmpty();
00247   m_ivmap.clear();
00248   if(m_dataPtr != NULL)
00249     {
00250       delete[] m_dataPtr;
00251       m_dataPtr = NULL;
00252     }
00253   m_isDefined = false;
00254 }
00255 /*************************/
00256 template <class T> inline
00257 bool
00258 IVSFAB<T>::isDefined() const
00259 {
00260   return (m_isDefined);
00261 }
00262 /*************************/
00263 template <class T> inline
00264 int
00265 IVSFAB<T>::numIvs() const
00266 {
00267   return m_nIvs;
00268 }
00269 /*************************/
00270 template <class T> inline
00271 int
00272 IVSFAB<T>::nComp() const
00273 {
00274   return m_nComp;
00275 }
00276 /*************************/
00277 template <class T> inline
00278 T&
00279 IVSFAB<T>::operator() (const IntVect& a_ndin,
00280                        const int& a_comp)
00281 {
00282  CH_assert(isDefined());
00283  CH_assert(a_comp >= 0);
00284  CH_assert(a_comp < m_nComp);
00285   int iloc = getIndex(a_ndin, a_comp);
00286   return(m_dataPtr[iloc]);
00287 }
00288 /**************************/
00289 template <class T> inline
00290 const T&
00291 IVSFAB<T>::operator() (const IntVect& a_ndin,
00292                        const int& a_comp) const
00293 {
00294  CH_assert(isDefined());
00295  CH_assert(a_comp >= 0);
00296  CH_assert(a_comp < m_nComp);
00297   int iloc = getIndex(a_ndin, a_comp);
00298   return(m_dataPtr[iloc]);
00299 }
00300 /******************/
00301 template <class T> inline
00302 const T*
00303 IVSFAB<T>::dataPtr(const int& a_comp) const
00304 {
00305  CH_assert(isDefined());
00306  CH_assert(a_comp >= 0);
00307  CH_assert(a_comp < m_nComp);
00308   return m_dataPtr + a_comp*m_nIvs;
00309 }
00310 /******************/
00311 template <class T> inline
00312 T*
00313 IVSFAB<T>::dataPtr(const int& a_comp)
00314 {
00315  CH_assert(isDefined());
00316  CH_assert(a_comp >= 0);
00317  CH_assert(a_comp < m_nComp);
00318   return m_dataPtr + a_comp*m_nIvs;
00319 }
00320 /******************/
00321 template <class T> inline
00322 const int*
00323 IVSFAB<T>::loVect() const
00324 {
00325   return m_loVect.getVect();
00326 }
00327 /******************/
00328 template <class T> inline
00329 const int*
00330 IVSFAB<T>::hiVect() const
00331 {
00332   return m_hiVect.getVect();
00333 }
00334 /******************/
00335 template <class T> inline
00336 void
00337 IVSFAB<T>::setDefaultValues()
00338 {
00339   m_isDefined = false;
00340   m_dataPtr = NULL;
00341   m_nIvs = 0;
00342   m_nComp = 0;
00343   m_loVect = IntVect::Unit;
00344   m_hiVect = IntVect::Zero;
00345 }
00346 /******************/
00347 template <class T> inline
00348 IVSFAB<T>&
00349 IVSFAB<T>::operator= (const IVSFAB<T>& a_input)
00350 {
00351   MayDay::Error("IVSFAB operator = not defined");
00352   return *this;
00353 }
00354 /******************/
00355 template <class T> inline
00356 IVSFAB<T>::IVSFAB (const IVSFAB<T>& a_input)
00357 {
00358   MayDay::Error("IVSFAB copy constructor not defined");
00359 }
00360 
00361 #endif

Generated on Wed Oct 5 13:52:08 2005 for Chombo&AMRSelfGravity by  doxygen 1.4.1