00001 #include "CH_Timer.H"
00002 #include "Box.H"
00003 template <class TCoef>
00004 Stencil<TCoef>::Stencil(){};
00005 template <class TCoef>
00006 Stencil<TCoef>::Stencil(pair<Shift,TCoef> a_pair,
00007 Point a_destRefratio,
00008 Shift a_destShift,
00009 Point a_srcRefratio)
00010 {
00011 m_coef.push_back(a_pair.second);
00012 m_offsets.push_back(a_pair.first.m_shift);
00013 m_destRefratio = a_destRefratio;
00014 m_srcRefratio = a_srcRefratio;
00015 m_destShift = a_destShift.m_shift;
00016 };
00017
00018 template <class TCoef>
00019 Stencil<TCoef>::Stencil(vector<TCoef> a_vecT,
00020 vector<Point> a_vecPt,
00021 Point a_destRefratio,
00022 Point a_destShift,
00023 Point a_srcRefratio)
00024 {
00025 m_coef = a_vecT;
00026 m_offsets = a_vecPt;
00027 m_destRefratio = a_destRefratio;
00028 m_srcRefratio = a_srcRefratio;
00029 m_destShift = a_destShift;
00030
00031 };
00032
00033 template <class TCoef>
00034 Stencil<TCoef> Stencil<TCoef>::operator+
00035 (const Stencil<TCoef> a_stencil) const
00036 {
00037 if ((m_destShift != a_stencil.m_destShift) ||
00038 (m_destRefratio != a_stencil.m_destRefratio))
00039 {
00040 cout << "error - trying to add two stencils with different"
00041 << " LHS shifts / ratios" << endl;
00042 abort();
00043 }
00044 vector<TCoef> newCoefs = a_stencil.m_coef;
00045 vector<Point> newOffsets = a_stencil.m_offsets;
00046 for (int l1 = 0 ; l1 < m_coef.size();l1++)
00047 {
00048 Point loc = m_offsets[l1];
00049 bool isThere = false;
00050 int locThere;
00051 for (int l2 = 0;l2 < a_stencil.m_coef.size();l2++)
00052 {
00053 if (a_stencil.m_offsets[l2] == loc)
00054 {
00055 isThere = true;
00056 locThere = l2;
00057 }
00058 }
00059 if (isThere)
00060 {
00061 newCoefs[locThere] += m_coef[l1];
00062 }
00063 else
00064 {
00065 newCoefs.push_back(m_coef[l1]);
00066 newOffsets.push_back(m_offsets[l1]);
00067 }
00068 }
00069 return Stencil(newCoefs,newOffsets,m_destRefratio,m_destShift,m_srcRefratio);
00070 };
00071
00072 template <class TCoef>
00073 Stencil<TCoef> Stencil<TCoef>::operator*
00074 (const Stencil<TCoef> a_stencil) const
00075 {
00076 cout << "warning - this is wrong. Must fix." << endl;
00077 abort();
00078 vector<TCoef> newCoefs = a_stencil.m_coef;
00079 vector<Point> newOffsets = a_stencil.m_offsets;
00080 for (int l1 = 0 ; l1 < m_coef.size();l1++)
00081 {
00082 Point loc = m_offsets[l1];
00083 int locThere;
00084 bool isThere = false;
00085 for (int l2 = 0;l2 < a_stencil.m_coef.size();l2++)
00086 {
00087 if (a_stencil.m_offsets[l2] == loc)
00088 {
00089 isThere = true;
00090 locThere = l2;
00091 }
00092 }
00093 if (isThere)
00094 {
00095 newCoefs[locThere] += m_coef[l1];
00096 }
00097 else
00098 {
00099 newCoefs.push_back(m_coef[l1]);
00100 newOffsets.push_back(m_offsets[l1]);
00101 }
00102 }
00103 return Stencil(newCoefs,newOffsets,m_destRefratio,m_destShift,m_srcRefratio);
00104 };
00105
00106 template <class TCoef>
00107 void Stencil<TCoef>::operator*=(const TCoef& a_coef)
00108 {
00109 for (int l = 0; l < m_coef.size(); l++)
00110 {
00111 m_coef[l]*=a_coef;
00112 }
00113 };
00114
00115 template <class TCoef>
00116 void Stencil<TCoef>::stencilDump() const
00117 {
00118 Stencil<TCoef> tmp = *this;
00119 cout << "coefs and offsets :" << endl ;
00120 for (int k = 0; k < tmp.m_coef.size(); k++)
00121 {
00122 cout << k << " , "<< m_coef[k] << " , ( " ;
00123 for (int dir = 0;dir < DIM; dir++)
00124 {
00125 cout << tmp.m_offsets[k][dir] << " ";
00126 }
00127 cout << ") ; " ;
00128 cout << endl;
00129 }
00130 cout << "sourceRef, destRef, and destShift: " << m_srcRefratio << m_destRefratio << m_destShift << endl ;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 cout << endl;
00149 };
00150
00151
00152
00153
00154
00155