SquareMatrix< Type > Class Template Reference

A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix. More...

Inheritance diagram for SquareMatrix< Type >:
[legend]
Collaboration diagram for SquareMatrix< Type >:
[legend]

Public Member Functions

 SquareMatrix ()=default
 Default construct. More...
 
 SquareMatrix (const SquareMatrix &)=default
 Copy construct. More...
 
SquareMatrixoperator= (const SquareMatrix &)=default
 Copy assignment. More...
 
 SquareMatrix (const label n)
 Construct for given size (rows == cols) More...
 
 SquareMatrix (const label n, const Foam::zero)
 
 SquareMatrix (const label n, const Type &val)
 
template<class AnyType >
 SquareMatrix (const label n, const Identity< AnyType >)
 
template<class AnyType >
 SquareMatrix (const labelPair &dims, const Identity< AnyType >)
 
 SquareMatrix (const labelPair &dims)
 
 SquareMatrix (const labelPair &dims, const Foam::zero)
 
 SquareMatrix (const labelPair &dims, const Type &val)
 
 SquareMatrix (const label m, const label n, const Foam::zero)
 
template<class MatrixType >
 SquareMatrix (const ConstMatrixBlock< MatrixType > &mat)
 Construct from const sub-matrix block. More...
 
template<class MatrixType >
 SquareMatrix (const MatrixBlock< MatrixType > &mat)
 Construct from sub-matrix block. More...
 
 SquareMatrix (const RectangularMatrix< Type > &mat)
 
 SquareMatrix (Istream &is)
 Construct from Istream. More...
 
autoPtr< SquareMatrix< Type > > clone () const
 Clone. More...
 
void resize (const label m)
 Resize the matrix preserving the elements. More...
 
void resize (const label m, const label n)
 Resize the matrix preserving the elements (compatibility) More...
 
void setSize (const label m)
 Resize the matrix preserving the elements. More...
 
void shallowResize (const label m)
 Resize the matrix without reallocating storage (unsafe) More...
 
bool symmetric () const
 Return true if the square matrix is effectively symmetric/Hermitian. More...
 
bool tridiagonal () const
 Return true if the square matrix is reduced tridiagonal. More...
 
template<class CompOp >
List< label > sortPermutation (CompOp &compare) const
 
void applyPermutation (const List< label > &p)
 
void operator= (SquareMatrix< Type > &&mat)
 Move assignment. More...
 
void operator= (const Foam::zero)
 Assign all elements to zero. More...
 
void operator= (const Type &val)
 Assign all elements to value. More...
 
template<class AnyType >
void operator= (const Identity< AnyType >)
 Set to identity matrix. More...
 
template<class CompOp >
Foam::List< Foam::label > sortPermutation (CompOp &compare) const
 
- Public Member Functions inherited from Matrix< SquareMatrix< Type >, Type >
Foam::tmp< Foam::Field< Type > > AmulImpl (const ListType &x) const
 
Foam::tmp< Foam::Field< Type > > TmulImpl (const ListType &x) const
 
 Matrix () noexcept
 Default construct (empty matrix) More...
 
 Matrix (const label m, const label n)
 Construct given number of rows/columns. More...
 
 Matrix (const label m, const label n, const Foam::zero)
 
 Matrix (const label m, const label n, const Type &val)
 
 Matrix (const labelPair &dims)
 Construct given number of rows/columns. More...
 
 Matrix (const labelPair &dims, const Foam::zero)
 
 Matrix (const labelPair &dims, const Type &val)
 
 Matrix (const Matrix< SquareMatrix< Type >, Type > &mat)
 Copy construct. More...
 
 Matrix (Matrix< SquareMatrix< Type >, Type > &&mat)
 Move construct. More...
 
 Matrix (const Matrix< Form2, Type > &mat)
 Copy constructor from Matrix of a different form. More...
 
 Matrix (const ConstMatrixBlock< MatrixType > &Mb)
 Construct from a block of another Matrix. More...
 
 Matrix (const MatrixBlock< MatrixType > &Mb)
 Construct from a block of another Matrix. More...
 
 Matrix (Istream &is)
 Construct from Istream. More...
 
autoPtr< mTypeclone () const
 Clone. More...
 
 ~Matrix ()
 Destructor. More...
 
label m () const noexcept
 The number of rows. More...
 
label n () const noexcept
 The number of columns. More...
 
label size () const
 The number of elements in Matrix (m*n) More...
 
labelPair sizes () const
 Return row/column sizes. More...
 
bool empty () const noexcept
 Return true if Matrix is empty (i.e., size() is zero) More...
 
const Type * cdata () const noexcept
 
Type * data () noexcept
 
const char * cdata_bytes () const noexcept
 
char * data_bytes () noexcept
 
std::streamsize size_bytes () const noexcept
 
std::streamsize byteSize () const
 
const Type * rowData (const label irow) const
 Return const pointer to data in the specified row. More...
 
Type * rowData (const label irow)
 Return pointer to data in the specified row. More...
 
const Type & at (const label idx) const
 Linear addressing const element access. More...
 
Type & at (const label idx)
 Linear addressing element access. More...
 
ConstMatrixBlock< mTypesubColumn (const label colIndex, const label rowIndex=0, label len=-1) const
 Return const column or column's subset of Matrix. More...
 
MatrixBlock< mTypesubColumn (const label colIndex, const label rowIndex=0, label len=-1)
 Return column or column's subset of Matrix. More...
 
ConstMatrixBlock< mTypesubRow (const label rowIndex, const label colIndex=0, label len=-1) const
 Return const row or const row's subset of Matrix. More...
 
MatrixBlock< mTypesubRow (const label rowIndex, const label colIndex=0, label len=-1)
 Return row or row's subset of Matrix. More...
 
ConstMatrixBlock< mTypesubMatrix (const label rowIndex, const label colIndex, label szRows=-1, label szCols=-1) const
 Return const sub-block of Matrix. More...
 
MatrixBlock< mTypesubMatrix (const label rowIndex, const label colIndex, label szRows=-1, label szCols=-1)
 Return sub-block of Matrix. More...
 
ConstMatrixBlock< mTypeblock (const label rowIndex, const label colIndex) const
 Access Field as a ConstMatrixBlock. More...
 
MatrixBlock< mTypeblock (const label rowIndex, const label colIndex)
 Access Field as a MatrixBlock. More...
 
ConstMatrixBlock< mTypeblock (const label m, const label n, const label mStart, const label nStart) const
 Deprecated(2019-04) - use subMatrix() More...
 
MatrixBlock< mTypeblock (const label m, const label n, const label mStart, const label nStart)
 Deprecated(2019-04) - use subMatrix() More...
 
Foam::ConstMatrixBlock< Foam::Matrix< SquareMatrix< Type >, Type > > block (const label rowIndex, const label colIndex) const
 
Foam::MatrixBlock< Foam::Matrix< SquareMatrix< Type >, Type > > block (const label rowIndex, const label colIndex)
 
void checki (const label irow) const
 Check index i is within valid range [0, m) More...
 
void checkj (const label jcol) const
 Check index j is within valid range [0, n) More...
 
void checkSize () const
 Check that dimensions are positive, non-zero. More...
 
bool uniform () const
 True if all entries have identical values, and Matrix is non-empty. More...
 
void clear ()
 Clear Matrix, i.e. set sizes to zero. More...
 
List< Type > release ()
 
void swap (Matrix< SquareMatrix< Type >, Type > &mat)
 Swap contents. More...
 
void transfer (Matrix< SquareMatrix< Type >, Type > &mat)
 
void resize (const label m, const label n)
 Change Matrix dimensions, preserving the elements. More...
 
void resize_nocopy (const label mrow, const label ncol)
 Change Matrix dimensions without preserving existing content. More...
 
void setSize (const label m, const label n)
 Change Matrix dimensions, preserving the elements. More...
 
void shallowResize (const label m, const label n)
 Resize Matrix without reallocating storage (unsafe) More...
 
void round (const scalar tol=SMALL)
 Round elements with magnitude smaller than tol (SMALL) to zero. More...
 
SquareMatrix< Type > T () const
 Return conjugate transpose of Matrix. More...
 
SquareMatrix< Type > transpose () const
 Return non-conjugate transpose of Matrix. More...
 
tmp< Field< Type > > Amul (const UList< Type > &x) const
 Right-multiply Matrix by a column vector (A * x) More...
 
tmp< Field< Type > > Amul (const IndirectListBase< Type, Addr > &x) const
 Right-multiply Matrix by a column vector (A * x) More...
 
Foam::tmp< Foam::Field< Type > > Amul (const IndirectListBase< Type, Addr > &x) const
 
tmp< Field< Type > > Tmul (const UList< Type > &x) const
 Left-multiply Matrix by a row vector (x * A) More...
 
tmp< Field< Type > > Tmul (const IndirectListBase< Type, Addr > &x) const
 Left-multiply Matrix by a row vector (x * A) More...
 
Foam::tmp< Foam::Field< Type > > Tmul (const IndirectListBase< Type, Addr > &x) const
 
List< Type > diag () const
 Extract the diagonal elements. Method may change in the future. More...
 
void diag (const UList< Type > &list)
 Assign diagonal of Matrix. More...
 
Type trace () const
 Return the trace. More...
 
scalar columnNorm (const label colIndex, const bool noSqrt=false) const
 Return L2-Norm of chosen column. More...
 
scalar norm (const bool noSqrt=false) const
 Return Frobenius norm of Matrix. More...
 
const Type * operator[] (const label irow) const
 Return const pointer to data in the specified row - rowData(). More...
 
Type * operator[] (const label irow)
 Return pointer to data in the specified row - rowData(). More...
 
const Type & operator() (const label irow, const label jcol) const
 (i, j) const element access operator More...
 
Type & operator() (const label irow, const label jcol)
 (i, j) element access operator More...
 
void operator= (const Matrix< SquareMatrix< Type >, Type > &mat)
 Copy assignment. Takes linear time. More...
 
void operator= (Matrix< SquareMatrix< Type >, Type > &&mat)
 Move assignment. More...
 
void operator= (const ConstMatrixBlock< MatrixType > &Mb)
 Assignment to a block of another Matrix. More...
 
void operator= (const MatrixBlock< MatrixType > &Mb)
 Assignment to a block of another Matrix. More...
 
void operator= (const Foam::zero)
 Assignment of all elements to zero. More...
 
void operator= (const Type &val)
 Assignment of all elements to the given value. More...
 
void operator+= (const Matrix< SquareMatrix< Type >, Type > &other)
 Matrix addition. More...
 
void operator+= (const Type &s)
 Matrix scalar addition. More...
 
void operator-= (const Matrix< SquareMatrix< Type >, Type > &other)
 Matrix subtraction. More...
 
void operator-= (const Type &s)
 Matrix scalar subtraction. More...
 
void operator*= (const Type &s)
 Matrix scalar multiplication. More...
 
void operator/= (const Type &s)
 Matrix scalar division. More...
 
iterator begin () noexcept
 Return an iterator to begin traversing a Matrix. More...
 
const_iterator begin () const noexcept
 Return const_iterator to begin traversing a constant Matrix. More...
 
iterator end () noexcept
 Return an iterator to end traversing a Matrix. More...
 
const_iterator end () const noexcept
 Return const_iterator to end traversing a constant Matrix. More...
 
const_iterator cbegin () const noexcept
 Return const_iterator to begin traversing a constant Matrix. More...
 
const_iterator cend () const noexcept
 Return const_iterator to end traversing a constant Matrix. More...
 
bool readMatrix (Istream &is)
 Read Matrix from Istream, discarding existing contents. More...
 
OstreamwriteMatrix (Ostream &os, const label shortLen=0) const
 
label mRows () const noexcept
 The number of rows - same as m() More...
 
label nRows () const noexcept
 The number of rows - same as m() More...
 
label nCols () const noexcept
 The number of columns - same as n() More...
 
const Type * v () const
 Deprecated(2019-04) raw data pointer, const access. More...
 
Type * v ()
 Deprecated(2019-04) raw data pointer, non-const access. More...
 
ConstMatrixBlock< mTypecol (const label m, const label mStart, const label nStart) const
 Deprecated(2019-04) - use subColumn() More...
 
MatrixBlock< mTypecol (const label m, const label mStart, const label nStart)
 Deprecated(2019-04) - use subColumn() More...
 
void col (const label m, const label rowStart) const=delete
 Deleted(2019-04) - use subColumn() More...
 
void col (const label m, const label rowStart)=delete
 Deleted(2019-04) - use subColumn() More...
 

Additional Inherited Members

- Public Types inherited from Matrix< SquareMatrix< Type >, Type >
typedef Matrix< SquareMatrix< Type >, Type > mType
 Matrix type. More...
 
typedef Type cmptType
 Component type. More...
 
typedef Type * iterator
 Random access iterator for traversing a Matrix. More...
 
typedef const Type * const_iterator
 Random access iterator for traversing a Matrix. More...
 
- Static Public Member Functions inherited from Matrix< SquareMatrix< Type >, Type >
static const Matrix< SquareMatrix< Type >, Type > & null ()
 Return a null Matrix. More...
 

Detailed Description

template<class Type>
class Foam::SquareMatrix< Type >

A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.

See also
Test-SquareMatrix.C
Source files

Definition at line 63 of file SquareMatrix.H.

Constructor & Destructor Documentation

◆ SquareMatrix() [1/15]

SquareMatrix ( )
default

Default construct.

◆ SquareMatrix() [2/15]

SquareMatrix ( const SquareMatrix< Type > &  )
default

Copy construct.

◆ SquareMatrix() [3/15]

SquareMatrix ( const label  n)
inlineexplicit

Construct for given size (rows == cols)

Definition at line 41 of file SquareMatrixI.H.

◆ SquareMatrix() [4/15]

SquareMatrix ( const label  n,
const Foam::zero   
)
inline

Construct for given size (rows == cols) initializing all elements to zero

Definition at line 48 of file SquareMatrixI.H.

◆ SquareMatrix() [5/15]

SquareMatrix ( const label  n,
const Type &  val 
)
inline

Construct for given size (rows == cols) initializing all elements to the given value

Definition at line 59 of file SquareMatrixI.H.

◆ SquareMatrix() [6/15]

SquareMatrix ( const label  n,
const Identity< AnyType >   
)
inline

Construct for given size (rows == cols) initializing to the identity matrix

Definition at line 71 of file SquareMatrixI.H.

References Matrix< SquareMatrix< Type >, Type >::n(), and Matrix< SquareMatrix< Type >, Type >::operator()().

Here is the call graph for this function:

◆ SquareMatrix() [7/15]

SquareMatrix ( const labelPair dims,
const Identity< AnyType >   
)
inline

Construct for given size (rows == cols) by using a labelPair initializing to the identity matrix

Definition at line 88 of file SquareMatrixI.H.

◆ SquareMatrix() [8/15]

SquareMatrix ( const labelPair dims)
inlineexplicit

Construct given number of rows/columns by using a labelPair (checked to be equal)

For constructor consistency in rectangular matrices

Definition at line 106 of file SquareMatrixI.H.

◆ SquareMatrix() [9/15]

SquareMatrix ( const labelPair dims,
const Foam::zero   
)
inline

Construct given number of rows/columns by using a labelPair (checked to be equal) and initializing all elements to zero

For constructor consistency with rectangular matrices

Definition at line 118 of file SquareMatrixI.H.

◆ SquareMatrix() [10/15]

SquareMatrix ( const labelPair dims,
const Type &  val 
)
inline

Construct given number of rows/columns by using a labelPair (checked to be equal) and initializing all elements to the given value

For constructor consistency with rectangular matrices

Definition at line 131 of file SquareMatrixI.H.

◆ SquareMatrix() [11/15]

SquareMatrix ( const label  m,
const label  n,
const Foam::zero   
)
inline

Construct given number of rows/columns (checked to be equal) initializing all elements to zero

Definition at line 144 of file SquareMatrixI.H.

◆ SquareMatrix() [12/15]

SquareMatrix ( const ConstMatrixBlock< MatrixType > &  mat)
inline

Construct from const sub-matrix block.

Definition at line 159 of file SquareMatrixI.H.

◆ SquareMatrix() [13/15]

SquareMatrix ( const MatrixBlock< MatrixType > &  mat)
inline

Construct from sub-matrix block.

Definition at line 172 of file SquareMatrixI.H.

◆ SquareMatrix() [14/15]

SquareMatrix ( const RectangularMatrix< Type > &  mat)
inlineexplicit

Construct as copy of a RectangularMatrix which is checked to be square

Definition at line 184 of file SquareMatrixI.H.

◆ SquareMatrix() [15/15]

SquareMatrix ( Istream is)
inlineexplicit

Construct from Istream.

Definition at line 196 of file SquareMatrixI.H.

References CHECK_MATRIX_IS_SQUARE, Matrix< SquareMatrix< Type >, Type >::m(), and Matrix< SquareMatrix< Type >, Type >::n().

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/5]

SquareMatrix & operator= ( const SquareMatrix< Type > &  )
default

Copy assignment.

◆ clone()

Foam::autoPtr< Foam::SquareMatrix< Type > > clone
inline

Clone.

Definition at line 206 of file SquareMatrixI.H.

References Foam::New().

Here is the call graph for this function:

◆ resize() [1/2]

void resize ( const label  m)
inline

Resize the matrix preserving the elements.

Definition at line 215 of file SquareMatrixI.H.

References resize().

Here is the call graph for this function:

◆ resize() [2/2]

void resize ( const label  m,
const label  n 
)
inline

Resize the matrix preserving the elements (compatibility)

Definition at line 222 of file SquareMatrixI.H.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, n, and resize().

Here is the call graph for this function:

◆ setSize()

void setSize ( const label  m)
inline

Resize the matrix preserving the elements.

Definition at line 235 of file SquareMatrixI.H.

References resize().

Here is the call graph for this function:

◆ shallowResize()

void shallowResize ( const label  m)
inline

Resize the matrix without reallocating storage (unsafe)

Definition at line 242 of file SquareMatrixI.H.

Referenced by ODESolver::resizeMatrix().

Here is the caller graph for this function:

◆ symmetric()

bool symmetric
inline

Return true if the square matrix is effectively symmetric/Hermitian.

Definition at line 249 of file SquareMatrixI.H.

References Foam::mag(), and n.

Here is the call graph for this function:

◆ tridiagonal()

bool tridiagonal
inline

Return true if the square matrix is reduced tridiagonal.

Definition at line 266 of file SquareMatrixI.H.

References Foam::mag(), and n.

Here is the call graph for this function:

◆ sortPermutation() [1/2]

List< label > sortPermutation ( CompOp &  compare) const

Return a sort permutation labelList according to a given comparison on the diagonal entries

◆ applyPermutation()

void applyPermutation ( const List< label > &  p)

Column-reorder this Matrix according to a given permutation labelList

Definition at line 56 of file SquareMatrix.C.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, Foam::nl, p, and Matrix< Form, Type >::subColumn().

Here is the call graph for this function:

◆ operator=() [2/5]

void operator= ( SquareMatrix< Type > &&  mat)
inline

Move assignment.

Definition at line 294 of file SquareMatrixI.H.

◆ operator=() [3/5]

void operator= ( const Foam::zero  )
inline

Assign all elements to zero.

Definition at line 301 of file SquareMatrixI.H.

References Foam::Zero.

◆ operator=() [4/5]

void operator= ( const Type &  val)
inline

Assign all elements to value.

Definition at line 308 of file SquareMatrixI.H.

◆ operator=() [5/5]

void operator= ( const Identity< AnyType >  )

Set to identity matrix.

Definition at line 86 of file SquareMatrix.C.

References n.

◆ sortPermutation() [2/2]

Foam::List< Foam::label > sortPermutation ( CompOp &  compare) const

Definition at line 37 of file SquareMatrix.C.

References p.


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