00001 #ifdef CH_LANG_CC
00002
00003
00004
00005
00006
00007
00008
00009 #endif
00010
00011 #ifndef _AGGSTENCILI_H_
00012 #define _AGGSTENCILI_H_
00013
00014
00015 template <class srcData_t, class dstData_t>
00016 AggStencil<srcData_t, dstData_t>::
00017 AggStencil(const Vector<RefCountedPtr<BaseIndex> > & a_dstVoFs,
00018 const Vector<RefCountedPtr<BaseStencil> > & a_vofStencil,
00019 const srcData_t & a_srcData,
00020 const dstData_t & a_dstData)
00021 {
00022 CH_TIME("AggSten.constructor");
00023 m_ebstencil.resize(a_dstVoFs.size());
00024 m_dstAccess.resize(a_dstVoFs.size());
00025
00026 for (int idst = 0; idst < a_dstVoFs.size(); idst++)
00027 {
00028 const BaseIndex& dstVoF = *a_dstVoFs[idst];
00029 m_dstAccess[idst].dataID = a_dstData.dataType(dstVoF);
00030 m_dstAccess[idst].offset = a_dstData.offset(dstVoF, 0);
00031
00032 const BaseStencil& sten = *a_vofStencil[idst];
00033 m_ebstencil[idst].resize(sten.size());
00034 for (int isten = 0; isten < sten.size(); isten++)
00035 {
00036 const BaseIndex& stencilVoF = sten.index(isten);
00037 m_ebstencil[idst][isten].first.offset = a_srcData.offset(stencilVoF, sten.variable(isten));
00038 m_ebstencil[idst][isten].first.dataID = a_srcData.dataType(stencilVoF);
00039 m_ebstencil[idst][isten].second = sten.weight(isten);
00040 }
00041 }
00042
00043 }
00044
00045 template <class srcData_t, class dstData_t>
00046 void
00047 AggStencil<srcData_t, dstData_t>::
00048 apply(dstData_t & a_lph,
00049 const srcData_t & a_phi,
00050 const int & a_varDest,
00051 const bool & a_incrementOnly) const
00052 {
00053 int varSrc = 0; int nComp = 1;
00054 apply(a_lph, a_phi, varSrc, a_varDest, nComp, a_incrementOnly);
00055 }
00056
00057 template <class srcData_t, class dstData_t>
00058 void
00059 AggStencil<srcData_t, dstData_t>::
00060 apply(dstData_t & a_lph,
00061 const srcData_t & a_phi,
00062 const int & a_src,
00063 const int & a_dst,
00064 const int & a_nco,
00065 const bool & a_incrementOnly) const
00066 {
00067
00068 CH_TIME("AggSten::apply");
00069 const int numtypelph = a_lph.numDataTypes();
00070 const int numtypephi = a_phi.numDataTypes();
00071 Vector<Real*> dataPtrsLph(numtypelph);
00072 Vector<const Real*> dataPtrsPhi(numtypephi);
00073 for (int icomp = 0; icomp < a_nco; icomp++)
00074 {
00075 int varDst = a_dst + icomp;
00076 int varSrc = a_src + icomp;
00077 for (int ivec = 0; ivec < numtypelph; ivec++)
00078 {
00079 dataPtrsLph[ivec] = a_lph.dataPtr(ivec, varDst);
00080 }
00081
00082 for (int ivec = 0; ivec < numtypephi; ivec++)
00083 {
00084 dataPtrsPhi[ivec] = a_phi.dataPtr(ivec, varSrc);
00085 }
00086
00087 for (int idst = 0; idst < m_ebstencil.size(); idst++)
00088 {
00089 Real* lphiPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
00090 Real& lphi = *lphiPtr;
00091 if (!a_incrementOnly)
00092 {
00093 lphi = 0.;
00094 }
00095 const stencil_t& ebstencil = m_ebstencil[idst];
00096 for (int isten = 0; isten < ebstencil.size(); isten++)
00097 {
00098 const Real& weight = ebstencil[isten].second;
00099 const long& offset = ebstencil[isten].first.offset;
00100 const int & dataID = ebstencil[isten].first.dataID;
00101 const Real& phiVal = *(dataPtrsPhi[dataID] + offset);
00102 lphi += phiVal*weight;
00103 }
00104 ch_flops()+= ebstencil.size()*2;
00105 }
00106 }
00107 }
00108
00109 template <class srcData_t, class dstData_t>
00110 void
00111 AggStencil<srcData_t, dstData_t>::
00112 cache(const dstData_t& a_lph) const
00113 {
00114
00115
00116 m_cacheDst.resize( m_ebstencil.size(), Vector<Real>(a_lph.nComp(), 0.));
00117 CH_TIME("AggSten::cache");
00118 Vector<const Real*> dataPtrsLph(a_lph.numDataTypes());
00119 for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
00120 {
00121 for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
00122 {
00123 dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
00124 }
00125
00126 for (int idst = 0; idst < m_ebstencil.size(); idst++)
00127 {
00128 const Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
00129 m_cacheDst[idst][ivar] = *lphPtr;
00130 }
00131 }
00132 }
00133
00134 template <class srcData_t, class dstData_t>
00135 void
00136 AggStencil<srcData_t, dstData_t>::
00137 uncache(dstData_t& a_lph) const
00138 {
00139 CH_TIME("AggSten::uncache");
00140 Vector<Real*> dataPtrsLph(a_lph.numDataTypes());
00141 for (int ivar = 0; ivar < a_lph.nComp(); ivar++)
00142 {
00143 for (int ivec = 0; ivec < dataPtrsLph.size(); ivec++)
00144 {
00145 dataPtrsLph[ivec] = a_lph.dataPtr(ivec, ivar);
00146 }
00147
00148 for (int idst = 0; idst < m_ebstencil.size(); idst++)
00149 {
00150 Real* lphPtr = dataPtrsLph[m_dstAccess[idst].dataID] + m_dstAccess[idst].offset;
00151 *lphPtr = m_cacheDst[idst][ivar];
00152 }
00153 }
00154 }
00155
00156
00157 #endif