IFEM 90A354
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
SystemMatrix Class Referenceabstract

Base class for representing a system matrix on different formats. More...

#include <SystemMatrix.h>

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

Public Member Functions

virtual ~SystemMatrix ()
 Empty destructor.
 
virtual LinAlg::MatrixType getType () const =0
 Returns the matrix type.
 
virtual SystemMatrixcopy () const =0
 Creates a copy of the system matrix and returns a pointer to it.
 
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 size_t dim (int idim=1) const =0
 Returns the dimension of the system matrix.
 
virtual void initAssembly (const SAM &sam, char=0)=0
 Initializes the element assembly process.
 
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.
 
virtual void init ()=0
 Initializes the matrix to zero assuming it is properly dimensioned.
 
void initNonZeroEqs ()
 Initializes the nonZeroEqs flags.
 
bool flagNonZeroEq (int ieq=0)
 Flags equation ieq as pivot element with non-zero contributions.
 
bool flagNonZeroEqs (const SAM &sam, 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.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, int e)=0
 Adds an element matrix into the associated system matrix.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, int e)=0
 Adds an element matrix into the associated system matrix.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, const IntVec &meq)=0
 Adds an element matrix into the associated system matrix.
 
virtual bool assemble (const Matrix &eM, const IntVec &meq)=0
 Adds an element matrix into the associated system matrix.
 
virtual bool augment (const SystemMatrix &, size_t, size_t)
 Augments a similar matrix symmetrically to the current matrix.
 
virtual bool truncate (Real=Real(1.0e-16))
 Truncates all small matrix elements to zero.
 
virtual void mult (Real alpha)=0
 Multiplication with a scalar.
 
virtual bool add (const SystemMatrix &, Real=Real(1))
 Adds a matrix with similar structure to the current matrix.
 
virtual bool add (Real, int=0)
 Adds a constant to the diagonal of current matrix.
 
virtual bool multiply (const SystemVector &, SystemVector &) const
 Performs a matrix-vector multiplication.
 
virtual bool solve (SystemVector &b, Real *rc=nullptr)=0
 Solves the linear system of equations for a given right-hand-side.
 
virtual bool solve (const SystemVector &b, SystemVector &x)
 Solves the linear system of equations for a given right-hand-side.
 
virtual bool solve (SystemVector &b, Matrix &x)
 Solves a linear system of equations for multiple right-hand-sides.
 
virtual Real Linfnorm () const =0
 Returns the L-infinity norm of the matrix.
 
virtual void dump (std::ostream &, LinAlg::StorageFormat, const char *=nullptr)
 Dumps the system matrix on a specified format.
 
virtual void dump (const char *fileName, std::streamsize precision=0, LinAlg::StorageFormat format=LinAlg::FLAT)
 Dumps the system matrix to specified file.
 
virtual bool load (const char *, bool=false)
 Loads the system matrix from specified file.
 
StdVector operator* (const SystemVector &b) const
 Calculates a matrix-vector product.
 
StdVector operator/ (const SystemVector &b)
 Solves a linear equation system.
 

Static Public Member Functions

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.
 

Protected Member Functions

 SystemMatrix ()
 Default constructor.
 
 SystemMatrix (const SystemMatrix &a)
 Copy constructor.
 
virtual std::ostream & write (std::ostream &os) const
 Writes the system matrix to the given output stream.
 

Private Attributes

std::vector< bool > nonZeroEqs
 Flags equations with non-zero contributions.
 

Friends

std::ostream & operator<< (std::ostream &os, const SystemMatrix &A)
 Global stream operator printing the matrix contents.
 

Detailed Description

Base class for representing a system matrix on different formats.

The purpose of this class is to define a clean interface for the system matrix and underlying equation solvers, such that the finite element implementation can be performed without paying attention to the actual solver being used.

Member Function Documentation

◆ add() [1/2]

virtual bool SystemMatrix::add ( const SystemMatrix ,
Real  = Real(1) 
)
inlinevirtual

Adds a matrix with similar structure to the current matrix.

Reimplemented in DenseMatrix, DiagMatrix, SparseMatrix, and SPRMatrix.

Referenced by endAssembly(), SIMbase::getRayleighDampingMatrix(), and eig::solve().

◆ add() [2/2]

virtual bool SystemMatrix::add ( Real  ,
int  = 0 
)
inlinevirtual

Adds a constant to the diagonal of current matrix.

Reimplemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, and PETScMatrix.

◆ assemble() [1/4]

virtual bool SystemMatrix::assemble ( const Matrix eM,
const IntVec meq 
)
pure 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 associated SAM object.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, PETScMatrix, and SPRMatrix.

◆ assemble() [2/4]

virtual bool SystemMatrix::assemble ( const Matrix eM,
const SAM sam,
int  e 
)
pure 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

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, PETScMatrix, and SPRMatrix.

Referenced by ASMs1D::assembleL2matrices(), ASMs2DLag::assembleL2matrices(), ASMs3DLag::assembleL2matrices(), ASMu2D::assembleL2matrices(), ASMu3D::assembleL2matrices(), SAM::assembleSystem(), and SAM::assembleSystem().

◆ assemble() [3/4]

virtual bool SystemMatrix::assemble ( const Matrix eM,
const SAM sam,
SystemVector B,
const IntVec meq 
)
pure 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.

Implemented in DiagMatrix, SparseMatrix, SPRMatrix, PETScMatrix, SPRMatrix, and DenseMatrix.

◆ assemble() [4/4]

virtual bool SystemMatrix::assemble ( const Matrix eM,
const SAM sam,
SystemVector B,
int  e 
)
pure 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]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.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, PETScMatrix, and SPRMatrix.

◆ augment()

virtual bool SystemMatrix::augment ( const SystemMatrix ,
size_t  ,
size_t   
)
inlinevirtual

Augments a similar matrix symmetrically to the current matrix.

Reimplemented in DenseMatrix, and SparseMatrix.

◆ compressPattern()

virtual void SystemMatrix::compressPattern ( )
inlinevirtual

Compresses the sparsity pattern.

Reimplemented in SparseMatrix.

Referenced by eig::solve().

◆ copy()

virtual SystemMatrix * SystemMatrix::copy ( ) const
pure virtual

Creates a copy of the system matrix and returns a pointer to it.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

Referenced by SIMbase::getLHSmatrix(), and eig::solve().

◆ dim()

virtual size_t SystemMatrix::dim ( int  idim = 1) const
pure virtual

Returns the dimension of the system matrix.

Implemented in DenseMatrix, SPRMatrix, SparseMatrix, PETScMatrix, DiagMatrix, and ISTLMatrix.

Referenced by _eig_ax(), eig_sol_(), empty(), initNonZeroEqs(), isZero(), eig::solve(), and solve().

◆ dump()

virtual void SystemMatrix::dump ( std::ostream &  ,
LinAlg::StorageFormat  ,
const char *  = nullptr 
)
inlinevirtual

Dumps the system matrix on a specified format.

Reimplemented in SPRMatrix, DenseMatrix, DiagMatrix, and SparseMatrix.

Referenced by dump(), SIMbase::dumpEqSys(), and NewmarkSIM::solveStep().

◆ endAssembly()

bool SystemMatrix::endAssembly ( )
virtual

Finalizes the system matrix assembly.

This method will insert 1.0e9 on the diagonal, for all equations without contributions, such that the remaining equations can be solved for, if the method initNonZeroEqs() was invoked before the assembly started.

Reimplemented in ISTLMatrix, and PETScMatrix.

References add(), and nonZeroEqs.

Referenced by ISTLMatrix::endAssembly(), PETScMatrix::endAssembly(), and ASMbase::globalL2projection().

◆ getType()

virtual LinAlg::MatrixType SystemMatrix::getType ( ) const
pure virtual

Returns the matrix type.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

◆ init()

virtual void SystemMatrix::init ( )
pure virtual

Initializes the matrix to zero assuming it is properly dimensioned.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

◆ initAssembly()

virtual void SystemMatrix::initAssembly ( const SAM sam,
char  = 0 
)
pure virtual

Initializes the element assembly process.

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

This method must be called once before the element assembly loop.

Implemented in SparseMatrix, DenseMatrix, DiagMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

◆ Linfnorm()

virtual Real SystemMatrix::Linfnorm ( ) const
pure virtual

Returns the L-infinity norm of the matrix.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

◆ load()

virtual bool SystemMatrix::load ( const char *  ,
bool  = false 
)
inlinevirtual

Loads the system matrix from specified file.

Reimplemented in DenseMatrix, and SPRMatrix.

Referenced by NewmarkSIM::solveStep().

◆ lockPattern()

virtual bool SystemMatrix::lockPattern ( bool  )
inlinevirtual

Locks or unlocks the sparsity pattern.

Reimplemented in SparseMatrix.

◆ mult()

virtual void SystemMatrix::mult ( Real  alpha)
pure virtual

Multiplication with a scalar.

Implemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, and PETScMatrix.

Referenced by SIMbase::getRayleighDampingMatrix().

◆ multiply()

virtual bool SystemMatrix::multiply ( const SystemVector ,
SystemVector  
) const
inlinevirtual

◆ preAssemble()

virtual void SystemMatrix::preAssemble ( const std::vector< IntVec > &  ,
size_t  = 0 
)
inlinevirtual

Initializes the element sparsity pattern based on node connections.

Reimplemented in PETScMatrix, and SparseMatrix.

Referenced by ASMs2DLag::assembleL2matrices(), ASMs3DLag::assembleL2matrices(), ASMu2D::assembleL2matrices(), and ASMu3D::assembleL2matrices().

◆ solve() [1/3]

virtual bool SystemMatrix::solve ( const SystemVector b,
SystemVector x 
)
inlinevirtual

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

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

Reimplemented in DenseMatrix, DiagMatrix, SparseMatrix, SPRMatrix, ISTLMatrix, and PETScMatrix.

References SystemVector::copy(), and solve().

◆ solve() [2/3]

bool SystemMatrix::solve ( SystemVector b,
Matrix x 
)
virtual

Solves a linear system of equations for multiple right-hand-sides.

Parameters
bRight-hand-side vectors on input, solution vectors on output
[out]xMatrix of solution vectors (row-oriented)

Reimplemented in PETScMatrix, DenseMatrix, DiagMatrix, SparseMatrix, and SPRMatrix.

References SystemVector::dim(), dim(), SystemVector::getRef(), Real, utl::matrix< T >::resize(), and solve().

◆ solve() [3/3]

virtual bool SystemMatrix::solve ( SystemVector b,
Real rc = nullptr 
)
pure 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)

Implemented in DiagMatrix, SPRMatrix, ISTLMatrix, PETScMatrix, DenseMatrix, SparseMatrix, DenseMatrix, DiagMatrix, SparseMatrix, and SPRMatrix.

Referenced by eig_sol_(), ASMbase::globalL2projection(), operator/(), operator/(), solve(), solve(), and SIMbase::solveEqSystem().

◆ truncate()

virtual bool SystemMatrix::truncate ( Real  = Real(1.0e-16))
inlinevirtual

Truncates all small matrix elements to zero.

Reimplemented in SparseMatrix.

◆ write()

virtual std::ostream & SystemMatrix::write ( std::ostream &  os) const
inlineprotectedvirtual

Writes the system matrix to the given output stream.

Reimplemented in DenseMatrix, DiagMatrix, SparseMatrix, and SPRMatrix.


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