DMatrix Class Template Reference
[Vector and Matrix]
#include <DMatrix.h>

Detailed Description
template<class T_>
class OFELI::DMatrix< T_ >
To store dense matrices.
This class enables storing and manipulating general dense matrices. Matrices can be square or rectangle ones.
Template Argument :
- T_ data type (double, float, int, ...)
Public Member Functions | |
| void | Add (size_t i, size_t j, const T_ &x) |
| Add constant x to entry (i,j) of the matrix. | |
| void | Assembly (const Side *sd, const DMatrix< T_ > &a) |
| Assembly of side matrix into global matrix. | |
| void | Assembly (const Side *sd, T_ *a) |
| Assembly of side matrix into global matrix. | |
| void | Assembly (const Element *el, const DMatrix< T_ > &a) |
| Assembly of element matrix into global matrix. | |
| void | Assembly (const Element *el, T_ *a) |
| Assembly of element matrix into global matrix. | |
| DMatrix (const DMatrix< T_ > &m) | |
| Copy Constructor. | |
| DMatrix (Vect< T_ > &v) | |
| Constructor that uses a Vect instance. | |
| DMatrix (size_t nr, size_t nc) | |
| Constructor for a matrix with nr rows and nc columns. | |
| DMatrix (size_t nr) | |
| Constructor for a matrix with nr rows and nr columns. | |
| DMatrix () | |
| Default constructor. Initializes a zero-dimension matrix. | |
| int | Factor () |
| Factorize matrix (LU factorization). | |
| int | FactorAndSolve (Vect< T_ > &b) |
| Factorize matrix and solve the linear system. | |
| T_ * | getArray () const |
| Return matrix as C-Array. | |
| size_t | getColInd (size_t i) const |
| Return storage information. | |
| Vect< T_ > | getColumn (size_t j) const |
| Get j-th column vector. | |
| T_ | getDiag (size_t k) const |
| Return k-th diagonal entry of A. | |
| T_ | getEntry (size_t i, size_t j) const |
| Return entry (i,j) of matrix. | |
| unsigned long | getLength () const |
| Return number of stored terms in matrix. | |
| size_t | getNbColumns () const |
| Return number of columns. | |
| size_t | getNbRows () const |
| Return number of rows. | |
| void | getPrintView (size_t &rmin, size_t &rmax, size_t &cmin, size_t &cmax) const |
| Return window data for matrix printing. | |
| Vect< T_ > | getRow (size_t i) const |
| Get i-th row vector. | |
| virtual size_t | getRowPtr (size_t i) const |
| Return Row pointer for row i (See the description for class SpMatrix). | |
| size_t | getSize () const |
| Return matrix dimension (Number of rows and columns). | |
| bool | isDiagonal () const |
| Say if matrix is diagonal or not. | |
| bool | isFactorized () const |
| Say if matrix is factorized or not. | |
| void | Mult (const Vect< T_ > &x, Vect< T_ > &y) const |
| Multiply matrix by vector x and save result in y. | |
| void | MultAdd (const Vect< T_ > &x, Vect< T_ > &y) const |
| Multiply matrix by vector 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 result to y. | |
| const T_ | operator() (size_t i) const |
| Operator () with one argument (Constant version). | |
| T_ & | operator() (size_t i, size_t j) |
| Operator () (Non constant version). | |
| T_ | operator() (size_t i, size_t j) const |
| Operator () (Constant version). | |
| DMatrix & | operator*= (const T_ &x) |
| Operator *=. | |
| Matrix & | operator+= (const Matrix< T_ > &m) |
| Operator +=. | |
| DMatrix & | operator+= (const T_ &x) |
| Operator +=. | |
| DMatrix & | operator+= (const DMatrix< T_ > &m) |
| Operator +=. | |
| Matrix & | operator-= (const Matrix< T_ > &m) |
| Operator -=. | |
| DMatrix & | operator-= (const T_ &x) |
| Operator -=. | |
| DMatrix & | operator-= (const DMatrix< T_ > &m) |
| Operator -=. | |
| DMatrix & | operator= (const T_ &x) |
| Operator =. | |
| DMatrix & | operator= (DMatrix< T_ > &m) |
| Operator =. | |
| T_ | operator[] (size_t k) const |
| Operator [] (Constant version). | |
| T_ & | operator[] (size_t k) |
| Operator [] (Non constant version). | |
| void | Prescribe (size_t dof, const class Mesh &mesh, 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 | Prescribe (const class Mesh &mesh, Vect< T_ > &b, int flag=0) |
| Impose by a penalty method a homegeneous (=0) essential boundary condition. | |
| void | Prescribe (const class Mesh &mesh, Vect< T_ > &b, const Vect< T_ > &u, int flag=0) |
| Impose by a penalty method an essential boundary condition. | |
| void | PrescribeSide (const class Mesh &mesh) |
| Impose by a penalty method an essential boundary condition when DOFs are supported by sides. | |
| void | Resize (size_t nr, size_t nc) |
| Set size (number of rows and columns) of matrix. | |
| void | Resize (size_t size) |
| Set size (number of rows) of matrix. | |
| void | Set (size_t i, size_t j, const T_ &x) |
| Assign a constant value x to an entry of the matrix. | |
| void | setDiag () |
| Store diagonal entries in a separate internal vector. | |
| void | setDiagonal (const class Mesh &mesh) |
| Initialize matrix storage in the case where only diagonal terms are stored. | |
| void | setPenal (double p) |
| Set Penalty Parameter (For boundary condition prescription). | |
| void | setPrintView (size_t rmin, size_t rmax, size_t cmin, size_t cmax) |
| set a window for matrix printing | |
| int | Solve (const Vect< T_ > &b, Vect< T_ > &x) |
| Solve system with factorized matrix (forward and back substitution). | |
| int | Solve (Vect< T_ > &b) |
| Solve system with factorized matrix (forward and back substitution). | |
| void | TMult (const Vect< T_ > &x, Vect< T_ > &y) const |
| Multiply transpose of matrix by vector x and add result in y. | |
| ~DMatrix () | |
| Destructor. | |
Constructor & Destructor Documentation
| DMatrix | ( | size_t | nr | ) |
Constructor for a matrix with nr rows and nr columns.
Matrix entries are set to 0.
References DMatrix::Resize().
| DMatrix | ( | size_t | nr, | |
| size_t | nc | |||
| ) |
Constructor for a matrix with nr rows and nc columns.
Matrix entries are set to 0.
References DMatrix::Resize().
Constructor that uses a Vect instance.
The class uses the memory space occupied by this vector.
- Parameters:
-
[in] v Vector to copy
References Vect::getSize().
Copy Constructor.
- Parameters:
-
[in] m Matrix to copy
References DMatrix::_fact, and DMatrix::Resize().
Member Function Documentation
| void Add | ( | size_t | i, | |
| size_t | j, | |||
| const T_ & | x | |||
| ) | [virtual] |
Add constant x to entry (i,j) of the matrix.
- Parameters:
-
[in] i row index [in] j column index [in] x Constant to add
Implements Matrix.
Assembly of side matrix into global matrix.
Case where side matrix is given by a DMatrix instance.
References Matrix::Add(), Node::getDOF(), Node::getNbDOF(), Side::getNbNodes(), and Side::getPtrNode().
| void Assembly | ( | const Side * | sd, | |
| T_ * | a | |||
| ) | [inherited] |
Assembly of side matrix into global matrix.
Case where side matrix is given by a C-array.
- Parameters:
-
[in] sd Pointer to side instance [in] a Side matrix as a C-array instance
References Matrix::Add(), Node::getDOF(), Node::getNbDOF(), Side::getNbNodes(), and Side::getPtrNode().
Assembly of element matrix into global matrix.
Case where element matrix is given by a DMatrix instance.
References Matrix::Add(), Node::getDOF(), Node::getNbDOF(), Element::getNbNodes(), and Element::getPtrNode().
| void Assembly | ( | const Element * | el, | |
| T_ * | a | |||
| ) | [inherited] |
Assembly of element matrix into global matrix.
Case where element matrix is given by a C-array.
- Parameters:
-
[in] el Pointer to element instance [in] a Element matrix as a C-array
References Matrix::Add(), Node::getDOF(), Node::getNbDOF(), Element::getNbNodes(), and Element::getPtrNode().
| int Factor | ( | ) | [virtual] |
Factorize matrix (LU factorization).
- Return values:
-
ret - 0 if factorization was normally performed,
- n if the n-th pivot is null.
Implements Matrix.
References OFELI::Abs(), and OFELI_TOLERANCE.
| int FactorAndSolve | ( | Vect< T_ > & | b | ) | [inherited] |
Factorize matrix and solve the linear system.
This is available only if the storage class enables it.
References Matrix::Factor(), and Matrix::Solve().
| T_ * getArray | ( | ) | const |
Return matrix as C-Array.
Matrix is stored row by row.
| T_ getDiag | ( | size_t | k | ) | const [inherited] |
Return k-th diagonal entry of A.
First entry is given by GetDiag(1).
| void getPrintView | ( | size_t & | rmin, | |
| size_t & | rmax, | |||
| size_t & | cmin, | |||
| size_t & | cmax | |||
| ) | const [inherited] |
Return window data for matrix printing.
- Parameters:
-
[out] rmin first row index to view [out] rmax last row index to view [out] cmin first column index to view [out] cmax last column index to view
Referenced by OFELI::operator<<().
| bool isFactorized | ( | ) | const [inherited] |
Say if matrix is factorized or not.
If the matrix was not factorized, the class does not allow solving by a direct solver.
Multiply matrix by vector x and save result in y.
- Parameters:
-
[in] x Vector to add to y [out] y Result.
Implements Matrix.
References OFELI::Clear(), and DMatrix::MultAdd().
Multiply matrix by vector x and add result to y.
- Parameters:
-
[in] x Vector to add to y [in,out] y on input, vector to add to. On output, result.
Implements Matrix.
Multiply matrix by vector a*x and add result to y.
- Parameters:
-
[in] a constant to multiply by [in] x Vector to multiply by a [in,out] y on input, vector to add to. On output, result.
Implements Matrix.
Referenced by DMatrix::Mult().
| const T_ operator() | ( | size_t | i | ) | const [virtual] |
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] i entry index
Implements Matrix.
| T_ & operator() | ( | size_t | i, | |
| size_t | j | |||
| ) | [virtual] |
Operator () (Non constant version).
Return a(i,j)
- Parameters:
-
[in] i row index [in] j column index
Implements Matrix.
| T_ operator() | ( | size_t | i, | |
| size_t | j | |||
| ) | const [virtual] |
Operator () (Constant version).
Return a(i,j)
- Parameters:
-
[in] i row index [in] j column index
Implements Matrix.
| DMatrix< T_ > & operator*= | ( | const T_ & | x | ) |
Operator +=.
Add matrix m to current matrix instance.
| DMatrix< T_ > & operator+= | ( | const T_ & | x | ) |
Operator +=.
Add matrix m to current matrix instance.
Operator -=.
Subtract matrix m from current matrix instance.
| DMatrix< T_ > & operator-= | ( | const T_ & | x | ) |
Operator -=.
Subtract matrix m from current matrix instance.
| DMatrix< T_ > & operator= | ( | const T_ & | x | ) |
Operator =.
Copy matrix m to current matrix instance.
| T_ operator[] | ( | size_t | k | ) | const [inherited] |
Operator [] (Constant version).
Returns k-th stored element in matrix Index k starts at 0.
Reimplemented in SpMatrix, and SpMatrix< double >.
| T_& operator[] | ( | size_t | k | ) | [inherited] |
Operator [] (Non constant version).
Returns k-th stored element in matrix Index k starts at 0.
| void Prescribe | ( | size_t | dof, | |
| const class Mesh & | mesh, | |||
| Vect< T_ > & | b, | |||
| const Vect< T_ > & | u, | |||
| int | flag = 0 | |||
| ) | [inherited] |
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] dof Label of the concerned degree of freedom (DOF). [in] mesh Mesh instance from which information is extracted. [in,out] b Vect instance that contains right-hand side. [in] u Vect instance that conatins imposed valued at DOFs where they are to be imposed. [in] flag Parameter 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).
References Node::getCode(), Matrix::getEntry(), Node::getLabel(), Mesh::getNode(), Matrix::Set(), and Mesh::topNode().
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] mesh Mesh instance from which information is extracted. [in,out] b Vect instance that contains right-hand side. [in] flag Parameter 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).
References Node::getCode(), Node::getDOF(), Matrix::getEntry(), Node::getNbDOF(), Mesh::getNode(), Matrix::Set(), and Mesh::topNode().
| void Prescribe | ( | const class Mesh & | mesh, | |
| Vect< T_ > & | b, | |||
| const Vect< T_ > & | u, | |||
| int | flag = 0 | |||
| ) | [inherited] |
Impose by a penalty method an 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] mesh Mesh instance from which information is extracted. [in,out] b Vect instance that contains right-hand side. [in] u Vect instance that conatins imposed valued at DOFs where they are to be imposed. [in] flag Parameter 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).
References Node::getCode(), Node::getDOF(), Matrix::getEntry(), Node::getNbDOF(), Mesh::getNode(), Matrix::Set(), and Mesh::topNode().
| void PrescribeSide | ( | const class Mesh & | mesh | ) | [inherited] |
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(..).
- Parameters:
-
[in] mesh Mesh instance from which information is extracted.
References Side::getCode(), Side::getDOF(), Matrix::getEntry(), Side::getNbDOF(), Mesh::getSide(), Matrix::Set(), and Mesh::topSide().
| void Resize | ( | size_t | nr, | |
| size_t | nc | |||
| ) |
Set size (number of rows and columns) of matrix.
- Parameters:
-
[in] nr Number of rows. [in] nc Number of columns.
References OFELI::Clear().
| void Resize | ( | size_t | size | ) |
Set size (number of rows) of matrix.
- Parameters:
-
[in] size Number of rows and columns.
References OFELI::Clear().
Referenced by DMatrix::DMatrix().
| void Set | ( | size_t | i, | |
| size_t | j, | |||
| const T_ & | x | |||
| ) | [virtual] |
Assign a constant value x to an entry of the matrix.
- Parameters:
-
[in] i row index of matrix [in] j column index of matrix [in] x Value to assign to a(i,j).
Implements Matrix.
| void setDiagonal | ( | const class Mesh & | mesh | ) | [inherited] |
Initialize matrix storage in the case where only diagonal terms are stored.
This member function is to be used for explicit time integration schemes
References OFELI::Clear(), and Mesh::getNbEq().
| void setPrintView | ( | size_t | rmin, | |
| size_t | rmax, | |||
| size_t | cmin, | |||
| size_t | cmax | |||
| ) |
set a window for matrix printing
- Parameters:
-
[in] rmin first row index to view [in] rmax last row index to view [in] cmin first column index to view [in] cmax last column index to view
Reimplemented from Matrix.
Solve system with factorized matrix (forward and back substitution).
- Parameters:
-
[in] b Vect instance that contains right-hand side [out] x Vect instance that contains solution
- Return values:
-
ret = - 0 if solution was normally performed,
- n if the n-th pivot is null.
Reimplemented from Matrix.
References DMatrix::Solve().
| int Solve | ( | Vect< T_ > & | b | ) | [virtual] |
Solve system with factorized matrix (forward and back substitution).
- Parameters:
-
[in,out] b Vect instance that contains right-hand side on input and solution on output.
- Return values:
-
ret = - 0 if solution was normally performed,
- n if the n-th pivot is null.
Implements Matrix.
References OFELI::Abs(), and OFELI_TOLERANCE.
Referenced by DMatrix::Solve().
Multiply transpose of matrix by vector x and add result in y.
- Parameters:
-
[in] x Vector to add to y [in,out] y on input, vector to add to. On output, result.
Implements Matrix.