00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
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 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
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 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 assert(a_fromBox == a_toBox);
00173 assert(isDefined());
00174 assert(a_src.isDefined());
00175 assert(a_srcInterval.size() == a_dstInterval.size());
00176 assert(a_dstInterval.begin() >= 0);
00177 assert(a_srcInterval.begin() >= 0);
00178 assert(a_dstInterval.end() < m_nComp);
00179 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;
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;
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 assert(isDefined());
00229 assert(m_ivs.contains(a_iv));
00230 assert((a_comp >= 0) && (a_comp < m_nComp));
00231
00232 int ioffset = m_ivmap(a_iv, 0);
00233 assert(ioffset >= 0);
00234 assert(ioffset < m_nIvs);
00235
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 assert(isDefined());
00283 assert(a_comp >= 0);
00284 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 assert(isDefined());
00295 assert(a_comp >= 0);
00296 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 assert(isDefined());
00306 assert(a_comp >= 0);
00307 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 assert(isDefined());
00316 assert(a_comp >= 0);
00317 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