![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsSparseVector_Matrix3x3.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (12/22/2009) 00009 UPDATE (04/10/2009) 00010 ******************************************************************************/ 00011 #include "TAPsSparseVector_Matrix3x3.hpp" 00012 // Using Inclusion Model (i.e. definitions are included in declarations) 00013 // (this name.cpp is included in name.hpp) 00014 // Each friend is defined directly inside its declaration. 00015 00016 BEGIN_NAMESPACE_TAPs 00017 //============================================================================= 00018 // Constructors 00019 //----------------------------------------------------------------------------- 00020 template <typename T> 00021 SparseVector_Matrix3x3<T>::SparseVector_Matrix3x3 ( unsigned int size ) 00022 : m_List( size ) 00023 {} 00024 //----------------------------------------------------------------------------- 00025 template <typename T> 00026 SparseVector_Matrix3x3<T>::SparseVector_Matrix3x3 ( SparseVector_Matrix3x3<T> const &orig ) 00027 { 00028 m_List = orig.m_List; 00029 } 00030 //----------------------------------------------------------------------------- 00031 template <typename T> 00032 SparseVector_Matrix3x3<T>::~SparseVector_Matrix3x3 () 00033 { 00034 00035 } 00036 //----------------------------------------------------------------------------- 00037 template <typename T> 00038 std::string SparseVector_Matrix3x3<T>::StrInfo () const 00039 { 00040 std::ostringstream ss; 00041 ss << "SparseVector_Matrix3x3<" << typeid(T).name() << "> has " << m_List.size() << " elements:\n"; 00042 std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator it = m_List.begin(); 00043 while ( it != m_List.end() ) { 00044 ss << "idx:"<<it->idx<<"\t"<< it->M << "\n"; 00045 ++it; 00046 } 00047 return ss.str(); 00048 } 00049 //----------------------------------------------------------------------------- 00050 00051 //============================================================================= 00052 // Assignment Operator 00053 //----------------------------------------------------------------------------- 00054 template <typename T> 00055 SparseVector_Matrix3x3<T> & SparseVector_Matrix3x3<T>::operator= ( SparseVector_Matrix3x3<T> const &orig ) 00056 { 00057 m_List = orig.m_List; 00058 return *this; 00059 } 00060 //----------------------------------------------------------------------------- 00061 template <typename T> 00062 void SparseVector_Matrix3x3<T>::SetTo ( SparseVector_Matrix3x3<T> const &orig ) 00063 { 00064 assert( m_List.size() == orig.m_List.size() ); 00065 std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator A = orig.m_List.begin(); 00066 std::list< SparseVector_Matrix3x3_ElementData<T> >::iterator B = m_List.begin(); 00067 while ( B != m_List.end() ) { 00068 B->M[0] = A->M[0]; 00069 B->M[1] = A->M[1]; 00070 B->M[2] = A->M[2]; 00071 B->M[3] = A->M[3]; 00072 B->M[4] = A->M[4]; 00073 B->M[5] = A->M[5]; 00074 B->M[6] = A->M[6]; 00075 B->M[7] = A->M[7]; 00076 B->M[8] = A->M[8]; 00077 ++A; 00078 ++B; 00079 } 00080 } 00081 //----------------------------------------------------------------------------- 00082 //============================================================================= 00083 00084 //============================================================================= 00085 // Assignment Operator 00086 //----------------------------------------------------------------------------- 00087 template <typename T> 00088 bool SparseVector_Matrix3x3<T>::Insert ( unsigned int index, Matrix3x3<T> const &M ) 00089 { 00090 std::list< SparseVector_Matrix3x3_ElementData<T> >::iterator it = m_List.begin(); 00091 while( it != m_List.end() ) { 00092 if ( it->idx >= index ) { 00093 if ( it->idx == index ) return false; 00094 m_List.insert( it, SparseVector_Matrix3x3_ElementData<T>( index, M ) ); 00095 return true; 00096 } 00097 ++it; 00098 } 00099 m_List.push_back( SparseVector_Matrix3x3_ElementData<T>( index, M ) ); 00100 return true; 00101 } 00102 //----------------------------------------------------------------------------- 00103 00104 //============================================================================= 00105 // Operations 00106 //----------------------------------------------------------------------------- 00107 template <typename T> 00108 Vector3<T> SparseVector_Matrix3x3<T>::Mul ( 00109 std::vector< Vector3<T> > const &V // input: a dense vector 00110 ) const 00111 { 00112 Vector3<T> O; 00113 std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator it = m_List.begin(); 00114 while ( it != m_List.end() ) { 00115 O += it->M * V[it->idx]; 00116 ++it; 00117 } 00118 return O; 00119 } 00121 //template <typename T> 00122 //Vector3<T> SparseVector_Matrix3x3<T>::MulForFEM_wSkippedElements ( 00123 // std::vector< Vector3<T> > const &V, // input: a dense vector 00124 // std::vector< bool > const &Skip //!< input: list of skipped rows 00125 //) const 00126 //{ 00127 // Vector3<T> O; 00128 // std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator it = m_List.begin(); 00129 // while ( it != m_List.end() ) { 00130 // if ( Skip[it->idx] == false ) { 00131 // O += it->M * V[it->idx]; 00132 // } 00133 // ++it; 00134 // } 00135 // return O; 00136 //} 00137 //----------------------------------------------------------------------------- 00138 template <typename T> 00139 void SparseVector_Matrix3x3<T>::MulForSparseSymmetricMatrix ( 00140 unsigned int r, // input: the row of the sparse matrix that this vector is from 00141 std::vector< Vector3<T> > const &I, // input: a dense vector 00142 std::vector< Vector3<T> > &O // output: a dense vector 00143 ) const 00144 { 00145 std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator it = m_List.begin(); 00146 O[r] += it->M * I[r]; 00147 ++it; 00148 while ( it != m_List.end() ) { 00149 //O[r] += it->M * I[it->idx]; 00150 O[r][0] += it->M[0]*I[it->idx][0] + it->M[1]*I[it->idx][1] + it->M[2]*I[it->idx][2]; 00151 O[r][1] += it->M[3]*I[it->idx][0] + it->M[4]*I[it->idx][1] + it->M[5]*I[it->idx][2]; 00152 O[r][2] += it->M[6]*I[it->idx][0] + it->M[7]*I[it->idx][1] + it->M[8]*I[it->idx][2]; 00153 //O[it->idx] += it->M.GetTranspose() * I[r]; 00154 O[it->idx][0] += it->M[0]*I[r][0] + it->M[3]*I[r][1] + it->M[6]*I[r][2]; 00155 O[it->idx][1] += it->M[1]*I[r][0] + it->M[4]*I[r][1] + it->M[7]*I[r][2]; 00156 O[it->idx][2] += it->M[2]*I[r][0] + it->M[5]*I[r][1] + it->M[8]*I[r][2]; 00157 ++it; 00158 } 00159 } 00160 //----------------------------------------------------------------------------- 00161 template <typename T> 00162 void SparseVector_Matrix3x3<T>::UpdateAdd ( unsigned int index, Matrix3x3<T> const &M ) 00163 { 00164 std::list< SparseVector_Matrix3x3_ElementData<T> >::iterator it = m_List.begin(); 00165 while( it != m_List.end() ) { 00166 if ( it->idx >= index ) { 00167 // Update the data 00168 if ( it->idx == index ) { 00169 it->M += M; 00170 } 00171 // Insert the data into the list 00172 else { 00173 m_List.insert( it, SparseVector_Matrix3x3_ElementData<T>( index, M ) ); 00174 } 00175 return; 00176 } 00177 ++it; 00178 } 00179 // Add as the first element 00180 m_List.push_back( SparseVector_Matrix3x3_ElementData<T>( index, M ) ); 00181 } 00182 //----------------------------------------------------------------------------- 00183 template <typename T> 00184 bool SparseVector_Matrix3x3<T>::Remove ( unsigned int index ) 00185 { 00186 std::list< Data_xyz<T> >::iterator it = m_List.begin(); 00187 while( it != m_List.end() ) { 00188 if ( it->idx == index ) { 00189 m_List.erase( it ); 00190 return true; 00191 } 00192 ++it; 00193 } 00194 return false; 00195 } 00196 //----------------------------------------------------------------------------- 00197 template <typename T> 00198 bool SparseVector_Matrix3x3<T>::SetData ( unsigned int index, Matrix3x3<T> const &M ) 00199 { 00200 std::list< Data_xyz<T> >::iterator it = m_List.begin(); 00201 while( it != m_List.end() ) { 00202 if ( it->idx == index ) { 00203 it->M = M; 00204 return true; 00205 } 00206 ++it; 00207 } 00208 return false; 00209 } 00210 //----------------------------------------------------------------------------- 00211 template <typename T> 00212 Matrix3x3<T> * SparseVector_Matrix3x3<T>::ReturnMatrix3x3 ( unsigned int index ) 00213 { 00214 std::list< SparseVector_Matrix3x3_ElementData<T> >::iterator it = m_List.begin(); 00215 while( it != m_List.end() ) { 00216 if ( it->idx == index ) { 00217 return &(it->M); 00218 } 00219 ++it; 00220 } 00221 return NULL; 00222 } 00223 //----------------------------------------------------------------------------- 00224 template <typename T> 00225 Matrix3x3<T> const * SparseVector_Matrix3x3<T>::ReturnMatrix3x3 ( unsigned int index ) const 00226 { 00227 std::list< SparseVector_Matrix3x3_ElementData<T> >::const_iterator it = m_List.begin(); 00228 while( it != m_List.end() ) { 00229 if ( it->idx == index ) { 00230 return &(it->M); 00231 } 00232 ++it; 00233 } 00234 return NULL; 00235 } 00236 //----------------------------------------------------------------------------- 00237 template <typename T> 00238 unsigned int SparseVector_Matrix3x3<T>::NumOfElements () const 00239 { 00240 return m_List.size(); 00241 } 00242 //----------------------------------------------------------------------------- 00243 template <typename T> 00244 std::list< SparseVector_Matrix3x3_ElementData<T> > const & 00245 SparseVector_Matrix3x3<T>::RefToElements () const 00246 { 00247 return m_List; 00248 } 00249 //----------------------------------------------------------------------------- 00250 template <typename T> 00251 std::list< SparseVector_Matrix3x3_ElementData<T> > & 00252 SparseVector_Matrix3x3<T>::RefToElements () 00253 { 00254 return m_List; 00255 } 00256 //----------------------------------------------------------------------------- 00257 //============================================================================= 00258 00259 //============================================================================= 00260 END_NAMESPACE_TAPs 00261 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00262 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----