OpenMD 3.2
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OpenMD::SquareMatrix3< Real > Class Template Reference
Inheritance diagram for OpenMD::SquareMatrix3< Real >:

Public Types

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

Public Member Functions

 SquareMatrix3 ()
 default constructor
 SquareMatrix3 (Real s)
 Constructs and initializes every element of this matrix to a scalar.
 SquareMatrix3 (Real *array)
 Constructs and initializes from an array.
 SquareMatrix3 (const SquareMatrix< Real, 3 > &m)
 copy constructor
 SquareMatrix3 (const RectMatrix< Real, 3, 3 > &m)
 Construct from a RectMatrix (e.g.
 SquareMatrix3 (const Vector3< Real > &eulerAngles)
 SquareMatrix3 (Real phi, Real theta, Real psi)
 SquareMatrix3 (const Quaternion< Real > &q)
 SquareMatrix3 (Real w, Real x, Real y, Real z)
SquareMatrix3< Real > & operator= (const RectMatrix< Real, 3, 3 > &m)
 copy assignment operator
SquareMatrix3< Real > & operator= (const Quaternion< Real > &q)
void setupRotMat (const Vector3< Real > &eulerAngles)
 Sets this matrix to a rotation matrix by three euler angles @ param euler.
void setupRotMat (Real phi, Real theta, Real psi)
 Sets this matrix to a rotation matrix by three euler angles.
void setupRotMat (const Quaternion< Real > &quat)
 Sets this matrix to a rotation matrix by quaternion.
void setupRotMat (Real w, Real x, Real y, Real z)
 Sets this matrix to a rotation matrix by quaternion.
void setupSkewMat (Vector3< Real > v)
void setupSkewMat (Real v1, Real v2, Real v3)
void setupVoigtTensor (Vector< Real, 6 > vt)
 Sets this matrix to a symmetric tensor using Voigt Notation.
void setupVoigtTensor (Real v1, Real v2, Real v3, Real v4, Real v5, Real v6)
void setupUpperTriangularVoigtTensor (Vector< Real, 6 > vt)
 Sets this matrix to an upper-triangular (asymmetric) tensor using Voigt Notation.
void setupUpperTriangularVoigtTensor (Real v1, Real v2, Real v3, Real v4, Real v5, Real v6)
void axisAngle (Vector3d axis, RealType angle)
 Uses Rodrigues' rotation formula for a rotation matrix.
Quaternion< Real > toQuaternion ()
 Returns the quaternion from this rotation matrix.
Vector3< Real > toEulerAngles ()
 Returns the euler angles from this rotation matrix.
bool closeEnough (const Real &a, const Real &b, const Real &epsilon=std::numeric_limits< Real >::epsilon())
Vector3< Real > toRPY ()
Vector< Real, 6 > toVoigtTensor ()
Real determinant () const
 Returns the determinant of this matrix.
Real trace () const
 Returns the trace of this matrix.
SquareMatrix3< Real > inverse () const
 Sets the value of this matrix to the inverse of itself.
SquareMatrix3< Real > transpose () const
Public Member Functions inherited from OpenMD::SquareMatrix< Real, 3 >
 SquareMatrix ()
 default 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 ()
 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.
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 add (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the sum of itself and m (*this += m).
void sub (const RectMatrix< Real, Row, Col > &m)
 Sets the value of this matrix to the difference of itself and m (*this -= m).
void mul (Real s)
 Sets the value of this matrix to the scalar multiplication of itself (*this *= s).
void div (Real s)
 Sets the value of this matrix to the scalar division of itself (*this /= 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 void diagonalize (SquareMatrix3< Real > &a, Vector3< Real > &w, SquareMatrix3< Real > &v)
 Extract the eigenvalues and eigenvectors from a 3x3 matrix.
Static Public Member Functions inherited from OpenMD::SquareMatrix< Real, 3 >
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>
class OpenMD::SquareMatrix3< Real >

Definition at line 71 of file SquareMatrix3.hpp.

Member Typedef Documentation

◆ ElemPoinerType

template<typename Real>
using OpenMD::SquareMatrix3< Real >::ElemPoinerType = Real*

Definition at line 74 of file SquareMatrix3.hpp.

◆ ElemType

template<typename Real>
using OpenMD::SquareMatrix3< Real >::ElemType = Real

Definition at line 73 of file SquareMatrix3.hpp.

Constructor & Destructor Documentation

◆ SquareMatrix3() [1/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( )
inline

default constructor

Definition at line 77 of file SquareMatrix3.hpp.

Referenced by diagonalize().

◆ SquareMatrix3() [2/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( Real s)
inline

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

Definition at line 80 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [3/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( Real * array)
inline

Constructs and initializes from an array.

Definition at line 83 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [4/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( const SquareMatrix< Real, 3 > & m)
inline

copy constructor

Definition at line 86 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [5/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( const RectMatrix< Real, 3, 3 > & m)
inline

Construct from a RectMatrix (e.g.

the result of matrix arithmetic).

Definition at line 89 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [6/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( const Vector3< Real > & eulerAngles)
inline

Definition at line 91 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [7/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( Real phi,
Real theta,
Real psi )
inline

Definition at line 95 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [8/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( const Quaternion< Real > & q)
inline

Definition at line 99 of file SquareMatrix3.hpp.

◆ SquareMatrix3() [9/9]

template<typename Real>
OpenMD::SquareMatrix3< Real >::SquareMatrix3 ( Real w,
Real x,
Real y,
Real z )
inline

Definition at line 101 of file SquareMatrix3.hpp.

Member Function Documentation

◆ axisAngle()

template<typename Real>
void OpenMD::SquareMatrix3< Real >::axisAngle ( Vector3d axis,
RealType angle )
inline

Uses Rodrigues' rotation formula for a rotation matrix.

Parameters
axisthe axis to rotate around
anglethe angle to rotate (in radians)

Definition at line 232 of file SquareMatrix3.hpp.

◆ closeEnough()

template<typename Real>
bool OpenMD::SquareMatrix3< Real >::closeEnough ( const Real & a,
const Real & b,
const Real & epsilon = std::numeric_limits<Real>::epsilon() )
inline

Definition at line 348 of file SquareMatrix3.hpp.

◆ determinant()

template<typename Real>
Real OpenMD::SquareMatrix3< Real >::determinant ( ) const
inline

◆ diagonalize()

template<typename Real>
void OpenMD::SquareMatrix3< Real >::diagonalize ( SquareMatrix3< Real > & a,
Vector3< Real > & w,
SquareMatrix3< Real > & v )
static

Extract the eigenvalues and eigenvectors from a 3x3 matrix.

The eigenvectors (the columns of V) will be normalized. The eigenvectors are aligned optimally with the x, y, and z axes respectively.

Parameters
asymmetric matrix whose eigenvectors are to be computed. On return, the matrix is overwritten
wwill 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.
Warning
a will be overwritten
Todo

Definition at line 493 of file SquareMatrix3.hpp.

References OpenMD::cross(), determinant(), OpenMD::RectMatrix< Real, Row, Col >::getRow(), OpenMD::SquareMatrix< Real, 3 >::identity(), OpenMD::SquareMatrix< Real, 3 >::jacobi(), OpenMD::Vector< Real, Dim >::normalize(), OpenMD::RectMatrix< Real, Row, Col >::setRow(), SquareMatrix3(), and OpenMD::RectMatrix< Real, Row, Col >::swapRow().

◆ inverse()

template<typename Real>
SquareMatrix3< Real > OpenMD::SquareMatrix3< Real >::inverse ( ) const
inline

Sets the value of this matrix to the inverse of itself.

Note
since this simple algorithm can be applied to invert a 3 by 3 matrix, we hide the implementation of inverse in SquareMatrix class

Definition at line 428 of file SquareMatrix3.hpp.

Referenced by OpenMD::Velocitizer::removeAngularDrift(), OpenMD::Snapshot::setBoundingBox(), and OpenMD::Snapshot::setHmat().

◆ operator=() [1/2]

template<typename Real>
SquareMatrix3< Real > & OpenMD::SquareMatrix3< Real >::operator= ( const Quaternion< Real > & q)
inline

Definition at line 110 of file SquareMatrix3.hpp.

◆ operator=() [2/2]

template<typename Real>
SquareMatrix3< Real > & OpenMD::SquareMatrix3< Real >::operator= ( const RectMatrix< Real, 3, 3 > & m)
inline

copy assignment operator

Definition at line 104 of file SquareMatrix3.hpp.

◆ setupRotMat() [1/4]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupRotMat ( const Quaternion< Real > & quat)
inline

Sets this matrix to a rotation matrix by quaternion.

Parameters
quat

Definition at line 157 of file SquareMatrix3.hpp.

◆ setupRotMat() [2/4]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupRotMat ( const Vector3< Real > & eulerAngles)
inline

Sets this matrix to a rotation matrix by three euler angles @ param euler.

Definition at line 119 of file SquareMatrix3.hpp.

Referenced by OpenMD::SquareMatrix3< RealType >::setupRotMat(), and OpenMD::SquareMatrix3< RealType >::setupRotMat().

◆ setupRotMat() [3/4]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupRotMat ( Real phi,
Real theta,
Real psi )
inline

Sets this matrix to a rotation matrix by three euler angles.

Parameters
phi
theta
psi

Definition at line 129 of file SquareMatrix3.hpp.

◆ setupRotMat() [4/4]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupRotMat ( Real w,
Real x,
Real y,
Real z )
inline

Sets this matrix to a rotation matrix by quaternion.

Parameters
wthe first element
xthe second element
ythe third element
zthe fourth element

Definition at line 168 of file SquareMatrix3.hpp.

◆ setupSkewMat() [1/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupSkewMat ( Real v1,
Real v2,
Real v3 )
inline

Definition at line 175 of file SquareMatrix3.hpp.

◆ setupSkewMat() [2/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupSkewMat ( Vector3< Real > v)
inline

Definition at line 173 of file SquareMatrix3.hpp.

◆ setupUpperTriangularVoigtTensor() [1/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupUpperTriangularVoigtTensor ( Real v1,
Real v2,
Real v3,
Real v4,
Real v5,
Real v6 )
inline

Definition at line 217 of file SquareMatrix3.hpp.

◆ setupUpperTriangularVoigtTensor() [2/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupUpperTriangularVoigtTensor ( Vector< Real, 6 > vt)
inline

Sets this matrix to an upper-triangular (asymmetric) tensor using Voigt Notation.

Parameters
vt

Definition at line 213 of file SquareMatrix3.hpp.

Referenced by OpenMD::SquareMatrix3< RealType >::setupUpperTriangularVoigtTensor().

◆ setupVoigtTensor() [1/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupVoigtTensor ( Real v1,
Real v2,
Real v3,
Real v4,
Real v5,
Real v6 )
inline

Definition at line 195 of file SquareMatrix3.hpp.

◆ setupVoigtTensor() [2/2]

template<typename Real>
void OpenMD::SquareMatrix3< Real >::setupVoigtTensor ( Vector< Real, 6 > vt)
inline

Sets this matrix to a symmetric tensor using Voigt Notation.

Parameters
vt

Definition at line 191 of file SquareMatrix3.hpp.

Referenced by OpenMD::SquareMatrix3< RealType >::setupVoigtTensor().

◆ toEulerAngles()

template<typename Real>
Vector3< Real > OpenMD::SquareMatrix3< Real >::toEulerAngles ( )
inline

Returns the euler angles from this rotation matrix.

Returns
the euler angles in a vector
Exceptions
invalidrotation matrix We use so-called "x-convention", which is the most common definition. In this convention, the rotation given by Euler angles (phi, theta, psi), where the first rotation is by an angle phi about the z-axis, the second is by an angle theta (0 <= theta <= 180) about the x-axis, and the third is by an angle psi about the z-axis (again).

Definition at line 301 of file SquareMatrix3.hpp.

◆ toQuaternion()

template<typename Real>
Quaternion< Real > OpenMD::SquareMatrix3< Real >::toQuaternion ( )
inline

Returns the quaternion from this rotation matrix.

Returns
the quaternion from this rotation matrix
Exceptions
invalidrotation matrix

Definition at line 247 of file SquareMatrix3.hpp.

Referenced by OpenMD::MolecularRestraint::calcForce(), and OpenMD::ObjectRestraint::calcForce().

◆ toRPY()

template<typename Real>
Vector3< Real > OpenMD::SquareMatrix3< Real >::toRPY ( )
inline

Definition at line 354 of file SquareMatrix3.hpp.

◆ toVoigtTensor()

template<typename Real>
Vector< Real, 6 > OpenMD::SquareMatrix3< Real >::toVoigtTensor ( )
inline

Definition at line 393 of file SquareMatrix3.hpp.

◆ trace()

template<typename Real>
Real OpenMD::SquareMatrix3< Real >::trace ( ) const
inline

Returns the trace of this matrix.

Definition at line 418 of file SquareMatrix3.hpp.

◆ transpose()

template<typename Real>
SquareMatrix3< Real > OpenMD::SquareMatrix3< Real >::transpose ( ) const
inline

Definition at line 453 of file SquareMatrix3.hpp.


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