MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixSymmetric.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 MATRIXSYMMETRIC_H
27 #define MATRIXSYMMETRIC_H
28 
29 #include <cmath>
30 #include <sstream>
31 #include "Matrix.h"
32 
36 {
37 public:
38 
39  Mdouble XX, XY, XZ, YY, YZ, ZZ;
40 
41  operator Matrix3D() { return Matrix3D(XX, XY, XZ, XY, YY, YZ, XZ, YZ, ZZ); };
42 
43  inline MatrixSymmetric3D(void){}
44 
45  inline MatrixSymmetric3D (const Mdouble xx, const Mdouble xy, const Mdouble xz, const Mdouble yy, const Mdouble yz, const Mdouble zz)
46  {
47  XX = xx; XY = xy; XZ = xz;
48  YY = yy; YZ = yz;
49  ZZ = zz;
50  }
51 
52  inline void set_zero ()
53  {
54  XX = XY = XZ = YY = YZ = ZZ = 0.0;
55  }
56 
57  inline Mdouble trace () const
58  {
59  return (XX+YY+ZZ)/3;
60  }
61 
63  {
64  return MatrixSymmetric3D(XX + A.XX, XY + A.XY, XZ + A.XZ,
65  YY + A.YY, YZ + A.YZ, ZZ + A.ZZ);
66  }
67 
69  {
70  return MatrixSymmetric3D(XX - A.XX, XY - A.XY, XZ - A.XZ,
71  YY - A.YY, YZ - A.YZ, ZZ - A.ZZ);
72  }
73 
74  inline MatrixSymmetric3D operator + (const Mdouble A) const
75  {
76  return MatrixSymmetric3D(XX + A, XY + A, XZ + A,
77  YY + A, YZ + A, ZZ + A);
78  }
79 
80  inline MatrixSymmetric3D operator - (const Mdouble A) const
81  {
82  return MatrixSymmetric3D(XX - A, XY - A, XZ - A,
83  YY - A, YZ - A, ZZ - A);
84  }
85 
86  friend inline Vec3D operator * (const MatrixSymmetric3D A, const Vec3D B)
87  {
88  return Vec3D(A.XX*B.X+A.XY*B.Y+A.XZ*B.Z,
89  A.XY*B.X+A.YY*B.Y+A.YZ*B.Z,
90  A.XZ*B.X+A.YZ*B.Y+A.ZZ*B.Z);
91  }
92 
93  inline MatrixSymmetric3D operator * (const Mdouble A) const
94  {
95  return MatrixSymmetric3D(XX * A, XY * A, XZ * A,
96  YY * A, YZ * A, ZZ * A);
97  }
98 
99  inline MatrixSymmetric3D operator / (const Mdouble A) const
100  {
101  return MatrixSymmetric3D(XX / A, XY / A, XZ / A,
102  YY / A, YZ / A, ZZ / A);
103  }
104 
105  friend inline std::ostream& operator<<(std::ostream& os, const MatrixSymmetric3D &A)
106  {
107  os << A.XX << ' ' << A.XY << ' ' << A.XZ << " " << A.YY << ' ' << A.YZ << " " << A.ZZ;
108  return os;
109  }
110 
111  friend inline std::istream& operator>>(std::istream& is, MatrixSymmetric3D &A)
112  {
113  is >> A.XX >> A.XY >> A.XZ >> A.YY >> A.YZ >> A.ZZ;
114  return is;
115  }
116 
118  {
119  XX += A.XX;
120  XY += A.XY;
121  XZ += A.XZ;
122  YY += A.YY;
123  YZ += A.YZ;
124  ZZ += A.ZZ;
125  return *this;
126  }
127 
129  {
130  XX -= A.XX;
131  XY -= A.XY;
132  XZ -= A.XZ;
133  YY -= A.YY;
134  YZ -= A.YZ;
135  ZZ -= A.ZZ;
136  return *this;
137  }
138 
140  {
141  XX /= a;
142  XY /= a;
143  XZ /= a;
144  YY /= a;
145  YZ /= a;
146  ZZ /= a;
147  return *this;
148  }
149 
150  // Pointwise square
152  {
153  return MatrixSymmetric3D(sqr(A.XX), sqr(A.XY), sqr(A.XZ), sqr(A.YY), sqr(A.YZ), sqr(A.ZZ));
154  }
155 
156  // Pointwise square root
158  {
159  return MatrixSymmetric3D(sqrt(A.XX), sqrt(A.XY), sqrt(A.XZ), sqrt(A.YY), sqrt(A.YZ), sqrt(A.ZZ));
160  }
161 
162  //calculates A*A'
163  //friend inline MatrixSymmetric3D Dyadic(Vec3D A) {
164  // 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);
165  //}
166 };
167 
170  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, 0.5*(A.Y*B.Z+B.Y*A.Z), A.Z*B.Z);
171 }
172 
173 
174 #endif
Mdouble X
Definition: Vector.h:44
friend MatrixSymmetric3D sqrt(const MatrixSymmetric3D &A)
friend std::istream & operator>>(std::istream &is, MatrixSymmetric3D &A)
friend Vec3D operator*(const MatrixSymmetric3D A, const Vec3D B)
#define sqr(a)
Definition: ExtendedMath.h:36
MatrixSymmetric3D & operator-=(const MatrixSymmetric3D &A)
MatrixSymmetric3D & operator/=(const Mdouble a)
friend std::ostream & operator<<(std::ostream &os, const MatrixSymmetric3D &A)
MatrixSymmetric3D operator+(const MatrixSymmetric3D &A) const
MatrixSymmetric3D SymmetrizedDyadic(Vec3D A, Vec3D B)
calculates the symmetrized dyadic product ( )
double Mdouble
Definition: ExtendedMath.h:33
friend MatrixSymmetric3D square(const MatrixSymmetric3D &A)
MatrixSymmetric3D operator-(const MatrixSymmetric3D &A) const
MatrixSymmetric3D operator/(const Mdouble A) const
Mdouble Y
Definition: Vector.h:44
Implementation of a 3D matrix.
Definition: Matrix.h:35
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:40
Mdouble trace() const
MatrixSymmetric3D & operator+=(const MatrixSymmetric3D &A)
Mdouble Z
Definition: Vector.h:44
Implementation of a 3D symmetric matrix.
MatrixSymmetric3D(const Mdouble xx, const Mdouble xy, const Mdouble xz, const Mdouble yy, const Mdouble yz, const Mdouble zz)