$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_MATRIX_BASE_H 00021 #define LIBMESH_DENSE_MATRIX_BASE_H 00022 00023 // Local Includes 00024 #include "libmesh/libmesh_common.h" 00025 #include "libmesh/compare_types.h" 00026 00027 // C++ includes 00028 00029 namespace libMesh 00030 { 00031 00032 // Forward Delcarations 00033 template <typename T> class DenseVectorBase; 00034 00035 00036 00037 00045 template<typename T> 00046 class DenseMatrixBase 00047 { 00048 00049 protected: 00054 DenseMatrixBase(const unsigned int new_m=0, 00055 const unsigned int new_n=0) : _m(new_m), _n(new_n) {} 00056 00057 public: 00061 virtual ~DenseMatrixBase() {} 00062 00068 virtual void zero() = 0; 00069 00075 virtual T el(const unsigned int i, 00076 const unsigned int j) const = 0; 00077 00083 virtual T & el(const unsigned int i, 00084 const unsigned int j) = 0; 00085 00089 virtual void left_multiply (const DenseMatrixBase<T>& M2) = 0; 00090 00094 virtual void right_multiply (const DenseMatrixBase<T>& M3) = 0; 00095 00099 unsigned int m() const { return _m; } 00100 00104 unsigned int n() const { return _n; } 00105 00109 void print(std::ostream& os = libMesh::out) const; 00110 00116 friend std::ostream& operator << (std::ostream& os, const DenseMatrixBase<T>& m) 00117 { 00118 m.print(os); 00119 return os; 00120 } 00121 00126 void print_scientific(std::ostream& os) const; 00127 00133 template <typename T2, typename T3> 00134 typename boostcopy::enable_if_c< 00135 ScalarTraits<T2>::value, void >::type 00136 add (const T2 factor, 00137 const DenseMatrixBase<T3>& mat); 00138 00139 protected: 00140 00147 void multiply (DenseMatrixBase<T>& M1, 00148 const DenseMatrixBase<T>& M2, 00149 const DenseMatrixBase<T>& M3); 00150 00157 void condense(const unsigned int i, 00158 const unsigned int j, 00159 const T val, 00160 DenseVectorBase<T>& rhs); 00161 00165 unsigned int _m; 00166 00170 unsigned int _n; 00171 }; 00172 00173 00174 00175 00176 00177 00178 00179 template<typename T> 00180 template<typename T2, typename T3> 00181 inline 00182 typename boostcopy::enable_if_c< 00183 ScalarTraits<T2>::value, void >::type 00184 DenseMatrixBase<T>::add (const T2 factor, 00185 const DenseMatrixBase<T3>& mat) 00186 { 00187 libmesh_assert_equal_to (this->m(), mat.m()); 00188 libmesh_assert_equal_to (this->n(), mat.n()); 00189 00190 for (unsigned int j=0; j<this->n(); j++) 00191 for (unsigned int i=0; i<this->m(); i++) 00192 this->el(i,j) += factor*mat.el(i,j); 00193 } 00194 00195 00196 } // namespace libMesh 00197 00198 #endif // LIBMESH_DENSE_MATRIX_BASE_H