IFEM  90A354
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
utl::matrixBase< T > Class Template Referenceabstract

Common base class for multi-dimensional (2D and 3D) matrices. More...

#include <matrix.h>

Inheritance diagram for utl::matrixBase< T >:
Inheritance graph
[legend]

Public Member Functions

size_t dim (short int d=1) const
 Query dimensions.
 
size_t size () const
 Query total matrix size.
 
bool empty () const
 Check if the matrix is empty.
 
bool zero (T tol=T(0)) const
 Check if the matrix elements are all zero.
 
const vector< T > & toVec () const
 Type casting to a one-dimensional utl::vector, for access.
 
 operator const std::vector< T > & () const
 Type casting to a one-dimensional std::vector, for access.
 
 operator std::vector< T > & ()
 Type casting to a one-dimensional vector, for update.
 
T * ptr (size_t c=0)
 Access through pointer.
 
const T * ptr (size_t c=0) const
 Reference through pointer.
 
std::vector< T >::iterator begin ()
 Iterator to the start of the matrix elements.
 
std::vector< T >::iterator end ()
 Iterator to the end of the matrix elements.
 
void clear ()
 Clears the matrix and sets its dimension to zero.
 
void fill (T s)
 Fill the matrix with a scalar value.
 
void fill (const T *values, size_t n=0)
 Fill the matrix with data from an array.
 
matrixBase< T > & add (const matrixBase< T > &A, const T &alfa)
 Add the given matrix A scaled by alfa to *this.
 
matrixBase< T > & multiply (const T &c)
 Multiplication of this matrix by a scalar c.
 
norm2 (int inc=1) const
 Return the Euclidean norm of the matrix. More...
 
asum (int inc=1) const
 Return the sum of the absolute value of the matrix elements. More...
 
sum (int inc=1) const
 Return the sum of the matrix elements. More...
 

Protected Member Functions

 matrixBase ()
 The constructor is protected to allow sub-class instances only.
 
 matrixBase (vector< T > &vec)
 Constructor using an external vector for matrix element storage.
 
 matrixBase (size_t n_1, size_t n_2, size_t n_3=1, size_t n_4=1)
 Constructor creating a matrix of dimension \(n_1 \times n_2 \times n_3 \times n_4\).
 
 matrixBase (const matrixBase< T > &mat, bool copyContent=true)
 Copy constructor. More...
 
void redim (size_t n_1, size_t n_2, size_t n_3, size_t n_4, bool forceClear)
 Resize the matrix to dimension \(n_1 \times n_2 \times n_3 \times n_4\). More...
 
virtual void clearIfNrowChanged (size_t n1, size_t n2, size_t n3)=0
 Clears the matrix content if the first dimension(s) changed.
 

Protected Attributes

size_t n [4]
 Dimension of the matrix.
 
vector< T > & elem
 Actual matrix elements, stored column by column.
 

Private Attributes

vector< T > myElem
 Internal matrix storage.
 

Detailed Description

template<class T>
class utl::matrixBase< T >

Common base class for multi-dimensional (2D and 3D) matrices.

Contains the methods that the 2D and 3D matrices have in common.

Constructor & Destructor Documentation

◆ matrixBase()

template<class T >
utl::matrixBase< T >::matrixBase ( const matrixBase< T > &  mat,
bool  copyContent = true 
)
inlineprotected

Copy constructor.

Parameters
[in]matThe matrix to copy
[in]copyContentIf false, only copy the matrix dimension

References utl::matrixBase< T >::elem, and utl::matrixBase< T >::n.

Member Function Documentation

◆ asum()

template<class T >
T utl::matrixBase< T >::asum ( int  inc = 1) const
inline

Return the sum of the absolute value of the matrix elements.

Parameters
[in]incIncrement in the matrix element vector indices

References utl::matrixBase< T >::elem.

◆ norm2()

template<class T >
T utl::matrixBase< T >::norm2 ( int  inc = 1) const
inline

Return the Euclidean norm of the matrix.

Parameters
[in]incIncrement in the matrix element vector indices

References utl::matrixBase< T >::elem.

Referenced by StabilizationUtils::getTauPt().

◆ redim()

template<class T >
void utl::matrixBase< T >::redim ( size_t  n_1,
size_t  n_2,
size_t  n_3,
size_t  n_4,
bool  forceClear 
)
inlineprotected

Resize the matrix to dimension \(n_1 \times n_2 \times n_3 \times n_4\).

Will erase the previous content, but only if both the total matrix size, and any of its dimensions except the last are changed. It is therefore possible to add or remove a given number of elements in the last dimension of the matrix without loosing the contents of the other dimensions. If forceClear is true, the old matrix content is always erased.

References utl::matrixBase< T >::clear(), utl::matrixBase< T >::clearIfNrowChanged(), utl::matrixBase< T >::elem, utl::matrixBase< T >::fill(), utl::matrixBase< T >::n, utl::RETAIN, and utl::matrixBase< T >::size().

Referenced by utl::matrix3d< T >::resize(), utl::matrix4d< T >::resize(), and utl::matrix< T >::resize().

◆ sum()

template<class T >
T utl::matrixBase< T >::sum ( int  inc = 1) const
inline

Return the sum of the matrix elements.

Parameters
[in]incIncrement in the matrix element vector indices. If negative, the sum of matrix column -inc will be returned instead.

References utl::matrixBase< T >::elem, and utl::matrixBase< T >::n.

Referenced by ASMu2D::evaluateBasisNurbs().


The documentation for this class was generated from the following file: