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. More...
 
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 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 assemble (const Matrix &eM, const SAM &sam, int e)=0
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, int e)=0
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, const IntVec &meq)=0
 Adds an element matrix into the associated system matrix. More...
 
virtual bool assemble (const Matrix &eM, const IntVec &meq)=0
 Adds an element matrix into the associated system matrix. More...
 
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. More...
 
virtual bool solve (const SystemVector &b, SystemVector &x)
 Solves the linear system of equations for a given right-hand-side. More...
 
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

◆ 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 underlying SAM

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

◆ 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 PETScMatrix, SPRMatrix, SparseMatrix, DiagMatrix, and DenseMatrix.

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

◆ 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 DenseMatrix, PETScMatrix, SPRMatrix, SparseMatrix, and DiagMatrix.

◆ 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 PETScMatrix, SPRMatrix, SparseMatrix, DiagMatrix, and DenseMatrix.

◆ 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 PETScMatrix, and ISTLMatrix.

References add(), and nonZeroEqs.

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

◆ 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 PETScMatrix, ISTLMatrix, SPRMatrix, DiagMatrix, DenseMatrix, and SparseMatrix.

◆ solve() [1/2]

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 PETScMatrix, and ISTLMatrix.

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

◆ solve() [2/2]

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 SparseMatrix, DenseMatrix, PETScMatrix, ISTLMatrix, SPRMatrix, and DiagMatrix.

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


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