MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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.

Definition at line 36 of file MatrixSymmetric.h.

Constructor & Destructor Documentation

MatrixSymmetric3D::MatrixSymmetric3D ( )

Default constructor.

Default constructor

Definition at line 42 of file MatrixSymmetric.cc.

References setZero().

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

43 {
44  setZero();
45 }
void setZero()
Sets all elements to zero.
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

Definition at line 56 of file MatrixSymmetric.cc.

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

58 {
59  XX = xx;
60  XY = xy;
61  XZ = xz;
62  YY = yy;
63  YZ = yz;
64  ZZ = zz;
65 }
Mdouble XX
The six distinctive matrix elements.

Member Function Documentation

Mdouble MatrixSymmetric3D::determinant ( const MatrixSymmetric3D A)
static

Computes the determinant of a matrix.

Definition at line 313 of file MatrixSymmetric.cc.

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

Referenced by inverse().

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 }
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 326 of file MatrixSymmetric.cc.

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

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 }
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.

Definition at line 288 of file MatrixSymmetric.cc.

References inverse().

Referenced by BaseParticle::getAngularMomentum(), BaseParticle::getInertia(), and inverse().

289 {
290  return A.inverse();
291 }
static MatrixSymmetric3D inverse(const MatrixSymmetric3D &A)
Computes the inverse of a matrix; exits if the inverse doesn't exist.
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.

Definition at line 298 of file MatrixSymmetric.cc.

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

Referenced by BaseParticle::setInertia().

299 {
300  MatrixSymmetric3D result;
302  logger.assert(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 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
static Mdouble determinant(const MatrixSymmetric3D &A)
Computes the determinant of a matrix.
Implementation of a 3D symmetric matrix.
Mdouble XX
The six distinctive matrix elements.
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.

Definition at line 34 of file MatrixSymmetric.cc.

References XY, XZ, and YZ.

35 {
36  return {XX, XY, XZ, XY, YY, YZ, XZ, YZ, ZZ};
37 }
Mdouble XX
The six distinctive matrix elements.
MatrixSymmetric3D MatrixSymmetric3D::operator* ( Mdouble  a) const

Scalar multiplication.

Scalar multiplication

Parameters
[in]athe scalar
Returns
The multiplication result

Definition at line 144 of file MatrixSymmetric.cc.

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

145 {
146  return MatrixSymmetric3D(XX * a, XY * a, XZ * a,
147  YY * a, YZ * a, ZZ * a);
148 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 90 of file MatrixSymmetric.cc.

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

91 {
92  return MatrixSymmetric3D(XX + A.XX, XY + A.XY, XZ + A.XZ, YY + A.YY, YZ + A.YZ, ZZ + A.ZZ);
93 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
MatrixSymmetric3D MatrixSymmetric3D::operator+ ( Mdouble  a) const

Scalar addition.

Addition of a scalar

Parameters
[in]ascalar to be added
Returns
Result of the addition

Definition at line 110 of file MatrixSymmetric.cc.

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

111 {
112  return MatrixSymmetric3D(XX + a, XY + a, XZ + a, YY + a, YZ + a, ZZ + a);
113 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 189 of file MatrixSymmetric.cc.

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

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 }
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 100 of file MatrixSymmetric.cc.

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

101 {
102  return MatrixSymmetric3D(XX - A.XX, XY - A.XY, XZ - A.XZ, YY - A.YY, YZ - A.YZ, ZZ - A.ZZ);
103 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
MatrixSymmetric3D MatrixSymmetric3D::operator- ( Mdouble  a) const

Scalar substraction.

Substraction of a scalar

Parameters
[in]ascalar to be subtracted
Returns
Result of the substraction

Definition at line 120 of file MatrixSymmetric.cc.

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

121 {
122  return MatrixSymmetric3D(XX - a, XY - a, XZ - a, YY - a, YZ - a, ZZ - a);
123 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 205 of file MatrixSymmetric.cc.

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

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 }
Mdouble XX
The six distinctive matrix elements.
MatrixSymmetric3D MatrixSymmetric3D::operator/ ( Mdouble  a) const

Scalar division.

Scalar division

Parameters
[in]athe scalar to be divided by
Returns
The division result

Definition at line 155 of file MatrixSymmetric.cc.

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

156 {
157  return MatrixSymmetric3D(XX / a, XY / a, XZ / a, YY / a, YZ / a, ZZ / a);
158 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 221 of file MatrixSymmetric.cc.

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

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

Definition at line 263 of file MatrixSymmetric.cc.

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

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

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 X
the vector components
Definition: Vector.h:65
Mdouble Y
Definition: Vector.h:65
MatrixSymmetric3D()
Default constructor.
Mdouble Z
Definition: Vector.h:65
void MatrixSymmetric3D::setZero ( )

Sets all elements to zero.

Sets all elements of the symmetric matrix to 0.

Definition at line 70 of file MatrixSymmetric.cc.

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

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

71 {
72  XX = XY = XZ = YY = YZ = ZZ = 0.0;
73 }
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 250 of file MatrixSymmetric.cc.

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

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 }
MatrixSymmetric3D()
Default constructor.
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 238 of file MatrixSymmetric.cc.

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

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

239 {
242 }
MatrixSymmetric3D()
Default constructor.
T square(const T val)
squares a number
Definition: ExtendedMath.h:104
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 277 of file MatrixSymmetric.cc.

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

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 }
Mdouble X
the vector components
Definition: Vector.h:65
Mdouble Y
Definition: Vector.h:65
MatrixSymmetric3D()
Default constructor.
Mdouble Z
Definition: Vector.h:65
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.

Definition at line 80 of file MatrixSymmetric.cc.

References XX, YY, and ZZ.

81 {
82  return (XX + YY + ZZ) / 3;
83 }
Mdouble XX
The six distinctive matrix elements.

Friends And Related Function Documentation

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

Definition at line 132 of file MatrixSymmetric.cc.

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 }
Mdouble X
the vector components
Definition: Vector.h:65
Mdouble Y
Definition: Vector.h:65
Definition: Vector.h:49
Mdouble Z
Definition: Vector.h:65
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 166 of file MatrixSymmetric.cc.

167 {
168  os << A.XX << ' ' << A.XY << ' ' << A.XZ << " " << A.YY << ' ' << A.YZ << " " << A.ZZ;
169  return os;
170 }
Mdouble XX
The six distinctive matrix elements.
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

Definition at line 178 of file MatrixSymmetric.cc.

179 {
180  is >> A.XX >> A.XY >> A.XZ >> A.YY >> A.YZ >> A.ZZ;
181  return is;
182 }
Mdouble XX
The six distinctive matrix elements.

Member Data Documentation


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