00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _MINIIFFABI_H_
00012 #define _MINIIFFABI_H_
00013 #include "MayDay.H"
00014 #include "FaceIterator.H"
00015 #include <typeinfo>
00016 #include "NamespaceHeader.H"
00017
00018 template <class T>
00019 bool MiniIFFAB<T>::s_verbose = false;
00020
00021
00022 template <class T> inline
00023 MiniIFFAB<T>::MiniIFFAB()
00024 {
00025 setDefaultValues();
00026 }
00027
00028 template <class T> inline
00029 MiniIFFAB<T>::~MiniIFFAB()
00030 {
00031 clear();
00032 }
00033
00034 template <class T> inline
00035 MiniIFFAB<T>::
00036 MiniIFFAB(const IntVectSet& a_ivsin,
00037 const EBGraph& a_ebgraph,
00038 const int& a_direction,
00039 const int& a_nvarin)
00040 {
00041 setDefaultValues();
00042 define(a_ivsin, a_ebgraph, a_direction, a_nvarin);
00043 }
00044
00045 template <class T> inline
00046 void
00047 MiniIFFAB<T>::
00048 define(const IntVectSet& a_ivsin,
00049 const EBGraph& a_ebgraph,
00050 const int& a_direction,
00051 const int& a_nvarin)
00052 {
00053 clear();
00054 m_isDefined = true;
00055 CH_assert(a_nvarin > 0);
00056 CH_assert((a_direction >= 0) && (a_direction < SpaceDim));
00057
00058 m_direction = a_direction;
00059 m_ebgraph = a_ebgraph;
00060 m_nComp = a_nvarin;
00061 m_ivs = a_ivsin;
00062
00063 FaceStop::WhichFaces stopCrit = FaceStop::SurroundingWithBoundary;
00064 FaceIterator faceit(m_ivs, m_ebgraph, m_direction, stopCrit);
00065 m_faces = faceit.getVector();
00066 m_nFaces = m_faces.size();
00067
00068 m_data = new T[m_nComp*m_nFaces];
00069 }
00070
00071 template <class T> inline
00072 void
00073 MiniIFFAB<T>::
00074 setVal(const T& a_value)
00075 {
00076 CH_assert(isDefined());
00077 for(int ivec = 0; ivec < m_nFaces*m_nComp; ivec++)
00078 {
00079 m_data[ivec] = a_value;
00080 }
00081 }
00082
00083 template <class T> inline
00084 void
00085 MiniIFFAB<T>::
00086 setVal(int ivar, const T& a_value)
00087 {
00088 CH_assert(isDefined());
00089 CH_assert(ivar >= 0);
00090 CH_assert(ivar < m_nComp);
00091
00092 for(int ivec = ivar; ivec < m_nFaces*m_nComp; ivec += m_nComp)
00093 {
00094 m_data[ivec] = a_value;
00095 }
00096 }
00097
00098 template <class T> inline
00099 void
00100 MiniIFFAB<T>::
00101 copy(const Box& a_fromBox,
00102 const Interval& a_dstInterval,
00103 const Box& a_toBox,
00104 const MiniIFFAB<T>& a_src,
00105 const Interval& a_srcInterval)
00106 {
00107 CH_assert(isDefined());
00108 CH_assert(a_src.isDefined());
00109 CH_assert(a_srcInterval.size() == a_dstInterval.size());
00110 CH_assert(a_dstInterval.begin() >= 0);
00111 CH_assert(a_srcInterval.begin() >= 0);
00112 CH_assert(a_dstInterval.end() < m_nComp);
00113 CH_assert(a_srcInterval.end() < a_src.m_nComp);
00114
00115 if((!m_ivs.isEmpty()) && (!a_src.m_ivs.isEmpty()))
00116 {
00117 CH_assert(a_fromBox == a_toBox);
00118 Box intBox = a_toBox;
00119 IntVectSet ivsIntersect = m_ivs;
00120 ivsIntersect &= a_src.m_ivs;
00121 ivsIntersect &= intBox;
00122 int compSize = a_srcInterval.size();
00123
00124 FaceStop::WhichFaces stopCrit = FaceStop::SurroundingWithBoundary;
00125 FaceIterator faceit(ivsIntersect, m_ebgraph, m_direction, stopCrit);
00126 for(faceit.reset(); faceit.ok(); ++faceit)
00127 {
00128 const FaceIndex& face = faceit();
00129 for(int icomp = 0; icomp < compSize; icomp++)
00130 {
00131 int isrccomp = a_srcInterval.begin() + icomp;
00132 int idstcomp = a_dstInterval.begin() + icomp;
00133 (*this)(face, idstcomp) = a_src(face, isrccomp);
00134 }
00135 }
00136 }
00137 }
00138
00139 template <class T> inline
00140 T*
00141 MiniIFFAB<T>::
00142 getIndex(const FaceIndex& a_face, const int& a_comp) const
00143 {
00144 CH_assert(m_isDefined);
00145 CH_assert((a_comp >= 0) && (a_comp < this->m_nComp));
00146
00147 T* dataPtr = this->m_data;
00148 bool found = false;
00149 T* retval=NULL;
00150 for(int iface = 0; iface < m_faces.size(); ++iface)
00151 {
00152 if(a_face == m_faces[iface])
00153 {
00154 found = true;
00155 retval=dataPtr;
00156 }
00157 if(found) break;
00158 dataPtr++;
00159 }
00160 if(!found)
00161 {
00162 MayDay::Error("MiniIFFAB:index not found");
00163 }
00164 retval += a_comp*this->m_nFaces;
00165 return retval;
00166
00167 }
00168
00169 template <class T> inline
00170 void
00171 MiniIFFAB<T>::
00172 clear()
00173 {
00174 if (m_data != NULL)
00175 {
00176 delete[] m_data;
00177 m_data = NULL;
00178 }
00179 m_faces.resize(0);
00180 setDefaultValues();
00181 }
00182
00183 template <class T> inline
00184 T&
00185 MiniIFFAB<T>::operator() (const FaceIndex& a_ndin,
00186 const int& a_comp)
00187 {
00188 CH_assert(isDefined());
00189 CH_assert(a_ndin.direction() == m_direction);
00190
00191 T* dataPtr = getIndex(a_ndin, a_comp);
00192 return(*dataPtr);
00193 }
00194
00195 template <class T> inline
00196 const T&
00197 MiniIFFAB<T>::operator() (const FaceIndex& a_ndin,
00198 const int& a_comp) const
00199 {
00200 CH_assert(isDefined());
00201 CH_assert(a_ndin.direction() == m_direction);
00202
00203 T* dataPtr = getIndex(a_ndin, a_comp);
00204 return(*dataPtr);
00205 }
00206
00207 template <class T> inline
00208 T*
00209 MiniIFFAB<T>::dataPtr(const int& a_comp)
00210 {
00211 CH_assert(a_comp >= 0);
00212 CH_assert(a_comp <= m_nComp);
00213 return m_data + a_comp*m_nFaces;
00214 }
00215
00216 template <class T> inline
00217 const T*
00218 MiniIFFAB<T>::dataPtr(const int& a_comp) const
00219 {
00220 CH_assert(a_comp >= 0);
00221 CH_assert(a_comp <= m_nComp);
00222 return m_data + a_comp*m_nFaces;
00223 }
00224
00225 template <class T> inline
00226 void
00227 MiniIFFAB<T>::setDefaultValues()
00228 {
00229 m_isDefined = false;
00230 m_data = NULL;
00231 m_nFaces = 0;
00232 m_nComp = 0;
00233 m_direction = -1;
00234 }
00235
00236 template <class T> inline
00237 void
00238 MiniIFFAB<T>::
00239 getFaceSubset(Vector<FaceIndex>& a_subFaces, const Box& a_subBox) const
00240 {
00241 a_subFaces.resize(0);
00242 for(int iface = 0; iface < m_faces.size(); iface++)
00243 {
00244 if((a_subBox.contains(m_faces[iface].gridIndex(Side::Lo))) ||
00245 (a_subBox.contains(m_faces[iface].gridIndex(Side::Hi))))
00246 {
00247 a_subFaces.push_back(m_faces[iface]);
00248 }
00249 }
00250 }
00251
00252 template <class T> inline
00253 int
00254 MiniIFFAB<T>::
00255 size(const Box& a_region,
00256 const Interval& a_comps) const
00257 {
00258 CH_assert(isDefined());
00259
00260 Vector<FaceIndex> faces;
00261 getFaceSubset(faces, a_region);
00262
00263
00264 int facesize = linearListSize(faces);
00265
00266
00267 int datasize = 0;
00268 for(int iface = 0; iface < faces.size(); iface++)
00269 {
00270 for(int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00271 {
00272 const T& dataPt = (*this)(faces[iface], icomp);
00273 int pointsize = CH_XD::linearSize(dataPt);
00274 datasize += pointsize;
00275 }
00276 }
00277
00278 int retval = facesize + datasize;
00279
00280 if(s_verbose)
00281 {
00282 pout() << "###############" << std::endl;
00283 pout() << "MiniIFFAB size() for region " << m_ebgraph.getRegion() << std::endl;
00284 pout() << " a_comps = (" << a_comps.begin() << "," << a_comps.end() << ")," << endl;
00285 pout() << "m_ivs = " << m_ivs;
00286 pout() << "size = " << retval << std::endl;
00287 pout() << "###############" << std::endl;
00288 }
00289
00290 return retval;
00291 }
00292
00293 template <class T> inline
00294 void
00295 MiniIFFAB<T>::
00296 linearOut(void* a_buf,
00297 const Box& a_region,
00298 const Interval& a_comps) const
00299 {
00300 CH_assert(isDefined());
00301 Vector<FaceIndex> faces;
00302 getFaceSubset(faces, a_region);
00303
00304
00305 unsigned char* charbuffer = (unsigned char *) a_buf;
00306 linearListOut(charbuffer, faces);
00307 charbuffer += linearListSize(faces);
00308
00309
00310 const MiniIFFAB<T>& thisFAB = *this;
00311 for(int iface = 0; iface < faces.size(); iface++)
00312 {
00313 const FaceIndex& face = faces[iface];
00314 for(int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00315 {
00316
00317 const T& dataPt = thisFAB(face, icomp);
00318 CH_XD::linearOut(charbuffer, dataPt);
00319
00320 charbuffer += CH_XD::linearSize(dataPt);
00321 }
00322 }
00323 }
00324
00325 template <class T> inline
00326 void
00327 MiniIFFAB<T>::
00328 linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00329 {
00330 CH_assert(isDefined());
00331
00332 unsigned char* charbuffer = (unsigned char *) a_buf;
00333 Vector<FaceIndex> faces;
00334 linearListIn(faces, charbuffer);
00335 charbuffer += linearListSize(faces);
00336
00337 for(int iface = 0; iface < faces.size(); iface++)
00338 {
00339 const FaceIndex& face = faces[iface];
00340 for(int icomp = a_comps.begin(); icomp <= a_comps.end(); icomp++)
00341 {
00342
00343 T& dataPt = (*this)(face, icomp);
00344 CH_XD::linearIn(dataPt, charbuffer) ;
00345
00346 charbuffer += CH_XD::linearSize(dataPt);
00347 }
00348 }
00349 }
00350
00351
00352
00353 #include "NamespaceFooter.H"
00354 #endif