Matrix3D Class Reference

Implementation of a 3D matrix. More...

#include <Matrix.h>

Public Member Functions

 Matrix3D ()
 default constructor More...
 
 Matrix3D (Mdouble xx, Mdouble xy, Mdouble xz, Mdouble yx, Mdouble yy, Mdouble yz, Mdouble zx, Mdouble zy, Mdouble zz)
 Alternative constructor, which let you define all elements. More...
 
 Matrix3D (const SmallMatrix< 3, 3 > &matrix)
 Alternative constructor, which takes a matrix of the same size. More...
 
void setZero ()
 Sets all elements to zero. More...
 
double trace () const
 Sum of the diagonal elements. More...
 
Vec3D diag () const
 The diagonal elements. More...
 
double determinant () const
 
double deviator () const
 Deviator. More...
 
Matrix3D operator+ (const Matrix3D &A) const
 Matrix addition. More...
 
Matrix3D operator- (const Matrix3D &A) const
 Matrix subtraction. More...
 
Matrix3D operator+ (Mdouble a) const
 Scalar addition. More...
 
Matrix3D operator- (Mdouble a) const
 Scalar subtraction. More...
 
Matrix3D operator* (Mdouble a) const
 Scalar multiplication. More...
 
Vec3D operator* (const Vec3D &a) const
 Vector multiplication. More...
 
Matrix3D operator* (const Matrix3D &a) const
 Matrix multiplication. More...
 
Matrix3D operator/ (Mdouble a) const
 Scalar division. More...
 
Matrix3Doperator+= (const Matrix3D &A)
 Matrix addition. More...
 
Matrix3Doperator-= (const Matrix3D &A)
 Matrix substraction. More...
 
Matrix3Doperator/= (Mdouble a)
 Scalar division. More...
 
Vec3D ldivide (const Vec3D &b)
 A.ldivide(b) computes the solution x to A*x=b. More...
 
Matrix3D getCylindricalTensorField (const Vec3D &p) const
 Returns the matrix in cylindrical coordinates. More...
 

Static Public Member Functions

static Matrix3D square (const Matrix3D &A)
 Calculates the pointwise square. More...
 
static Matrix3D sqrt (const Matrix3D &A)
 Calculates the pointwise square root. More...
 
static Matrix3D dyadic (const Vec3D &a, const Vec3D &b)
 Calculates the dyadic product of a two Vec3D: \(a \otimes b\). More...
 
static Matrix3D cross (const Vec3D &a, const Matrix3D &b)
 'Special' cross product; CP of vector with each column of a matrix More...
 
static Matrix3D inverse (const Matrix3D &A)
 Computes the inverse of a matrix. More...
 

Public Attributes

Mdouble XX
 all nine matrix elements More...
 
Mdouble XY
 
Mdouble XZ
 
Mdouble YX
 
Mdouble YY
 
Mdouble YZ
 
Mdouble ZX
 
Mdouble ZY
 
Mdouble ZZ
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix3D &A)
 Add elements to ostream. More...
 
std::istream & operator>> (std::istream &is, Matrix3D &A)
 Add elements to istream. More...
 

Detailed Description

Implementation of a 3D matrix.

Constructor & Destructor Documentation

◆ Matrix3D() [1/3]

Matrix3D::Matrix3D ( )

default constructor

default constructor, which is empty (i.e., only creates the object)

14 {
15  setZero();
16 }
void setZero()
Sets all elements to zero.
Definition: Matrix.cc:54

References setZero().

Referenced by cross(), dyadic(), getCylindricalTensorField(), operator*(), operator+(), operator-(), operator/(), sqrt(), and square().

◆ Matrix3D() [2/3]

Matrix3D::Matrix3D ( Mdouble  xx,
Mdouble  xy,
Mdouble  xz,
Mdouble  yx,
Mdouble  yy,
Mdouble  yz,
Mdouble  zx,
Mdouble  zy,
Mdouble  zz 
)

Alternative constructor, which let you define all elements.

Alternative constructor. Let's you specify ALL 9 elements of the 3x3 matrix.

Parameters
[in][all]xx/xy/xz /yx/yy/yz /zx/zy/zz are all nine elements (left-to-right, top-to-bottom) of the 3D matrix.
26 {
27  XX = xx;
28  XY = xy;
29  XZ = xz;
30  YX = yx;
31  YY = yy;
32  YZ = yz;
33  ZX = zx;
34  ZY = zy;
35  ZZ = zz;
36 }
Matrix< float, 2, 1 > xy
Definition: LLT_solve.cpp:6
Mdouble YX
Definition: Kernel/Math/Matrix.h:22
Mdouble ZX
Definition: Kernel/Math/Matrix.h:22
Mdouble XY
Definition: Kernel/Math/Matrix.h:22
Mdouble YY
Definition: Kernel/Math/Matrix.h:22
Mdouble ZY
Definition: Kernel/Math/Matrix.h:22
Mdouble ZZ
Definition: Kernel/Math/Matrix.h:22
Mdouble YZ
Definition: Kernel/Math/Matrix.h:22
Mdouble XZ
Definition: Kernel/Math/Matrix.h:22
Mdouble XX
all nine matrix elements
Definition: Kernel/Math/Matrix.h:22

References XX, xy, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ Matrix3D() [3/3]

Matrix3D::Matrix3D ( const SmallMatrix< 3, 3 > &  matrix)

Alternative constructor, which takes a matrix of the same size.

39 {
40  XX = matrix(0, 0);
41  XY = matrix(0, 1);
42  XZ = matrix(0, 2);
43  YX = matrix(1, 0);
44  YY = matrix(1, 1);
45  YZ = matrix(1, 2);
46  ZX = matrix(2, 0);
47  ZY = matrix(2, 1);
48  ZZ = matrix(2, 2);
49 }
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor >, 0, Eigen::OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Definition: common.h:85

References matrix(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

Member Function Documentation

◆ cross()

Matrix3D Matrix3D::cross ( const Vec3D a,
const Matrix3D B 
)
static

'Special' cross product; CP of vector with each column of a matrix

Returns a matrix, who's columns are the inner product of a given vector with the corresponding columns of a given matrix

Parameters
[in]avector
[in]Bmatrix
Returns
Resulting matrix
317 {
318  return Matrix3D(
319  a.Y * B.ZX - a.Z * B.YX, a.Y * B.ZY - a.Z * B.YY, a.Y * B.ZZ - a.Z * B.YZ,
320  a.Z * B.XX - a.X * B.ZX, a.Z * B.XY - a.X * B.ZY, a.Z * B.XZ - a.X * B.ZZ,
321  a.X * B.YX - a.Y * B.XX, a.X * B.YY - a.Y * B.XY, a.X * B.YZ - a.Y * B.XZ);
322 }
Matrix3D()
default constructor
Definition: Matrix.cc:13
Definition: matrices.h:74
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, and Matrix3D().

◆ determinant()

double Matrix3D::determinant ( ) const
inline

Returns the determinant of this matrix https://www.mathsisfun.com/algebra/matrix-determinant.html

61  {
62  return XX*(YY*ZZ-YZ*ZY) - XY*(YX*ZZ-YZ*ZX) + XZ*(YX*ZY-YY*ZX);
63  }

References XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ deviator()

Mdouble Matrix3D::deviator ( ) const

Deviator.

Returns an invariant of the deviatoric tensor, scaled such that it is equal to shear stress for the stress tensor.

Returns
resulting scalar
83 {
84  const Mdouble P = trace() / 3.0;
87 }
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
double trace() const
Sum of the diagonal elements.
Definition: Matrix.cc:63
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
T square(const T val)
squares a number
Definition: ExtendedMath.h:86

References Global_Physical_Variables::P, sqrt(), mathsFunc::square(), trace(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ diag()

Vec3D Matrix3D::diag ( ) const

The diagonal elements.

Returns the sum of the diagonal elements of the matrix.

Returns
The trace of the matrix divided by 3 as an Mdouble
73 {
74  return Vec3D(XX, YY, ZZ);
75 }
Definition: Kernel/Math/Vector.h:30

References XX, YY, and ZZ.

◆ dyadic()

Matrix3D Matrix3D::dyadic ( const Vec3D a,
const Vec3D b 
)
static

Calculates the dyadic product of a two Vec3D: \(a \otimes b\).

Dyadic product of two vectors

Parameters
[in]afirst vector
[in]bsecond vector
Returns
Resulting matrix
303 {
304  return Matrix3D(a.X * b.X, a.X * b.Y, a.X * b.Z,
305  a.Y * b.X, a.Y * b.Y, a.Y * b.Z,
306  a.Z * b.X, a.Z * b.Y, a.Z * b.Z);
307 }
Scalar * b
Definition: benchVecAdd.cpp:17

References a, b, and Matrix3D().

Referenced by CGFields::GradVelocityField::addParticleDifferentialStatistics(), DPMBase::getKineticStress(), DPMBase::getStaticStress(), main(), CGFields::StandardFields::setFields(), and CGFields::StandardFieldsBinning::setFields().

◆ getCylindricalTensorField()

Matrix3D Matrix3D::getCylindricalTensorField ( const Vec3D p) const

Returns the matrix in cylindrical coordinates.

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

Returns
Transformed vector
374 {
375  //define sin(A)=y/r, cos(A)=x/r
376  const Mdouble r = std::sqrt(p.X * p.X + p.Y * p.Y);
377  Mdouble s = p.Y / r;
378  Mdouble c = p.X / r;
379  if (r == 0)
380  {
381  s = 0;
382  c = 1;
383  }
384  const Matrix3D M = Matrix3D(XX * c + XY * s, -XX * s + XY * c, XZ,
385  YX * c + YY * s, -YX * s + YY * c, YZ,
386  ZX * c + ZY * s, -ZX * s + ZY * c, ZZ);
387  return Matrix3D(M.XX * c + M.YX * s, -M.XX * s + M.YX * c, M.ZX,
388  M.XY * c + M.YY * s, -M.XY * s + M.YY * c, M.ZY,
389  M.XZ * c + M.YZ * s, -M.XZ * s + M.YZ * c, M.ZZ);
390 }
float * p
Definition: Tutorial_Map_using.cpp:9
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Implementation of a 3D matrix.
Definition: Kernel/Math/Matrix.h:17
RealScalar s
Definition: level1_cplx_impl.h:130
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100

References calibrate::c, Matrix3D(), p, UniformPSDSelfTest::r, s, sqrt(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

Referenced by main(), and CGFields::StandardFields::setCylindricalFields().

◆ inverse()

Matrix3D Matrix3D::inverse ( const Matrix3D A)
static

Computes the inverse of a matrix.

Parameters
[in]AMatrix that should be inverted.
Returns
Inverse of matrix A.
329 {
330  Matrix3D result;
331  Mdouble det;
332  det = 1. / (A.XX * (A.YY * A.ZZ - A.YZ * A.ZY)
333  + A.XY * (A.YZ * A.ZX - A.YX * A.ZZ)
334  + A.XZ * (A.YX * A.ZY - A.YY * A.ZX));
335  result.XX = (A.YY * A.ZZ - A.YZ * A.ZY) * det;
336  result.XY = -(A.XY * A.ZZ - A.XZ * A.ZY) * det;
337  result.XZ = (A.XY * A.YZ - A.XZ * A.YY) * det;
338  result.YX = -(A.YX * A.ZZ - A.YZ * A.ZX) * det;
339  result.YY = (A.XX * A.ZZ - A.XZ * A.ZX) * det;
340  result.YZ = -(A.XX * A.YZ - A.XZ * A.YX) * det;
341  result.ZX = (A.YX * A.ZY - A.YY * A.ZX) * det;
342  result.ZY = -(A.XX * A.ZY - A.XY * A.ZX) * det;
343  result.ZZ = (A.XX * A.YY - A.XY * A.YX) * det;
344  return result;
345 }

References XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ ldivide()

Vec3D Matrix3D::ldivide ( const Vec3D b)

A.ldivide(b) computes the solution x to A*x=b.

Solve the linear system Ax = b: A.ldivide(b) computes the solution x to A*x=b.

Parameters
[in]bRight-handside in Ax = b, as a const-reference to a Vec3D
Returns
The solution x of Ax = b as a Vec3D.
353 {
354  Mdouble invdet = 1. / (XX * (YY * ZZ - YZ * ZY)
355  + XY * (YZ * ZX - YX * ZZ)
356  + XZ * (YX * ZY - YY * ZX));
357  return Vec3D(+(XY * YZ - YY * XZ) * b.Z
358  - (ZY * YZ - ZZ * YY) * b.X
359  + (ZY * XZ - ZZ * XY) * b.Y,
360  -(XX * YZ - XZ * YX) * b.Z
361  + (ZX * YZ - ZZ * YX) * b.X
362  - (ZX * XZ - XX * ZZ) * b.Y,
363  +(XX * YY - YX * XY) * b.Z
364  - (ZX * YY - YX * ZY) * b.X
365  + (ZX * XY - XX * ZY) * b.Y) * invdet;
366 }

References b, XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator*() [1/3]

Matrix3D Matrix3D::operator* ( const Matrix3D a) const

Matrix multiplication.

Todo:
check
164 {
165  return Matrix3D(XX * a.XX + XY * a.YX + XZ * a.ZX,
166  XX * a.XY + XY * a.YY + XZ * a.ZY,
167  XX * a.XZ + XY * a.YZ + XZ * a.ZZ,
168  YX * a.XX + YY * a.YX + YZ * a.ZX,
169  YX * a.XY + YY * a.YY + YZ * a.ZY,
170  YX * a.XZ + YY * a.YZ + YZ * a.ZZ,
171  ZX * a.XX + ZY * a.YX + ZZ * a.ZX,
172  ZX * a.XY + ZY * a.YY + ZZ * a.ZY,
173  ZX * a.XZ + ZY * a.YZ + ZZ * a.ZZ
174  );
175 }

References a, Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator*() [2/3]

Vec3D Matrix3D::operator* ( const Vec3D a) const

Vector multiplication.

Multiplication with vector

Parameters
[in]aVector to be multiplied with
Returns
Resulting vector
156 {
157  return Vec3D(XX * a.X + XY * a.Y + XZ * a.Z,
158  YX * a.X + YY * a.Y + YZ * a.Z,
159  ZX * a.X + ZY * a.Y + ZZ * a.Z);
160 }

References a, XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator*() [3/3]

Matrix3D Matrix3D::operator* ( Mdouble  a) const

Scalar multiplication.

Multiplication with scalar

Parameters
[in]aScalar to be multiplied with
Returns
resulting matrix
144 {
145  return Matrix3D(XX * a, XY * a, XZ * a,
146  YX * a, YY * a, YZ * a,
147  ZX * a, ZY * a, ZZ * a);
148 }

References a, Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator+() [1/2]

Matrix3D Matrix3D::operator+ ( const Matrix3D A) const

Matrix addition.

Addition of this matrix with given one

Parameters
[in]AMatrix to be added
Returns
resulting matrix
95 {
96  return Matrix3D(XX + A.XX, XY + A.XY, XZ + A.XZ,
97  YX + A.YX, YY + A.YY, YZ + A.YZ,
98  ZX + A.ZX, ZY + A.ZY, ZZ + A.ZZ);
99 }

References Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator+() [2/2]

Matrix3D Matrix3D::operator+ ( Mdouble  a) const

Scalar addition.

Addition of scalar

Parameters
[in]aScalar to be added
Returns
resulting matrix
120 {
121  return Matrix3D(XX + a, XY + a, XZ + a,
122  YX + a, YY + a, YZ + a,
123  ZX + a, ZY + a, ZZ + a);
124 }

References a, Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator+=()

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

Matrix addition.

Adds all elements of a given matrix to its own

Parameters
[in]A3D matrix to be added
Returns
(reference to) resulting (this) matrix
221 {
222  XX += A.XX;
223  XY += A.XY;
224  XZ += A.XZ;
225  YX += A.YX;
226  YY += A.YY;
227  YZ += A.YZ;
228  ZX += A.ZX;
229  ZY += A.ZY;
230  ZZ += A.ZZ;
231  return *this;
232 }

References XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator-() [1/2]

Matrix3D Matrix3D::operator- ( const Matrix3D A) const

Matrix subtraction.

Substraction of given matrix from this one

Parameters
[in]AMatrix to be subtracted
Returns
resulting matrix
108 {
109  return Matrix3D(XX - A.XX, XY - A.XY, XZ - A.XZ,
110  YX - A.YX, YY - A.YY, YZ - A.YZ,
111  ZX - A.ZX, ZY - A.ZY, ZZ - A.ZZ);
112 }

References Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator-() [2/2]

Matrix3D Matrix3D::operator- ( Mdouble  a) const

Scalar subtraction.

Substraction of scalar

Parameters
[in]aScalar to be subtracted
Returns
resulting matrix
132 {
133  return Matrix3D(XX - a, XY - a, XZ - a,
134  YX - a, YY - a, YZ - a,
135  ZX - a, ZY - a, ZZ - a);
136 }

References a, Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator-=()

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

Matrix substraction.

Substract all elements of a given matrix from its own

Parameters
[in]A3D matrix to be subtracted
Returns
(reference to) resulting (this) matrix
240 {
241  XX -= A.XX;
242  XY -= A.XY;
243  XZ -= A.XZ;
244  YX -= A.YX;
245  YY -= A.YY;
246  YZ -= A.YZ;
247  ZX -= A.ZX;
248  ZY -= A.ZY;
249  ZZ -= A.ZZ;
250  return *this;
251 }

References XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator/()

Matrix3D Matrix3D::operator/ ( Mdouble  a) const

Scalar division.

Division by a scalar

Parameters
[in]ascalar to be divided by
Returns
resulting matrix
183 {
184  return Matrix3D(XX / a, XY / a, XZ / a,
185  YX / a, YY / a, YZ / a,
186  ZX / a, ZY / a, ZZ / a);
187 }

References a, Matrix3D(), XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ operator/=()

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

Scalar division.

Division by a scalar

Parameters
[in]ascalar to be divided by
Returns
(reference to) resulting (this) matrix
259 {
260  XX /= a;
261  XY /= a;
262  XZ /= a;
263  YX /= a;
264  YY /= a;
265  YZ /= a;
266  ZX /= a;
267  ZY /= a;
268  ZZ /= a;
269  return *this;
270 }

References a, XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

◆ setZero()

void Matrix3D::setZero ( )

Sets all elements to zero.

Sets all elements to zero.

55 {
56  XX = XY = XZ = YX = YY = YZ = ZX = ZY = ZZ = 0.0;
57 }

References XX, XY, XZ, YX, YY, YZ, ZX, ZY, and ZZ.

Referenced by CylinderInsertionBoundary::CylinderInsertionBoundary(), Matrix3D(), CGFields::GradVelocityField::setZero(), CGFields::StandardFields::setZero(), and StressStrainControlBoundary::StressStrainControlBoundary().

◆ sqrt()

Matrix3D Matrix3D::sqrt ( const Matrix3D A)
static

Calculates the pointwise square root.

Takes the square root of all the elements in given matrix

Parameters
[in]AMatrix to be pointwise square rooted
Returns
Resulting matrix
290 {
291  return Matrix3D(std::sqrt(A.XX), std::sqrt(A.XY), std::sqrt(A.XZ),
292  std::sqrt(A.YX), std::sqrt(A.YY), std::sqrt(A.YZ),
293  std::sqrt(A.ZX), std::sqrt(A.ZY), std::sqrt(A.ZZ));
294 }

References Matrix3D(), and sqrt().

◆ square()

Matrix3D Matrix3D::square ( const Matrix3D A)
static

Calculates the pointwise square.

Squares all the elements in given matrix

Parameters
[in]AMatrix to be pointwise squared
Returns
Resulting matrix

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

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

◆ trace()

Mdouble Matrix3D::trace ( ) const

Sum of the diagonal elements.

Returns the sum of the diagonal elements of the matrix.

Returns
The trace of the matrix divided by 3 as an Mdouble
64 {
65  return XX + YY + ZZ;
66 }

References XX, YY, and ZZ.

Referenced by deviator().

Friends And Related Function Documentation

◆ operator<<

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

Add elements to ostream.

Adds all elements of a matrix to an ostream

Parameters
[out]osoutput stream
[in]A3D matrix
Returns
output stream with matrix elements added
196 {
197  os << A.XX << ' ' << A.XY << ' ' << A.XZ << ' '
198  << A.YX << ' ' << A.YY << ' ' << A.YZ << ' '
199  << A.ZX << ' ' << A.ZY << ' ' << A.ZZ;
200  return os;
201 }

◆ operator>>

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

Add elements to istream.

Reads the elements of a matrix from an istream

Parameters
[in,out]isinput stream
[out]A3D matrix
Returns
is input stream after the read operation.
210 {
211  is >> A.XX >> A.XY >> A.XZ >> A.YX >> A.YY >> A.YZ >> A.ZX >> A.ZY >> A.ZZ;
212  return is;
213 }

Member Data Documentation

◆ XX

◆ XY

◆ XZ

◆ YX

◆ YY

◆ YZ

◆ ZX

◆ ZY

◆ ZZ


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