libMesh
Loading...
Searching...
No Matches
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

 DenseMatrixBase (DenseMatrixBase &&)=default
 The 5 special functions can be defaulted for this class, as it does not manage any memory itself.
 
 DenseMatrixBase (const DenseMatrixBase &)=default
 
DenseMatrixBaseoperator= (const DenseMatrixBase &)=default
 
DenseMatrixBaseoperator= (DenseMatrixBase &&)=default
 
virtual ~DenseMatrixBase ()=default
 
virtual void zero ()=0
 Set every element in the matrix to 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
 Performs the operation: (*this) <- M2 * (*this)
 
virtual void right_multiply (const DenseMatrixBase< T > &M3)=0
 Performs the operation: (*this) <- (*this) * M3.
 
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.
 
void print_scientific (std::ostream &os, unsigned precision=8) const
 Prints the matrix entries with more decimal places in scientific notation.
 
template<typename T2 , typename T3 >
std::enable_if< ScalarTraits< T2 >::value, void >::type add (const T2 factor, const DenseMatrixBase< T3 > &mat)
 Adds factor to every element in the matrix.
 
DenseVector< T > diagonal () const
 Return the matrix diagonal.
 

Protected Member Functions

 DenseMatrixBase (const unsigned int new_m=0, const unsigned int new_n=0)
 Constructor.
 
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.
 

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)
 

Protected Attributes

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

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;.
 

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 46 of file dense_matrix_base.h.

Constructor & Destructor Documentation

◆ DenseMatrixBase() [1/3]

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

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 54 of file dense_matrix_base.h.

55 : _m(new_m), _n(new_n) {}
unsigned int _n
The column dimension.
unsigned int _m
The row dimension.

◆ DenseMatrixBase() [2/3]

template<typename T >
libMesh::DenseMatrixBase< T >::DenseMatrixBase ( DenseMatrixBase< T > &&  )
default

The 5 special functions can be defaulted for this class, as it does not manage any memory itself.

◆ DenseMatrixBase() [3/3]

template<typename T >
libMesh::DenseMatrixBase< T >::DenseMatrixBase ( const DenseMatrixBase< T > &  )
default

◆ ~DenseMatrixBase()

template<typename T >
virtual libMesh::DenseMatrixBase< T >::~DenseMatrixBase ( )
virtualdefault

Member Function Documentation

◆ add()

template<typename T >
template<typename T2 , typename T3 >
std::enable_if< ScalarTraits< T2 >::value, void >::type libMesh::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 195 of file dense_matrix_base.h.

197{
198 libmesh_assert_equal_to (this->m(), mat.m());
199 libmesh_assert_equal_to (this->n(), mat.n());
200
201 for (auto j : make_range(this->n()))
202 for (auto i : make_range(this->m()))
203 this->el(i,j) += factor*mat.el(i,j);
204}
virtual T el(const unsigned int i, const unsigned int j) const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

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

◆ condense()

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 73 of file dense_matrix_base_impl.h.

77 {
78 libmesh_assert_equal_to (this->_m, rhs.size());
79 libmesh_assert_equal_to (iv, jv);
80
81
82 // move the known value into the RHS
83 // and zero the column
84 for (auto i : make_range(this->m()))
85 {
86 rhs.el(i) -= this->el(i,jv)*val;
87 this->el(i,jv) = 0.;
88 }
89
90 // zero the row
91 for (auto j : make_range(this->n()))
92 this->el(iv,j) = 0.;
93
94 this->el(iv,jv) = 1.;
95 rhs.el(iv) = val;
96
97 }

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

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

◆ diagonal()

template<typename T >
DenseVector< T > libMesh::DenseMatrixBase< T >::diagonal ( ) const

Return the matrix diagonal.

Definition at line 37 of file dense_matrix_base_impl.h.

38 {
39 DenseVector<T> ret(_m);
40 for (decltype(_m) i = 0; i < _m; ++i)
41 ret(i) = el(i, i);
42 return ret;
43 }

Referenced by libMesh::DiagonalMatrix< T >::add_matrix().

◆ el() [1/2]

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

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

◆ el() [2/2]

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

◆ left_multiply()

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

◆ m()

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

Definition at line 104 of file dense_matrix_base.h.

104{ return _m; }

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

Referenced by libMesh::DenseMatrix< T >::_left_multiply_transpose(), libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_right_multiply_transpose(), libMesh::DenseMatrix< T >::_svd_solve_lapack(), libMesh::DenseMatrix< T >::add(), libMesh::DenseMatrixBase< T >::add(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::StaticCondensation::add_matrix(), libMesh::DiagonalMatrix< T >::add_matrix(), libMesh::EigenSparseMatrix< T >::add_matrix(), libMesh::LaspackMatrix< T >::add_matrix(), libMesh::PetscMatrix< T >::add_matrix(), libMesh::EpetraMatrix< T >::add_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::DenseMatrix< T >::get_transpose(), libMesh::DofMap::heterogeneously_constrain_element_jacobian_and_residual(), libMesh::DofMap::heterogeneously_constrain_element_residual(), libMesh::isfinite(), libMesh::isfinite(), libMesh::isinf(), libMesh::isinf(), libMesh::isnan(), libMesh::isnan(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DofMap::max_constraint_error(), libMesh::DenseMatrixBase< T >::multiply(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseMatrix< T >::operator=(), libMesh::RBEIMEvaluation::set_interpolation_matrix_entry(), DualShapeTest::testEdge2Lagrange(), DenseMatrixTest::testEVD_helper(), DenseMatrixTest::testSVD(), and MetaPhysicL::RawType< libMesh::DenseMatrix< T > >::value().

◆ multiply()

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 46 of file dense_matrix_base_impl.h.

49 {
50 // Assertions to make sure we have been
51 // passed matrices of the correct dimension.
52 libmesh_assert_equal_to (M1.m(), M2.m());
53 libmesh_assert_equal_to (M1.n(), M3.n());
54 libmesh_assert_equal_to (M2.n(), M3.m());
55
56 const unsigned int m_s = M2.m();
57 const unsigned int p_s = M2.n();
58 const unsigned int n_s = M1.n();
59
60 // Do it this way because there is a
61 // decent chance (at least for constraint matrices)
62 // that M3(k,j) = 0. when right-multiplying.
63 for (unsigned int k=0; k<p_s; k++)
64 for (unsigned int j=0; j<n_s; j++)
65 if (M3.el(k,j) != 0.)
66 for (unsigned int i=0; i<m_s; i++)
67 M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
68 }

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

◆ n()

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

Definition at line 109 of file dense_matrix_base.h.

109{ return _n; }

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

Referenced by libMesh::DenseMatrix< T >::_left_multiply_transpose(), libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_right_multiply_transpose(), libMesh::DenseMatrix< T >::_svd_solve_lapack(), libMesh::DenseMatrix< T >::add(), libMesh::DenseMatrixBase< T >::add(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::StaticCondensation::add_matrix(), libMesh::DiagonalMatrix< T >::add_matrix(), libMesh::EigenSparseMatrix< T >::add_matrix(), libMesh::LaspackMatrix< T >::add_matrix(), libMesh::PetscMatrix< T >::add_matrix(), libMesh::EpetraMatrix< T >::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::DofMap::build_constraint_matrix(), libMesh::DofMap::build_constraint_matrix_and_vector(), libMesh::DofMap::constrain_element_residual(), libMesh::DofMap::extract_local_vector(), libMesh::DenseMatrix< T >::get_transpose(), libMesh::DofMap::heterogeneously_constrain_element_jacobian_and_residual(), libMesh::DofMap::heterogeneously_constrain_element_residual(), libMesh::isfinite(), libMesh::isfinite(), libMesh::isinf(), libMesh::isinf(), libMesh::isnan(), libMesh::isnan(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DenseMatrix< T >::left_multiply(), libMesh::DofMap::max_constraint_error(), libMesh::DenseMatrixBase< T >::multiply(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseMatrix< T >::operator=(), libMesh::DenseMatrix< Real >::right_multiply(), libMesh::RBEIMEvaluation::set_interpolation_matrix_entry(), DualShapeTest::testEdge2Lagrange(), DenseMatrixTest::testSVD(), and MetaPhysicL::RawType< libMesh::DenseMatrix< T > >::value().

◆ operator=() [1/2]

template<typename T >
DenseMatrixBase & libMesh::DenseMatrixBase< T >::operator= ( const DenseMatrixBase< T > &  )
default

◆ operator=() [2/2]

template<typename T >
DenseMatrixBase & libMesh::DenseMatrixBase< T >::operator= ( DenseMatrixBase< T > &&  )
default

◆ print()

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 125 of file dense_matrix_base_impl.h.

126 {
127 for (auto i : make_range(this->m()))
128 {
129 for (auto j : make_range(this->n()))
130 os << std::setw(8)
131 << this->el(i,j) << " ";
132
133 os << std::endl;
134 }
135
136 return;
137 }

References libMesh::make_range().

◆ print_scientific()

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 101 of file dense_matrix_base_impl.h.

102 {
103 // save the initial format flags
104 std::ios_base::fmtflags os_flags = os.flags();
105
106 // Print the matrix entries.
107 for (auto i : make_range(this->m()))
108 {
109 for (auto j : make_range(this->n()))
110 os << std::setw(15)
111 << std::scientific
112 << std::setprecision(precision)
113 << this->el(i,j) << " ";
114
115 os << std::endl;
116 }
117
118 // reset the original format flags
119 os.flags(os_flags);
120 }

References libMesh::make_range().

◆ right_multiply()

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

◆ zero()

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

Friends And Related Symbol Documentation

◆ operator<<

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 121 of file dense_matrix_base.h.

122 {
123 m.print(os);
124 return os;
125 }

Member Data Documentation

◆ _m

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

◆ _n

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

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