#include <dense_matrix.h>
Inherits DenseMatrixBase< T >.
DenseMatrix (const unsigned int m=0, const unsigned int n=0)
virtual ~DenseMatrix ()
virtual void zero ()
T operator() (const unsigned int i, const unsigned int j) const
T & operator() (const unsigned int i, const unsigned int j)
virtual T el (const unsigned int i, const unsigned int j) const
virtual T & el (const unsigned int i, const unsigned int j)
virtual void left_multiply (const DenseMatrixBase< T > &M2)
virtual void right_multiply (const DenseMatrixBase< T > &M3)
void vector_mult (DenseVector< T > &dest, const DenseVector< T > &arg) const
void vector_mult_add (DenseVector< T > &dest, const T factor, const DenseVector< T > &arg) const
void get_principal_submatrix (unsigned int sub_m, unsigned int sub_n, DenseMatrix< T > &dest) const
void get_principal_submatrix (unsigned int sub_m, DenseMatrix< T > &dest) const
DenseMatrix< T > & operator= (const DenseMatrix< T > &other_matrix)
void swap (DenseMatrix< T > &other_matrix)
void resize (const unsigned int m, const unsigned int n)
void scale (const T factor)
DenseMatrix< T > & operator*= (const T factor)
void add (const T factor, const DenseMatrix< T > &mat)
bool operator== (const DenseMatrix< T > &mat) const
bool operator!= (const DenseMatrix< T > &mat) const
DenseMatrix< T > & operator+= (const DenseMatrix< T > &mat)
DenseMatrix< T > & operator-= (const DenseMatrix< T > &mat)
Real min () const
Real max () const
Real l1_norm () const
Real linfty_norm () const
void left_multiply_transpose (const DenseMatrix< T > &A)
void right_multiply_transpose (const DenseMatrix< T > &A)
T transpose (const unsigned int i, const unsigned int j) const
void get_transpose (DenseMatrix< T > &dest) const
std::vector< T > & get_values ()
const std::vector< T > & get_values () const
void condense (const unsigned int i, const unsigned int j, const T val, DenseVector< T > &rhs)
void lu_solve (DenseVector< T > &b, DenseVector< T > &x, const bool partial_pivot=false)
template<typename T2 > void cholesky_solve (DenseVector< T2 > &b, DenseVector< T2 > &x)
T det ()
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)
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)
unsigned int _m
unsigned int _n
enum DecompositionType { LU = 0, CHOLESKY = 1, NONE }
enum _BLAS_Multiply_Flag { LEFT_MULTIPLY = 0, RIGHT_MULTIPLY, LEFT_MULTIPLY_TRANSPOSE, RIGHT_MULTIPLY_TRANSPOSE }
void _lu_decompose (const bool partial_pivot=false)
void _lu_back_substitute (DenseVector< T > &b, DenseVector< T > &x, const bool partial_pivot=false) const
void _cholesky_decompose ()
template<typename T2 > void _cholesky_back_substitute (DenseVector< T2 > &b, DenseVector< T2 > &x) const
void _multiply_blas (const DenseMatrixBase< T > &other, _BLAS_Multiply_Flag flag)
std::vector< T > _val
DecompositionType _decomposition_type
std::ostream & operator<< (std::ostream &os, const DenseMatrixBase< T > &m)
Author:
Definition at line 49 of file dense_matrix.h.
Enumerator:
Definition at line 377 of file dense_matrix.h.
{
LEFT_MULTIPLY = 0,
RIGHT_MULTIPLY,
LEFT_MULTIPLY_TRANSPOSE,
RIGHT_MULTIPLY_TRANSPOSE
};
Enumerator:
Definition at line 364 of file dense_matrix.h.
{LU=0, CHOLESKY=1, NONE};
Definition at line 430 of file dense_matrix.h.
References DenseMatrix< T >::resize().
: DenseMatrixBase<T>(m,n),
#if defined(LIBMESH_HAVE_PETSC) && defined(LIBMESH_USE_REAL_NUMBERS)
use_blas(true),
#else
use_blas(false),
#endif
_decomposition_type(NONE)
{
this->resize(m,n);
}
Definition at line 67 of file dense_matrix.h.
{}
Definition at line 561 of file dense_matrix.C.
References DenseVector< T >::resize().
{
// Shorthand notation for number of rows and columns.
const unsigned int
m = this->m(),
n = this->n();
// Just to be really sure...
libmesh_assert(m==n);
// A convenient reference to *this
const DenseMatrix<T>& A = *this;
// Now compute the solution to Ax =b using the factorization.
x.resize(m);
// Solve for Ly=b
for (unsigned int i=0; i<n; ++i)
{
for (unsigned int k=0; k<i; ++k)
b(i) -= A(i,k)*x(k);
x(i) = b(i) / A(i,i);
}
// Solve for L^T x = y
for (unsigned int i=0; i<n; ++i)
{
const unsigned int ib = (n-1)-i;
for (unsigned int k=(ib+1); k<n; ++k)
x(ib) -= A(k,ib) * x(k);
x(ib) /= A(ib,ib);
}
}
Definition at line 510 of file dense_matrix.C.
{
// If we called this function, there better not be any
// previous decomposition of the matrix.
libmesh_assert(this->_decomposition_type == NONE);
// Shorthand notation for number of rows and columns.
const unsigned int
m = this->m(),
n = this->n();
// Just to be really sure...
libmesh_assert(m==n);
// A convenient reference to *this
DenseMatrix<T>& A = *this;
for (unsigned int i=0; i<m; ++i)
{
for (unsigned int j=i; j<n; ++j)
{
for (unsigned int k=0; k<i; ++k)
A(i,j) -= A(i,k) * A(j,k);
if (i == j)
{
#ifndef LIBMESH_USE_COMPLEX_NUMBERS
if (A(i,j) <= 0.0)
{
std::cerr << 'Error! Can only use Cholesky decomposition '
<< 'with symmetric positive definite matrices.'
<< std::endl;
libmesh_error();
}
#endif
A(i,i) = std::sqrt(A(i,j));
}
else
A(j,i) = A(i,j) / A(i,i);
}
}
// Set the flag for CHOLESKY decomposition
this->_decomposition_type = CHOLESKY;
}
Definition at line 321 of file dense_matrix.C.
References DenseVector< T >::resize(), DenseVector< T >::size(), and libMesh::zero.
{
const unsigned int
n = this->n();
libmesh_assert (this->m() == n);
libmesh_assert (this->m() == b.size());
x.resize (n);
// A convenient reference to *this
const DenseMatrix<T>& A = *this;
// Transform the RHS vector
for (unsigned int i=0; i<(n-1); i++)
{
// Get the diagonal entry and take its inverse
const T diag = A(i,i);
libmesh_assert (diag != libMesh::zero);
const T diag_inv = 1./diag;
// Get the entry b(i) and store it
const T bi = b(i);
for (unsigned int j=(i+1); j<n; j++)
b(j) -= bi*A(j,i)*diag_inv;
}
// Perform back-substitution
{
x(n-1) = b(n-1)/A(n-1,n-1);
for (unsigned int i=0; i<=(n-1); i++)
{
const unsigned int ib = (n-1)-i;
// Get the diagonal and take its inverse
const T diag = A(ib,ib);
libmesh_assert (diag != libMesh::zero);
const T diag_inv = 1./diag;
for (unsigned int j=(ib+1); j<n; j++)
{
b(ib) -= A(ib,j)*x(j);
x(ib) = b(ib)*diag_inv;
}
}
}
}
Definition at line 380 of file dense_matrix.C.
References libMesh::zero.
{
// If this function was called, there better not be any
// previous decomposition of the matrix.
libmesh_assert(this->_decomposition_type == NONE);
// Get the matrix size and make sure it is square
const unsigned int
m = this->m();
libmesh_assert (m == this->n());
// A convenient reference to *this
DenseMatrix<T>& A = *this;
// Straight, vanilla LU factorization without pivoting
if (!partial_pivot)
{
// For each row in the matrix
for (unsigned int i=0; i<m; i++)
{
// Get the diagonal entry and take its inverse
const T diag = A(i,i);
libmesh_assert (diag != libMesh::zero);
const T diag_inv = 1./diag;
// For each row in the submatrix
for (unsigned int j=i+1; j<m; j++)
{
// Get the scale factor for this row
const T fact = A(j,i)*diag_inv;
// For each column in the subrow scale it
// by the factor
for (unsigned int k=i+1; k<m; k++)
A(j,k) -= fact*A(i,k);
}
}
}
// Do partial pivoting.
else
{
libmesh_error();
}
// Set the flag for LU decomposition
this->_decomposition_type = LU;
}
Definition at line 606 of file dense_matrix.C.
References DenseMatrix< T >::_val, DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
{
int result_size = 0;
// For each case, determine the size of the final result make sure
// that the inner dimensions match
switch (flag)
{
case LEFT_MULTIPLY:
{
result_size = other.m() * this->n();
if (other.n() == this->m())
break;
}
case RIGHT_MULTIPLY:
{
result_size = other.n() * this->m();
if (other.m() == this->n())
break;
}
case LEFT_MULTIPLY_TRANSPOSE:
{
result_size = other.n() * this->n();
if (other.m() == this->m())
break;
}
case RIGHT_MULTIPLY_TRANSPOSE:
{
result_size = other.m() * this->m();
if (other.n() == this->n())
break;
}
default:
{
std::cout << 'Unknown flag selected or matrices are ';
std::cout << 'incompatible for multiplication.' << std::endl;
libmesh_error();
}
}
// For this to work, the passed arg. must actually be a DenseMatrix<T>
const DenseMatrix<T>* const_that = dynamic_cast< const DenseMatrix<T>* >(&other);
if (!const_that)
{
std::cerr << 'Unable to cast input matrix to usable type.' << std::endl;
libmesh_error();
}
// Also, although 'that' is logically const in this BLAS routine,
// the PETSc BLAS interface does not specify that any of the inputs are
// const. To use it, I must cast away const-ness.
DenseMatrix<T>* that = const_cast< DenseMatrix<T>* > (const_that);
// Initialize A, B pointers for LEFT_MULTIPLY* cases
DenseMatrix<T>
*A = this,
*B = that;
// For RIGHT_MULTIPLY* cases, swap the meaning of A and B.
// Here is a full table of combinations we can pass to BLASgemm, and what the answer is when finished:
// pass A B -> (Fortran) -> A^T B^T -> (C++) -> (A^T B^T)^T -> (identity) -> B A 'lt multiply'
// pass B A -> (Fortran) -> B^T A^T -> (C++) -> (B^T A^T)^T -> (identity) -> A B 'rt multiply'
// pass A B^T -> (Fortran) -> A^T B -> (C++) -> (A^T B)^T -> (identity) -> B^T A 'lt multiply t'
// pass B^T A -> (Fortran) -> B A^T -> (C++) -> (B A^T)^T -> (identity) -> A B^T 'rt multiply t'
if (flag==RIGHT_MULTIPLY || flag==RIGHT_MULTIPLY_TRANSPOSE)
std::swap(A,B);
// transa, transb values to pass to blas
char
transa[] = 'n',
transb[] = 'n';
// Integer values to pass to BLAS:
//
// M
// In Fortran, the number of rows of op(A),
// In the BLAS documentation, typically known as 'M'.
//
// In C/C++, we set:
// M = n_cols(A) if (transa='n')
// n_rows(A) if (transa='t')
int M = static_cast<int>( A->n() );
// N
// In Fortran, the number of cols of op(B), and also the number of cols of C.
// In the BLAS documentation, typically known as 'N'.
//
// In C/C++, we set:
// N = n_rows(B) if (transb='n')
// n_cols(B) if (transb='t')
int N = static_cast<int>( B->m() );
// K
// In Fortran, the number of cols of op(A), and also
// the number of rows of op(B). In the BLAS documentation,
// typically known as 'K'.
//
// In C/C++, we set:
// K = n_rows(A) if (transa='n')
// n_cols(A) if (transa='t')
int K = static_cast<int>( A->m() );
// LDA (leading dimension of A). In our cases,
// LDA is always the number of columns of A.
int LDA = static_cast<int>( A->n() );
// LDB (leading dimension of B). In our cases,
// LDB is always the number of columns of B.
int LDB = static_cast<int>( B->n() );
if (flag == LEFT_MULTIPLY_TRANSPOSE)
{
transb[0] = 't';
N = static_cast<int>( B->n() );
}
else if (flag == RIGHT_MULTIPLY_TRANSPOSE)
{
transa[0] = 't';
std::swap(M,K);
}
// LDC (leading dimension of C). LDC is the
// number of columns in the solution matrix.
int LDC = M;
// Scalar values to pass to BLAS
//
// scalar multiplying the whole product AB
T alpha = 1.;
// scalar multiplying C, which is the original matrix.
T beta = 0.;
// Storage for the result
std::vector<T> result (result_size);
// Finally ready to call the BLAS
BLASgemm_(transa, transb, &M, &N, &K, &alpha, &(A->_val[0]), &LDA, &(B->_val[0]), &LDB, &beta, &result[0], &LDC);
// Update the relevant dimension for this matrix.
switch (flag)
{
case LEFT_MULTIPLY: { this->_m = other.m(); break; }
case RIGHT_MULTIPLY: { this->_n = other.n(); break; }
case LEFT_MULTIPLY_TRANSPOSE: { this->_m = other.n(); break; }
case RIGHT_MULTIPLY_TRANSPOSE: { this->_n = other.m(); break; }
default:
{
std::cout << 'Unknown flag selected.' << std::endl;
libmesh_error();
}
}
// Swap my data vector with the result
this->_val.swap(result);
}
Definition at line 569 of file dense_matrix.h.
References DenseMatrix< T >::_val.
Referenced by FEMSystem::assembly().
{
for (unsigned int i=0; i<_val.size(); i++)
_val[i] += factor * mat._val[i];
}
Definition at line 183 of file dense_matrix_base.h.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
{
libmesh_assert (this->m() == mat.m());
libmesh_assert (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);
}
Definition at line 473 of file dense_matrix.C.
Referenced by FEBase::coarsened_dof_values(), FEBase::compute_periodic_constraints(), FEBase::compute_proj_constraints(), System::ProjectVector::operator()(), and HPCoarsenTest::select_refinement().
{
// Check for a previous decomposition
switch(this->_decomposition_type)
{
case NONE:
{
this->_cholesky_decompose ();
break;
}
case CHOLESKY:
{
// Already factored, just need to call back_substitute.
break;
}
default:
{
std::cerr << 'Error! This matrix already has a '
<< 'different decomposition...'
<< std::endl;
libmesh_error();
}
}
// Perform back substitution
this->_cholesky_back_substitute (b, x);
}
Definition at line 263 of file dense_matrix.h.
Referenced by DenseMatrix< Number >::condense().
{ DenseMatrixBase<T>::condense (i, j, val, rhs); }
Definition at line 57 of file dense_matrix_base.C.
References DenseVectorBase< T >::el(), and DenseVectorBase< T >::size().
{
libmesh_assert (this->_m == rhs.size());
libmesh_assert (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;
}
Definition at line 436 of file dense_matrix.C.
{
// First LU decompose the matrix (without partial pivoting).
// Note that the lu_decompose routine will check to see if the
// matrix is square so we don't worry about it.
if (this->_decomposition_type == NONE)
this->_lu_decompose(false);
else if (this->_decomposition_type != LU)
{
std::cerr << 'Error! Can't compute the determinant under '
<< 'the current decomposition.'
<< std::endl;
libmesh_error();
}
// A variable to keep track of the running product of diagonal terms.
T determinant = 1.;
// Loop over diagonal terms, computing the product. In practice,
// be careful because this value could easily become too large to
// fit in a double or float. To be safe, one should keep track of
// the power (of 10) of the determinant in a separate variable
// and maintain an order 1 value for the determinant itself.
for (unsigned int i=0; i<this->m(); i++)
determinant *= (*this)(i,i);
// Return the determinant
return determinant;
}
Implements DenseMatrixBase< T >.
Definition at line 90 of file dense_matrix.h.
{ return (*this)(i,j); }
Implements DenseMatrixBase< T >.
Definition at line 96 of file dense_matrix.h.
{ return (*this)(i,j); }
Definition at line 256 of file dense_matrix.C.
References DenseMatrix< T >::resize().
{
libmesh_assert( (sub_m <= this->m()) && (sub_n <= this->n()) );
dest.resize(sub_m, sub_n);
for(unsigned int i=0; i<sub_m; i++)
for(unsigned int j=0; j<sub_n; j++)
dest(i,j) = (*this)(i,j);
}
Definition at line 269 of file dense_matrix.C.
{
get_principal_submatrix(sub_m, sub_m, dest);
}
Definition at line 275 of file dense_matrix.C.
References DenseMatrixBase< T >::m(), DenseMatrixBase< T >::n(), and DenseMatrix< T >::resize().
{
dest.resize(this->n(), this->m());
for (unsigned int i=0; i<dest.m(); i++)
for (unsigned int j=0; j<dest.n(); j++)
dest(i,j) = (*this)(j,i);
}
Definition at line 250 of file dense_matrix.h.
Referenced by EpetraMatrix< T >::add_matrix(), and PetscMatrix< T >::add_matrix().
{ return _val; }
Definition at line 255 of file dense_matrix.h.
{ return _val; }
Referenced by FEMSystem::assembly().
{
libmesh_assert (this->_m);
libmesh_assert (this->_n);
Real columnsum = 0.;
for (unsigned int i=0; i!=this->_m; i++)
{
columnsum += std::abs((*this)(i,0));
}
Real my_max = columnsum;
for (unsigned int j=1; j!=this->_n; j++)
{
columnsum = 0.;
for (unsigned int i=0; i!=this->_m; i++)
{
columnsum += std::abs((*this)(i,j));
}
my_max = (my_max > columnsum? my_max : columnsum);
}
return my_max;
}
Implements DenseMatrixBase< T >.
Definition at line 44 of file dense_matrix.C.
References DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
{
if (this->use_blas)
this->_multiply_blas(M2, LEFT_MULTIPLY);
else
{
// (*this) <- M2 * (*this)
// Where:
// (*this) = (m x n),
// M2 = (m x p),
// M3 = (p x n)
// M3 is a copy of *this before it gets resize()d
DenseMatrix<T> M3(*this);
// Resize *this so that the result can fit
this->resize (M2.m(), M3.n());
// Call the multiply function in the base class
this->multiply(*this, M2, M3);
}
}
Definition at line 71 of file dense_matrix.C.
References DenseMatrixBase< T >::m(), DenseMatrixBase< T >::n(), and DenseMatrix< T >::transpose().
Referenced by DofMap::constrain_element_matrix(), and DofMap::constrain_element_matrix_and_vector().
{
if (this->use_blas)
this->_multiply_blas(A, LEFT_MULTIPLY_TRANSPOSE);
else
{
//Check to see if we are doing (A^T)*A
if (this == &A)
{
//libmesh_here();
DenseMatrix<T> B(*this);
// Simple but inefficient way
// return this->left_multiply_transpose(B);
// More efficient, but more code way
// If A is mxn, the result will be a square matrix of Size n x n.
const unsigned int m = A.m();
const unsigned int n = A.n();
// resize() *this and also zero out all entries.
this->resize(n,n);
// Compute the lower-triangular part
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=0; j<=i; ++j)
for (unsigned int k=0; k<m; ++k) // inner products are over m
(*this)(i,j) += B(k,i)*B(k,j);
// Copy lower-triangular part into upper-triangular part
for (unsigned int i=0; i<n; ++i)
for (unsigned int j=i+1; j<n; ++j)
(*this)(i,j) = (*this)(j,i);
}
else
{
DenseMatrix<T> B(*this);
this->resize (A.n(), B.n());
libmesh_assert (A.m() == B.m());
libmesh_assert (this->m() == A.n());
libmesh_assert (this->n() == B.n());
const unsigned int m_s = A.n();
const unsigned int p_s = A.m();
const unsigned int n_s = this->n();
// Do it this way because there is a
// decent chance (at least for constraint matrices)
// that A.transpose(i,k) = 0.
for (unsigned int i=0; i<m_s; i++)
for (unsigned int k=0; k<p_s; k++)
if (A.transpose(i,k) != 0.)
for (unsigned int j=0; j<n_s; j++)
(*this)(i,j) += A.transpose(i,k)*B(k,j);
}
}
}
{
libmesh_assert (this->_m);
libmesh_assert (this->_n);
Real rowsum = 0.;
for (unsigned int j=0; j!=this->_n; j++)
{
rowsum += std::abs((*this)(0,j));
}
Real my_max = rowsum;
for (unsigned int i=1; i!=this->_m; i++)
{
rowsum = 0.;
for (unsigned int j=0; j!=this->_n; j++)
{
rowsum += std::abs((*this)(i,j));
}
my_max = (my_max > rowsum? my_max : rowsum);
}
return my_max;
}
Definition at line 286 of file dense_matrix.C.
Referenced by PatchRecoveryErrorEstimator::EstimateError::operator()().
{
// Check for a previous decomposition
switch(this->_decomposition_type)
{
case NONE:
{
this->_lu_decompose (partial_pivot);
break;
}
case LU:
{
// Already factored, just need to call back_substitute.
break;
}
default:
{
std::cerr << 'Error! This matrix already has a '
<< 'different decomposition...'
<< std::endl;
libmesh_error();
}
}
// Perform back substitution
this->_lu_back_substitute (b, x, partial_pivot);
}
Definition at line 98 of file dense_matrix_base.h.
Referenced by DenseMatrix< T >::_multiply_blas(), DenseMatrixBase< T >::add(), EpetraMatrix< T >::add_matrix(), PetscMatrix< T >::add_matrix(), LaspackMatrix< T >::add_matrix(), DofMap::build_constraint_matrix(), 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_transpose(), DenseMatrix< T >::left_multiply(), DenseMatrix< T >::left_multiply_transpose(), DofMap::max_constraint_error(), DenseMatrixBase< T >::multiply(), PatchRecoveryErrorEstimator::EstimateError::operator()(), DenseMatrix< T >::right_multiply(), and DenseMatrix< T >::right_multiply_transpose().
{ return _m; }
Definition at line 650 of file dense_matrix.h.
References libmesh_real().
{
libmesh_assert (this->_m);
libmesh_assert (this->_n);
Real my_max = libmesh_real((*this)(0,0));
for (unsigned int i=0; i!=this->_m; i++)
{
for (unsigned int j=0; j!=this->_n; j++)
{
Real current = libmesh_real((*this)(i,j));
my_max = (my_max > current? my_max : current);
}
}
return my_max;
}
Definition at line 629 of file dense_matrix.h.
References libmesh_real().
{
libmesh_assert (this->_m);
libmesh_assert (this->_n);
Real my_min = libmesh_real((*this)(0,0));
for (unsigned int i=0; i!=this->_m; i++)
{
for (unsigned int j=0; j!=this->_n; j++)
{
Real current = libmesh_real((*this)(i,j));
my_min = (my_min < current? my_min : current);
}
}
return my_min;
}
Definition at line 30 of file dense_matrix_base.C.
References DenseMatrixBase< T >::el(), DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
{
// Assertions to make sure we have been
// passed matrices of the correct dimension.
libmesh_assert (M1.m() == M2.m());
libmesh_assert (M1.n() == M3.n());
libmesh_assert (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);
}
Definition at line 103 of file dense_matrix_base.h.
Referenced by DenseMatrix< T >::_multiply_blas(), DenseMatrixBase< T >::add(), EpetraMatrix< T >::add_matrix(), PetscMatrix< T >::add_matrix(), LaspackMatrix< T >::add_matrix(), DofMap::build_constraint_matrix(), 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_transpose(), DenseMatrix< T >::left_multiply(), DenseMatrix< T >::left_multiply_transpose(), DofMap::max_constraint_error(), DenseMatrixBase< T >::multiply(), PatchRecoveryErrorEstimator::EstimateError::operator()(), DenseMatrix< T >::right_multiply(), and DenseMatrix< T >::right_multiply_transpose().
{ return _n; }
Definition at line 592 of file dense_matrix.h.
References DenseMatrix< T >::_val.
{
for (unsigned int i=0; i<_val.size(); i++)
if (_val[i] != mat._val[i])
return true;
return false;
}
Definition at line 516 of file dense_matrix.h.
{
libmesh_assert (i*j<_val.size());
libmesh_assert (i < this->_m);
libmesh_assert (j < this->_n);
// return _val[(i) + (this->_m)*(j)]; // col-major
return _val[(i)*(this->_n) + (j)]; // row-major
}
Definition at line 532 of file dense_matrix.h.
{
libmesh_assert (i*j<_val.size());
libmesh_assert (i < this->_m);
libmesh_assert (j < this->_n);
//return _val[(i) + (this->_m)*(j)]; // col-major
return _val[(i)*(this->_n) + (j)]; // row-major
}
Definition at line 559 of file dense_matrix.h.
References MeshTools::Modification::scale().
{
this->scale(factor);
return *this;
}
Definition at line 605 of file dense_matrix.h.
References DenseMatrix< T >::_val.
{
for (unsigned int i=0; i<_val.size(); i++)
_val[i] += mat._val[i];
return *this;
}
Definition at line 617 of file dense_matrix.h.
References DenseMatrix< T >::_val.
{
for (unsigned int i=0; i<_val.size(); i++)
_val[i] -= mat._val[i];
return *this;
}
Definition at line 501 of file dense_matrix.h.
References DenseMatrix< T >::_decomposition_type, DenseMatrixBase< T >::_m, DenseMatrixBase< T >::_n, and DenseMatrix< T >::_val.
{
this->_m = other_matrix._m;
this->_n = other_matrix._n;
_val = other_matrix._val;
_decomposition_type = other_matrix._decomposition_type;
return *this;
}
Definition at line 579 of file dense_matrix.h.
References DenseMatrix< T >::_val.
{
for (unsigned int i=0; i<_val.size(); i++)
if (_val[i] != mat._val[i])
return false;
return true;
}
Definition at line 127 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;
}
Definition at line 85 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
}
Definition at line 474 of file dense_matrix.h.
References libMesh::zero.
Referenced by HPCoarsenTest::add_projection(), DofMap::build_constraint_matrix(), FEBase::coarsened_dof_values(), FEBase::compute_periodic_constraints(), FEBase::compute_proj_constraints(), DenseMatrix< T >::DenseMatrix(), DenseMatrix< T >::get_principal_submatrix(), DenseMatrix< T >::get_transpose(), System::ProjectVector::operator()(), FEMContext::reinit(), and HPCoarsenTest::select_refinement().
{
_val.resize(m*n);
this->_m = m;
this->_n = n;
_decomposition_type = NONE;
this->zero();
}
Implements DenseMatrixBase< T >.
Definition at line 139 of file dense_matrix.C.
References DenseMatrixBase< T >::m(), and DenseMatrixBase< T >::n().
Referenced by DofMap::build_constraint_matrix(), DofMap::constrain_element_matrix(), and DofMap::constrain_element_matrix_and_vector().
{
if (this->use_blas)
this->_multiply_blas(M3, RIGHT_MULTIPLY);
else
{
// (*this) <- M3 * (*this)
// Where:
// (*this) = (m x n),
// M2 = (m x p),
// M3 = (p x n)
// M2 is a copy of *this before it gets resize()d
DenseMatrix<T> M2(*this);
// Resize *this so that the result can fit
this->resize (M2.m(), M3.n());
this->multiply(*this, M2, M3);
}
}
Definition at line 165 of file dense_matrix.C.
References DenseMatrixBase< T >::m(), DenseMatrixBase< T >::n(), and DenseMatrix< T >::transpose().
{
if (this->use_blas)
this->_multiply_blas(B, RIGHT_MULTIPLY_TRANSPOSE);
else
{
//Check to see if we are doing B*(B^T)
if (this == &B)
{
//libmesh_here();
DenseMatrix<T> A(*this);
// Simple but inefficient way
// return this->right_multiply_transpose(A);
// More efficient, more code
// If B is mxn, the result will be a square matrix of Size m x m.
const unsigned int m = B.m();
const unsigned int n = B.n();
// resize() *this and also zero out all entries.
this->resize(m,m);
// Compute the lower-triangular part
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=0; j<=i; ++j)
for (unsigned int k=0; k<n; ++k) // inner products are over n
(*this)(i,j) += A(i,k)*A(j,k);
// Copy lower-triangular part into upper-triangular part
for (unsigned int i=0; i<m; ++i)
for (unsigned int j=i+1; j<m; ++j)
(*this)(i,j) = (*this)(j,i);
}
else
{
DenseMatrix<T> A(*this);
this->resize (A.m(), B.m());
libmesh_assert (A.n() == B.n());
libmesh_assert (this->m() == A.m());
libmesh_assert (this->n() == B.m());
const unsigned int m_s = A.m();
const unsigned int p_s = A.n();
const unsigned int n_s = this->n();
// Do it this way because there is a
// decent chance (at least for constraint matrices)
// that B.transpose(k,j) = 0.
for (unsigned int j=0; j<n_s; j++)
for (unsigned int k=0; k<p_s; k++)
if (B.transpose(k,j) != 0.)
for (unsigned int i=0; i<m_s; i++)
(*this)(i,j) += A(i,k)*B.transpose(k,j);
}
}
}
Definition at line 549 of file dense_matrix.h.
{
for (unsigned int i=0; i<_val.size(); i++)
_val[i] *= factor;
}
Definition at line 460 of file dense_matrix.h.
References DenseMatrix< T >::_decomposition_type, DenseMatrixBase< T >::_m, DenseMatrixBase< T >::_n, and DenseMatrix< T >::_val.
Referenced by FEMSystem::assembly(), EulerSolver::element_residual(), Euler2Solver::element_residual(), EulerSolver::side_residual(), and Euler2Solver::side_residual().
{
std::swap(this->_m, other_matrix._m);
std::swap(this->_n, other_matrix._n);
_val.swap(other_matrix._val);
DecompositionType _temp = _decomposition_type;
_decomposition_type = other_matrix._decomposition_type;
other_matrix._decomposition_type = _temp;
}
Definition at line 725 of file dense_matrix.h.
Referenced by DofMap::constrain_element_dyad_matrix(), DofMap::constrain_element_matrix_and_vector(), DofMap::constrain_element_vector(), DenseMatrix< T >::left_multiply_transpose(), and DenseMatrix< T >::right_multiply_transpose().
{
// Implement in terms of operator()
return (*this)(j,i);
}
Definition at line 227 of file dense_matrix.C.
References DenseVector< T >::size(), and DenseVector< T >::zero().
{
const unsigned int n_rows = this->m();
const unsigned int n_cols = this->n();
// Make sure the sizes are compatible
libmesh_assert(n_cols == arg.size());
libmesh_assert(n_rows == dest.size());
dest.zero();
DenseMatrix<T> A(*this);
for(unsigned int i=0; i<n_rows; i++)
for(unsigned int j=0; j<n_cols; j++)
dest(i) += A(i,j)*arg(j);
}
Definition at line 246 of file dense_matrix.C.
References DenseVector< T >::add(), and DenseVector< T >::size().
{
DenseVector<T> temp(arg.size());
this->vector_mult(temp, arg);
dest.add(factor, temp);
}
Implements DenseMatrixBase< T >.
Definition at line 490 of file dense_matrix.h.
Referenced by HPCoarsenTest::add_projection(), FEMSystem::assembly(), FEBase::coarsened_dof_values(), EulerSolver::element_residual(), Euler2Solver::element_residual(), System::ProjectVector::operator()(), HPCoarsenTest::select_refinement(), EulerSolver::side_residual(), and Euler2Solver::side_residual().
{
_decomposition_type = NONE;
std::fill (_val.begin(), _val.end(), 0.);
}
Definition at line 115 of file dense_matrix_base.h.
{
m.print(os);
return os;
}
Definition at line 370 of file dense_matrix.h.
Referenced by DenseMatrix< T >::operator=(), and DenseMatrix< T >::swap().
Definition at line 164 of file dense_matrix_base.h.
Referenced by DenseMatrixBase< Number >::m(), DenseMatrix< T >::operator=(), and DenseMatrix< T >::swap().
Definition at line 169 of file dense_matrix_base.h.
Referenced by DenseMatrixBase< Number >::n(), DenseMatrix< T >::operator=(), and DenseMatrix< T >::swap().
Definition at line 321 of file dense_matrix.h.
Referenced by DenseMatrix< T >::_multiply_blas(), DenseMatrix< T >::add(), DenseMatrix< Number >::get_values(), DenseMatrix< T >::operator!=(), DenseMatrix< T >::operator+=(), DenseMatrix< T >::operator-=(), DenseMatrix< T >::operator=(), DenseMatrix< T >::operator==(), and DenseMatrix< T >::swap().
Definition at line 314 of file dense_matrix.h.
Generated automatically by Doxygen for libMesh from the source code.