libMesh
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
libMesh::DenseMatrixBase< T > Class Template Referenceabstract

Defines an abstract dense matrix base class for use in Finite Element-type computations. More...

#include <dense_matrix_base.h>

Inheritance diagram for libMesh::DenseMatrixBase< T >:
[legend]

Public Member Functions

virtual ~DenseMatrixBase ()
 Destructor. More...
 
virtual void zero ()=0
 Set every element in the matrix to 0. More...
 
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
 Performs the operation: (*this) <- M2 * (*this) More...
 
virtual void right_multiply (const DenseMatrixBase< T > &M3)=0
 Performs the operation: (*this) <- (*this) * M3. More...
 
unsigned int m () const
 
unsigned int n () const
 
void print (std::ostream &os=libMesh::out) const
 Pretty-print the matrix, by default to libMesh::out. More...
 
void print_scientific (std::ostream &os, unsigned precision=8) const
 Prints the matrix entries with more decimal places in scientific notation. More...
 
template<typename T2 , typename T3 >
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type add (const T2 factor, const DenseMatrixBase< T3 > &mat)
 Adds factor to every element in the matrix. More...
 

Protected Member Functions

 DenseMatrixBase (const unsigned int new_m=0, const unsigned int new_n=0)
 Constructor. More...
 
void condense (const unsigned int i, const unsigned int j, const T val, DenseVectorBase< T > &rhs)
 Condense-out the (i,j) entry of the matrix, forcing it to take on the value val. More...
 

Static Protected Member Functions

static void multiply (DenseMatrixBase< T > &M1, const DenseMatrixBase< T > &M2, const DenseMatrixBase< T > &M3)
 Helper function - Performs the computation M1 = M2 * M3 where: M1 = (m x n) M2 = (m x p) M3 = (p x n) More...
 

Protected Attributes

unsigned int _m
 The row dimension. More...
 
unsigned int _n
 The column dimension. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const DenseMatrixBase< T > &m)
 Formatted print as above but allows you to do DenseMatrix K; libMesh::out << K << std::endl;. More...
 

Detailed Description

template<typename T>
class libMesh::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.

Author
John W. Peterson
Date
2003

Definition at line 44 of file dense_matrix_base.h.

Constructor & Destructor Documentation

template<typename T>
libMesh::DenseMatrixBase< T >::DenseMatrixBase ( const unsigned int  new_m = 0,
const unsigned int  new_n = 0 
)
protected

Constructor.

Creates a dense matrix of dimension m by n. Protected so that there is no way the user can create one.

Definition at line 52 of file dense_matrix_base.h.

53  : _m(new_m), _n(new_n) {}
unsigned int _n
The column dimension.
unsigned int _m
The row dimension.
template<typename T>
virtual libMesh::DenseMatrixBase< T >::~DenseMatrixBase ( )
virtual

Member Function Documentation

template<typename T >
template<typename T2 , typename T3 >
boostcopy::enable_if_c< ScalarTraits< T2 >::value, void >::type libMesh::DenseMatrixBase< T >::add ( const T2  factor,
const DenseMatrixBase< T3 > &  mat 
)

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 libMesh::DenseMatrixBase< T >::el(), libMesh::DenseMatrixBase< T >::m(), and libMesh::DenseMatrixBase< T >::n().

185 {
186  libmesh_assert_equal_to (this->m(), mat.m());
187  libmesh_assert_equal_to (this->n(), mat.n());
188 
189  for (unsigned int j=0; j<this->n(); j++)
190  for (unsigned int i=0; i<this->m(); i++)
191  this->el(i,j) += factor*mat.el(i,j);
192 }
unsigned int n() const
unsigned int m() const
virtual T el(const unsigned int i, const unsigned int j) const =0
template<typename T >
void libMesh::DenseMatrixBase< T >::condense ( const unsigned int  i,
const unsigned int  j,
const T  val,
DenseVectorBase< T > &  rhs 
)
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 58 of file dense_matrix_base.C.

References libMesh::DenseVectorBase< T >::el(), and libMesh::DenseVectorBase< T >::size().

Referenced by libMesh::DenseMatrix< Real >::condense().

62 {
63  libmesh_assert_equal_to (this->_m, rhs.size());
64  libmesh_assert_equal_to (iv, jv);
65 
66 
67  // move the known value into the RHS
68  // and zero the column
69  for (unsigned int i=0; i<this->m(); i++)
70  {
71  rhs.el(i) -= this->el(i,jv)*val;
72  this->el(i,jv) = 0.;
73  }
74 
75  // zero the row
76  for (unsigned int j=0; j<this->n(); j++)
77  this->el(iv,j) = 0.;
78 
79  this->el(iv,jv) = 1.;
80  rhs.el(iv) = val;
81 
82 }
unsigned int n() const
unsigned int m() const
virtual T el(const unsigned int i, const unsigned int j) const =0
unsigned int _m
The row dimension.
template<typename T>
virtual T libMesh::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 libMesh::DenseSubMatrix< T >, libMesh::DenseMatrix< T >, libMesh::DenseMatrix< Number >, and libMesh::DenseMatrix< Real >.

Referenced by libMesh::DenseMatrixBase< T >::add(), libMesh::DenseMatrixBase< T >::multiply(), and libMesh::DenseMatrixBase< T >::~DenseMatrixBase().

template<typename T>
virtual T& libMesh::DenseMatrixBase< T >::el ( const unsigned int  i,
const unsigned int  j 
)
pure virtual
Returns
The (i,j) element of the matrix as a writable reference. Since internal data representations may differ, you must redefine this function.

Implemented in libMesh::DenseSubMatrix< T >, libMesh::DenseMatrix< T >, libMesh::DenseMatrix< Number >, and libMesh::DenseMatrix< Real >.

template<typename T>
virtual void libMesh::DenseMatrixBase< T >::left_multiply ( const DenseMatrixBase< T > &  M2)
pure virtual

Performs the operation: (*this) <- M2 * (*this)

Implemented in libMesh::DenseSubMatrix< T >, and libMesh::DenseMatrix< T >.

Referenced by libMesh::DenseMatrixBase< T >::~DenseMatrixBase().

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::m ( ) const
Returns
The row-dimension of the matrix.

Definition at line 97 of file dense_matrix_base.h.

References libMesh::DenseMatrixBase< T >::_m.

Referenced by libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_svd_solve_lapack(), libMesh::DenseMatrixBase< T >::add(), libMesh::DenseMatrix< T >::add(), libMesh::SparseMatrix< T >::add_block_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DofMap::build_constraint_matrix(), libMesh::DofMap::build_constraint_matrix_and_vector(), libMesh::DofMap::extract_local_vector(), libMesh::DofMap::get_local_constraints(), libMesh::DenseMatrix< T >::get_transpose(), libMesh::DofMap::heterogenously_constrain_element_matrix_and_vector(), libMesh::DofMap::heterogenously_constrain_element_vector(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DenseMatrix< T >::left_multiply_transpose(), libMesh::DofMap::max_constraint_error(), libMesh::DenseMatrixBase< T >::multiply(), libMesh::DenseSubMatrix< T >::operator()(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseSubMatrix< T >::reposition(), libMesh::DenseMatrix< T >::right_multiply(), libMesh::DenseMatrix< T >::right_multiply_transpose(), libMesh::DenseMatrix< T >::scale_column(), DenseMatrixTest::testEVD_helper(), DenseMatrixTest::testSVD(), and libMesh::DenseSubMatrix< T >::zero().

97 { return _m; }
unsigned int _m
The row dimension.
template<typename T >
void libMesh::DenseMatrixBase< T >::multiply ( DenseMatrixBase< T > &  M1,
const DenseMatrixBase< T > &  M2,
const DenseMatrixBase< T > &  M3 
)
staticprotected

Helper function - Performs the computation M1 = M2 * M3 where: M1 = (m x n) M2 = (m x p) M3 = (p x n)

Definition at line 31 of file dense_matrix_base.C.

References libMesh::DenseMatrixBase< T >::el(), libMesh::DenseMatrixBase< T >::m(), and libMesh::DenseMatrixBase< T >::n().

34 {
35  // Assertions to make sure we have been
36  // passed matrices of the correct dimension.
37  libmesh_assert_equal_to (M1.m(), M2.m());
38  libmesh_assert_equal_to (M1.n(), M3.n());
39  libmesh_assert_equal_to (M2.n(), M3.m());
40 
41  const unsigned int m_s = M2.m();
42  const unsigned int p_s = M2.n();
43  const unsigned int n_s = M1.n();
44 
45  // Do it this way because there is a
46  // decent chance (at least for constraint matrices)
47  // that M3(k,j) = 0. when right-multiplying.
48  for (unsigned int k=0; k<p_s; k++)
49  for (unsigned int j=0; j<n_s; j++)
50  if (M3.el(k,j) != 0.)
51  for (unsigned int i=0; i<m_s; i++)
52  M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
53 }
template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::n ( ) const
Returns
The column-dimension of the matrix.

Definition at line 102 of file dense_matrix_base.h.

References libMesh::DenseMatrixBase< T >::_n, libMesh::out, and libMesh::DenseMatrixBase< T >::print().

Referenced by libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_svd_solve_lapack(), libMesh::DenseMatrixBase< T >::add(), libMesh::DenseMatrix< T >::add(), libMesh::SparseMatrix< T >::add_block_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DofMap::build_constraint_matrix(), libMesh::DofMap::build_constraint_matrix_and_vector(), libMesh::DofMap::extract_local_vector(), libMesh::DofMap::get_local_constraints(), libMesh::DenseMatrix< T >::get_transpose(), libMesh::DofMap::heterogenously_constrain_element_matrix_and_vector(), libMesh::DofMap::heterogenously_constrain_element_vector(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DenseMatrix< T >::left_multiply_transpose(), libMesh::DofMap::max_constraint_error(), libMesh::DenseMatrixBase< T >::multiply(), libMesh::DenseSubMatrix< T >::operator()(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseSubMatrix< T >::reposition(), libMesh::DenseMatrix< T >::right_multiply(), libMesh::DenseMatrix< T >::right_multiply_transpose(), DenseMatrixTest::testSVD(), and libMesh::DenseSubMatrix< T >::zero().

102 { return _n; }
unsigned int _n
The column dimension.
template<typename T >
void libMesh::DenseMatrixBase< T >::print ( std::ostream &  os = libMesh::out) const

Pretty-print the matrix, by default to libMesh::out.

Definition at line 128 of file dense_matrix_base.C.

Referenced by libMesh::DenseMatrixBase< T >::n().

129 {
130  for (unsigned int i=0; i<this->m(); i++)
131  {
132  for (unsigned int j=0; j<this->n(); j++)
133  os << std::setw(8)
134  << this->el(i,j) << " ";
135 
136  os << std::endl;
137  }
138 
139  return;
140 }
unsigned int n() const
unsigned int m() const
virtual T el(const unsigned int i, const unsigned int j) const =0
template<typename T >
void libMesh::DenseMatrixBase< T >::print_scientific ( std::ostream &  os,
unsigned  precision = 8 
) const

Prints the matrix entries with more decimal places in scientific notation.

Definition at line 86 of file dense_matrix_base.C.

87 {
88 #ifndef LIBMESH_BROKEN_IOSTREAM
89 
90  // save the initial format flags
91  std::ios_base::fmtflags os_flags = os.flags();
92 
93  // Print the matrix entries.
94  for (unsigned int i=0; i<this->m(); i++)
95  {
96  for (unsigned int j=0; j<this->n(); j++)
97  os << std::setw(15)
98  << std::scientific
99  << std::setprecision(precision)
100  << this->el(i,j) << " ";
101 
102  os << std::endl;
103  }
104 
105  // reset the original format flags
106  os.flags(os_flags);
107 
108 #else
109 
110  // Print the matrix entries.
111  for (unsigned int i=0; i<this->m(); i++)
112  {
113  for (unsigned int j=0; j<this->n(); j++)
114  os << std::setprecision(precision)
115  << this->el(i,j)
116  << " ";
117 
118  os << std::endl;
119  }
120 
121 
122 #endif
123 }
unsigned int n() const
unsigned int m() const
virtual T el(const unsigned int i, const unsigned int j) const =0
template<typename T>
virtual void libMesh::DenseMatrixBase< T >::right_multiply ( const DenseMatrixBase< T > &  M3)
pure virtual

Performs the operation: (*this) <- (*this) * M3.

Implemented in libMesh::DenseMatrix< T >, and libMesh::DenseSubMatrix< T >.

Referenced by libMesh::DenseMatrixBase< T >::~DenseMatrixBase().

template<typename T>
virtual void libMesh::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 libMesh::DenseSubMatrix< T >, libMesh::DenseMatrix< T >, libMesh::DenseMatrix< Number >, and libMesh::DenseMatrix< Real >.

Referenced by libMesh::DenseMatrixBase< T >::~DenseMatrixBase().

Friends And Related Function Documentation

template<typename T>
std::ostream& operator<< ( std::ostream &  os,
const DenseMatrixBase< T > &  m 
)
friend

Formatted print as above but allows you to do DenseMatrix K; libMesh::out << K << std::endl;.

Definition at line 114 of file dense_matrix_base.h.

115  {
116  m.print(os);
117  return os;
118  }
unsigned int m() const

Member Data Documentation

template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::_m
protected
template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::_n
protected

The documentation for this class was generated from the following files: