walberla::math::Matrix2< Type > Class Template Reference

Detailed Description

template<typename Type>
class walberla::math::Matrix2< Type >

Efficient, generic implementation of a 2x2 matrix.

The Matrix2 class is the representation of a 2x2 matrix with a total of 9 statically allocated elements of arbitrary type. The naming convention of the elements is as follows:

                      \f[\left(\begin{array}{*{2}{c}}
                      xx & xy  \\
                      yx & yy  \\
                      \end{array}\right)\f]\n

These elements can be accessed directly with the 1D subscript operator or with the 2D function operator. The numbering of the matrix elements is

                      \f[\left(\begin{array}{*{3}{c}}
                      0 & 1  \\
                      2 & 3  \\
                      \end{array}\right)\f]

#include <Types.h>

Public Member Functions

constexpr Matrix2 ()
 The default constructor for Matrix2. More...
 
constexpr Matrix2 (Type init)
 Constructor for a homogeneous initialization of all elements. More...
 
constexpr Matrix2 (Type xx, Type xy, Type yx, Type yy)
 Constructor for a direct initialization of all matrix elements. More...
 
constexpr Matrix2 (const Type *init)
 Constructor for an array initializer. More...
 
constexpr Matrix2 (const Matrix2 &m)
 The copy constructor for Matrix2. More...
 
template<typename Other >
constexpr Matrix2 (const Matrix2< Other > &m)
 Conversion constructor from different Matrix2 instances. More...
 
template<typename Other >
Matrix2< Type > & operator= (const Matrix2< Other > &set)
 
template<typename Other >
Matrix2< Type > & operator+= (const Matrix2< Other > &rhs)
 
template<typename Other >
Matrix2< Type > & operator-= (const Matrix2< Other > &rhs)
 
template<typename Other >
Matrix2< Type > & operator*= (Other rhs)
 
template<typename Other >
Matrix2< Type > & operator*= (const Matrix2< Other > &rhs)
 
Operators
Matrix2operator= (Type set)
 Homogenous assignment to all matrix elements. More...
 
Matrix2operator= (const Matrix2 &set)
 Copy assignment operator for Matrix2. More...
 
template<typename Other >
Matrix2operator= (const Matrix2< Other > &set)
 Assignment operator for different Matrix2 instances. More...
 
template<typename Other >
bool operator== (const Matrix2< Other > &rhs) const
 Equality operator for the comparison of two matrices. More...
 
template<typename Other >
bool operator!= (const Matrix2< Other > &rhs) const
 Inequality operator for the comparison of two matrices. More...
 
Type & operator[] (uint_t index)
 1D-access to the matrix elements. More...
 
const Type & operator[] (uint_t index) const
 1D-access to the matrix elements. More...
 
Type & operator() (uint_t i, uint_t j)
 2D-access to the matrix elements. More...
 
const Type & operator() (uint_t i, uint_t j) const
 2D-access to the matrix elements. More...
 
Arithmetic operators

The return type of the arithmetic operators depends on the involved data types of

the matrices. HIGH denotes the more significant data type of the arithmetic operation

(for further detail see the MathTrait class description).

template<typename Other >
Matrix2operator+= (const Matrix2< Other > &rhs)
 Addition assignment operator for the addition of two matrices ( \( A+=B \)). More...
 
template<typename Other >
Matrix2operator-= (const Matrix2< Other > &rhs)
 Subtraction assignment operator for the subtraction of two matrices ( \( A-=B \)). More...
 
template<typename Other >
Matrix2operator*= (Other rhs)
 Multiplication assignment operator for the multiplication between a matrix and. More...
 
template<typename Other >
Matrix2operator*= (const Matrix2< Other > &rhs)
 Multiplication assignment operator for the multiplication between two matrices. More...
 
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > operator+ (const Matrix2< Other > &rhs) const
 Addition operator for the addition of two matrices ( \( A=B+C \)). More...
 
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > operator- (const Matrix2< Other > &rhs) const
 Subtraction operator for the subtraction of two matrices ( \( A=B-C \)). More...
 
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > operator* (Other rhs) const
 Multiplication operator for the multiplication of a matrix and a scalar value. More...
 
template<typename Other >
const Vector2< typename MathTrait< Type, Other >::High > operator* (const Vector2< Other > &rhs) const
 
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > operator* (const Matrix2< Other > &rhs) const
 Multiplication operator for the multiplication of two matrices ( \( A=B*C \)). More...
 
Utility functions

The return type of the utility functions depends on the involved data types of the

matrices. HIGH denotes the more significant data type of the utility operations

(for further detail see the MathTrait class description).

Type getDeterminant () const
 Calculation of the determinant of the matrix. More...
 
Matrix2transpose ()
 Transposing the matrix. More...
 
const Matrix2 getTranspose () const
 Calculation of the transpose of the matrix. More...
 
Matrix2invert ()
 Inverting the matrix. More...
 
const Matrix2 getInverse () const
 Calculation of the inverse of the matrix. More...
 
bool isSingular () const
 Singularity check for the matrix (det=0). More...
 
bool isSymmetric () const
 Checks if the matrix is symmetric. More...
 
Type * data ()
 

Private Attributes

Member variables
Type v_ [4]
 The nine statically allocated matrix elements. More...
 

Constructor & Destructor Documentation

◆ Matrix2() [1/6]

template<typename Type >
constexpr walberla::math::Matrix2< Type >::Matrix2
inlineexplicitconstexpr

The default constructor for Matrix2.

The diagonal matrix elements are initialized with 1, all other elements are initialized with 0.

◆ Matrix2() [2/6]

template<typename Type >
constexpr walberla::math::Matrix2< Type >::Matrix2 ( Type  init)
inlineexplicitconstexpr

Constructor for a homogeneous initialization of all elements.

Parameters
initInitial value for all matrix elements.

◆ Matrix2() [3/6]

template<typename Type >
constexpr walberla::math::Matrix2< Type >::Matrix2 ( Type  xx,
Type  xy,
Type  yx,
Type  yy 
)
inlineexplicitconstexpr

Constructor for a direct initialization of all matrix elements.

Parameters
xxThe initial value for the xx-component.
xyThe initial value for the xy-component.
yxThe initial value for the yx-component.
yyThe initial value for the yy-component.

◆ Matrix2() [4/6]

template<typename Type >
constexpr walberla::math::Matrix2< Type >::Matrix2 ( const Type *  init)
inlineexplicitconstexpr

Constructor for an array initializer.

Parameters
initPointer to the initialization array.

The array is assumed to have at least nine valid elements.

◆ Matrix2() [5/6]

template<typename Type >
constexpr walberla::math::Matrix2< Type >::Matrix2 ( const Matrix2< Type > &  m)
inlineconstexpr

The copy constructor for Matrix2.

Parameters
mMatrix to be copied.

The copy constructor is explicitly defined in order to enable/facilitate NRV optimization.

◆ Matrix2() [6/6]

template<typename Type >
template<typename Other >
constexpr walberla::math::Matrix2< Type >::Matrix2 ( const Matrix2< Other > &  m)
inlineconstexpr

Conversion constructor from different Matrix2 instances.

Parameters
mMatrix to be copied.

Member Function Documentation

◆ data()

template<typename Type >
Type* walberla::math::Matrix2< Type >::data ( )
inline

◆ getDeterminant()

template<typename Type >
Type walberla::math::Matrix2< Type >::getDeterminant
inline

Calculation of the determinant of the matrix.

Returns
The determinant of the matrix.

◆ getInverse()

template<typename Type >
const Matrix2< Type > walberla::math::Matrix2< Type >::getInverse
inline

Calculation of the inverse of the matrix.

Returns
The inverse of the matrix.

The calculation is performed with the matrix inversion by Cramer. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data types will result in a compile time error.

◆ getTranspose()

template<typename Type >
const Matrix2< Type > walberla::math::Matrix2< Type >::getTranspose
inline

Calculation of the transpose of the matrix.

Returns
The transpose of the matrix.

◆ invert()

template<typename Type >
Matrix2< Type > & walberla::math::Matrix2< Type >::invert
inline

Inverting the matrix.

Returns
Reference to the inverted matrix.

The calculation is performed with the matrix inversion by Cramer. This function is only defined for matrices of floating point type. The attempt to use this function with matrices of integral data types will result in a compile time error.

◆ isSingular()

template<typename Type >
bool walberla::math::Matrix2< Type >::isSingular
inline

Singularity check for the matrix (det=0).

Returns
true if the matrix is singular, false if not.

◆ isSymmetric()

template<typename Type >
bool walberla::math::Matrix2< Type >::isSymmetric
inline

Checks if the matrix is symmetric.

Returns
true if the matrix is symmetric, false if not.

◆ operator!=()

template<typename Type >
template<typename Other >
bool walberla::math::Matrix2< Type >::operator!= ( const Matrix2< Other > &  rhs) const
inline

Inequality operator for the comparison of two matrices.

Parameters
rhsThe right-hand-side matrix for the comparison.
Returns
bool

◆ operator()() [1/2]

template<typename Type >
Type & walberla::math::Matrix2< Type >::operator() ( uint_t  i,
uint_t  j 
)
inline

2D-access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range [0..2].
jAccess index for the column. The index has to be in the range [0..2].
Returns
Reference to the accessed value.

◆ operator()() [2/2]

template<typename Type >
const Type & walberla::math::Matrix2< Type >::operator() ( uint_t  i,
uint_t  j 
) const
inline

2D-access to the matrix elements.

Parameters
iAccess index for the row. The index has to be in the range [0..2].
jAccess index for the column. The index has to be in the range [0..2].
Returns
Reference-to-const to the accessed value.

◆ operator*() [1/3]

template<typename Type >
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > walberla::math::Matrix2< Type >::operator* ( const Matrix2< Other > &  rhs) const
inline

Multiplication operator for the multiplication of two matrices ( \( A=B*C \)).

Parameters
rhsThe right-hand-side matrix for the multiplication.
Returns
The resulting matrix.

◆ operator*() [2/3]

template<typename Type >
template<typename Other >
const Vector2< typename MathTrait< Type, Other >::High > walberla::math::Matrix2< Type >::operator* ( const Vector2< Other > &  rhs) const
inline

◆ operator*() [3/3]

template<typename Type >
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > walberla::math::Matrix2< Type >::operator* ( Other  rhs) const
inline

Multiplication operator for the multiplication of a matrix and a scalar value.

( \( A=B*s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
The scaled result matrix.

◆ operator*=() [1/4]

template<typename Type >
template<typename Other >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator*= ( const Matrix2< Other > &  rhs)
inline

Multiplication assignment operator for the multiplication between two matrices.

( \( A*=B \)).

Parameters
rhsThe right-hand-side matrix for the multiplication.
Returns
Reference to the matrix.

◆ operator*=() [2/4]

template<typename Type >
template<typename Other >
Matrix2<Type>& walberla::math::Matrix2< Type >::operator*= ( const Matrix2< Other > &  rhs)
inline

◆ operator*=() [3/4]

template<typename Type >
template<typename Other >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator*= ( Other  rhs)
inline

Multiplication assignment operator for the multiplication between a matrix and.

a scalar value ( \( A*=s \)).

Parameters
rhsThe right-hand-side scalar value for the multiplication.
Returns
Reference to the matrix.

◆ operator*=() [4/4]

template<typename Type >
template<typename Other >
Matrix2<Type>& walberla::math::Matrix2< Type >::operator*= ( Other  rhs)
inline

◆ operator+()

template<typename Type >
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > walberla::math::Matrix2< Type >::operator+ ( const Matrix2< Other > &  rhs) const
inline

Addition operator for the addition of two matrices ( \( A=B+C \)).

Parameters
rhsThe right-hand-side matrix to be added to the matrix.
Returns
The sum of the two matrices.

◆ operator+=() [1/2]

template<typename Type >
template<typename Other >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator+= ( const Matrix2< Other > &  rhs)
inline

Addition assignment operator for the addition of two matrices ( \( A+=B \)).

Parameters
rhsThe right-hand-side matrix to be added to the matrix.
Returns
Reference to the matrix.

◆ operator+=() [2/2]

template<typename Type >
template<typename Other >
Matrix2<Type>& walberla::math::Matrix2< Type >::operator+= ( const Matrix2< Other > &  rhs)
inline

◆ operator-()

template<typename Type >
template<typename Other >
const Matrix2< typename MathTrait< Type, Other >::High > walberla::math::Matrix2< Type >::operator- ( const Matrix2< Other > &  rhs) const
inline

Subtraction operator for the subtraction of two matrices ( \( A=B-C \)).

Parameters
rhsThe right-hand-side matrix to be subtracted from the matrix.
Returns
The difference of the two matrices.

◆ operator-=() [1/2]

template<typename Type >
template<typename Other >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator-= ( const Matrix2< Other > &  rhs)
inline

Subtraction assignment operator for the subtraction of two matrices ( \( A-=B \)).

Parameters
rhsThe right-hand-side matrix to be subtracted from the matrix.
Returns
Reference to the matrix.

◆ operator-=() [2/2]

template<typename Type >
template<typename Other >
Matrix2<Type>& walberla::math::Matrix2< Type >::operator-= ( const Matrix2< Other > &  rhs)
inline

◆ operator=() [1/4]

template<typename Type >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator= ( const Matrix2< Type > &  set)
inline

Copy assignment operator for Matrix2.

Parameters
setMatrix to be copied.
Returns
Reference to the assigned matrix.

Explicit definition of a copy assignment operator for performance reasons.

◆ operator=() [2/4]

template<typename Type >
template<typename Other >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator= ( const Matrix2< Other > &  set)
inline

Assignment operator for different Matrix2 instances.

Parameters
setMatrix to be copied.
Returns
Reference to the assigned matrix.

◆ operator=() [3/4]

template<typename Type >
template<typename Other >
Matrix2<Type>& walberla::math::Matrix2< Type >::operator= ( const Matrix2< Other > &  set)
inline

◆ operator=() [4/4]

template<typename Type >
Matrix2< Type > & walberla::math::Matrix2< Type >::operator= ( Type  set)
inline

Homogenous assignment to all matrix elements.

Parameters
setScalar value to be assigned to all matrix elements.
Returns
Reference to the assigned matrix.

◆ operator==()

template<typename Type >
template<typename Other >
bool walberla::math::Matrix2< Type >::operator== ( const Matrix2< Other > &  rhs) const
inline

Equality operator for the comparison of two matrices.

Parameters
rhsThe right-hand-side matrix for the comparison.
Returns
bool

◆ operator[]() [1/2]

template<typename Type >
Type & walberla::math::Matrix2< Type >::operator[] ( uint_t  index)
inline

1D-access to the matrix elements.

Parameters
indexAccess index. The index has to be in the range \([0..8]\).
Returns
Reference to the accessed value.

◆ operator[]() [2/2]

template<typename Type >
const Type & walberla::math::Matrix2< Type >::operator[] ( uint_t  index) const
inline

1D-access to the matrix elements.

Parameters
indexAccess index. The index has to be in the range \([0..8]\).
Returns
Reference-to-const to the accessed value.

◆ transpose()

template<typename Type >
Matrix2< Type > & walberla::math::Matrix2< Type >::transpose
inline

Transposing the matrix.

Returns
Reference to the transposed matrix.

Member Data Documentation

◆ v_

template<typename Type >
Type walberla::math::Matrix2< Type >::v_[4]
private

The nine statically allocated matrix elements.

Access to the matrix elements is gained via the subscript or function call operator. The order of the elements is

\[\left(\begin{array}{*{2}{c}} 0 & 1 \\ 2 & 3 \\ \end{array}\right)\]


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