$extrastylesheet
libMesh::DenseMatrixBase< T > Class Template Reference

#include <dense_matrix_base.h>

Inheritance diagram for libMesh::DenseMatrixBase< T >:

List of all members.

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=libMesh::out) 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 new_m=0, const unsigned int new_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 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, 2003

Definition at line 46 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 
) [inline, 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 54 of file dense_matrix_base.h.

                                              : _m(new_m), _n(new_n) {}
template<typename T>
virtual libMesh::DenseMatrixBase< T >::~DenseMatrixBase ( ) [inline, virtual]

Destructor. Empty.

Definition at line 61 of file dense_matrix_base.h.

{}

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 
) [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 184 of file dense_matrix_base.h.

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

{
  libmesh_assert_equal_to (this->m(), mat.m());
  libmesh_assert_equal_to (this->n(), mat.n());

  for (unsigned int j=0; j<this->n(); j++)
    for (unsigned int i=0; i<this->m(); i++)
      this->el(i,j) += factor*mat.el(i,j);
}
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().

{
  libmesh_assert_equal_to (this->_m, rhs.size());
  libmesh_assert_equal_to (iv, jv);


  // move the known value into the RHS
  // and zero the column
  for (unsigned int i=0; i<this->m(); i++)
    {
      rhs.el(i) -= this->el(i,jv)*val;
      this->el(i,jv) = 0.;
    }

  // zero the row
  for (unsigned int j=0; j<this->n(); j++)
    this->el(iv,j) = 0.;

  this->el(iv,jv) = 1.;
  rhs.el(iv) = val;

}
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 >, and libMesh::DenseMatrix< Number >.

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

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 writeable reference. Since internal data representations may differ, you must redefine this function.

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

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

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

Definition at line 99 of file dense_matrix_base.h.

Referenced by libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_svd_lapack(), libMesh::DenseMatrixBase< T >::add(), libMesh::DenseMatrix< T >::add(), libMesh::SparseMatrix< T >::add_block_matrix(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::EigenSparseMatrix< T >::add_matrix(), libMesh::LaspackMatrix< T >::add_matrix(), libMesh::EpetraMatrix< T >::add_matrix(), libMesh::PetscMatrix< T >::add_matrix(), libMesh::DofMap::build_constraint_matrix(), libMesh::DofMap::build_constraint_matrix_and_vector(), libMesh::DofMap::constrain_element_dyad_matrix(), libMesh::DofMap::constrain_element_matrix(), libMesh::DofMap::constrain_element_matrix_and_vector(), libMesh::DofMap::constrain_element_vector(), libMesh::DofMap::extract_local_vector(), 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::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseMatrix< T >::operator=(), libMesh::DenseMatrix< T >::right_multiply(), and libMesh::DenseMatrix< T >::right_multiply_transpose().

{ return _m; }
template<typename T>
void libMesh::DenseMatrixBase< T >::multiply ( DenseMatrixBase< T > &  M1,
const DenseMatrixBase< T > &  M2,
const DenseMatrixBase< T > &  M3 
) [protected]

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().

{
  // Assertions to make sure we have been
  // passed matrices of the correct dimension.
  libmesh_assert_equal_to (M1.m(), M2.m());
  libmesh_assert_equal_to (M1.n(), M3.n());
  libmesh_assert_equal_to (M2.n(), M3.m());

  const unsigned int m_s = M2.m();
  const unsigned int p_s = M2.n();
  const unsigned int n_s = M1.n();

  // Do it this way because there is a
  // decent chance (at least for constraint matrices)
  // that M3(k,j) = 0. when right-multiplying.
  for (unsigned int k=0; k<p_s; k++)
    for (unsigned int j=0; j<n_s; j++)
      if (M3.el(k,j) != 0.)
        for (unsigned int i=0; i<m_s; i++)
          M1.el(i,j) += M2.el(i,k) * M3.el(k,j);
}
template<typename T>
unsigned int libMesh::DenseMatrixBase< T >::n ( ) const [inline]
Returns:
the column-dimension of the matrix.

Definition at line 104 of file dense_matrix_base.h.

Referenced by libMesh::DenseMatrix< T >::_multiply_blas(), libMesh::DenseMatrix< T >::_svd_lapack(), libMesh::DenseMatrixBase< T >::add(), libMesh::DenseMatrix< T >::add(), libMesh::SparseMatrix< T >::add_block_matrix(), libMesh::PetscMatrix< T >::add_block_matrix(), libMesh::EigenSparseMatrix< T >::add_matrix(), libMesh::LaspackMatrix< T >::add_matrix(), libMesh::EpetraMatrix< T >::add_matrix(), libMesh::PetscMatrix< T >::add_matrix(), libMesh::DofMap::build_constraint_matrix(), libMesh::DofMap::build_constraint_matrix_and_vector(), libMesh::DofMap::constrain_element_dyad_matrix(), libMesh::DofMap::constrain_element_matrix(), libMesh::DofMap::constrain_element_matrix_and_vector(), libMesh::DofMap::constrain_element_vector(), libMesh::DofMap::extract_local_vector(), 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::WeightedPatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::PatchRecoveryErrorEstimator::EstimateError::operator()(), libMesh::DenseMatrix< T >::operator=(), libMesh::DenseMatrix< T >::right_multiply(), and libMesh::DenseMatrix< T >::right_multiply_transpose().

{ return _n; }
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.

{
  for (unsigned int i=0; i<this->m(); i++)
    {
      for (unsigned int j=0; j<this->n(); j++)
        os << std::setw(8)
           << this->el(i,j) << " ";

      os << std::endl;
    }

  return;
}
template<typename T >
void libMesh::DenseMatrixBase< T >::print_scientific ( std::ostream &  os) const

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

Definition at line 86 of file dense_matrix_base.C.

{
#ifndef LIBMESH_BROKEN_IOSTREAM

  // save the initial format flags
  std::ios_base::fmtflags os_flags = os.flags();

  // Print the matrix entries.
  for (unsigned int i=0; i<this->m(); i++)
    {
      for (unsigned int j=0; j<this->n(); j++)
        os << std::setw(15)
           << std::scientific
           << std::setprecision(8)
           << this->el(i,j) << " ";

      os << std::endl;
    }

  // reset the original format flags
  os.flags(os_flags);

#else

  // Print the matrix entries.
  for (unsigned int i=0; i<this->m(); i++)
    {
      for (unsigned int j=0; j<this->n(); j++)
        os << std::setprecision(8)
           << this->el(i,j)
           << " ";

      os << std::endl;
    }


#endif
}
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::DenseMatrix< Number >.

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


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

  {
    m.print(os);
    return os;
  }

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: