$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_DENSE_SUBMATRIX_H 00021 #define LIBMESH_DENSE_SUBMATRIX_H 00022 00023 // Local Includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/dense_matrix.h" 00026 #include "libmesh/dense_subvector.h" 00027 00028 // C++ includes 00029 00030 namespace libMesh 00031 { 00032 00033 00034 00043 // ------------------------------------------------------------ 00044 // DenseSubMatrix class definition 00045 template<typename T> 00046 class DenseSubMatrix : public DenseMatrixBase<T> 00047 { 00048 public: 00049 00056 DenseSubMatrix(DenseMatrix<T>& new_parent, 00057 const unsigned int ioff=0, 00058 const unsigned int joff=0, 00059 const unsigned int m=0, 00060 const unsigned int n=0); 00061 00065 DenseSubMatrix (const DenseSubMatrix<T>& other_matrix); 00066 00070 virtual ~DenseSubMatrix() {} 00071 00072 00076 DenseMatrix<T>& parent () { return _parent_matrix; } 00077 00081 virtual void zero(); 00082 00086 T operator() (const unsigned int i, 00087 const unsigned int j) const; 00088 00092 T & operator() (const unsigned int i, 00093 const unsigned int j); 00094 00098 virtual T el(const unsigned int i, 00099 const unsigned int j) const { return (*this)(i,j); } 00100 00104 virtual T & el(const unsigned int i, 00105 const unsigned int j) { return (*this)(i,j); } 00106 00110 virtual void left_multiply (const DenseMatrixBase<T>& M2); 00111 00115 virtual void right_multiply (const DenseMatrixBase<T>& M3); 00116 00120 void reposition(const unsigned int ioff, 00121 const unsigned int joff, 00122 const unsigned int new_m, 00123 const unsigned int new_n); 00124 00128 unsigned int i_off() const { return _i_off; } 00129 00133 unsigned int j_off() const { return _j_off; } 00134 00141 void condense(const unsigned int i, 00142 const unsigned int j, 00143 const T val, 00144 DenseSubVector<T>& rhs) 00145 { 00146 this->parent().condense(this->i_off()+i, 00147 this->j_off()+j, 00148 val, rhs.parent()); 00149 } 00150 00151 private: 00152 00156 DenseMatrix<T>& _parent_matrix; 00157 00161 unsigned int _i_off; 00162 00166 unsigned int _j_off; 00167 }; 00168 00169 00170 // -------------------------------------------------- 00171 // Constructor 00172 template<typename T> 00173 inline 00174 DenseSubMatrix<T>::DenseSubMatrix(DenseMatrix<T>& new_parent, 00175 const unsigned int ioff, 00176 const unsigned int joff, 00177 const unsigned int new_m, 00178 const unsigned int new_n) 00179 : DenseMatrixBase<T>(new_m,new_n), 00180 _parent_matrix(new_parent) 00181 { 00182 this->reposition (ioff, joff, new_m, new_n); 00183 } 00184 00185 00186 // Copy Constructor 00187 template<typename T> 00188 inline 00189 DenseSubMatrix<T>::DenseSubMatrix(const DenseSubMatrix<T>& other_matrix) 00190 : DenseMatrixBase<T>(other_matrix._m, other_matrix._n), 00191 _parent_matrix(other_matrix._parent_matrix) 00192 { 00193 _i_off = other_matrix._i_off; 00194 _j_off = other_matrix._j_off; 00195 } 00196 00197 00198 template<typename T> 00199 inline 00200 void DenseSubMatrix<T>::reposition(const unsigned int ioff, 00201 const unsigned int joff, 00202 const unsigned int new_m, 00203 const unsigned int new_n) 00204 { 00205 _i_off = ioff; 00206 _j_off = joff; 00207 this->_m = new_m; 00208 this->_n = new_n; 00209 00210 // Make sure we still fit in the parent matrix. 00211 libmesh_assert_less_equal ((this->i_off() + this->m()), _parent_matrix.m()); 00212 libmesh_assert_less_equal ((this->j_off() + this->n()), _parent_matrix.n()); 00213 } 00214 00215 00216 00217 template<typename T> 00218 inline 00219 void DenseSubMatrix<T>::zero() 00220 { 00221 for (unsigned int i=0; i<this->m(); i++) 00222 for (unsigned int j=0; j<this->n(); j++) 00223 _parent_matrix(i + this->i_off(), 00224 j + this->j_off()) = 0.; 00225 } 00226 00227 00228 00229 template<typename T> 00230 inline 00231 T DenseSubMatrix<T>::operator () (const unsigned int i, 00232 const unsigned int j) const 00233 { 00234 libmesh_assert_less (i, this->m()); 00235 libmesh_assert_less (j, this->n()); 00236 libmesh_assert_less (i + this->i_off(), _parent_matrix.m()); 00237 libmesh_assert_less (j + this->j_off(), _parent_matrix.n()); 00238 00239 return _parent_matrix (i + this->i_off(), 00240 j + this->j_off()); 00241 } 00242 00243 00244 template<typename T> 00245 inline 00246 T & DenseSubMatrix<T>::operator () (const unsigned int i, 00247 const unsigned int j) 00248 { 00249 libmesh_assert_less (i, this->m()); 00250 libmesh_assert_less (j, this->n()); 00251 libmesh_assert_less (i + this->i_off(), _parent_matrix.m()); 00252 libmesh_assert_less (j + this->j_off(), _parent_matrix.n()); 00253 00254 return _parent_matrix (i + this->i_off(), 00255 j + this->j_off()); 00256 } 00257 00258 00259 } // namespace libMesh 00260 00261 00262 #endif // LIBMESH_DENSE_SUBMATRIX_H