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

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

#include <DiagMatrix.h>

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

Public Member Functions

 DiagMatrix (size_t m=0)
 Default constructor.
 
 DiagMatrix (const DiagMatrix &A)
 Copy constructor.
 
 DiagMatrix (const RealArray &data, size_t nrows=0)
 Special constructor taking data from a one-dimensional array.
 
virtual ~DiagMatrix ()
 Empty destructor.
 
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)
 Resizes the matrix to dimension \(r \times r\).
 
virtual size_t dim (int) const
 Returns the dimension of the system matrix.
 
VectorgetMat ()
 Access to the matrix itself.
 
Realoperator() (size_t r)
 Index-1 based element access.
 
const Realoperator() (size_t r) 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.
 
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.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, int e)
 Adds an element matrix into the associated system matrix.
 
virtual bool assemble (const Matrix &eM, const SAM &sam, SystemVector &B, const IntVec &meq)
 Adds an element matrix into the associated system matrix.
 
virtual bool assemble (const Matrix &eM, const IntVec &meq)
 Adds an element matrix into the associated system matrix.
 
bool assembleStruct (int val, const SAM &sam, const IntVec &meq)
 Assembles a validation matrix assuming unit element contributions.
 
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.
 
virtual bool add (Real sigma, int ieq)
 Adds the constant σ to the diagonal matrix.
 
virtual bool multiply (const SystemVector &B, SystemVector &C) const
 Performs the matrix-vector multiplication C = *this * B.
 
virtual bool solve (SystemVector &B, Real *)
 Solves the linear system of equations for a given right-hand-side.
 
virtual Real Linfnorm () const
 Returns the L-infinity norm of the matrix.
 
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.
 
- 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 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 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 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.
 

Protected Member Functions

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

Vector myMat
 The actual diagonal matrix.
 

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 diagonal system matrix.

Member Function Documentation

◆ add() [1/2]

bool DiagMatrix::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::vector< T >::add(), SystemMatrix::flagNonZeroEqs(), myMat, and utl::vector< T >::size().

◆ add() [2/2]

bool DiagMatrix::add ( Real  sigma,
int  ieq 
)
virtual

Adds the constant σ to the diagonal matrix.

Reimplemented from SystemMatrix.

References SystemMatrix::flagNonZeroEq(), myMat, Real, and utl::vector< T >::size().

◆ assemble() [1/4]

bool DiagMatrix::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

Implements SystemMatrix.

References SystemMatrix::flagNonZeroEq(), and myMat.

◆ assemble() [2/4]

bool DiagMatrix::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 assemble(), SAM::getElmEqns(), myMat, SAM::neq, utl::matrix< T >::rows(), and utl::vector< T >::size().

Referenced by assemble(), and assemble().

◆ assemble() [3/4]

bool DiagMatrix::assemble ( const Matrix eM,
const SAM sam,
SystemVector B,
const IntVec 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 utl::matrix< T >::cols(), SystemMatrix::flagNonZeroEqs(), SAM::meqn, SAM::mmceq, SAM::mpmceq, myMat, utl::matrix< T >::rows(), and SAM::ttcc.

◆ assemble() [4/4]

bool DiagMatrix::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 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.

Implements SystemMatrix.

References assemble().

◆ assembleStruct()

bool DiagMatrix::assembleStruct ( int  val,
const SAM sam,
const IntVec meq 
)

Assembles a validation matrix assuming unit element contributions.

Parameters
[in]valValue identifying current threading group
[in]samAuxiliary data for FE assembly management
[in]meqMatrix of element equation numbers

For validation of threading groups.

This method is doing the same as the above assemble() method, but where all element matrices are assumed identity matrices. The purpose is to verify that each equation only gets a single contribution within each threading group.

References SystemMatrix::flagNonZeroEqs(), SAM::meqn, SAM::mmceq, SAM::mpmceq, and myMat.

Referenced by ASMs2D::validateThreadGroups().

◆ copy()

virtual SystemMatrix * DiagMatrix::copy ( ) const
inlinevirtual

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

Implements SystemMatrix.

◆ dim()

virtual size_t DiagMatrix::dim ( int  ) const
inlinevirtual

Returns the dimension of the system matrix.

Implements SystemMatrix.

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

Referenced by ASMs2D::validateThreadGroups().

◆ dump()

void DiagMatrix::dump ( std::ostream &  os,
LinAlg::StorageFormat  format,
const char *  label 
)
virtual

Dumps the system matrix on a specified format.

Reimplemented from SystemMatrix.

References LinAlg::FLAT, LinAlg::MATLAB, LinAlg::MATRIX_MARKET, myMat, utl::vector< T >::size(), and utl::writeMatlab().

◆ getType()

virtual LinAlg::MatrixType DiagMatrix::getType ( ) const
inlinevirtual

Returns the matrix type.

Implements SystemMatrix.

References LinAlg::DIAG.

◆ init()

virtual void DiagMatrix::init ( )
inlinevirtual

Initializes the matrix to zero assuming it is properly dimensioned.

Implements SystemMatrix.

References utl::vector< T >::fill(), myMat, and Real.

◆ initAssembly()

void DiagMatrix::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::vector< T >::resize().

◆ Linfnorm()

virtual Real DiagMatrix::Linfnorm ( ) const
inlinevirtual

Returns the L-infinity norm of the matrix.

Implements SystemMatrix.

References myMat, and utl::vector< T >::normInf().

◆ mult()

virtual void DiagMatrix::mult ( Real  alpha)
inlinevirtual

Multiplication with a scalar.

Implements SystemMatrix.

References myMat.

◆ multiply()

bool DiagMatrix::multiply ( const SystemVector B,
SystemVector C 
) const
virtual

Performs the matrix-vector multiplication C = *this * B.

Reimplemented from SystemMatrix.

References SystemVector::dim(), SystemVector::getPtr(), SystemVector::getRef(), myMat, utl::vector< T >::ptr(), Real, and utl::vector< T >::size().

◆ redim()

bool DiagMatrix::redim ( size_t  r)
inline

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

Will preserve existing matrix content within the new dimension.

References myMat, utl::vector< T >::resize(), and utl::RETAIN.

◆ solve() [1/4]

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 from SystemMatrix.

◆ solve() [2/4]

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 from SystemMatrix.

◆ solve() [3/4]

bool DiagMatrix::solve ( SystemVector B,
Real  
)
virtual

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

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

Implements SystemMatrix.

References utl::vector< T >::empty(), SystemVector::getPtr(), myMat, and Real.

◆ solve() [4/4]

virtual bool SystemMatrix::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.

◆ write()

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

Writes the system matrix to the given output stream.

Reimplemented from SystemMatrix.

References myMat.


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