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

43 {
44  setZero();
45 }
void setZero()
Sets all elements to zero.
Definition: MatrixSymmetric.cc:70

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
58 {
59  XX = xx;
60  XY = xy;
61  XZ = xz;
62  YY = yy;
63  YZ = yz;
64  ZZ = zz;
65 }
Mdouble ZZ
Definition: MatrixSymmetric.h:42
Mdouble YY
Definition: MatrixSymmetric.h:42
Mdouble XZ
Definition: MatrixSymmetric.h:42
Mdouble XY
Definition: MatrixSymmetric.h:42
Mdouble XX
The six distinctive matrix elements.
Definition: MatrixSymmetric.h:42
Mdouble YZ
Definition: MatrixSymmetric.h:42

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

Member Function Documentation

◆ determinant()

Mdouble MatrixSymmetric3D::determinant ( const MatrixSymmetric3D A)
static

Computes the determinant of a matrix.

314 {
315  return 1. / (A.XX * (A.YY * A.ZZ - A.YZ * A.YZ)
316  + A.XY * (A.YZ * A.XZ - A.XY * A.ZZ)
317  + A.XZ * (A.XY * A.YZ - A.YY * A.XZ));
318 }
@ A
Definition: StatisticsVector.h:42

References A.

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
327 {
328 // //define sin(A)=y/r, cos(A)=x/r
329 // Mdouble r = std::sqrt(p.X*p.X+p.Y*p.Y);
330 // Mdouble s = p.Y/r;
331 // Mdouble c = p.X/r;
332 // if (r==0) {
333 // s=0;
334 // c=1;
335 // }
336  return *this;
337 }

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.
299 {
300  MatrixSymmetric3D result;
302  logger.assert_debug(det != 0,
303  "determinant is not zero"); //should be replaced by the condition number or sth. like fabs(det)>1e-5*norm.
304  result.XX = (YY * ZZ - YZ * YZ) * det;
305  result.XY = -(XY * ZZ - XZ * YZ) * det;
306  result.XZ = (XY * YZ - XZ * YY) * det;
307  result.YY = (XX * ZZ - XZ * XZ) * det;
308  result.YZ = -(XX * YZ - XZ * XY) * det;
309  result.ZZ = (XX * YY - XY * XY) * det;
310  return result;
311 }
double Mdouble
Definition: GeneralDefine.h:34
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:37
static Mdouble determinant(const MatrixSymmetric3D &A)
Computes the determinant of a matrix.
Definition: MatrixSymmetric.cc:313

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.
289 {
290  return A.inverse();
291 }

References A.

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.
35 {
36  return {XX, XY, XZ, XY, YY, YZ, XZ, YZ, ZZ};
37 }

References XY, XZ, and YZ.

◆ operator*()

MatrixSymmetric3D MatrixSymmetric3D::operator* ( Mdouble  a) const

Scalar multiplication.

Scalar multiplication

Parameters
[in]athe scalar
Returns
The multiplication result
145 {
146  return MatrixSymmetric3D(XX * a, XY * a, XZ * a,
147  YY * a, YZ * a, ZZ * a);
148 }
MatrixSymmetric3D()
Default constructor.
Definition: MatrixSymmetric.cc:42

References 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
91 {
92  return MatrixSymmetric3D(XX + A.XX, XY + A.XY, XZ + A.XZ, YY + A.YY, YZ + A.YZ, ZZ + A.ZZ);
93 }

References A, 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
111 {
112  return MatrixSymmetric3D(XX + a, XY + a, XZ + a, YY + a, YZ + a, ZZ + a);
113 }

References 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
190 {
191  XX += A.XX;
192  XY += A.XY;
193  XZ += A.XZ;
194  YY += A.YY;
195  YZ += A.YZ;
196  ZZ += A.ZZ;
197  return *this;
198 }

References A, 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
101 {
102  return MatrixSymmetric3D(XX - A.XX, XY - A.XY, XZ - A.XZ, YY - A.YY, YZ - A.YZ, ZZ - A.ZZ);
103 }

References A, 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
121 {
122  return MatrixSymmetric3D(XX - a, XY - a, XZ - a, YY - a, YZ - a, ZZ - a);
123 }

References 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
206 {
207  XX -= A.XX;
208  XY -= A.XY;
209  XZ -= A.XZ;
210  YY -= A.YY;
211  YZ -= A.YZ;
212  ZZ -= A.ZZ;
213  return *this;
214 }

References A, 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
156 {
157  return MatrixSymmetric3D(XX / a, XY / a, XZ / a, YY / a, YZ / a, ZZ / a);
158 }

References 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
222 {
223  XX /= a;
224  XY /= a;
225  XZ /= a;
226  YY /= a;
227  YZ /= a;
228  ZZ /= a;
229  return *this;
230 }

References 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.
264 {
265  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);
266 }
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66

References MatrixSymmetric3D(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

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

◆ setZero()

void MatrixSymmetric3D::setZero ( )

Sets all elements to zero.

Sets all elements of the symmetric matrix to 0.

71 {
72  XX = XY = XZ = YY = YZ = ZZ = 0.0;
73 }

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

Referenced by MatrixSymmetric3D(), BaseParticle::setInfiniteInertia(), 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
251 {
252  return MatrixSymmetric3D(std::sqrt(A.XX), std::sqrt(A.XY), std::sqrt(A.XZ), std::sqrt(A.YY), std::sqrt(A.YZ),
253  std::sqrt(A.ZZ));
254 }

References A, and MatrixSymmetric3D().

◆ 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
239 {
242 }
T square(const T val)
squares a number
Definition: ExtendedMath.h:106

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

Referenced by 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
278 {
279  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,
280  0.5 * (a.Y * b.Z + b.Y * a.Z), a.Z * b.Z);
281 }

References MatrixSymmetric3D(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

◆ 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.
81 {
82  return (XX + YY + ZZ) / 3;
83 }

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
133 {
134  return Vec3D(A.XX * b.X + A.XY * b.Y + A.XZ * b.Z,
135  A.XY * b.X + A.YY * b.Y + A.YZ * b.Z,
136  A.XZ * b.X + A.YZ * b.Y + A.ZZ * b.Z);
137 }
Definition: Vector.h:51

◆ 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
167 {
168  os << A.XX << ' ' << A.XY << ' ' << A.XZ << " " << A.YY << ' ' << A.YZ << " " << A.ZZ;
169  return os;
170 }

◆ 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
179 {
180  is >> A.XX >> A.XY >> A.XZ >> A.YY >> A.YZ >> A.ZZ;
181  return is;
182 }

Member Data Documentation

◆ XX

◆ XY

◆ XZ

◆ YY

◆ YZ

◆ ZZ


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