LocalMatrix< T_, NR_, NC_ > Class Template Reference

Handles small size matrices like element matrices, with a priori known size. More...

#include <LocalMatrix.h>

Public Member Functions

 LocalMatrix ()
 Default constructor.
 
 LocalMatrix (const LocalMatrix< T_, NR_, NC_ > &m)
 Copy constructor.
 
 LocalMatrix (Element *el, const SpMatrix< T_ > &a)
 Constructor of a local matrix associated to element from a SpMatrix.
 
 LocalMatrix (Element *el, const SkMatrix< T_ > &a)
 Constructor of a local matrix associated to element from a SkMatrix.
 
 LocalMatrix (Element *el, const SkSMatrix< T_ > &a)
 Constructor of a local matrix associated to element from a SkSMatrix.
 
 ~LocalMatrix ()
 Destructor.
 
T_ & operator() (size_t i, size_t j)
 Operator () (Non constant version)
 
T_ operator() (size_t i, size_t j) const
 Operator () (Constant version)
 
void Localize (Element *el, const SpMatrix< T_ > &a)
 Initialize matrix as element matrix from global SpMatrix.
 
void Localize (Element *el, const SkMatrix< T_ > &a)
 Initialize matrix as element matrix from global SkMatrix.
 
void Localize (Element *el, const SkSMatrix< T_ > &a)
 Initialize matrix as element matrix from global SkSMatrix.
 
LocalMatrix< T_, NR_, NC_ > & operator= (const LocalMatrix< T_, NR_, NC_ > &m)
 Operator =
 
void clear ()
 Clear matrix.
 
LocalMatrix< T_, NR_, NC_ > & operator= (const T_ &x)
 Operator =
 
LocalMatrix< T_, NR_, NC_ > & operator+= (const LocalMatrix< T_, NR_, NC_ > &m)
 Operator +=
 
LocalMatrix< T_, NR_, NC_ > & operator-= (const LocalMatrix< T_, NR_, NC_ > &m)
 Operator -=
 
LocalVect< T_, NR_ > operator* (LocalVect< T_, NC_ > &x)
 Operator *
 
LocalMatrix< T_, NR_, NC_ > & operator+= (const T_ &x)
 Operator +=
 
LocalMatrix< T_, NR_, NC_ > & operator-= (const T_ &x)
 Operator -=
 
LocalMatrix< T_, NR_, NC_ > & operator*= (const T_ &x)
 Operator *=
 
LocalMatrix< T_, NR_, NC_ > & operator/= (const T_ &x)
 Operator /=
 
void MultAdd (const LocalVect< T_, NC_ > &x, LocalVect< T_, NR_ > &y)
 Multiply matrix by vector and add result to vector.
 
void MultAddScal (const T_ &a, const LocalVect< T_, NC_ > &x, LocalVect< T_, NR_ > &y)
 Multiply matrix by scaled vector and add result to vector.
 
void Mult (const LocalVect< T_, NC_ > &x, LocalVect< T_, NR_ > &y)
 Multiply matrix by vector.
 
void Symmetrize ()
 Symmetrize matrix.
 
int Factor ()
 Factorize matrix.
 
int solve (LocalVect< T_, NR_ > &b)
 Forward and backsubstitute to solve a linear system.
 
int FactorAndSolve (LocalVect< T_, NR_ > &b)
 Factorize matrix and solve linear system.
 
void Invert (LocalMatrix< T_, NR_, NC_ > &A)
 Calculate inverse of matrix.
 
T_ getInnerProduct (const LocalVect< T_, NC_ > &x, const LocalVect< T_, NR_ > &y)
 Calculate inner product witrh respect to matrix.
 
T_ * get ()
 Return pointer to matrix as a C-array.
 

Detailed Description

template<class T_, size_t NR_, size_t NC_>
class OFELI::LocalMatrix< T_, NR_, NC_ >

Handles small size matrices like element matrices, with a priori known size.

The template class LocalMatrix treats small size matrices. Typically, this class is recommended to store element and side arrays.
Internally, no dynamic storage is used.

Template Parameters
T_Data type (double, float, complex<double>, ...)
NR_number of rows of matrix
NC_number of columns of matrix
Author
Rachid Touzani

Constructor & Destructor Documentation

◆ LocalMatrix() [1/4]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix ( )

Default constructor.

Constructs a matrix with 0 rows and 0 columns

◆ LocalMatrix() [2/4]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix ( Element el,
const SpMatrix< T_ > &  a 
)

Constructor of a local matrix associated to element from a SpMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SpMatrix.

◆ LocalMatrix() [3/4]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix ( Element el,
const SkMatrix< T_ > &  a 
)

Constructor of a local matrix associated to element from a SkMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SkMatrix.

◆ LocalMatrix() [4/4]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix ( Element el,
const SkSMatrix< T_ > &  a 
)

Constructor of a local matrix associated to element from a SkSMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SkSMatrix.

Member Function Documentation

◆ clear()

template<class T_ , size_t NR_, size_t NC_>
void clear ( )

Clear matrix.

Set all matrix entries to zero

◆ Factor()

template<class T_ , size_t NR_, size_t NC_>
int Factor ( )

Factorize matrix.

Performs a LU factorization.

Returns
  • 0: Factorization has ended normally,
  • n: n-th pivot was zero.

◆ FactorAndSolve()

template<class T_ , size_t NR_, size_t NC_>
int FactorAndSolve ( LocalVect< T_, NR_ > &  b)

Factorize matrix and solve linear system.

Parameters
[in,out]bRight-hand side in input and solution vector in output.
Returns
0 if solution was performed normally. n if n-th pivot is zero. This function simply calls Factor() then Solve(b).

◆ getInnerProduct()

template<class T_ , size_t NR_, size_t NC_>
T_ getInnerProduct ( const LocalVect< T_, NC_ > &  x,
const LocalVect< T_, NR_ > &  y 
)

Calculate inner product witrh respect to matrix.

Returns the product xTAy

Parameters
[in]xLeft vector
[in]yRight vector
Returns
Resulting product

◆ Invert()

template<class T_ , size_t NR_, size_t NC_>
void Invert ( LocalMatrix< T_, NR_, NC_ > &  A)

Calculate inverse of matrix.

Parameters
[out]AInverse of matrix

◆ Localize() [1/3]

template<class T_ , size_t NR_, size_t NC_>
void Localize ( Element el,
const SkMatrix< T_ > &  a 
)

Initialize matrix as element matrix from global SkMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SkMatrix. This function is called by its corresponding constructor.

◆ Localize() [2/3]

template<class T_ , size_t NR_, size_t NC_>
void Localize ( Element el,
const SkSMatrix< T_ > &  a 
)

Initialize matrix as element matrix from global SkSMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SkSMatrix. This function is called by its corresponding constructor.

◆ Localize() [3/3]

template<class T_ , size_t NR_, size_t NC_>
void Localize ( Element el,
const SpMatrix< T_ > &  a 
)

Initialize matrix as element matrix from global SpMatrix.

Parameters
[in]elPointer to Element
[in]aGlobal matrix as instance of class SpMatrix. This function is called by its corresponding constructor.

◆ Mult()

template<class T_ , size_t NR_, size_t NC_>
void Mult ( const LocalVect< T_, NC_ > &  x,
LocalVect< T_, NR_ > &  y 
)

Multiply matrix by vector.

Parameters
[in]xVector to multiply matrix by.
[out]yResulting vector.

◆ MultAdd()

template<class T_ , size_t NR_, size_t NC_>
void MultAdd ( const LocalVect< T_, NC_ > &  x,
LocalVect< T_, NR_ > &  y 
)

Multiply matrix by vector and add result to vector.

Parameters
[in]xVector to multiply matrix by.
[out]yResulting vector (y += a * x)

◆ MultAddScal()

template<class T_ , size_t NR_, size_t NC_>
void MultAddScal ( const T_ &  a,
const LocalVect< T_, NC_ > &  x,
LocalVect< T_, NR_ > &  y 
)

Multiply matrix by scaled vector and add result to vector.

Parameters
[in]aConstant to premultiply by vector x.
[in]x(Scaled) vector to multiply matrix by.
[out]yResulting vector (y += a * x)

◆ operator()() [1/2]

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

Operator () (Non constant version)

Returns entry at row i and column j.

◆ operator()() [2/2]

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

Operator () (Constant version)

Returns entry at row i and column j.

◆ operator*()

template<class T_ , size_t NR_, size_t NC_>
LocalVect< T_, NR_ > operator* ( LocalVect< T_, NC_ > &  x)

Operator *

Return a Vect instance as product of current matrix by vector x.

◆ operator*=()

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator*= ( const T_ &  x)

Operator *=

Multiply matrix entries by constant x.

◆ operator+=() [1/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator+= ( const LocalMatrix< T_, NR_, NC_ > &  m)

Operator +=

Add m to current matrix.

◆ operator+=() [2/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator+= ( const T_ &  x)

Operator +=

Add constant x to current matrix entries.

◆ operator-=() [1/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator-= ( const LocalMatrix< T_, NR_, NC_ > &  m)

Operator -=

Subtract m from current matrix.

◆ operator-=() [2/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator-= ( const T_ &  x)

Operator -=

Subtract x from current matrix entries.

◆ operator/=()

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator/= ( const T_ &  x)

Operator /=

Divide by x current matrix entries.

◆ operator=() [1/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator= ( const LocalMatrix< T_, NR_, NC_ > &  m)

Operator =

Copy instance m into current instance.

◆ operator=() [2/2]

template<class T_ , size_t NR_, size_t NC_>
LocalMatrix< T_, NR_, NC_ > & operator= ( const T_ &  x)

Operator =

Assign matrix to identity times x

◆ solve()

template<class T_ , size_t NR_, size_t NC_>
int solve ( LocalVect< T_, NR_ > &  b)

Forward and backsubstitute to solve a linear system.

Parameters
[in]bRight-hand side in input and solution vector in output.
Returns
  • 0: Solution was performed normally.
  • n: n-th pivot is zero.
Note
Matrix must have been factorized at first.

◆ Symmetrize()

template<class T_ , size_t NR_, size_t NC_>
void Symmetrize ( )

Symmetrize matrix.

Fill upper triangle to form a symmetric matrix.