Matrix< T_ > Class Template Referenceabstract

Virtual class to handle matrices for all storage formats. More...

#include <Matrix.h>

Inheritance diagram for Matrix< T_ >:
BMatrix< real_t > DMatrix< real_t > DSMatrix< real_t > SpMatrix< real_t > BMatrix< T_ > DMatrix< T_ > DSMatrix< T_ > SkMatrix< T_ > SkSMatrix< T_ > SpMatrix< T_ > TrMatrix< T_ >

Public Member Functions

 Matrix ()
 Default constructor.
 
 Matrix (const Matrix< T_ > &m)
 Copy Constructor.
 
virtual ~Matrix ()
 Destructor.
 
virtual void reset ()
 Set matrix to 0 and reset factorization parameter.
 
size_t getNbRows () const
 Return number of rows.
 
size_t getNbColumns () const
 Return number of columns.
 
string getName () const
 Return name of matrix.
 
MatrixSize getMatrixSize () const
 Return storage type.
 
void setPenal (real_t p)
 Set Penalty Parameter (For boundary condition prescription).
 
void setDiagonal ()
 Set the matrix as diagonal.
 
T_ getDiag (size_t k) const
 Return k-th diagonal entry of matrix.
 
size_t size () const
 Return matrix dimension (Number of rows and columns).
 
virtual void MultAdd (const Vect< T_ > &x, Vect< T_ > &y) const =0
 Multiply matrix by vector x and add to y
 
virtual void MultAdd (T_ a, const Vect< T_ > &x, Vect< T_ > &y) const =0
 Multiply matrix by vector a*x and add to y
 
virtual void Mult (const Vect< T_ > &x, Vect< T_ > &y) const =0
 Multiply matrix by vector x and save in y
 
virtual void TMult (const Vect< T_ > &v, Vect< T_ > &w) const =0
 Multiply transpose of matrix by vector x and save in y
 
virtual void Axpy (T_ a, const Matrix< T_ > *x)=0
 Add to matrix the product of a matrix by a scalar.
 
void setDiagonal (Mesh &mesh)
 Initialize matrix storage in the case where only diagonal terms are stored.
 
virtual void clear ()
 brief Set all matrix entries to zero
 
void Assembly (const Element &el, T_ *a)
 Assembly of element matrix into global matrix.
 
void Assembly (const Side &sd, T_ *a)
 Assembly of side matrix into global matrix.
 
void Prescribe (Vect< T_ > &b, const Vect< T_ > &u, int flag=0)
 Impose by a penalty method an essential boundary condition, using the Mesh instance provided by the constructor.
 
void Prescribe (int dof, int code, Vect< T_ > &b, const Vect< T_ > &u, int flag=0)
 Impose by a penalty method an essential boundary condition to a given degree of freedom for a given code.
 
void Prescribe (Vect< T_ > &b, int flag=0)
 Impose by a penalty method a homegeneous (=0) essential boundary condition.
 
void Prescribe (size_t dof, Vect< T_ > &b, const Vect< T_ > &u, int flag=0)
 Impose by a penalty method an essential boundary condition when only one DOF is treated.
 
void PrescribeSide ()
 Impose by a penalty method an essential boundary condition when DOFs are supported by sides.
 
virtual void add (size_t i, size_t j, const T_ &val)=0
 Add val to entry (i,j).
 
virtual void add (size_t i, const T_ &val)=0
 Add val to entry i.
 
virtual int Factor ()=0
 Factorize matrix. Available only if the storage class enables it.
 
virtual int solve (Vect< T_ > &b, bool fact=true)=0
 Solve the linear system.
 
virtual int solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=true)=0
 Solve the linear system.
 
int FactorAndSolve (Vect< T_ > &b)
 Factorize matrix and solve the linear system.
 
int FactorAndSolve (const Vect< T_ > &b, Vect< T_ > &x)
 Factorize matrix and solve the linear system.
 
size_t getLength () const
 Return number of stored terms in matrix.
 
int isDiagonal () const
 Say if matrix is diagonal or not.
 
int isFactorized () const
 Say if matrix is factorized or not.
 
virtual size_t getColInd (size_t i) const
 Return Column index for column i (See the description for class SpMatrix).
 
virtual size_t getRowPtr (size_t i) const
 Return Row pointer for row i (See the description for class SpMatrix).
 
virtual void set (size_t i, size_t j, const T_ &val)=0
 Assign a value to an entry of the matrix.
 
virtual T_ at (size_t i, size_t j)=0
 Return a value of a matrix entry.
 
virtual T_ & operator() (size_t i, size_t j)=0
 Operator () (Non constant version).
 
virtual T_ operator() (size_t i, size_t j) const =0
 Operator () (Non constant version).
 
T_ operator() (size_t i) const
 Operator () with one argument (Constant version).
 
T_ & operator() (size_t i)
 Operator () with one argument (Non Constant version).
 
T_ & operator[] (size_t k)
 Operator [] (Non constant version).
 
T_ operator[] (size_t k) const
 Operator [] (Constant version).
 
Matrixoperator= (Matrix< T_ > &m)
 Operator =.
 
Matrixoperator+= (const Matrix< T_ > &m)
 Operator +=.
 
Matrixoperator-= (const Matrix< T_ > &m)
 Operator -=.
 
Matrixoperator= (const T_ &x)
 Operator =.
 
Matrixoperator*= (const T_ &x)
 Operator *=.
 
Matrixoperator+= (const T_ &x)
 Operator +=.
 
Matrixoperator-= (const T_ &x)
 Operator -=.
 
virtual T_ get (size_t i, size_t j) const =0
 Return entry (i,j) of matrix if this one is stored, 0 else.
 

Detailed Description

template<class T_>
class OFELI::Matrix< T_ >

Virtual class to handle matrices for all storage formats.

This class enables storing and manipulating dense matrices. The template parameter is the type of matrix entries. Any matrix entry can be accessed by the () operator: For instance, if A is an instance of this class, A(i,j) stands for the entry at the i-th row and j-th column, i and j starting from 1. Entries of A can be assigned a value by the same operator.

Template Parameters
<T_>Data type (real_t, float, complex<real_t>, ...)
Author
Rachid Touzani

Constructor & Destructor Documentation

◆ Matrix()

template<class T_ >
Matrix ( )

Default constructor.

Initializes a zero-size matrix.

Member Function Documentation

◆ Assembly() [1/2]

template<class T_ >
void Assembly ( const Element el,
T_ *  a 
)

Assembly of element matrix into global matrix.

Case where element matrix is given by a C-array.

Parameters
[in]elPointer to element instance
[in]aElement matrix as a C-array

◆ Assembly() [2/2]

template<class T_ >
void Assembly ( const Side sd,
T_ *  a 
)

Assembly of side matrix into global matrix.

Case where side matrix is given by a C-array.

Parameters
[in]sdPointer to side instance
[in]aSide matrix as a C-array instance

◆ at()

template<class T_ >
virtual T_ at ( size_t  i,
size_t  j 
)
pure virtual

Return a value of a matrix entry.

Parameters
[in]iRow index (starts at 1)
[in]jColumn index (starts at 1)

Implemented in BMatrix< T_ >, BMatrix< real_t >, DMatrix< T_ >, DMatrix< real_t >, DSMatrix< T_ >, DSMatrix< real_t >, SkMatrix< T_ >, SkSMatrix< T_ >, SpMatrix< T_ >, SpMatrix< real_t >, and TrMatrix< T_ >.

◆ Axpy()

template<class T_ >
virtual void Axpy ( T_  a,
const Matrix< T_ > *  x 
)
pure virtual

Add to matrix the product of a matrix by a scalar.

Parameters
[in]aScalar to premultiply
[in]xMatrix by which a is multiplied. The result is added to current instance

Implemented in DMatrix< T_ >, DSMatrix< T_ >, SkMatrix< T_ >, SkSMatrix< T_ >, SpMatrix< T_ >, TrMatrix< T_ >, and BMatrix< T_ >.

◆ FactorAndSolve() [1/2]

template<class T_ >
int FactorAndSolve ( const Vect< T_ > &  b,
Vect< T_ > &  x 
)

Factorize matrix and solve the linear system.

This is available only if the storage class enables it.

Parameters
[in]bVect instance that contains right-hand side
[out]xVect instance that contains solution
Returns
  • 0 if solution was normally performed
  • n if the n-th pivot is nul

◆ FactorAndSolve() [2/2]

template<class T_ >
int FactorAndSolve ( Vect< T_ > &  b)

Factorize matrix and solve the linear system.

This is available only if the storage cass enables it.

Parameters
[in,out]bVect instance that contains right-hand side on input and solution on output

◆ getDiag()

template<class T_ >
T_ getDiag ( size_t  k) const

Return k-th diagonal entry of matrix.

First entry is given by getDiag(1).

◆ isFactorized()

template<class T_ >
int isFactorized ( ) const

Say if matrix is factorized or not.

If the matrix was not factorized, the class does not allow solving by a direct solver.

◆ operator()() [1/4]

template<class T_ >
T_ & operator() ( size_t  i)

Operator () with one argument (Non Constant version).

Returns i-th position in the array storing matrix entries. The first entry is at location 1. Entries are stored row by row.

Parameters
[in]ientry index

◆ operator()() [2/4]

template<class T_ >
T_ operator() ( size_t  i) const

Operator () with one argument (Constant version).

Returns i-th position in the array storing matrix entries. The first entry is at location 1. Entries are stored row by row.

Parameters
[in]ientry index

◆ operator()() [3/4]

template<class T_ >
virtual T_ operator() ( size_t  i,
size_t  j 
) const
pure virtual

Operator () (Non constant version).

Returns the (i,j) entry of the matrix.

Parameters
[in]iRow index
[in]jColumn index

Implemented in BMatrix< T_ >, BMatrix< real_t >, DMatrix< T_ >, DMatrix< real_t >, DSMatrix< T_ >, DSMatrix< real_t >, SkMatrix< T_ >, SkSMatrix< T_ >, SpMatrix< T_ >, SpMatrix< real_t >, and TrMatrix< T_ >.

◆ operator()() [4/4]

template<class T_ >
virtual T_ & operator() ( size_t  i,
size_t  j 
)
pure virtual

Operator () (Non constant version).

Returns the (i,j) entry of the matrix.

Parameters
[in]iRow index
[in]jColumn index

Implemented in BMatrix< T_ >, BMatrix< real_t >, DMatrix< T_ >, DMatrix< real_t >, DSMatrix< T_ >, DSMatrix< real_t >, SkMatrix< T_ >, SkSMatrix< T_ >, SpMatrix< T_ >, SpMatrix< real_t >, and TrMatrix< T_ >.

◆ operator*=()

template<class T_ >
Matrix & operator*= ( const T_ &  x)

Operator *=.

Premultiply matrix entries by constant value x

◆ operator+=() [1/2]

template<class T_ >
Matrix & operator+= ( const Matrix< T_ > &  m)

Operator +=.

Add matrix m to current matrix instance.

◆ operator+=() [2/2]

template<class T_ >
Matrix & operator+= ( const T_ &  x)

Operator +=.

Add constant value x to all matrix entries.

◆ operator-=() [1/2]

template<class T_ >
Matrix & operator-= ( const Matrix< T_ > &  m)

Operator -=.

Subtract matrix m from current matrix instance.

◆ operator-=() [2/2]

template<class T_ >
Matrix & operator-= ( const T_ &  x)

Operator -=.

Subtract constant value x from all matrix entries.

◆ operator=() [1/2]

template<class T_ >
Matrix & operator= ( const T_ &  x)

Operator =.

Assign constant value x to all matrix entries.

◆ operator=() [2/2]

template<class T_ >
Matrix & operator= ( Matrix< T_ > &  m)

Operator =.

Copy matrix m to current matrix instance.

◆ operator[]() [1/2]

template<class T_ >
T_ & operator[] ( size_t  k)

Operator [] (Non constant version).

Returns k-th stored element in matrix Index k starts at 0.

◆ operator[]() [2/2]

template<class T_ >
T_ operator[] ( size_t  k) const

Operator [] (Constant version).

Returns k-th stored element in matrix Index k starts at 0.

◆ Prescribe() [1/4]

template<class T_ >
void Prescribe ( int  dof,
int  code,
Vect< T_ > &  b,
const Vect< T_ > &  u,
int  flag = 0 
)

Impose by a penalty method an essential boundary condition to a given degree of freedom for a given code.

This member function modifies diagonal terms in matrix and terms in vector that correspond to degrees of freedom with nonzero code in order to impose a boundary condition. The penalty parameter is defined by default equal to 1.e20. It can be modified by member function setPenal(..).

Parameters
[in]dofDegree of freedom for which a boundary condition is to be enforced
[in]codeCode for which a boundary condition is to be enforced
[in,out]bVect instance that contains right-hand side.
[in]uVect instance that contains imposed valued at DOFs where they are to be imposed.
[in]flagParameter to determine whether only the right-hand side is to be modified
(dof>0) or both matrix and right-hand side (dof=0, default value).

◆ Prescribe() [2/4]

template<class T_ >
void Prescribe ( size_t  dof,
Vect< T_ > &  b,
const Vect< T_ > &  u,
int  flag = 0 
)

Impose by a penalty method an essential boundary condition when only one DOF is treated.

This member function modifies diagonal terms in matrix and terms in vector that correspond to degrees of freedom with nonzero code in order to impose a boundary condition. This gunction is to be used if only one DOF per node is treated in the linear system. The penalty parameter is by default equal to 1.e20. It can be modified by member function setPenal.

Parameters
[in]dofLabel of the concerned degree of freedom (DOF).
[in,out]bVect instance that contains right-hand side.
[in]uVect instance that conatins imposed valued at DOFs where they are to be imposed.
[in]flagParameter to determine whether only the right-hand side is to be modified (dof>0)
or both matrix and right-hand side (dof=0, default value).

◆ Prescribe() [3/4]

template<class T_ >
void Prescribe ( Vect< T_ > &  b,
const Vect< T_ > &  u,
int  flag = 0 
)

Impose by a penalty method an essential boundary condition, using the Mesh instance provided by the constructor.

This member function modifies diagonal terms in matrix and terms in vector that correspond to degrees of freedom with nonzero code in order to impose a boundary condition. The penalty parameter is defined by default equal to 1.e20. It can be modified by member function setPenal(..).

Parameters
[in,out]bVect instance that contains right-hand side.
[in]uVect instance that contains imposed valued at DOFs where they are to be imposed.
[in]flagParameter to determine whether only the right-hand side is to be modified (dof>0)
or both matrix and right-hand side (dof=0, default value).

◆ Prescribe() [4/4]

template<class T_ >
void Prescribe ( Vect< T_ > &  b,
int  flag = 0 
)

Impose by a penalty method a homegeneous (=0) essential boundary condition.

This member function modifies diagonal terms in matrix and terms in vector that correspond to degrees of freedom with nonzero code in order to impose a boundary condition. The penalty parameter is defined by default equal to 1.e20. It can be modified by member function setPenal(..).

Parameters
[in,out]bVect instance that contains right-hand side.
[in]flagParameter to determine whether only the right-hand side is to be modified (dof>0)
or both matrix and right-hand side (dof=0, default value).

◆ PrescribeSide()

template<class T_ >
void PrescribeSide ( )

Impose by a penalty method an essential boundary condition when DOFs are supported by sides.

This member function modifies diagonal terms in matrix and terms in vector that correspond to degrees of freedom with nonzero code in order to impose a boundary condition. The penalty parameter is defined by default equal to 1.e20. It can be modified by member function setPenal(..).

◆ reset()

template<class T_ >
virtual void reset ( )
virtual

Set matrix to 0 and reset factorization parameter.

Warning
This function must be used if after a factorization, the matrix has been modified

Reimplemented in DMatrix< T_ >, and DMatrix< real_t >.

◆ set()

template<class T_ >
virtual void set ( size_t  i,
size_t  j,
const T_ &  val 
)
pure virtual

Assign a value to an entry of the matrix.

Parameters
[in]iRow index
[in]jColumn index
[in]valValue to assign

Implemented in BMatrix< T_ >, DMatrix< T_ >, DSMatrix< T_ >, SkMatrix< T_ >, SkSMatrix< T_ >, SpMatrix< T_ >, and TrMatrix< T_ >.

◆ setDiagonal()

template<class T_ >
void setDiagonal ( Mesh mesh)

Initialize matrix storage in the case where only diagonal terms are stored.

This member function is to be used for explicit time integration schemes

◆ solve() [1/2]

template<class T_ >
virtual int solve ( const Vect< T_ > &  b,
Vect< T_ > &  x,
bool  fact = true 
)
pure virtual

Solve the linear system.

If the inherited class is SpMatrix, the function uses an iterative method once this one has been chosen. Otherwise, the method solves the linear system by factorization.

Parameters
[in]bVect instance that contains right-hand side
[out]xVect instance that contains solution
[in]factSet to true if factorization is to be performed, false if not. [Default: true]
Returns
  • 0 if solution was normally performed
  • n if the n-th pivot is null
    Solution is performed only is factorization has previouly been invoked.

Implemented in BMatrix< T_ >, SpMatrix< T_ >, TrMatrix< T_ >, DMatrix< T_ >, DSMatrix< T_ >, SkMatrix< T_ >, and SkSMatrix< T_ >.

◆ solve() [2/2]

template<class T_ >
virtual int solve ( Vect< T_ > &  b,
bool  fact = true 
)
pure virtual

Solve the linear system.

If the inherited class is SpMatrix, the function uses an iterative method once this one has been chosen. Otherwise, the method solves the linear system by factorization.

Implemented in BMatrix< T_ >, DMatrix< T_ >, DSMatrix< T_ >, SkMatrix< T_ >, SkSMatrix< T_ >, and TrMatrix< T_ >.