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
00075 this->m_data.resize(this->m_nVoFs*this->m_nComp);
00076 VoFIterator vofit(this->m_ivs, this->m_ebgraph);
00077 m_vofs = vofit.getVector();
00078 }
00079 }
00080 }
00081
00082
00083
00084 template <class T> inline
00085 int MiniIVFAB<T>::size(const Box& a_region,
00086 const Interval& a_comps) const
00087 {
00088 CH_assert(this->isDefined());
00089 int count = 0;
00090 T tmp;
00091
00092 for (int i=0; i<m_vofs.size(); i++)
00093 {
00094 if (a_region.contains(m_vofs[i].gridIndex())) count++;
00095 }
00096 if (count > 0)
00097 {
00098 return sizeof(int) + count*CH_XD::linearSize(m_vofs[0]) + count*a_comps.size()*CH_XD::linearSize(tmp);
00099 }
00100 return sizeof(int);
00101 }
00102
00103 template <class T> inline
00104 void MiniIVFAB<T>::linearOut(void* a_buf,
00105 const Box& a_region,
00106 const Interval& a_comps) const
00107 {
00108 CH_assert(this->isDefined());
00109 char* buffer = (char*)a_buf;
00110 buffer += sizeof(int);
00111 int count = 0;
00112 if (m_vofs.size()>0)
00113 {
00114 const T* ptr = &(this->m_data[0]);
00115 for (int i=0; i<m_vofs.size(); i++, ptr++)
00116 {
00117 const VolIndex& v = m_vofs[i];
00118 if (a_region.contains(v.gridIndex()))
00119 {
00120 count++;
00121 CH_XD::linearOut(buffer, v);
00122 buffer+= CH_XD::linearSize(v);
00123 for (int c=a_comps.begin(); c<=a_comps.end(); c++)
00124 {
00125 CH_XD::linearOut(buffer, *(ptr+c*(this->m_nVoFs)));
00126 buffer += CH_XD::linearSize(*ptr);
00127 }
00128 }
00129 }
00130 }
00131 int* b = (int*)a_buf;
00132 *b = count;
00133 }
00134
00135 template <class T> inline
00136 void MiniIVFAB<T>::linearIn(void* a_buf, const Box& a_region, const Interval& a_comps)
00137 {
00138 CH_assert(this->isDefined());
00139 int* b = (int*)a_buf;
00140 int count = *b;
00141 char* buffer = (char*)a_buf;
00142 buffer += sizeof(int);
00143 for (int i=0; i<count; i++)
00144 {
00145 VolIndex v;
00146 CH_XD::linearIn(v, buffer);
00147 buffer += linearSize(v);
00148 for (int c=a_comps.begin(); c<=a_comps.end(); c++)
00149 {
00150 T* ptr = getIndex(v, c);
00151 CH_XD::linearIn(*ptr, buffer);
00152 buffer+=CH_XD::linearSize(*ptr);
00153 }
00154 }
00155 }
00156
00157 template <class T> inline
00158 T*
00159 MiniIVFAB<T>::getIndex(const VolIndex& a_vof, const int& a_comp) const
00160 {
00161 CH_assert(this->isDefined());
00162 CH_assert(this->m_ivs.contains(a_vof.gridIndex()));
00163 CH_assert((a_comp >= 0) && (a_comp < this->m_nComp));
00164
00165 T* dataPtr = (T*)&(this->m_data[0]);
00166 for (int i=0; i<m_vofs.size(); ++i)
00167 {
00168 if (a_vof == m_vofs[i]) break;
00169 dataPtr++;
00170 }
00171 dataPtr += a_comp*this->m_nVoFs;
00172 return dataPtr;
00173 }
00174
00175 template <class T> inline
00176 void
00177 MiniIVFAB<T>::clear()
00178 {
00179 m_vofs.resize(0);
00180 BaseIVFAB<T>::clear();
00181 }
00182
00183
00184
00185
00186 template <class T> inline
00187 const Vector<VolIndex>&
00188 MiniIVFAB<T>::getVoFs() const
00189 {
00190 return m_vofs;
00191 }
00192
00193
00194
00195 template <class T> inline
00196 void
00197 MiniIVFAB<T>::setDefaultValues()
00198 {
00199 BaseIVFAB<T>::setDefaultValues();
00200 m_vofs.resize(0);
00201 }
00202
00203 #include "NamespaceFooter.H"
00204 #endif
00205