DenseMatrixBase< T > Class Template Reference
#include <dense_matrix_base.h>

Public Member Functions | |
| virtual | ~DenseMatrixBase () |
| virtual void | zero ()=0 |
| virtual T | el (const unsigned int i, const unsigned int j) const =0 |
| virtual T & | el (const unsigned int i, const unsigned int j)=0 |
| virtual void | left_multiply (const DenseMatrixBase< T > &M2)=0 |
| virtual void | right_multiply (const DenseMatrixBase< T > &M3)=0 |
| unsigned int | m () const |
| unsigned int | n () const |
| void | print (std::ostream &os) const |
| void | print_scientific (std::ostream &os) const |
| template<typename T2 , typename T3 > | |
| boostcopy::enable_if_c < ScalarTraits< T2 >::value, void >::type | add (const T2 factor, const DenseMatrixBase< T3 > &mat) |
Protected Member Functions | |
| DenseMatrixBase (const unsigned int m=0, const unsigned int n=0) | |
| void | multiply (DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3) |
| void | condense (const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs) |
Protected Attributes | |
| unsigned int | _m |
| unsigned int | _n |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const DenseMatrixBase< T > &m) |
Detailed Description
template<typename T>
class DenseMatrixBase< T >
Defines an abstract dense matrix base class for use in Finite Element-type computations. Specialized dense matrices, for example DenseSubMatrices, can be derived from this class.
Definition at line 45 of file dense_matrix_base.h.
Constructor & Destructor Documentation
| DenseMatrixBase< T >::DenseMatrixBase | ( | const unsigned int | m = 0, |
|
| const unsigned int | n = 0 | |||
| ) | [inline, protected] |
| virtual DenseMatrixBase< T >::~DenseMatrixBase | ( | ) | [inline, virtual] |
Member Function Documentation
| boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type DenseMatrixBase< T >::add | ( | const T2 | factor, | |
| const DenseMatrixBase< T3 > & | mat | |||
| ) | [inline] |
Adds factor to every element in the matrix. This should only work if T += T2 * T3 is valid C++ and if T2 is scalar. Return type is void
Definition at line 183 of file dense_matrix_base.h.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
00185 { 00186 libmesh_assert (this->m() == mat.m()); 00187 libmesh_assert (this->n() == mat.n()); 00188 00189 for (unsigned int j=0; j<this->n(); j++) 00190 for (unsigned int i=0; i<this->m(); i++) 00191 this->el(i,j) += factor*mat.el(i,j); 00192 }
| void DenseMatrixBase< T >::condense | ( | const unsigned int | i, | |
| const unsigned int | j, | |||
| const T | val, | |||
| DenseVectorBase< T > & | rhs | |||
| ) | [inline, protected] |
Condense-out the (i,j) entry of the matrix, forcing it to take on the value val. This is useful in numerical simulations for applying boundary conditions. Preserves the symmetry of the matrix.
Definition at line 57 of file dense_matrix_base.C.
References DenseMatrixBase< T >::_m, DenseMatrixBase< T >::el(), DenseVectorBase< T >::el(), DenseMatrixBase< T >::m(), DenseMatrixBase< T >::n(), and DenseVectorBase< T >::size().
00061 { 00062 libmesh_assert (this->_m == rhs.size()); 00063 libmesh_assert (iv == jv); 00064 00065 00066 // move the known value into the RHS 00067 // and zero the column 00068 for (unsigned int i=0; i<this->m(); i++) 00069 { 00070 rhs.el(i) -= this->el(i,jv)*val; 00071 this->el(i,jv) = 0.; 00072 } 00073 00074 // zero the row 00075 for (unsigned int j=0; j<this->n(); j++) 00076 this->el(iv,j) = 0.; 00077 00078 this->el(iv,jv) = 1.; 00079 rhs.el(iv) = val; 00080 00081 }
| virtual T& DenseMatrixBase< T >::el | ( | const unsigned int | i, | |
| const unsigned int | j | |||
| ) | [pure virtual] |
- Returns:
- the
(i,j) element of the matrix as a writeable reference. Since internal data representations may differ, you must redefine this function.
Implemented in DenseMatrix< T >, and DenseMatrix< Real >.
| virtual T DenseMatrixBase< T >::el | ( | const unsigned int | i, | |
| const unsigned int | j | |||
| ) | const [pure virtual] |
- Returns:
- the
(i,j) element of the matrix. Since internal data representations may differ, you must redefine this function.
Implemented in DenseMatrix< T >, and DenseMatrix< Real >.
Referenced by DenseMatrixBase< T >::add(), DenseMatrixBase< T >::condense(), DenseMatrixBase< T >::multiply(), DenseMatrixBase< T >::print(), and DenseMatrixBase< T >::print_scientific().
| virtual void DenseMatrixBase< T >::left_multiply | ( | const DenseMatrixBase< T > & | M2 | ) | [pure virtual] |
Performs the operation: (*this) <- M2 * (*this)
Implemented in DenseMatrix< T >, and DenseMatrix< Real >.
| unsigned int DenseMatrixBase< T >::m | ( | ) | const [inline] |
- Returns:
- the row-dimension of the matrix.
Definition at line 98 of file dense_matrix_base.h.
References DenseMatrixBase< T >::_m.
Referenced by DenseMatrix< T >::_cholesky_back_substitute(), DenseMatrix< T >::_cholesky_decompose(), DenseMatrix< T >::_lu_back_substitute(), DenseMatrix< T >::_lu_back_substitute_lapack(), DenseMatrix< T >::_lu_decompose(), DenseMatrix< T >::_lu_decompose_lapack(), DenseMatrix< T >::_matvec_blas(), DenseMatrix< T >::_multiply_blas(), DenseMatrixBase< T >::add(), EpetraMatrix< T >::add_matrix(), PetscMatrix< T >::add_matrix(), LaspackMatrix< T >::add_matrix(), DofMap::build_constraint_matrix(), DenseMatrixBase< T >::condense(), DofMap::constrain_element_dyad_matrix(), DofMap::constrain_element_matrix(), DofMap::constrain_element_matrix_and_vector(), DofMap::constrain_element_vector(), DenseMatrix< T >::det(), DofMap::extract_local_vector(), DenseMatrix< T >::get_principal_submatrix(), DenseMatrix< T >::get_transpose(), DenseMatrix< T >::left_multiply(), DenseMatrix< T >::left_multiply_transpose(), DenseMatrix< T >::lu_solve(), DofMap::max_constraint_error(), DenseMatrixBase< T >::multiply(), PatchRecoveryErrorEstimator::EstimateError::operator()(), DenseMatrixBase< T >::print(), DenseMatrixBase< T >::print_scientific(), DenseMatrix< T >::right_multiply(), DenseMatrix< T >::right_multiply_transpose(), and DenseMatrix< T >::vector_mult().
00098 { return _m; }
| void DenseMatrixBase< T >::multiply | ( | DenseMatrixBase< T > & | M1, | |
| const DenseMatrixBase< T > & | M2, | |||
| const DenseMatrixBase< T > & | M3 | |||
| ) | [inline, protected] |
Performs the computation M1 = M2 * M3 where: M1 = (m x n) M2 = (m x p) M3 = (p x n)
Definition at line 30 of file dense_matrix_base.C.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
Referenced by DenseMatrix< T >::left_multiply(), and DenseMatrix< T >::right_multiply().
00033 { 00034 // Assertions to make sure we have been 00035 // passed matrices of the correct dimension. 00036 libmesh_assert (M1.m() == M2.m()); 00037 libmesh_assert (M1.n() == M3.n()); 00038 libmesh_assert (M2.n() == M3.m()); 00039 00040 const unsigned int m_s = M2.m(); 00041 const unsigned int p_s = M2.n(); 00042 const unsigned int n_s = M1.n(); 00043 00044 // Do it this way because there is a 00045 // decent chance (at least for constraint matrices) 00046 // that M3(k,j) = 0. when right-multiplying. 00047 for (unsigned int k=0; k<p_s; k++) 00048 for (unsigned int j=0; j<n_s; j++) 00049 if (M3.el(k,j) != 0.) 00050 for (unsigned int i=0; i<m_s; i++) 00051 M1.el(i,j) += M2.el(i,k) * M3.el(k,j); 00052 }
| unsigned int DenseMatrixBase< T >::n | ( | ) | const [inline] |
- Returns:
- the column-dimension of the matrix.
Definition at line 103 of file dense_matrix_base.h.
References DenseMatrixBase< T >::_n.
Referenced by DenseMatrix< T >::_cholesky_back_substitute(), DenseMatrix< T >::_cholesky_decompose(), DenseMatrix< T >::_lu_back_substitute(), DenseMatrix< T >::_lu_decompose_lapack(), DenseMatrix< T >::_matvec_blas(), DenseMatrix< T >::_multiply_blas(), DenseMatrixBase< T >::add(), EpetraMatrix< T >::add_matrix(), PetscMatrix< T >::add_matrix(), LaspackMatrix< T >::add_matrix(), DofMap::build_constraint_matrix(), DenseMatrixBase< T >::condense(), DofMap::constrain_element_dyad_matrix(), DofMap::constrain_element_matrix(), DofMap::constrain_element_matrix_and_vector(), DofMap::constrain_element_vector(), DofMap::extract_local_vector(), DenseMatrix< T >::get_principal_submatrix(), DenseMatrix< T >::get_transpose(), DenseMatrix< T >::left_multiply(), DenseMatrix< T >::left_multiply_transpose(), DenseMatrix< T >::lu_solve(), DofMap::max_constraint_error(), DenseMatrixBase< T >::multiply(), PatchRecoveryErrorEstimator::EstimateError::operator()(), DenseMatrixBase< T >::print(), DenseMatrixBase< T >::print_scientific(), DenseMatrix< T >::right_multiply(), DenseMatrix< T >::right_multiply_transpose(), and DenseMatrix< T >::vector_mult().
00103 { return _n; }
| void DenseMatrixBase< T >::print | ( | std::ostream & | os | ) | const [inline] |
Pretty-print the matrix to stdout.
Definition at line 127 of file dense_matrix_base.C.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
00128 { 00129 for (unsigned int i=0; i<this->m(); i++) 00130 { 00131 for (unsigned int j=0; j<this->n(); j++) 00132 os << std::setw(8) 00133 << this->el(i,j) << " "; 00134 00135 os << std::endl; 00136 } 00137 00138 return; 00139 }
| void DenseMatrixBase< T >::print_scientific | ( | std::ostream & | os | ) | const [inline] |
Prints the matrix entries with more decimal places in scientific notation.
Definition at line 85 of file dense_matrix_base.C.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
00086 { 00087 #ifndef LIBMESH_BROKEN_IOSTREAM 00088 00089 // save the initial format flags 00090 std::ios_base::fmtflags os_flags = os.flags(); 00091 00092 // Print the matrix entries. 00093 for (unsigned int i=0; i<this->m(); i++) 00094 { 00095 for (unsigned int j=0; j<this->n(); j++) 00096 os << std::setw(15) 00097 << std::scientific 00098 << std::setprecision(8) 00099 << this->el(i,j) << " "; 00100 00101 os << std::endl; 00102 } 00103 00104 // reset the original format flags 00105 os.flags(os_flags); 00106 00107 #else 00108 00109 // Print the matrix entries. 00110 for (unsigned int i=0; i<this->m(); i++) 00111 { 00112 for (unsigned int j=0; j<this->n(); j++) 00113 os << std::setprecision(8) 00114 << this->el(i,j) 00115 << " "; 00116 00117 os << std::endl; 00118 } 00119 00120 00121 #endif 00122 }
| virtual void DenseMatrixBase< T >::right_multiply | ( | const DenseMatrixBase< T > & | M3 | ) | [pure virtual] |
Performs the operation: (*this) <- (*this) * M3
Implemented in DenseMatrix< T >, and DenseMatrix< Real >.
| virtual void DenseMatrixBase< T >::zero | ( | ) | [pure virtual] |
Set every element in the matrix to 0. You must redefine what you mean by zeroing the matrix since it depends on how your values are stored.
Implemented in DenseMatrix< T >, and DenseMatrix< Real >.
Friends And Related Function Documentation
| std::ostream& operator<< | ( | std::ostream & | os, | |
| const DenseMatrixBase< T > & | m | |||
| ) | [friend] |
Formatted print as above but allows you to do DenseMatrix K; std::cout << K << std::endl;
Definition at line 115 of file dense_matrix_base.h.
00116 { 00117 m.print(os); 00118 return os; 00119 }
Member Data Documentation
unsigned int DenseMatrixBase< T >::_m [protected] |
The row dimension.
Definition at line 164 of file dense_matrix_base.h.
Referenced by DenseMatrix< T >::_multiply_blas(), DenseMatrixBase< T >::condense(), DenseMatrix< T >::l1_norm(), DenseMatrix< T >::linfty_norm(), DenseMatrixBase< T >::m(), DenseMatrix< T >::max(), DenseMatrix< T >::min(), DenseMatrix< T >::operator()(), DenseMatrix< T >::operator=(), DenseMatrix< T >::resize(), and DenseMatrix< T >::swap().
unsigned int DenseMatrixBase< T >::_n [protected] |
The column dimension.
Definition at line 169 of file dense_matrix_base.h.
Referenced by DenseMatrix< T >::_multiply_blas(), DenseMatrix< T >::l1_norm(), DenseMatrix< T >::linfty_norm(), DenseMatrix< T >::max(), DenseMatrix< T >::min(), DenseMatrixBase< T >::n(), DenseMatrix< T >::operator()(), DenseMatrix< T >::operator=(), DenseMatrix< T >::resize(), and DenseMatrix< T >::swap().
The documentation for this class was generated from the following files: