DSMatrix< T_ > Class Template Reference

To handle symmetric dense matrices. More...

#include <DSMatrix.h>

Inheritance diagram for DSMatrix< T_ >:
Matrix< T_ >

Public Member Functions

 DSMatrix ()
 Default constructor.
 
 DSMatrix (size_t dim)
 Constructor that for a symmetric matrix with given number of r‡qows.
 
 DSMatrix (const DSMatrix< T_ > &m)
 Copy Constructor.
 
 DSMatrix (Mesh &mesh, size_t dof=0, int is_diagonal=false)
 Constructor using mesh to initialize matrix.
 
 ~DSMatrix ()
 Destructor.
 
void setDiag ()
 Store diagonal entries in a separate internal vector.
 
void setSize (size_t dim)
 Set size (number of rows) of matrix.
 
void set (size_t i, size_t j, const T_ &val)
 Assign constant to entry (i,j) of the matrix.
 
void getColumn (size_t j, Vect< T_ > &v) const
 Get j-th column vector.
 
Vect< T_ > getColumn (size_t j) const
 Get j-th column vector.
 
void getRow (size_t i, Vect< T_ > &v) const
 Get i-th row vector.
 
Vect< T_ > getRow (size_t i) const
 Get i-th row vector.
 
void setRow (size_t i, const Vect< T_ > &v)
 Copy a given vector to a prescribed row in the matrix.
 
void setColumn (size_t j, const Vect< T_ > &v)
 Copy a given vector to a prescribed column in the matrix.
 
void setDiag (const T_ &a)
 Set matrix as diagonal and assign its diagonal entries as a constant.
 
void setDiag (const vector< T_ > &d)
 Set matrix as diagonal and assign its diagonal entries.
 
void add (size_t i, size_t j, const T_ &val)
 Add constant to an entry ofthe matrix.
 
T_ at (size_t i, size_t j)
 Return a value of a matrix entry.
 
T_ operator() (size_t i, size_t j) const
 Operator () (Constant version).
 
T_ & operator() (size_t i, size_t j)
 Operator () (Non constant version).
 
DSMatrix< T_ > & operator= (const DSMatrix< T_ > &m)
 Operator = Copy matrix m to current matrix instance.
 
DSMatrix< T_ > & operator= (const T_ &x)
 Operator = Assign matrix to identity times x.
 
DSMatrixoperator+= (const T_ &x)
 Operator +=.
 
DSMatrixoperator-= (const T_ &x)
 Operator -=.
 
int setLDLt ()
 Factorize matrix (LDLT)
 
void MultAdd (const Vect< T_ > &x, Vect< T_ > &y) const
 Multiply matrix by vector a*x and add result to y.
 
void MultAdd (T_ a, const Vect< T_ > &x, Vect< T_ > &y) const
 Multiply matrix by vector a*x and add to y.
 
void Mult (const Vect< T_ > &x, Vect< T_ > &y) const
 Multiply matrix by vector x and save result in y.
 
void TMult (const Vect< T_ > &x, Vect< T_ > &y) const
 Multiply transpose of matrix by vector x and add result in y.
 
void Axpy (T_ a, const DSMatrix< T_ > &m)
 Add to matrix the product of a matrix by a scalar.
 
void add (size_t i, const T_ &val)
 Add val to entry i.
 
void Axpy (T_ a, const Matrix< T_ > *m)
 Add to matrix the product of a matrix by a scalar.
 
int solve (Vect< T_ > &b, bool fact=true)
 Solve linear system.
 
int solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=true)
 Solve linear system.
 
const T_ * getArray ()
 Return matrix as C-Array. Matrix is stored row by row. Only lower triangle is stored.
 
T_ get (size_t i, size_t j) const
 Return entry (i,j) of matrix.
 
- Public Member Functions inherited from Matrix< T_ >
 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).
 
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 int Factor ()=0
 Factorize matrix. Available only if the storage class enables it.
 
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).
 
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 -=.
 

Detailed Description

template<class T_>
class OFELI::DSMatrix< T_ >

To handle symmetric dense matrices.

This class enables storing and manipulating symmetric dense matrices.

Template Parameters
T_Data type (double, float, complex<double>, ...)
Author
Rachid Touzani

Constructor & Destructor Documentation

◆ DSMatrix() [1/3]

template<class T_ >
DSMatrix ( size_t  dim)

Constructor that for a symmetric matrix with given number of r‡qows.

Parameters
[in]dimNumber of rows

◆ DSMatrix() [2/3]

template<class T_ >
DSMatrix ( const DSMatrix< T_ > &  m)

Copy Constructor.

Parameters
[in]mDSMatrix instance to copy

◆ DSMatrix() [3/3]

template<class T_ >
DSMatrix ( Mesh mesh,
size_t  dof = 0,
int  is_diagonal = false 
)

Constructor using mesh to initialize matrix.

Parameters
[in]meshMesh instance for which matrix graph is determined.
[in]dofOption parameter, with default value 0.
dof=1 means that only one degree of freedom for each node (or element or side) is taken to determine matrix structure. The value dof=0 means that matrix structure is determined using all DOFs.
[in]is_diagonalBoolean argument to say is the matrix is actually a diagonal matrix or not.

Member Function Documentation

◆ add()

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

Add constant to an entry ofthe matrix.

Parameters
[in]irow index
[in]jcolumn index
[in]valvalue to add to a(i,j)

Implements Matrix< T_ >.

◆ at()

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

Return a value of a matrix entry.

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

Implements Matrix< T_ >.

◆ Axpy() [1/2]

template<class T_ >
void Axpy ( T_  a,
const DSMatrix< T_ > &  m 
)

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

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

◆ Axpy() [2/2]

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

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

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

Implements Matrix< T_ >.

◆ getColumn() [1/2]

template<class T_ >
Vect< T_ > getColumn ( size_t  j) const

Get j-th column vector.

Parameters
[in]jIndex of column to extract
Returns
Vect instance where the column is stored
Remarks
Vector v does not need to be sized before. It is resized in the function

◆ getColumn() [2/2]

template<class T_ >
void getColumn ( size_t  j,
Vect< T_ > &  v 
) const

Get j-th column vector.

Parameters
[in]jIndex of column to extract
[out]vReference to Vect instance where the column is stored
Remarks
Vector v does not need to be sized before. It is resized in the function

◆ getRow() [1/2]

template<class T_ >
Vect< T_ > getRow ( size_t  i) const

Get i-th row vector.

Parameters
[in]iIndex of row to extract
Returns
Vect instance where the row is stored
Remarks
Vector v does not need to be sized before. It is resized in the function

◆ getRow() [2/2]

template<class T_ >
void getRow ( size_t  i,
Vect< T_ > &  v 
) const

Get i-th row vector.

Parameters
[in]iIndex of row to extract
[out]vReference to Vect instance where the row is stored
Remarks
Vector v does not need to be sized before. It is resized in the function

◆ MultAdd()

template<class T_ >
void MultAdd ( T_  a,
const Vect< T_ > &  x,
Vect< T_ > &  y 
) const
virtual

Multiply matrix by vector a*x and add to y.

Parameters
[in]aConstant to multiply by matrix
[in]xVector to multiply by matrix
[in,out]yVector to add to the result. y contains on output the result.

Implements Matrix< T_ >.

◆ operator()() [1/2]

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

Operator () (Non constant version).

Parameters
[in]iRow index
[in]jColumn index
Warning
To modify a value of an entry of the matrix it is safer not to modify both lower and upper triangles. Otherwise, wrong values will be assigned. If not sure, use the member functions set or add.

Implements Matrix< T_ >.

◆ operator()() [2/2]

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

Operator () (Constant version).

Parameters
[in]iRow index
[in]jColumn index

Implements Matrix< T_ >.

◆ operator+=()

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

Operator +=.

Add constant value x to all matrix entries.

◆ operator-=()

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

Operator -=.

Subtract constant value x from to all matrix entries.

◆ set()

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

Assign constant to entry (i,j) of the matrix.

Parameters
[in]irow index
[in]jcolumn index
[in]valvalue to assign to a(i,j)

Implements Matrix< T_ >.

◆ setColumn()

template<class T_ >
void setColumn ( size_t  j,
const Vect< T_ > &  v 
)

Copy a given vector to a prescribed column in the matrix.

Parameters
[in]jcolumn index to be assigned
[in]vVect instance to copy

◆ setDiag() [1/2]

template<class T_ >
void setDiag ( const T_ &  a)

Set matrix as diagonal and assign its diagonal entries as a constant.

Parameters
[in]aValue to assign to all diagonal entries

◆ setDiag() [2/2]

template<class T_ >
void setDiag ( const vector< T_ > &  d)

Set matrix as diagonal and assign its diagonal entries.

Parameters
[in]dVector entries to assign to matrix diagonal entries

◆ setLDLt()

template<class T_ >
int setLDLt ( )

Factorize matrix (LDLT)

Returns
  • 0, if factorization was normally performed,
  • n, if the n-th pivot is null.

◆ setRow()

template<class T_ >
void setRow ( size_t  i,
const Vect< T_ > &  v 
)

Copy a given vector to a prescribed row in the matrix.

Parameters
[in]irow index to be assigned
[in]vVect instance to copy

◆ setSize()

template<class T_ >
void setSize ( size_t  dim)

Set size (number of rows) of matrix.

Parameters
[in]dimNumber of rows and columns.

◆ solve() [1/2]

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

Solve linear system.

The matrix is factorized using the LDLt (Crout) decomposition. If this one is already factorized, no further factorization is performed. If the matrix has been modified the user has to refactorize it using the function setLDLt.

Parameters
[in]bVect instance that contains right-hand side.
[out]xVect instance that contains solution
[in]factSet true if matrix is to be factorized (Default value), false if not
Returns
  • 0 if solution was normally performed,
  • n if the n-th pivot is null.

Implements Matrix< T_ >.

◆ solve() [2/2]

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

Solve linear system.

The matrix is factorized using the LDLt (Crout) decomposition. If this one is already factorized, no further factorization is performed. If the matrix has been modified the user has to refactorize it using the function setLDLt.

Parameters
[in,out]bVect instance that contains right-hand side on input and solution on output.
[in]factSet true if matrix is to be factorized (Default value), false if not
Returns
  • 0 if solution was normally performed,
  • n if the n-th pivot is null.

Implements Matrix< T_ >.

◆ TMult()

template<class T_ >
void TMult ( const Vect< T_ > &  x,
Vect< T_ > &  y 
) const
virtual

Multiply transpose of matrix by vector x and add result in y.

Parameters
[in]xVector to add to y
[in,out]yon input, vector to add to. On output, result.

Implements Matrix< T_ >.