OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OpenMD::SquareMatrix< Real, Dim > Class Template Reference

A square matrix class. More...

#include "math/SquareMatrix.hpp"

+ Inheritance diagram for OpenMD::SquareMatrix< Real, Dim >:

Public Types

using ElemType = Real
 
using ElemPoinerType = Real*
 
- Public Types inherited from OpenMD::RectMatrix< Real, Dim, Dim >
using ElemType
 
using ElemPoinerType
 

Public Member Functions

 SquareMatrix ()
 default constructor
 
 SquareMatrix (Real s)
 Constructs and initializes every element of this matrix to a scalar.
 
 SquareMatrix (Real *array)
 Constructs and initializes from an array.
 
 SquareMatrix (const RectMatrix< Real, Dim, Dim > &m)
 copy constructor
 
SquareMatrix< Real, Dim > & operator= (const RectMatrix< Real, Dim, Dim > &m)
 copy assignment operator
 
SquareMatrix< Real, Dim > inverse ()
 Returns the inverse of this matrix.
 
Real determinant () const
 Returns the determinant of this matrix.
 
SquareMatrix< Real, Dim - 1 > cofactor (int p, int q)
 
Real trace () const
 Returns the trace of this matrix.
 
bool isSymmetric () const
 Tests if this matrix is symmetrix.
 
bool isOrthogonal ()
 Tests if this matrix is orthogonal.
 
bool isDiagonal () const
 Tests if this matrix is diagonal.
 
Vector< Real, Dim > diagonals () const
 Returns a column vector that contains the elements from the diagonal of m in the order R(0) = m(0,0), R(1) = m(1,1), and so on.
 
bool isUnitMatrix () const
 Tests if this matrix is the unit matrix.
 
SquareMatrix< Real, Dim > transpose () const
 Return the transpose of this matrix.
 
void diagonalize ()
 
- Public Member Functions inherited from OpenMD::RectMatrix< Real, Dim, Dim >
 RectMatrix ()
 default constructor
 
 RectMatrix (Real s)
 Constructs and initializes every element of this matrix to a scalar.
 
 RectMatrix (Real *array)
 
 RectMatrix (const RectMatrix< Real, Row, Col > &m)
 copy constructor
 
 ~RectMatrix ()
 destructor
 
RectMatrix< Real, Row, Col > & operator= (const RectMatrix< Real, Row, Col > &m)
 copy assignment operator
 
Real & operator() (unsigned int i, unsigned int j)
 Return the reference of a single element of this matrix.
 
Real operator() (unsigned int i, unsigned int j) const
 Return the value of a single element of this matrix.
 
void getArray (Real *array)
 Copy the internal data to an array.
 
Real * getArrayPointer ()
 Returns the pointer of internal array.
 
Vector< Real, Row > getRow (unsigned int row)
 Returns a row of this matrix as a vector.
 
void setRow (unsigned int row, const Vector< Real, Row > &v)
 Sets a row of this matrix.
 
Vector< Real, Col > getColumn (unsigned int col)
 Returns a column of this matrix as a vector.
 
void setColumn (unsigned int col, const Vector< Real, Col > &v)
 Sets a column of this matrix.
 
void swapRow (unsigned int i, unsigned int j)
 swap two rows of this matrix
 
void swapColumn (unsigned int i, unsigned int j)
 swap two Columns of this matrix
 
bool operator== (const RectMatrix< Real, Row, Col > &m)
 Tests if this matrix is identical to matrix m.
 
bool operator!= (const RectMatrix< Real, Row, Col > &m)
 Tests if this matrix is not equal to matrix m.
 
void negate ()
 Negates the value of this matrix in place.
 
void negate (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the negation of matrix m.
 
void add (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the sum of itself and m (*this += m).
 
void add (const RectMatrix< Real, Row, Col > &m1, const RectMatrix< Real, Row, Col > &m2)
 Sets the value of this matrix to the sum of m1 and m2 (*this = m1 + m2).
 
void sub (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the difference of itself and m (*this -= m).
 
void sub (const RectMatrix< Real, Row, Col > &m1, const RectMatrix< Real, Row, Col > &m2)
 Sets the value of this matrix to the difference of matrix m1 and m2 (*this = m1 - m2).
 
void mul (Real s)
 Sets the value of this matrix to the scalar multiplication of itself (*this *= s).
 
void mul (Real s, const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the scalar multiplication of matrix m (*this = s * m).
 
void div (Real s)
 Sets the value of this matrix to the scalar division of itself (*this /= s ).
 
void div (Real s, const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the scalar division of matrix m (*this = m /s).
 
RectMatrix< Real, Row, Col > & operator*= (const Real s)
 Multiples a scalar into every element of this matrix.
 
RectMatrix< Real, Row, Col > & operator/= (const Real s)
 Divides every element of this matrix by a scalar.
 
RectMatrix< Real, Row, Col > & operator+= (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the sum of the other matrix and itself (*this += m).
 
RectMatrix< Real, Row, Col > & operator-= (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the differerence of itself and the other matrix (*this -= m)
 
RectMatrix< Real, Col, Row > transpose () const
 Return the transpose of this matrix.
 
void setSubMatrix (unsigned int beginRow, unsigned int beginCol, const MatrixType &m)
 
void getSubMatrix (unsigned int beginRow, unsigned int beginCol, MatrixType &m)
 
unsigned int getNRow () const
 
unsigned int getNCol () const
 
Real frobeniusNorm ()
 

Static Public Member Functions

static SquareMatrix< Real, Dim > identity ()
 Returns an identity matrix.
 
static int jacobi (SquareMatrix< Real, Dim > &a, Vector< Real, Dim > &d, SquareMatrix< Real, Dim > &v)
 Jacobi iteration routines for computing eigenvalues/eigenvectors of real symmetric matrix.
 

Additional Inherited Members

- Protected Attributes inherited from OpenMD::RectMatrix< Real, Dim, Dim >
Real data_ [Row][Col]
 

Detailed Description

template<typename Real, int Dim>
class OpenMD::SquareMatrix< Real, Dim >

A square matrix class.

Template Parameters
Realthe element type
Dimthe dimension of the square matrix

Definition at line 66 of file SquareMatrix.hpp.

Member Typedef Documentation

◆ ElemPoinerType

template<typename Real , int Dim>
using OpenMD::SquareMatrix< Real, Dim >::ElemPoinerType = Real*

Definition at line 69 of file SquareMatrix.hpp.

◆ ElemType

template<typename Real , int Dim>
using OpenMD::SquareMatrix< Real, Dim >::ElemType = Real

Definition at line 68 of file SquareMatrix.hpp.

Constructor & Destructor Documentation

◆ SquareMatrix() [1/4]

template<typename Real , int Dim>
OpenMD::SquareMatrix< Real, Dim >::SquareMatrix ( )
inline

default constructor

Definition at line 72 of file SquareMatrix.hpp.

◆ SquareMatrix() [2/4]

template<typename Real , int Dim>
OpenMD::SquareMatrix< Real, Dim >::SquareMatrix ( Real s)
inline

Constructs and initializes every element of this matrix to a scalar.

Definition at line 79 of file SquareMatrix.hpp.

◆ SquareMatrix() [3/4]

template<typename Real , int Dim>
OpenMD::SquareMatrix< Real, Dim >::SquareMatrix ( Real * array)
inline

Constructs and initializes from an array.

Definition at line 82 of file SquareMatrix.hpp.

◆ SquareMatrix() [4/4]

template<typename Real , int Dim>
OpenMD::SquareMatrix< Real, Dim >::SquareMatrix ( const RectMatrix< Real, Dim, Dim > & m)
inline

copy constructor

Definition at line 85 of file SquareMatrix.hpp.

Member Function Documentation

◆ cofactor()

template<typename Real , int Dim>
SquareMatrix< Real, Dim - 1 > OpenMD::SquareMatrix< Real, Dim >::cofactor ( int p,
int q )
inline

Definition at line 145 of file SquareMatrix.hpp.

◆ determinant()

template<typename Real , int Dim>
Real OpenMD::SquareMatrix< Real, Dim >::determinant ( ) const
inline

Returns the determinant of this matrix.

Definition at line 126 of file SquareMatrix.hpp.

◆ diagonalize()

template<typename Real , int Dim>
void OpenMD::SquareMatrix< Real, Dim >::diagonalize ( )
inline
Todo
need implementation

Definition at line 242 of file SquareMatrix.hpp.

◆ diagonals()

template<typename Real , int Dim>
Vector< Real, Dim > OpenMD::SquareMatrix< Real, Dim >::diagonals ( ) const
inline

Returns a column vector that contains the elements from the diagonal of m in the order R(0) = m(0,0), R(1) = m(1,1), and so on.

Definition at line 212 of file SquareMatrix.hpp.

◆ identity()

template<typename Real , int Dim>
static SquareMatrix< Real, Dim > OpenMD::SquareMatrix< Real, Dim >::identity ( )
inlinestatic

Returns an identity matrix.

Definition at line 96 of file SquareMatrix.hpp.

◆ inverse()

template<typename Real , int Dim>
SquareMatrix< Real, Dim > OpenMD::SquareMatrix< Real, Dim >::inverse ( )
inline

Returns the inverse of this matrix.

Definition at line 112 of file SquareMatrix.hpp.

References OpenMD::invertMatrix().

◆ isDiagonal()

template<typename Real , int Dim>
bool OpenMD::SquareMatrix< Real, Dim >::isDiagonal ( ) const
inline

Tests if this matrix is diagonal.

Definition at line 199 of file SquareMatrix.hpp.

Referenced by OpenMD::SquareMatrix< Real, Dim >::isOrthogonal(), and OpenMD::SquareMatrix< Real, Dim >::isUnitMatrix().

◆ isOrthogonal()

template<typename Real , int Dim>
bool OpenMD::SquareMatrix< Real, Dim >::isOrthogonal ( )
inline

Tests if this matrix is orthogonal.

Definition at line 190 of file SquareMatrix.hpp.

References OpenMD::SquareMatrix< Real, Dim >::isDiagonal(), and OpenMD::SquareMatrix< Real, Dim >::transpose().

◆ isSymmetric()

template<typename Real , int Dim>
bool OpenMD::SquareMatrix< Real, Dim >::isSymmetric ( ) const
inline

Tests if this matrix is symmetrix.

Definition at line 180 of file SquareMatrix.hpp.

◆ isUnitMatrix()

template<typename Real , int Dim>
bool OpenMD::SquareMatrix< Real, Dim >::isUnitMatrix ( ) const
inline

Tests if this matrix is the unit matrix.

Definition at line 221 of file SquareMatrix.hpp.

References OpenMD::SquareMatrix< Real, Dim >::isDiagonal().

◆ jacobi()

template<typename Real , int Dim>
int OpenMD::SquareMatrix< Real, Dim >::jacobi ( SquareMatrix< Real, Dim > & a,
Vector< Real, Dim > & d,
SquareMatrix< Real, Dim > & v )
static

Jacobi iteration routines for computing eigenvalues/eigenvectors of real symmetric matrix.

Returns
true if success, otherwise return false
Parameters
asymmetric matrix whose eigenvectors are to be computed. On return, the matrix is overwritten
dwill contain the eigenvalues of the matrix On return of this function
vthe columns of this matrix will contain the eigenvectors. The eigenvectors are normalized and mutually orthogonal.

Definition at line 314 of file SquareMatrix.hpp.

◆ operator=()

template<typename Real , int Dim>
SquareMatrix< Real, Dim > & OpenMD::SquareMatrix< Real, Dim >::operator= ( const RectMatrix< Real, Dim, Dim > & m)
inline

copy assignment operator

Definition at line 89 of file SquareMatrix.hpp.

References OpenMD::RectMatrix< Real, Row, Col >::operator=().

Referenced by OpenMD::SquareMatrix3< Real >::operator=().

◆ trace()

template<typename Real , int Dim>
Real OpenMD::SquareMatrix< Real, Dim >::trace ( ) const
inline

Returns the trace of this matrix.

Definition at line 170 of file SquareMatrix.hpp.

◆ transpose()

template<typename Real , int Dim>
SquareMatrix< Real, Dim > OpenMD::SquareMatrix< Real, Dim >::transpose ( ) const
inline

Return the transpose of this matrix.

Definition at line 231 of file SquareMatrix.hpp.

Referenced by OpenMD::SquareMatrix< Real, Dim >::isOrthogonal().


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