Matrix.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MECURYDPM_MATRIX_H
27 #define MECURYDPM_MATRIX_H
28 
29 #include <cmath>
30 #include <sstream>
31 #include "Vector.h"
32 #include "SmallMatrix.h"
33 
37 class Matrix3D
38 {
39 public:
43  Mdouble XX, XY, XZ, YX, YY, YZ, ZX, ZY, ZZ;
44 
48  Matrix3D();
49 
53  Matrix3D(Mdouble xx, Mdouble xy, Mdouble xz, Mdouble yx, Mdouble yy, Mdouble yz,
54  Mdouble zx,
55  Mdouble zy,
56  Mdouble zz);
57 
61  Matrix3D(const SmallMatrix<3, 3>& matrix);
62 
66  void setZero();
67 
71  double trace() const;
72 
76  Vec3D diag() const;
77 
81  double deviator() const;
82 
86  Matrix3D operator+(const Matrix3D& A) const;
87 
91  Matrix3D operator-(const Matrix3D& A) const;
92 
96  Matrix3D operator+(Mdouble a) const;
97 
101  Matrix3D operator-(Mdouble a) const;
102 
106  Matrix3D operator*(Mdouble a) const;
107 
111  Vec3D operator*(const Vec3D& a) const;
112 
116  Matrix3D operator*(const Matrix3D& a) const;
117 
121  Matrix3D operator/(Mdouble a) const;
122 
126  friend std::ostream& operator<<(std::ostream& os, const Matrix3D& A);
127 
131  friend std::istream& operator>>(std::istream& is, Matrix3D& A);
132 
136  Matrix3D& operator+=(const Matrix3D& A);
137 
141  Matrix3D& operator-=(const Matrix3D& A);
142 
147 
151  static Matrix3D square(const Matrix3D& A);
152 
156  static Matrix3D sqrt(const Matrix3D& A);
157 
161  static Matrix3D dyadic(const Vec3D& a, const Vec3D& b);
162 
166  static Matrix3D cross(const Vec3D& a, const Matrix3D& b);
167 
171  static Matrix3D inverse(const Matrix3D& A);
172 
176  Vec3D ldivide(const Vec3D& b);
177 
181  Matrix3D getCylindricalTensorField(const Vec3D& p) const;
182 };
183 
184 
185 #endif
@ A
Definition: StatisticsVector.h:42
Implementation of a 3D matrix.
Definition: Matrix.h:38
void setZero()
Sets all elements to zero.
Definition: Matrix.cc:75
Matrix3D & operator+=(const Matrix3D &A)
Matrix addition.
Definition: Matrix.cc:241
Mdouble YX
Definition: Matrix.h:43
Matrix3D & operator/=(Mdouble a)
Scalar division.
Definition: Matrix.cc:279
Vec3D diag() const
The diagonal elements.
Definition: Matrix.cc:93
Matrix3D operator*(Mdouble a) const
Scalar multiplication.
Definition: Matrix.cc:164
friend std::istream & operator>>(std::istream &is, Matrix3D &A)
Add elements to istream.
Definition: Matrix.cc:230
Matrix3D operator-(const Matrix3D &A) const
Matrix subtraction.
Definition: Matrix.cc:128
double trace() const
Sum of the diagonal elements.
Definition: Matrix.cc:84
Mdouble ZX
Definition: Matrix.h:43
static Matrix3D dyadic(const Vec3D &a, const Vec3D &b)
Calculates the dyadic product of a two Vec3D: .
Definition: Matrix.cc:323
Mdouble XY
Definition: Matrix.h:43
Mdouble YY
Definition: Matrix.h:43
Matrix3D operator/(Mdouble a) const
Scalar division.
Definition: Matrix.cc:203
Mdouble ZY
Definition: Matrix.h:43
Mdouble ZZ
Definition: Matrix.h:43
Mdouble YZ
Definition: Matrix.h:43
Matrix3D & operator-=(const Matrix3D &A)
Matrix substraction.
Definition: Matrix.cc:260
friend std::ostream & operator<<(std::ostream &os, const Matrix3D &A)
Add elements to ostream.
Definition: Matrix.cc:216
static Matrix3D inverse(const Matrix3D &A)
Computes the inverse of a matrix.
Definition: Matrix.cc:349
Matrix3D getCylindricalTensorField(const Vec3D &p) const
Returns the matrix in cylindrical coordinates.
Definition: Matrix.cc:394
Mdouble XZ
Definition: Matrix.h:43
Matrix3D operator+(const Matrix3D &A) const
Matrix addition.
Definition: Matrix.cc:115
Mdouble XX
all nine matrix elements
Definition: Matrix.h:43
Vec3D ldivide(const Vec3D &b)
A.ldivide(b) computes the solution x to A*x=b.
Definition: Matrix.cc:373
static Matrix3D square(const Matrix3D &A)
Calculates the pointwise square.
Definition: Matrix.cc:298
static Matrix3D cross(const Vec3D &a, const Matrix3D &b)
'Special' cross product; CP of vector with each column of a matrix
Definition: Matrix.cc:337
double deviator() const
Deviator.
Definition: Matrix.cc:103
static Matrix3D sqrt(const Matrix3D &A)
Calculates the pointwise square root.
Definition: Matrix.cc:310
Matrix3D()
default constructor
Definition: Matrix.cc:34
Data type for small dense matrix.
Definition: SmallMatrix.h:68
Definition: Vector.h:51