IFEM  90A354
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
DenseMatrix Class Reference

Class for representing a dense system matrix. More...

#include <DenseMatrix.h>

Inheritance diagram for DenseMatrix:
Inheritance graph
[legend]
Collaboration diagram for DenseMatrix:
Collaboration graph
[legend]

Public Member Functions

 DenseMatrix (size_t m=0, size_t n=0, bool s=false)
 Default constructor.
 
 DenseMatrix (const DenseMatrix &A)
 Copy constructor.
 
 DenseMatrix (const RealArray &data, size_t nrows=0)
 Special constructor taking data from a one-dimensional array.
 
 DenseMatrix (const Matrix &A, bool s=false)
 Special constructor, type conversion from Matrix.
 
virtual ~DenseMatrix ()
 The destructor frees the dynamically allocated arrays.
 
virtual LinAlg::MatrixType getType () const
 Returns the matrix type.
 
virtual SystemMatrixcopy () const
 Creates a copy of the system matrix and returns a pointer to it.
 
bool redim (size_t r, size_t c)
 Resizes the matrix to dimension \(r \times c\). More...
 
void setSymmetric (bool s=true)
 Marks the matrix as symmetric. More...
 
virtual size_t dim (int idim) const
 Returns the dimension of the system matrix. More...
 
MatrixgetMat ()
 Access to the matrix itself.
 
Realoperator() (size_t r, size_t c)
 Index-1 based element access.
 
const Realoperator() (size_t r, size_t c) const
 Index-1 based element reference.
 
virtual void dump (std::ostream &os, LinAlg::StorageFormat format, const char *label)
 Dumps the system matrix on a specified format.
 
virtual void initAssembly (const SAM &sam, char)
 Initializes the element assembly process. More...
 
virtual void init ()
 Initializes the matrix to zero assuming it is properly dimensioned.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, int e)
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, int e)
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, const std::vector< int > &meq)
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const IntVec &meq)
 Adds an element matrix into the associated system matrix. More...
 
virtual bool augment (const SystemMatrix &B, size_t r0, size_t c0)
 Augments a similar matrix symmetrically to the current matrix. More...
 
virtual void mult (Real alpha)
 Multiplication with a scalar.
 
virtual bool add (const SystemMatrix &B, Real alpha)
 Adds a matrix with similar dimension to the current matrix. More...
 
virtual bool add (Real sigma, int ieq)
 Adds the constant σ to the diagonal of this matrix.
 
virtual bool multiply (const SystemVector &B, SystemVector &C) const
 Performs the matrix-vector multiplication C = *this * B.
 
virtual bool solve (SystemVector &B, Real *rc=nullptr)
 Solves the linear system of equations for a given right-hand-side. More...
 
bool solve (Matrix &B)
 Solves the linear system of equations for a given right-hand-side. More...
 
bool solveEig (RealArray &eigVal, Matrix &eigVec, int nev)
 Solves a standard symmetric-definite eigenproblem. More...
 
bool solveEigNon (RealArray &r_val, RealArray &c_val)
 Solves a non-symmetric eigenproblem. More...
 
bool solveEig (DenseMatrix &B, RealArray &eigVal, Matrix &eigVec, int nev, Real shift=Real(0))
 Solves a generalized symmetric-definite eigenproblem. More...
 
virtual Real Linfnorm () const
 Returns the L-infinity norm of the matrix.
 
virtual bool load (const char *fileName, bool binary)
 Loads the system matrix from specified file.
 
virtual bool solve (SystemVector &b, Real *rc=nullptr)=0
 Solves the linear system of equations for a given right-hand-side. More...
 
virtual bool solve (const SystemVector &b, SystemVector &x)
 Solves the linear system of equations for a given right-hand-side. More...
 
- Public Member Functions inherited from SystemMatrix
virtual ~SystemMatrix ()
 Empty destructor.
 
virtual bool lockPattern (bool)
 Locks or unlocks the sparsity pattern.
 
virtual bool empty () const
 Checks if the matrix is empty.
 
bool isZero () const
 Checks if the matrix have no non-zero contributions.
 
virtual void preAssemble (const std::vector< IntVec > &, size_t=0)
 Initializes the element sparsity pattern based on node connections.
 
virtual void compressPattern ()
 Compresses the sparsity pattern.
 
void initNonZeroEqs ()
 Initializes the nonZeroEqs flags.
 
bool flagNonZeroEqs (const IntVec &meq={})
 Flags the equations meq as pivots with non-zero contributions.
 
bool flagNonZeroEqs (const SystemMatrix &B)
 Flags the non-zero equations from B as non-zero pivots in this.
 
virtual bool endAssembly ()
 Finalizes the system matrix assembly. More...
 
virtual bool truncate (Real=Real(1.0e-16))
 Truncates all small matrix elements to zero.
 
virtual bool solve (const SystemVector &b, SystemVector &x)
 Solves the linear system of equations for a given right-hand-side. More...
 
virtual void dump (const char *fileName, std::streamsize precision=0, LinAlg::StorageFormat format=LinAlg::FLAT)
 Dumps the system matrix to specified file.
 
StdVector operator* (const SystemVector &b) const
 Calculates a matrix-vector product.
 
StdVector operator/ (const SystemVector &b)
 Solves a linear equation system.
 

Protected Member Functions

bool augment (const Matrix &B, size_t r0, size_t c0)
 Augments a dense matrix symmetrically to the current matrix. More...
 
bool augment (const SparseMatrix &B, size_t r0, size_t c0)
 Augments a sparse matrix symmetrically to the current matrix. More...
 
bool solve (Real *B, size_t nrhs, Real *rcond=nullptr)
 Solves the linear system of equations for a given right-hand-side. More...
 
virtual std::ostream & write (std::ostream &os) const
 Writes the system matrix to the given output stream.
 
- Protected Member Functions inherited from SystemMatrix
 SystemMatrix ()
 Default constructor.
 
 SystemMatrix (const SystemMatrix &a)
 Copy constructor.
 

Private Attributes

Matrix myMat
 The actual dense matrix.
 
int * ipiv
 Pivot indices used in solve.
 
bool symm
 Flags whether the matrix is symmetric or not.
 

Additional Inherited Members

- Static Public Member Functions inherited from SystemMatrix
static SystemMatrixcreate (const ProcessAdm *adm, LinAlg::MatrixType mType, int num_thread_SLU=1)
 Static method creating a matrix of the given type.
 
static SystemMatrixcreate (const ProcessAdm *adm, LinAlg::MatrixType mType, const LinSolParams &spar)
 Static method creating a matrix of the given type.
 

Detailed Description

Class for representing a dense system matrix.

Member Function Documentation

◆ add()

bool DenseMatrix::add ( const SystemMatrix B,
Real  alpha 
)
virtual

Adds a matrix with similar dimension to the current matrix.

Parameters
[in]BThe matrix to be added
[in]alphaScale factor for matrix B

Reimplemented from SystemMatrix.

References utl::matrix< T >::add(), utl::matrix< T >::cols(), SystemMatrix::flagNonZeroEqs(), SystemMatrix::isZero(), myMat, and utl::matrix< T >::rows().

◆ assemble() [1/4]

bool DenseMatrix::assemble ( const Matrix eM,
const IntVec meq 
)
virtual

Adds an element matrix into the associated system matrix.

Parameters
[in]eMThe element matrix
[in]meqMatrix of element equation numbers (0 based)
Returns
true on successful assembly, otherwise false

To be used when there is no underlying SAM

Implements SystemMatrix.

◆ assemble() [2/4]

bool DenseMatrix::assemble ( const Matrix eM,
const SAM sam,
int  e 
)
virtual

Adds an element matrix into the associated system matrix.

Parameters
[in]eMThe element matrix
[in]samAuxiliary data for FE assembly management
[in]eIdentifier for the element that eM belongs to
Returns
true on successful assembly, otherwise false

Implements SystemMatrix.

References assemDense(), utl::matrix< T >::cols(), SystemMatrix::flagNonZeroEqs(), SAM::getElmEqns(), SAM::madof, SAM::meqn, SAM::mmceq, SAM::mmnpc, SAM::mpar, SAM::mpmceq, SAM::mpmnpc, myMat, SAM::neq, utl::matrixBase< T >::ptr(), Real, utl::matrix< T >::rows(), and SAM::ttcc.

◆ assemble() [3/4]

bool DenseMatrix::assemble ( const Matrix eM,
const SAM sam,
SystemVector B,
const std::vector< int > &  meq 
)
virtual

Adds an element matrix into the associated system matrix.

Parameters
[in]eMThe element matrix
[in]samAuxiliary data for FE assembly management
BThe system right-hand-side vector
[in]meqMatrix of element equation numbers
Returns
true on successful assembly, otherwise false

When multi-point constraints are present, contributions from these are also added into the system right-hand-side vector, B.

Implements SystemMatrix.

References assemDense(), utl::matrix< T >::cols(), SystemMatrix::flagNonZeroEqs(), SAM::meqn, SAM::mmceq, SAM::mpmceq, myMat, SAM::neq, utl::matrix< T >::rows(), and SAM::ttcc.

◆ assemble() [4/4]

bool DenseMatrix::assemble ( const Matrix eM,
const SAM sam,
SystemVector B,
int  e 
)
virtual

Adds an element matrix into the associated system matrix.

Parameters
[in]eMThe element matrix
[in]samAuxiliary data describing the FE model topology, nodal DOF status and constraint equations
BThe system right-hand-side vector
[in]eIdentifier for the element that eM belongs to
Returns
true on successful assembly, otherwise false

When multi-point constraints are present, contributions from these are also added into the system right-hand-side vector, B.

Implements SystemMatrix.

References assemDense(), utl::matrix< T >::cols(), SystemMatrix::flagNonZeroEqs(), SAM::getElmEqns(), SystemVector::getPtr(), SAM::madof, SAM::meqn, SAM::mmceq, SAM::mmnpc, SAM::mpar, SAM::mpmceq, SAM::mpmnpc, myMat, SAM::neq, utl::matrixBase< T >::ptr(), utl::matrix< T >::rows(), and SAM::ttcc.

◆ augment() [1/3]

bool DenseMatrix::augment ( const Matrix B,
size_t  r0,
size_t  c0 
)
protected

Augments a dense matrix symmetrically to the current matrix.

Parameters
[in]BThe matrix to be augmented
[in]r0Row offset for the augmented matrix
[in]c0Column offset for the augmented matrix

References utl::matrix< T >::cols(), myMat, redim(), and utl::matrix< T >::rows().

◆ augment() [2/3]

bool DenseMatrix::augment ( const SparseMatrix B,
size_t  r0,
size_t  c0 
)
protected

Augments a sparse matrix symmetrically to the current matrix.

Parameters
[in]BThe matrix to be augmented
[in]r0Row offset for the augmented matrix
[in]c0Column offset for the augmented matrix

References SparseMatrix::cols(), SparseMatrix::getValues(), myMat, redim(), and SparseMatrix::rows().

◆ augment() [3/3]

bool DenseMatrix::augment ( const SystemMatrix B,
size_t  r0,
size_t  c0 
)
virtual

Augments a similar matrix symmetrically to the current matrix.

Parameters
[in]BThe matrix to be augmented
[in]r0Row offset for the augmented matrix
[in]c0Column offset for the augmented matrix

Reimplemented from SystemMatrix.

References myMat.

◆ dim()

virtual size_t DenseMatrix::dim ( int  idim) const
inlinevirtual

Returns the dimension of the system matrix.

Parameters
[in]idimWhich direction to return the dimension in

Implements SystemMatrix.

References utl::matrixBase< T >::dim(), myMat, and utl::matrixBase< T >::size().

◆ initAssembly()

void DenseMatrix::initAssembly ( const SAM sam,
char   
)
virtual

Initializes the element assembly process.

Parameters
[in]samAuxiliary data describing the FE model topology, etc.

Implements SystemMatrix.

References myMat, SAM::neq, and utl::matrix< T >::resize().

◆ redim()

bool DenseMatrix::redim ( size_t  r,
size_t  c 
)

Resizes the matrix to dimension \(r \times c\).

Will preserve existing matrix content within the new dimension.

References utl::matrix< T >::cols(), utl::matrix< T >::fillColumn(), utl::matrix< T >::getColumn(), myMat, utl::matrix< T >::resize(), utl::matrix< T >::rows(), and symm.

Referenced by augment().

◆ setSymmetric()

void DenseMatrix::setSymmetric ( bool  s = true)
inline

Marks the matrix as symmetric.

If marked as symmetric, Cholesky factorization will be employed.

References utl::matrix< T >::cols(), myMat, utl::matrix< T >::rows(), and symm.

◆ solve() [1/5]

virtual bool SystemMatrix::solve
inline

Solves the linear system of equations for a given right-hand-side.

Parameters
[in]bRight-hand-side vector
[out]xSolution vector

◆ solve() [2/5]

bool DenseMatrix::solve ( Matrix B)

Solves the linear system of equations for a given right-hand-side.

Parameters
BRight-hand-side matrix on input, solution matrix on output

References utl::matrix< T >::cols(), utl::matrixBase< T >::ptr(), and solve().

◆ solve() [3/5]

bool DenseMatrix::solve ( Real B,
size_t  nrhs,
Real rcond = nullptr 
)
protected

Solves the linear system of equations for a given right-hand-side.

Parameters
BRight-hand-side vectors on input, solution vectors on output
[in]nrhsNumber of right-hand-side vectors
[out]rcondReciprocal condition number of the LHS-matrix (optional)

This is the function which actually solves the equation system, using the LAPack library subroutines. The two public solve methods just forward to this method.

References utl::matrix< T >::cols(), dgecon_(), dgesv_(), dgetrs_(), dlange_(), dposv_(), dpotrs_(), ipiv, myMat, utl::matrixBase< T >::ptr(), Real, utl::matrix< T >::rows(), and symm.

◆ solve() [4/5]

bool DenseMatrix::solve ( SystemVector B,
Real rc = nullptr 
)
virtual

Solves the linear system of equations for a given right-hand-side.

Parameters
BRight-hand-side vector on input, solution vector on output
[out]rcReciprocal condition number of the LHS-matrix (optional)

Implements SystemMatrix.

References SystemVector::dim(), SystemVector::getPtr(), myMat, utl::matrix< T >::rows(), and solve().

Referenced by SplineInterpolator::interpolate(), SplineInterpolator::leastsquare_approximation(), SplineInterpolator::quasiinterpolate(), ASMs2D::scRecovery(), ASMu2D::scRecovery(), and ASMu3D::scRecovery().

◆ solve() [5/5]

virtual bool SystemMatrix::solve

Solves the linear system of equations for a given right-hand-side.

Parameters
bRight-hand-side vector on input, solution vector on output
[out]rcReciprocal condition number of the LHS-matrix (optional)

Referenced by solve().

◆ solveEig() [1/2]

bool DenseMatrix::solveEig ( DenseMatrix B,
RealArray eigVal,
Matrix eigVec,
int  nev,
Real  shift = Real(0) 
)

Solves a generalized symmetric-definite eigenproblem.

Parameters
BSymmetric and positive definite mass matrix.
[out]eigValComputed eigenvalues
[out]eigVecComputed eigenvectors stored column by column
[in]nevThe number of eigenvalues and eigenvectors to compute
[in]shiftEigenvalue shift (unused)

The eigenproblem is assumed to be on the form A x = λ B x where A ( = *this ) and B both are assumed to be symmetric and B also to be positive definite. The eigenproblem is solved by the LAPack library subroutine DSYGVX.

See also
LAPack library documentation https://www.netlib.org/lapack/.

References utl::matrix< T >::cols(), dsygvx_(), myMat, utl::matrixBase< T >::ptr(), Real, utl::matrix< T >::resize(), and utl::matrix< T >::rows().

◆ solveEig() [2/2]

bool DenseMatrix::solveEig ( RealArray eigVal,
Matrix eigVec,
int  nev 
)

Solves a standard symmetric-definite eigenproblem.

Parameters
[out]eigValComputed eigenvalues
[out]eigVecComputed eigenvectors stored column by column
[in]nevThe number of eigenvalues and eigenvectors to compute

The eigenproblem is assumed to be on the form A x = λ x where A ( = *this ) is assumed to be symmetric and positive definite. The eigenproblem is solved by the LAPack library subroutine DSYEVX.

See also
LAPack library documentation https://www.netlib.org/lapack/.

References utl::matrix< T >::cols(), dsyevx_(), myMat, utl::matrixBase< T >::ptr(), Real, utl::matrix< T >::resize(), and utl::matrix< T >::rows().

Referenced by eig::solve().

◆ solveEigNon()

bool DenseMatrix::solveEigNon ( RealArray r_val,
RealArray c_val 
)

Solves a non-symmetric eigenproblem.

See also
LAPack library documentation.
Parameters
[out]r_valReal part of the computed eigenvalues
[out]c_valComplex part of the computed eigenvalues

The eigenproblem is assumed to be on the form A x = λ x where A ( = *this ) is a square non-symmetric matrix. The eigenproblem is solved by the LAPack library subroutine DGEEV.

See also
LAPack library documentation https://www.netlib.org/lapack/.

References dgeev_(), myMat, utl::matrixBase< T >::ptr(), Real, and utl::matrix< T >::rows().

Referenced by Legendre::GL().


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