To handle square matrices in skyline storage format. More...
#include <SkMatrix.h>

Public Member Functions | |
SkMatrix () | |
Default constructor. More... | |
SkMatrix (size_t size, int is_diagonal=false) | |
Constructor that initializes a dense symmetric matrix. More... | |
SkMatrix (Mesh &mesh, size_t dof=0, int is_diagonal=false) | |
Constructor using mesh to initialize skyline structure of matrix. More... | |
SkMatrix (const Vect< size_t > &ColHt) | |
Constructor that initializes skyline structure of matrix using vector of column heights. More... | |
SkMatrix (const SkMatrix< T_ > &m) | |
Copy Constructor. | |
~SkMatrix () | |
Destructor. | |
void | setMesh (Mesh &mesh, size_t dof=0) |
Determine mesh graph and initialize matrix. More... | |
void | setSkyline (Mesh &mesh) |
Determine matrix structure. More... | |
void | setDiag () |
Store diagonal entries in a separate internal vector. | |
void | setDOF (size_t i) |
Choose DOF to activate. More... | |
void | set (size_t i, size_t j, const T_ &val) |
Assign a value to an entry ofthe matrix. More... | |
void | Axpy (T_ a, const SkMatrix< T_ > &m) |
Add to matrix the product of a matrix by a scalar. More... | |
void | Axpy (T_ a, const Matrix< T_ > *m) |
Add to matrix the product of a matrix by a scalar. More... | |
void | MultAdd (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply matrix by vector x and add to y . More... | |
void | TMultAdd (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply transpose of matrix by vector x and add to y . More... | |
void | MultAdd (T_ a, const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply matrix by a vector and add to another one. More... | |
void | Mult (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply matrix by vector x and save in y . More... | |
void | TMult (const Vect< T_ > &x, Vect< T_ > &y) const |
Multiply transpose of matrix by vector x and save in y . More... | |
void | add (size_t i, size_t j, const T_ &val) |
Add a constant value to an entry ofthe matrix. More... | |
size_t | getColHeight (size_t i) const |
Return column height. More... | |
T_ | operator() (size_t i, size_t j) const |
Operator () (Constant version). More... | |
T_ & | operator() (size_t i, size_t j) |
Operator () (Non constant version). More... | |
void | DiagPrescribe (Mesh &mesh, Vect< T_ > &b, const Vect< T_ > &u, int flag=0) |
Impose an essential boundary condition. More... | |
void | DiagPrescribe (Vect< T_ > &b, const Vect< T_ > &u, int flag=0) |
Impose an essential boundary condition using the Mesh instance provided by the constructor. More... | |
SkMatrix< T_ > & | operator= (const SkMatrix< T_ > &m) |
Operator =. More... | |
SkMatrix< T_ > & | operator= (const T_ &x) |
Operator =. More... | |
SkMatrix< T_ > & | operator+= (const SkMatrix< T_ > &m) |
Operator +=. More... | |
SkMatrix< T_ > & | operator+= (const T_ &x) |
Operator +=. More... | |
SkMatrix< T_ > & | operator*= (const T_ &x) |
Operator *=. More... | |
int | setLU () |
Factorize the matrix (LU factorization) More... | |
int | solve (Vect< T_ > &b, bool fact=true) |
Solve linear system. More... | |
int | solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=true) |
Solve linear system. More... | |
T_ * | get () const |
Return C-Array. More... | |
T_ | get (size_t i, size_t j) const |
Return entry (i,j) of matrix if this one is stored, 0 else. | |
void | add (size_t i, const T_ &val) |
Add val to entry i . | |
![]() | |
Matrix () | |
Default constructor. More... | |
Matrix (const Matrix< T_ > &m) | |
Copy Constructor. | |
virtual | ~Matrix () |
Destructor. | |
virtual void | reset () |
Set matrix to 0 and reset factorization parameter. More... | |
size_t | getNbRows () const |
Return number of rows. | |
size_t | getNbColumns () const |
Return number of columns. | |
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. More... | |
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. More... | |
void | setDiagonal (Mesh &mesh) |
Initialize matrix storage in the case where only diagonal terms are stored. More... | |
virtual void | clear () |
brief Set all matrix entries to zero | |
void | Assembly (const Element &el, T_ *a) |
Assembly of element matrix into global matrix. More... | |
void | Assembly (const Side &sd, T_ *a) |
Assembly of side matrix into global matrix. More... | |
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. More... | |
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. More... | |
void | Prescribe (Vect< T_ > &b, int flag=0) |
Impose by a penalty method a homegeneous (=0) essential boundary condition. More... | |
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. More... | |
void | PrescribeSide () |
Impose by a penalty method an essential boundary condition when DOFs are supported by sides. More... | |
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. More... | |
virtual int | solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=true)=0 |
Solve the linear system. More... | |
int | FactorAndSolve (Vect< T_ > &b) |
Factorize matrix and solve the linear system. More... | |
int | FactorAndSolve (const Vect< T_ > &b, Vect< T_ > &x) |
Factorize matrix and solve the linear system. More... | |
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. More... | |
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. More... | |
virtual T_ & | operator() (size_t i, size_t j)=0 |
Operator () (Non constant version). More... | |
virtual T_ | operator() (size_t i, size_t j) const =0 |
Operator () (Non constant version). More... | |
T_ | operator() (size_t i) const |
Operator () with one argument (Constant version). More... | |
T_ & | operator() (size_t i) |
Operator () with one argument (Non Constant version). More... | |
T_ & | operator[] (size_t k) |
Operator [] (Non constant version). More... | |
T_ | operator[] (size_t k) const |
Operator [] (Constant version). More... | |
Matrix & | operator= (Matrix< T_ > &m) |
Operator =. More... | |
Matrix & | operator+= (const Matrix< T_ > &m) |
Operator +=. More... | |
Matrix & | operator-= (const Matrix< T_ > &m) |
Operator -=. More... | |
Matrix & | operator= (const T_ &x) |
Operator =. More... | |
Matrix & | operator*= (const T_ &x) |
Operator *=. More... | |
Matrix & | operator+= (const T_ &x) |
Operator +=. More... | |
Matrix & | operator-= (const T_ &x) |
Operator -=. More... | |
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
class OFELI::SkMatrix< T_ >
To handle square matrices in skyline storage format.
This template class allows storing and manipulating a matrix in skyline storage format.
The matrix entries are stored in 2 vectors column by column as in the following example:
/ \ / \ | l0 . | | u0 u1 0 0 u7 | | l1 l2 . | | u2 u3 0 u8 | | 0 l3 l4 . | | ... u4 u5 u9 | | 0 0 l5 l6 | | u6 u10 | | l7 l8 l9 l10 l11 | | u11 | \ / \ /
- Template Parameters
-
T_ Data type (double, float, complex<double>, ...)
- Copyright
- GNU Lesser Public License
Constructor & Destructor Documentation
◆ SkMatrix() [1/4]
SkMatrix | ( | ) |
Default constructor.
Initializes a zero-dimension matrix
◆ SkMatrix() [2/4]
SkMatrix | ( | size_t | size, |
int | is_diagonal = false |
||
) |
Constructor that initializes a dense symmetric matrix.
Normally, for a dense matrix this is not the right class.
- Parameters
-
[in] size Number of matrix rows (and columns). [in] is_diagonal Boolean to select if the matrix is diagonal or not [Default: false]
◆ SkMatrix() [3/4]
Constructor using mesh to initialize skyline structure of matrix.
- Parameters
-
[in] mesh Mesh instance for which matrix graph is determined. [in] dof Option 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 valuedof=0
means that matrix structure is determined using all DOFs.[in] is_diagonal Boolean argument to say is the matrix is actually a diagonal matrix or not.
◆ SkMatrix() [4/4]
Constructor that initializes skyline structure of matrix using vector of column heights.
- Parameters
-
[in] ColHt Vect instance that contains rows lengths of matrix.
Member Function Documentation
◆ add()
|
virtual |
Add a constant value to an entry ofthe matrix.
- Parameters
-
[in] i Row index [in] j Column index [in] val Constant value to add to a(i,j)
Implements Matrix< T_ >.
◆ Axpy() [1/2]
|
virtual |
Add to matrix the product of a matrix by a scalar.
- Parameters
-
[in] a Scalar to premultiply [in] m Matrix by which a
is multiplied. The result is added to current instance
Implements Matrix< T_ >.
◆ Axpy() [2/2]
void Axpy | ( | T_ | a, |
const SkMatrix< T_ > & | m | ||
) |
Add to matrix the product of a matrix by a scalar.
- Parameters
-
[in] a Scalar to premultiply [in] m Matrix by which a
is multiplied. The result is added to current instance
◆ DiagPrescribe() [1/2]
Impose 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. It can be modified by member function setPenal(..).
- Parameters
-
[in] mesh Mesh instance from which information is extracted. [in] 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).
◆ DiagPrescribe() [2/2]
Impose 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. It can be modified by member function setPenal(..).
◆ get()
T_ * get | ( | ) | const |
Return C-Array.
Skyline of matrix is stored row by row.
◆ getColHeight()
size_t getColHeight | ( | size_t | i | ) | const |
Return column height.
Column height at entry i
is returned.
◆ Mult()
Multiply matrix by vector x
and save in y
.
- Parameters
-
[in] x Vector to multiply by matrix [out] y Vector that contains on output the result.
Implements Matrix< T_ >.
◆ MultAdd() [1/2]
Multiply matrix by vector x
and add to y
.
- Parameters
-
[in] x Vector to multiply by matrix [in,out] y Vector to add to the result. y
contains on output the result.
Implements Matrix< T_ >.
◆ MultAdd() [2/2]
Multiply matrix by a vector and add to another one.
- Parameters
-
[in] a Constant to multiply by matrix [in] x Vector to multiply by matrix [in,out] y Vector to add to the result. y
contains on output the result.
Implements Matrix< T_ >.
◆ operator()() [1/2]
|
virtual |
Operator () (Non constant version).
- Parameters
-
[in] i Row index [in] j Column index
Implements Matrix< T_ >.
◆ operator()() [2/2]
|
virtual |
Operator () (Constant version).
- Parameters
-
[in] i Row index [in] j Column index
Implements Matrix< T_ >.
◆ operator*=()
SkMatrix< T_ > & operator*= | ( | const T_ & | x | ) |
Operator *=.
Premultiply matrix entries by constant value x
.
◆ operator+=() [1/2]
Operator +=.
Add matrix m
to current matrix instance.
◆ operator+=() [2/2]
SkMatrix< T_ > & operator+= | ( | const T_ & | x | ) |
Operator +=.
Add constant value x
to matrix entries.
◆ operator=() [1/2]
Operator =.
Copy matrix m
to current matrix instance.
◆ operator=() [2/2]
SkMatrix< T_ > & operator= | ( | const T_ & | x | ) |
Operator =.
define the matrix as a diagonal one with all diagonal entries equal to x
.
◆ set()
|
virtual |
Assign a value to an entry ofthe matrix.
- Parameters
-
[in] i Row index (starting at i=1
)[in] j Column index (starting at i=1
)[in] val Value to assign to entry a(i,j)
Implements Matrix< T_ >.
◆ setDOF()
void setDOF | ( | size_t | i | ) |
Choose DOF to activate.
This function is available only if variable dof
is equal to 1 in the constructor
- Parameters
-
[in] i Index of the DOF
◆ setLU()
int setLU | ( | ) |
Factorize the matrix (LU factorization)
LU factorization of the matrix is realized. Note that since this is an in place factorization, the contents of the matrix are modified.
- Returns
-
0
if factorization was normally performed, -
n
if then
-th pivot is null.
-
- Remarks
- A flag in this class indicates after factorization that this one has been realized, so that, if the member function solve is called after this no further factorization is done.
◆ setMesh()
void setMesh | ( | Mesh & | mesh, |
size_t | dof = 0 |
||
) |
Determine mesh graph and initialize matrix.
This member function is called by constructor with the same arguments
- Parameters
-
[in] mesh Mesh instance for which matrix graph is determined. [in] dof Option 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 valuedof=0
means that matrix structure is determined using all DOFs.
◆ setSkyline()
void setSkyline | ( | Mesh & | mesh | ) |
◆ solve() [1/2]
Solve linear system.
The linear system having the current instance as a matrix is solved by using the LU decomposition. Solution is thus realized after a factorization step and a forward/backward substitution step. The factorization step is realized only if this was not already done.
Note that this function modifies the matrix contents is a factorization is performed. Naturally, if the the matrix has been modified after using this function, the user has to refactorize it using the function setLU. This is because the class has no non-expensive way to detect if the matrix has been modified. The function setLU realizes the factorization step only.
- Parameters
-
[in] b Vect instance that contains right-hand side. [out] x Vect instance that contains solution [in] fact Set true if matrix is to be factorized (Default value), false if not
- Returns
-
0
if solution was normally performed, -
n
if then
-th pivot is null.
-
Implements Matrix< T_ >.
◆ solve() [2/2]
|
virtual |
Solve linear system.
The linear system having the current instance as a matrix is solved by using the LU decomposition. Solution is thus realized after a factorization step and a forward/backward substitution step. The factorization step is realized only if this was not already done.
Note that this function modifies the matrix contents is a factorization is performed. Naturally, if the the matrix has been modified after using this function, the user has to refactorize it using the function setLU. This is because the class has no non-expensive way to detect if the matrix has been modified. The function setLU realizes the factorization step only.
- Parameters
-
[in,out] b Vect instance that contains right-hand side on input and solution on output. [in] fact Set true if matrix is to be factorized (Default value), false if not
- Returns
-
0
if solution was normally performed, -
n
if then
-th pivot is null.
-
Implements Matrix< T_ >.
◆ TMult()
Multiply transpose of matrix by vector x
and save in y
.
- Parameters
-
[in] x Vector to multiply by matrix [out] y Vector that contains on output the result.
Implements Matrix< T_ >.