MatrixSymmetric3D Class Reference

Implementation of a 3D symmetric matrix. More...

#include <MatrixSymmetric.h>

Public Member Functions

 operator Matrix3D () const
 Casting operator; casts MatrixSymmetric3D to Matrix3D. More...
 
 MatrixSymmetric3D ()
 Default constructor. More...
 
 MatrixSymmetric3D (Mdouble xx, Mdouble xy, Mdouble xz, Mdouble yy, Mdouble yz, Mdouble zz)
 Alternative constructor, with all (6) elements as arguments. More...
 
void setZero ()
 Sets all elements to zero. More...
 
Mdouble trace () const
 Returns the MEAN of the diagonal elements (i.e. the trace divided by three). More...
 
MatrixSymmetric3D operator+ (const MatrixSymmetric3D &A) const
 Matrix addition. More...
 
MatrixSymmetric3D operator- (const MatrixSymmetric3D &A) const
 Matrix substraction. More...
 
MatrixSymmetric3D operator+ (Mdouble a) const
 Scalar addition. More...
 
MatrixSymmetric3D operator- (Mdouble a) const
 Scalar substraction. More...
 
MatrixSymmetric3D operator* (Mdouble a) const
 Scalar multiplication. More...
 
MatrixSymmetric3D operator/ (Mdouble a) const
 Scalar division. More...
 
MatrixSymmetric3Doperator+= (const MatrixSymmetric3D &A)
 Matrix addition. More...
 
MatrixSymmetric3Doperator-= (const MatrixSymmetric3D &A)
 Matrix substraction. More...
 
MatrixSymmetric3Doperator/= (Mdouble a)
 Scalar division. More...
 
MatrixSymmetric3D inverse () const
 Computes the inverse of a matrix; exits if the inverse doesn't exist. More...
 
MatrixSymmetric3D getCylindricalTensorField (const Vec3D &p) const
 Returns the matrix in cylindrical coordinates. More...
 

Static Public Member Functions

static MatrixSymmetric3D square (const MatrixSymmetric3D &A)
 Calculates the pointwise square. More...
 
static MatrixSymmetric3D sqrt (const MatrixSymmetric3D &A)
 Calculates the pointwise square root. More...
 
static MatrixSymmetric3D selfDyadic (const Vec3D &a)
 Calculates the dyadic product of a Vec3D with itself: \(a \otimes a\). More...
 
static MatrixSymmetric3D symmetrisedDyadic (const Vec3D &a, const Vec3D &b)
 Calculates the symmetrised dyadic product of two Vec3D: \( \frac{1}{2}(a \otimes b + b \otimes a) \). More...
 
static MatrixSymmetric3D inverse (const MatrixSymmetric3D &A)
 Computes the inverse of a matrix; exits if the inverse doesn't exist. More...
 
static Mdouble determinant (const MatrixSymmetric3D &A)
 Computes the determinant of a matrix. More...
 

Public Attributes

Mdouble XX
 The six distinctive matrix elements. More...
 
Mdouble XY
 
Mdouble XZ
 
Mdouble YY
 
Mdouble YZ
 
Mdouble ZZ
 

Friends

Vec3D operator* (const MatrixSymmetric3D &A, const Vec3D &b)
 Vector multiplication. More...
 
std::ostream & operator<< (std::ostream &os, const MatrixSymmetric3D &A)
 Add elements to an ostream. More...
 
std::istream & operator>> (std::istream &is, MatrixSymmetric3D &A)
 Add elements to an istream. More...
 

Detailed Description

Implementation of a 3D symmetric matrix.

Constructor & Destructor Documentation

◆ MatrixSymmetric3D() [1/2]

MatrixSymmetric3D::MatrixSymmetric3D ( )

Default constructor.

Default constructor

22 {
23  setZero();
24 }
void setZero()
Sets all elements to zero.
Definition: MatrixSymmetric.cc:49

References setZero().

Referenced by operator*(), operator+(), operator-(), operator/(), selfDyadic(), sqrt(), square(), and symmetrisedDyadic().

◆ MatrixSymmetric3D() [2/2]

MatrixSymmetric3D::MatrixSymmetric3D ( Mdouble  xx,
Mdouble  xy,
Mdouble  xz,
Mdouble  yy,
Mdouble  yz,
Mdouble  zz 
)

Alternative constructor, with all (6) elements as arguments.

Alternative constructor, lets you define all (6) elements

Parameters
[in]xxinitializer for an element of the matrix
[in]xyinitializer for an element of the matrix
[in]xzinitializer for an element of the matrix
[in]yyinitializer for an element of the matrix
[in]yzinitializer for an element of the matrix
[in]zzinitializer for an element of the matrix
37 {
38  XX = xx;
39  XY = xy;
40  XZ = xz;
41  YY = yy;
42  YZ = yz;
43  ZZ = zz;
44 }
Matrix< float, 2, 1 > xy
Definition: LLT_solve.cpp:6
Mdouble ZZ
Definition: MatrixSymmetric.h:21
Mdouble YY
Definition: MatrixSymmetric.h:21
Mdouble XZ
Definition: MatrixSymmetric.h:21
Mdouble XY
Definition: MatrixSymmetric.h:21
Mdouble XX
The six distinctive matrix elements.
Definition: MatrixSymmetric.h:21
Mdouble YZ
Definition: MatrixSymmetric.h:21

References XX, xy, XY, XZ, YY, YZ, and ZZ.

Member Function Documentation

◆ determinant()

Mdouble MatrixSymmetric3D::determinant ( const MatrixSymmetric3D A)
static

Computes the determinant of a matrix.

293 {
294  return 1. / (A.XX * (A.YY * A.ZZ - A.YZ * A.YZ)
295  + A.XY * (A.YZ * A.XZ - A.XY * A.ZZ)
296  + A.XZ * (A.XY * A.YZ - A.YY * A.XZ));
297 }
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47

Referenced by inverse().

◆ getCylindricalTensorField()

MatrixSymmetric3D MatrixSymmetric3D::getCylindricalTensorField ( const Vec3D p) const

Returns the matrix in cylindrical coordinates.

Todo:
implement MatrixSymmetric3D::getCylindricalTensorField

Transforms the (Cartesian) vector to cylindrical coordinates. See https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates

Returns
Transformed vector
306 {
307 // //define sin(A)=y/r, cos(A)=x/r
308 // Mdouble r = std::sqrt(p.X*p.X+p.Y*p.Y);
309 // Mdouble s = p.Y/r;
310 // Mdouble c = p.X/r;
311 // if (r==0) {
312 // s=0;
313 // c=1;
314 // }
315  return *this;
316 }

Referenced by CGFields::StandardFields::setCylindricalFields().

◆ inverse() [1/2]

MatrixSymmetric3D MatrixSymmetric3D::inverse ( ) const

Computes the inverse of a matrix; exits if the inverse doesn't exist.

Used for inverting matrices like the inertia tensor.

Parameters
[in]AMatrix that should be inverted.
Returns
Inverse of matrix A.
278 {
279  MatrixSymmetric3D result;
281  logger.assert_debug(det != 0,
282  "determinant is not zero"); //should be replaced by the condition number or sth. like fabs(det)>1e-5*norm.
283  result.XX = (YY * ZZ - YZ * YZ) * det;
284  result.XY = -(XY * ZZ - XZ * YZ) * det;
285  result.XZ = (XY * YZ - XZ * YY) * det;
286  result.YY = (XX * ZZ - XZ * XZ) * det;
287  result.YZ = -(XX * YZ - XZ * XY) * det;
288  result.ZZ = (XX * YY - XY * XY) * det;
289  return result;
290 }
double Mdouble
Definition: GeneralDefine.h:13
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
Implementation of a 3D symmetric matrix.
Definition: MatrixSymmetric.h:16
static Mdouble determinant(const MatrixSymmetric3D &A)
Computes the determinant of a matrix.
Definition: MatrixSymmetric.cc:292

References determinant(), logger, XX, XY, XZ, YY, YZ, and ZZ.

Referenced by BaseParticle::setInertia().

◆ inverse() [2/2]

MatrixSymmetric3D MatrixSymmetric3D::inverse ( const MatrixSymmetric3D A)
static

Computes the inverse of a matrix; exits if the inverse doesn't exist.

Used for inverting matrices like the inertia tensor.

Parameters
[in]AMatrix that should be inverted.
Returns
Inverse of matrix A.
268 {
269  return A.inverse();
270 }

Referenced by ClumpParticle::ClumpParticle(), ClumpParticle::computeMass(), BaseParticle::getAngularMomentum(), BaseParticle::getInertia(), ClumpParticle::rotateTensorOfInertia(), and ClumpParticle::setInitInertia().

◆ operator Matrix3D()

MatrixSymmetric3D::operator Matrix3D ( ) const
explicit

Casting operator; casts MatrixSymmetric3D to Matrix3D.

This operator casts a MatrixSymmetric3D object to a Matrix3D object when needed.

Returns
The output is a symmetric matrix of type Matrix3D.
14 {
15  return {XX, XY, XZ, XY, YY, YZ, XZ, YZ, ZZ};
16 }

References XX, XY, XZ, YY, and YZ.

◆ operator*()

MatrixSymmetric3D MatrixSymmetric3D::operator* ( Mdouble  a) const

Scalar multiplication.

Scalar multiplication

Parameters
[in]athe scalar
Returns
The multiplication result
124 {
125  return MatrixSymmetric3D(XX * a, XY * a, XZ * a,
126  YY * a, YZ * a, ZZ * a);
127 }
MatrixSymmetric3D()
Default constructor.
Definition: MatrixSymmetric.cc:21
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator+() [1/2]

MatrixSymmetric3D MatrixSymmetric3D::operator+ ( const MatrixSymmetric3D A) const

Matrix addition.

Addition of symmetric 3D matrices

Parameters
[in]Asymmetric matrix to be added
Returns
Result of the addition
70 {
71  return MatrixSymmetric3D(XX + A.XX, XY + A.XY, XZ + A.XZ, YY + A.YY, YZ + A.YZ, ZZ + A.ZZ);
72 }

References MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator+() [2/2]

MatrixSymmetric3D MatrixSymmetric3D::operator+ ( Mdouble  a) const

Scalar addition.

Addition of a scalar

Parameters
[in]ascalar to be added
Returns
Result of the addition
90 {
91  return MatrixSymmetric3D(XX + a, XY + a, XZ + a, YY + a, YZ + a, ZZ + a);
92 }

References a, MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator+=()

MatrixSymmetric3D & MatrixSymmetric3D::operator+= ( const MatrixSymmetric3D A)

Matrix addition.

Matrix addition

Parameters
[in]Athe matrix to be added to this one
Returns
(reference to) this matrix, i.e. the result of the addition
169 {
170  XX += A.XX;
171  XY += A.XY;
172  XZ += A.XZ;
173  YY += A.YY;
174  YZ += A.YZ;
175  ZZ += A.ZZ;
176  return *this;
177 }

References XX, XY, XZ, YY, YZ, and ZZ.

◆ operator-() [1/2]

MatrixSymmetric3D MatrixSymmetric3D::operator- ( const MatrixSymmetric3D A) const

Matrix substraction.

Substraction of symmetric 3D matrices

Parameters
[in]Asymmetric matrix to be subtracted
Returns
Result of the substraction
80 {
81  return MatrixSymmetric3D(XX - A.XX, XY - A.XY, XZ - A.XZ, YY - A.YY, YZ - A.YZ, ZZ - A.ZZ);
82 }

References MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator-() [2/2]

MatrixSymmetric3D MatrixSymmetric3D::operator- ( Mdouble  a) const

Scalar substraction.

Substraction of a scalar

Parameters
[in]ascalar to be subtracted
Returns
Result of the substraction
100 {
101  return MatrixSymmetric3D(XX - a, XY - a, XZ - a, YY - a, YZ - a, ZZ - a);
102 }

References a, MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator-=()

MatrixSymmetric3D & MatrixSymmetric3D::operator-= ( const MatrixSymmetric3D A)

Matrix substraction.

Matrix substraction

Parameters
[in]Athe matrix to be subtracted
Returns
(reference to) this matrix, which is the result of the substraction
185 {
186  XX -= A.XX;
187  XY -= A.XY;
188  XZ -= A.XZ;
189  YY -= A.YY;
190  YZ -= A.YZ;
191  ZZ -= A.ZZ;
192  return *this;
193 }

References XX, XY, XZ, YY, YZ, and ZZ.

◆ operator/()

MatrixSymmetric3D MatrixSymmetric3D::operator/ ( Mdouble  a) const

Scalar division.

Scalar division

Parameters
[in]athe scalar to be divided by
Returns
The division result
135 {
136  return MatrixSymmetric3D(XX / a, XY / a, XZ / a, YY / a, YZ / a, ZZ / a);
137 }

References a, MatrixSymmetric3D(), XX, XY, XZ, YY, YZ, and ZZ.

◆ operator/=()

MatrixSymmetric3D & MatrixSymmetric3D::operator/= ( Mdouble  a)

Scalar division.

Scalar division

Parameters
[in]athe scalar to be divided by
Returns
(reference to) this matrix, which is the result of the division
201 {
202  XX /= a;
203  XY /= a;
204  XZ /= a;
205  YY /= a;
206  YZ /= a;
207  ZZ /= a;
208  return *this;
209 }

References a, XX, XY, XZ, YY, YZ, and ZZ.

◆ selfDyadic()

MatrixSymmetric3D MatrixSymmetric3D::selfDyadic ( const Vec3D a)
static

Calculates the dyadic product of a Vec3D with itself: \(a \otimes a\).

Calculates the dyadic product of a 3D vector with itself, which (obviously) results in a symmetric 3D matrix. NB: this is a STATIC function!

Parameters
[in]athe 3D vector
Returns
the resulting symmetric 3D matrix.
243 {
244  return MatrixSymmetric3D(a.X * a.X, a.X * a.Y, a.X * a.Z, a.Y * a.Y, a.Y * a.Z, a.Z * a.Z);
245 }

References a, and MatrixSymmetric3D().

Referenced by CGFields::DisplacementField::setFields(), and CGFields::StandardFields::setFields().

◆ setZero()

void MatrixSymmetric3D::setZero ( )

Sets all elements to zero.

Sets all elements of the symmetric matrix to 0.

50 {
51  XX = XY = XZ = YY = YZ = ZZ = 0.0;
52 }

References XX, XY, XZ, YY, YZ, and ZZ.

Referenced by MatrixSymmetric3D(), BaseParticle::setInfiniteInertia(), CGFields::DisplacementField::setZero(), CGFields::OrientationField::setZero(), and CGFields::StandardFields::setZero().

◆ sqrt()

MatrixSymmetric3D MatrixSymmetric3D::sqrt ( const MatrixSymmetric3D A)
static

Calculates the pointwise square root.

Pointwise square roots the matrix, i.e. takes the sq. root of each element. NB: this is a STATIC function!

Parameters
[in]AThe matrix to be pointwise square rooted
Returns
Resulting matrix
230 {
231  return MatrixSymmetric3D(std::sqrt(A.XX), std::sqrt(A.XY), std::sqrt(A.XZ), std::sqrt(A.YY), std::sqrt(A.YZ),
232  std::sqrt(A.ZZ));
233 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134

References MatrixSymmetric3D(), and sqrt().

◆ square()

MatrixSymmetric3D MatrixSymmetric3D::square ( const MatrixSymmetric3D A)
static

Calculates the pointwise square.

Pointwise squares the matrix, i.e. takes the square of each element. NB: is a STATIC function!

Parameters
[in]AThe matrix to be pointwise squared
Returns
Resulting matrix
218 {
221 }
T square(const T val)
squares a number
Definition: ExtendedMath.h:86

References MatrixSymmetric3D(), and mathsFunc::square().

Referenced by CGFields::DisplacementField::getSquared(), CGFields::OrientationField::getSquared(), and CGFields::StandardFields::getSquared().

◆ symmetrisedDyadic()

MatrixSymmetric3D MatrixSymmetric3D::symmetrisedDyadic ( const Vec3D a,
const Vec3D b 
)
static

Calculates the symmetrised dyadic product of two Vec3D: \( \frac{1}{2}(a \otimes b + b \otimes a) \).

Calculates the dyadic product of two 3D vectors, and 'symmetrises' the resulting matrix by taking the average of each pair of opposing non-diagonal elements. NB: this is a STATIC function!

Parameters
[in]athe first 3D vector
[in]bthe second 3D vector
Returns
the resulting symmetric 3D matrix
257 {
258  return MatrixSymmetric3D(a.X * b.X, 0.5 * (a.X * b.Y + b.X * a.Y), 0.5 * (a.X * b.Z + b.X * a.Z), a.Y * b.Y,
259  0.5 * (a.Y * b.Z + b.Y * a.Z), a.Z * b.Z);
260 }
Scalar * b
Definition: benchVecAdd.cpp:17

References a, b, and MatrixSymmetric3D().

◆ trace()

Mdouble MatrixSymmetric3D::trace ( ) const

Returns the MEAN of the diagonal elements (i.e. the trace divided by three).

Returns the MEAN of the diagonal matrix elements, which is technically the trace divided by the number of diagonal elements.

Returns
The mean of the diagonal elements.
60 {
61  return (XX + YY + ZZ) / 3;
62 }

References XX, YY, and ZZ.

Friends And Related Function Documentation

◆ operator*

Vec3D operator* ( const MatrixSymmetric3D A,
const Vec3D b 
)
friend

Vector multiplication.

Multiplication of a symmetric 3D matrix with a vector (global operator, friend of this class)

Parameters
[in]Athe matrix
[in]bthe vector
Returns
The multiplication result
112 {
113  return Vec3D(A.XX * b.X + A.XY * b.Y + A.XZ * b.Z,
114  A.XY * b.X + A.YY * b.Y + A.YZ * b.Z,
115  A.XZ * b.X + A.YZ * b.Y + A.ZZ * b.Z);
116 }
Definition: Kernel/Math/Vector.h:30

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const MatrixSymmetric3D A 
)
friend

Add elements to an ostream.

Adds all elements of a symmetric 3D matrix to an ostream

Parameters
[in,out]osoutput stream
[in]Athe matrix
Returns
(reference to) output stream with matrix elements added
146 {
147  os << A.XX << ' ' << A.XY << ' ' << A.XZ << " " << A.YY << ' ' << A.YZ << " " << A.ZZ;
148  return os;
149 }

◆ operator>>

std::istream& operator>> ( std::istream &  is,
MatrixSymmetric3D A 
)
friend

Add elements to an istream.

Reads the elements of a symmetric 3D matrix from an istream

Parameters
[in,out]isinput stream,
[out]Athe matrix
Returns
(reference to) input stream from with matrix elements were read
158 {
159  is >> A.XX >> A.XY >> A.XZ >> A.YY >> A.YZ >> A.ZZ;
160  return is;
161 }

Member Data Documentation

◆ XX

◆ XY

◆ XZ

◆ YY

◆ YZ

◆ ZZ


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