BMatrix< T_ > Class Template Reference

To handle band matrices. More...

#include <BMatrix.h>

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

Public Member Functions

 BMatrix ()
 Default constructor.
 
 BMatrix (size_t size, int ld, int ud)
 Constructor that for a band matrix with given size and bandwidth.
 
 BMatrix (const BMatrix &m)
 Copy Constructor.
 
 ~BMatrix ()
 Destructor.
 
void setSize (size_t size, int ld, int ud)
 Set size (number of rows) and storage of matrix.
 
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
 
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 save result in y
 
void Axpy (T_ a, const BMatrix< T_ > &x)
 Add to matrix the product of a matrix by a scalar.
 
void Axpy (T_ a, const Matrix< T_ > *x)
 Add to matrix the product of a matrix by a scalar.
 
void set (size_t i, size_t j, const T_ &val)
 Add constant val to an entry (i,j) of the matrix.
 
void add (size_t i, size_t j, const T_ &val)
 Add constant val value to an entry (i,j) of the 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).
 
BMatrix< T_ > & operator= (const BMatrix< T_ > &m)
 Operator =.
 
BMatrix< T_ > & operator= (const T_ &x)
 Operator = Assign matrix to identity times x.
 
BMatrix< T_ > & operator*= (const T_ &x)
 Operator *=.
 
BMatrix< T_ > & operator+= (const T_ &x)
 Operator +=.
 
int setLU ()
 Factorize the matrix (LU factorization)
 
int solve (Vect< T_ > &b, bool fact=false)
 Solve linear system.
 
int solve (const Vect< T_ > &b, Vect< T_ > &x, bool fact=false)
 Solve linear system.
 
T_ * get () const
 Return C-Array.
 
T_ get (size_t i, size_t j) const
 Return entry (i,j) of matrix.
 
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.
 
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::BMatrix< T_ >

To handle band matrices.

This class enables storing and manipulating band matrices. The matrix can have different numbers of lower and upper co-diagonals

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

Constructor & Destructor Documentation

◆ BMatrix() [1/2]

template<class T_ >
BMatrix ( )

Default constructor.

Initialize a zero dimension band matrix

◆ BMatrix() [2/2]

template<class T_ >
BMatrix ( size_t  size,
int  ld,
int  ud 
)

Constructor that for a band matrix with given size and bandwidth.

Assign 0 to all matrix entries.

Parameters
[in]sizeNumber of rows and columns
[in]ldNumber of lower co-diagonals (must be >= 0)
[in]udNumber of upper co-diagonals (must be >= 0)
Remarks
Works only if ud+ld+1 <= size

Member Function Documentation

◆ 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 BMatrix< T_ > &  x 
)

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

◆ Axpy() [2/2]

template<class T_ >
void Axpy ( T_  a,
const Matrix< T_ > *  x 
)
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

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

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_ >
BMatrix< T_ > & operator*= ( const T_ &  x)

Operator *=.

Premultiply matrix entries by constant value x

◆ operator+=()

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

Operator +=.

Add constant x to matrix entries.

◆ operator=()

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

Operator =.

Copy matrix m to current matrix instance.

◆ setLU()

template<class T_ >
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 the n-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.

◆ setSize()

template<class T_ >
void setSize ( size_t  size,
int  ld,
int  ud 
)

Set size (number of rows) and storage of matrix.

Parameters
[in]sizeNumber of rows and columns
[in]ldNumber of lower co-diagonals (must be > 0)
[in]udNumber of upper co-diagonals (must be > 0)

◆ solve() [1/2]

template<class T_ >
int solve ( const Vect< T_ > &  b,
Vect< T_ > &  x,
bool  fact = false 
)
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]bVect instance that contains right-hand side.
[out]xVect instance that contains solution
[in]factUnused argument
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 = false 
)
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]bVect instance that contains right-hand side on input and solution on output.
[in]factUnused argument
Returns
  • 0 if solution was normally performed,
  • n if the n-th pivot is null.

Implements Matrix< T_ >.