To handle matrices in sparse storage format. More...
#include <SpMatrix.h>
Public Member Functions | |
| SpMatrix () | |
| Default constructor. | |
| SpMatrix (size_t nr, size_t nc) | |
| Constructor that initializes current instance as a dense matrix. | |
| SpMatrix (size_t size, int is_diagonal=false) | |
| Constructor that initializes current instance as a dense matrix. | |
| SpMatrix (Mesh &mesh, size_t dof=0, int is_diagonal=false) | |
| Constructor using a Mesh instance. | |
| SpMatrix (const vector< RC > &I, int opt=1) | |
| Constructor for a square matrix using non zero row and column indices. | |
| SpMatrix (const vector< RC > &I, const Vect< T_ > &a, int opt=1) | |
| Constructor for a square matrix using non zero row and column indices. | |
| SpMatrix (size_t nr, size_t nc, const vector< size_t > &row_ptr, const vector< size_t > &col_ind) | |
| Constructor for a rectangle matrix. | |
| SpMatrix (size_t nr, size_t nc, const vector< size_t > &row_ptr, const vector< size_t > &col_ind, const vector< T_ > &a) | |
| Constructor for a rectangle matrix. | |
| SpMatrix (const vector< size_t > &row_ptr, const vector< size_t > &col_ind) | |
| Constructor for a rectangle matrix. | |
| SpMatrix (const vector< size_t > &row_ptr, const vector< size_t > &col_ind, const vector< T_ > &a) | |
| Constructor for a rectangle matrix. | |
| SpMatrix (const SpMatrix &m) | |
| Copy constructor. | |
| ~SpMatrix () | |
| Destructor. | |
| void | Identity () |
| Define matrix as identity. | |
| void | Dense () |
| Define matrix as a dense one. | |
| void | Diagonal () |
| Define matrix as a diagonal one. | |
| void | Diagonal (const T_ &a) |
Define matrix as a diagonal one with diagonal entries equal to a | |
| void | Laplace1D (size_t n, real_t h) |
| Sets the matrix as the one for the Laplace equation in 1-D. | |
| void | Laplace2D (size_t nx, size_t ny) |
| Sets the matrix as the one for the Laplace equation in 2-D. | |
| void | setMesh (Mesh &mesh, size_t dof=0) |
| Determine mesh graph and initialize matrix. | |
| void | setOneDOF () |
| Activate 1-DOF per node option. | |
| void | setSides () |
| Activate Sides option. | |
| void | setDiag () |
| Store diagonal entries in a separate internal vector. | |
| void | DiagPrescribe (Mesh &mesh, Vect< T_ > &b, const Vect< T_ > &u) |
| Impose by a diagonal method an essential boundary condition. | |
| void | DiagPrescribe (Vect< T_ > &b, const Vect< T_ > &u) |
| Impose by a diagonal method an essential boundary condition using the Mesh instance provided by the constructor. | |
| void | setSize (size_t size) |
| Set size of matrix (case where it's a square matrix). | |
| void | setSize (size_t nr, size_t nc) |
| Set size (number of rows) of matrix. | |
| void | setGraph (const vector< RC > &I, int opt=1) |
| Set graph of matrix by giving a vector of its nonzero entries. | |
| Vect< T_ > | getRow (size_t i) const |
Get i-th row vector. | |
| Vect< T_ > | getColumn (size_t j) const |
Get j-th column vector. | |
| T_ | at (size_t i, size_t j) |
| Return a value of a matrix entry. | |
| T_ & | operator() (size_t i, size_t j) |
| Operator () (Non constant version) | |
| T_ | operator() (size_t i, size_t j) const |
Operator () (Constant version) | |
| T_ | operator() (size_t i) const |
Operator () with one argument (Constant version) | |
| T_ | operator[] (size_t i) const |
Operator [] (Constant version). | |
| Vect< T_ > | operator* (const Vect< T_ > &x) const |
Operator * to multiply matrix by a vector. | |
| SpMatrix< T_ > & | operator*= (const T_ &a) |
Operator *= to premultiply matrix by a constant. | |
| void | getMesh (Mesh &mesh) |
| Get mesh instance whose reference will be stored in current instance of SpMatrix. | |
| void | Mult (const Vect< T_ > &x, Vect< T_ > &y) const |
| Multiply matrix by vector and save in another one. | |
| void | MultAdd (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply matrix by vector x and add 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 | TMult (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply transpose of matrix by vector x and save in y. | |
| void | Axpy (T_ a, const SpMatrix< T_ > &m) |
| Add to matrix the product of a matrix by a scalar. | |
| void | Axpy (T_ a, const Matrix< T_ > *m) |
| Add to matrix the product of a matrix by a scalar. | |
| void | set (size_t i, size_t j, const T_ &val) |
| Assign a value to an entry of the matrix. | |
| void | add (size_t i, size_t j, const T_ &val) |
| Add a value to an entry of the matrix. | |
| void | operator= (const T_ &x) |
| Operator =. | |
| size_t | getColInd (size_t i) const |
| Return storage information. | |
| size_t | getRowPtr (size_t i) const |
Return Row pointer at position i. | |
| int | solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=false) |
| Solve the linear system of equations. | |
| void | setSolver (Iteration solver=CG_SOLVER, Preconditioner prec=DIAG_PREC, int max_it=1000, real_t toler=1.e-8) |
| Choose solver and preconditioner for an iterative procedure. | |
| void | clear () |
| brief Set all matrix entries to zero | |
| T_ * | get () const |
| Return C-Array. | |
| T_ | get (size_t i, size_t j) const |
Return entry (i,j) of matrix if this one is stored, 0 otherwise. | |
| void | add (size_t i, const T_ &val) |
Add val to entry i. | |
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. | |
| 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. | |
| virtual int | solve (Vect< T_ > &b, 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. | |
| 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). | |
| Matrix & | operator= (Matrix< T_ > &m) |
| Operator =. | |
| Matrix & | operator+= (const Matrix< T_ > &m) |
| Operator +=. | |
| Matrix & | operator-= (const Matrix< T_ > &m) |
| Operator -=. | |
| Matrix & | operator= (const T_ &x) |
| Operator =. | |
| Matrix & | operator*= (const T_ &x) |
| Operator *=. | |
| Matrix & | operator+= (const T_ &x) |
| Operator +=. | |
| Matrix & | operator-= (const T_ &x) |
| Operator -=. | |
To handle matrices in sparse storage format.
This template class enables storing and manipulating a sparse matrix, i.e. only nonzero terms are stored. Internally, the matrix is stored as a vector instance and uses for the definition of its graph a Vect<size_t> instance row_ptr and a Vect<size_t> instance col_ind that contains respectively addresses of first element of each row and column indices.
To illustrate this, consider the matrix
1 2 0
3 4 0
0 5 0
Such a matrix is stored in the vector<real_t> instance {1,2,3,4,5}. The vectors row_ptr and col_ind are respectively: {0,2,4,5}, {1,2,1,2,2}
| T_ | Data type (double, float, complex<double>, ...) |