00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _MINIIVFABI_H_
00012 #define _MINIIVFABI_H_
00013 #include "MayDay.H"
00014 #include "IntVectSet.H"
00015 #include "VoFIterator.H"
00016 #include "parstream.H"
00017 #include "SPMD.H"
00018 #include "DebugOut.H"
00019 #include "EBDebugOut.H"
00020 #include "SPMD.H"
00021 #include "NamespaceHeader.H"
00022
00023
00024
00025 template <class T> inline
00026 MiniIVFAB<T>::MiniIVFAB()
00027 {
00028 setDefaultValues();
00029 }
00030
00031 template <class T> inline
00032 MiniIVFAB<T>::~MiniIVFAB()
00033 {
00034 clear();
00035 }
00036
00037 template <class T> inline
00038 MiniIVFAB<T>::MiniIVFAB(const IntVectSet& a_ivsin,
00039 const EBGraph& a_ebgraph,
00040 const int& a_nvarin)
00041 {
00042 setDefaultValues();
00043 define(a_ivsin, a_ebgraph, a_nvarin);
00044 }
00045
00046 template <class T> inline
00047 void
00048 MiniIVFAB<T>::define(const IntVectSet& a_ivsin,
00049 const EBGraph& a_ebGraph,
00050 const int& a_nvarin)
00051 {
00052 clear();
00053 this->m_isDefined = true;
00054 CH_assert(a_nvarin > 0);
00055
00056 this->m_ivs = a_ivsin;
00057 this->m_nComp = a_nvarin;
00058 this->m_ebgraph = a_ebGraph;
00059 this->m_nVoFs = 0;
00060
00061 if(!a_ivsin.isEmpty())
00062 {
00063
00064 IVSIterator ivsit(this->m_ivs);
00065 for(ivsit.reset(); ivsit.ok(); ++ivsit)
00066 {
00067 this->m_nVoFs += this->m_ebgraph.numVoFs(ivsit());
00068 }
00069
00070
00071
00072 if(this->m_nVoFs > 0)
00073 {
00074 this->m_data = new T[this->m_nVoFs*this->m_nComp];
00075 VoFIterator vofit(this->m_ivs, this->m_ebgraph);
00076 m_vofs = vofit.getVector();
00077 }
00078 }
00079 }
00080
00081
00082
00083 template <class T> inline
00084 int MiniIVFAB<T>::size(const Box& a_region,
00085 const Interval& a_comps) const
00086 {
00087 CH_assert(this->isDefined());
00088 int count = 0;
00089 T tmp;
00090
00091 for(int i=0; i<m_vofs.size(); i++)
00092 {
00093 if(a_region.contains(m_vofs[i].gridIndex())) count++;
00094 }
00095 if(count > 0)
00096 {
00097 return sizeof(int) + count*CH_XD::linearSize(m_vofs[0]) + count*a_comps.size()*CH_XD::linearSize(tmp);
00098 }
00099 return sizeof(int);
00100 }
00101
00102 template <class T> inline
00103 void MiniIVFAB<T>::linearOut(void* a_buf,
00104 const Box& a_region,
00105 const Interval& a_comps) const
00106 {
00107 CH_assert(this->isDefined());
00108 char* buffer = (char*)a_buf;
00109 buffer += sizeof(int);
00110 int count = 0;
00111 const T* ptr = this->m_data;
00112 for(int i=0; i<m_vofs.size(); i++, ptr++)
00113 {
00114 const VolIndex& v = m_vofs[i];
00115 if(a_region.contains(v.gridIndex()))
00116 {
00117 count++;
00118 CH_XD::linearOut(buffer, v);
00119 buffer+= CH_XD::linearSize(v);
00120 for(int c=a_comps.begin(); c<=a_comps.end(); c++)
00121 {
00122 CH_XD::linearOut(buffer, *(ptr+c*(this->m_nVoFs)));
00123 buffer += CH_XD::linearSize(*ptr);
00124 }
00125 }
00126 }
00127 int* b = (int*)a_buf;
00128 *b = count;
00129 }
00130
00131 template <class T> inline
00132 void MiniIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00133 {
00134 CH_assert(this->isDefined());
00135 int* b = (int*)a_buf;
00136 int count = *b;
00137 char* buffer = (char*)a_buf;
00138 buffer += sizeof(int);
00139 for(int i=0; i<count; i++)
00140 {
00141 VolIndex v;
00142 CH_XD::linearIn(v, buffer);
00143 buffer += linearSize(v);
00144 for(int c=a_comps.begin(); c<=a_comps.end(); c++)
00145 {
00146 T* ptr = getIndex(v, c);
00147 CH_XD::linearIn(*ptr, buffer);
00148 buffer+=CH_XD::linearSize(*ptr);
00149 }
00150 }
00151 }
00152
00153 template <class T> inline
00154 T*
00155 MiniIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
00156 {
00157 CH_assert(this->isDefined());
00158 CH_assert(this->m_ivs.contains(a_vof.gridIndex()));
00159 CH_assert((a_comp >= 0) && (a_comp < this->m_nComp));
00160
00161 T* dataPtr = this->m_data;
00162 for(int i=0; i<m_vofs.size(); ++i)
00163 {
00164 if(a_vof == m_vofs[i]) break;
00165 dataPtr++;
00166 }
00167 dataPtr += a_comp*this->m_nVoFs;
00168 return dataPtr;
00169 }
00170
00171 template <class T> inline
00172 void
00173 MiniIVFAB<T>::clear()
00174 {
00175 this->m_nComp = 0;
00176 this->m_nVoFs = 0;
00177 this->m_ivs.makeEmpty();
00178 m_vofs.resize(0);
00179 if(this->m_data != NULL)
00180 {
00181 delete[] this->m_data;
00182 this->m_data = NULL;
00183 }
00184 this->m_isDefined = false;
00185 }
00186
00187
00188
00189
00190
00191
00192 template <class T> inline
00193 void
00194 MiniIVFAB<T>::setDefaultValues()
00195 {
00196 BaseIVFAB<T>::setDefaultValues();
00197 m_vofs.resize(0);
00198 }
00199
00200 #include "NamespaceFooter.H"
00201 #endif
00202