MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixSymmetric.cc
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 #include "MatrixSymmetric.h"
27 #include "ExtendedMath.h"
28 
34 MatrixSymmetric3D::operator Matrix3D() const
35 {
36  return Matrix3D(XX, XY, XZ, XY, YY, YZ, XZ, YZ, ZZ);
37 }
38 
43 {
44 }
45 
55 MatrixSymmetric3D::MatrixSymmetric3D(const Mdouble xx, const Mdouble xy, const Mdouble xz, const Mdouble yy, const Mdouble yz, const Mdouble zz)
56 {
57  XX = xx;
58  XY = xy;
59  XZ = xz;
60  YY = yy;
61  YZ = yz;
62  ZZ = zz;
63 }
64 
69 {
70  XX = XY = XZ = YY = YZ = ZZ = 0.0;
71 }
72 
79 {
80  return (XX + YY + ZZ) / 3;
81 }
82 
89  {
90  return MatrixSymmetric3D(XX + A.XX, XY + A.XY, XZ + A.XZ, YY + A.YY, YZ + A.YZ, ZZ + A.ZZ);
91 }
92 
99  {
100  return MatrixSymmetric3D(XX - A.XX, XY - A.XY, XZ - A.XZ, YY - A.YY, YZ - A.YZ, ZZ - A.ZZ);
101 }
102 
109  {
110  return MatrixSymmetric3D(XX + a, XY + a, XZ + a, YY + a, YZ + a, ZZ + a);
111 }
112 
119  {
120  return MatrixSymmetric3D(XX - a, XY - a, XZ - a, YY - a, YZ - a, ZZ - a);
121 }
122 
131 {
132  return Vec3D(A.XX * b.X + A.XY * b.Y + A.XZ * b.Z,
133  A.XY * b.X + A.YY * b.Y + A.YZ * b.Z,
134  A.XZ * b.X + A.YZ * b.Y + A.ZZ * b.Z);
135 }
136 
143  {
144  return MatrixSymmetric3D(XX * a, XY * a, XZ * a,
145  YY * a, YZ * a, ZZ * a);
146 }
147 
154  {
155  return MatrixSymmetric3D(XX / a, XY / a, XZ / a, YY / a, YZ / a, ZZ / a);
156 }
157 
164 std::ostream& operator<<(std::ostream& os, const MatrixSymmetric3D& A)
165 {
166  os << A.XX << ' ' << A.XY << ' ' << A.XZ << " " << A.YY << ' ' << A.YZ << " " << A.ZZ;
167  return os;
168 }
169 
176 std::istream& operator>>(std::istream& is, MatrixSymmetric3D& A)
177 {
178  is >> A.XX >> A.XY >> A.XZ >> A.YY >> A.YZ >> A.ZZ;
179  return is;
180 }
181 
188 {
189  XX += A.XX;
190  XY += A.XY;
191  XZ += A.XZ;
192  YY += A.YY;
193  YZ += A.YZ;
194  ZZ += A.ZZ;
195  return *this;
196 }
197 
204 {
205  XX -= A.XX;
206  XY -= A.XY;
207  XZ -= A.XZ;
208  YY -= A.YY;
209  YZ -= A.YZ;
210  ZZ -= A.ZZ;
211  return *this;
212 }
213 
220 {
221  XX /= a;
222  XY /= a;
223  XZ /= a;
224  YY /= a;
225  YZ /= a;
226  ZZ /= a;
227  return *this;
228 }
229 
237 {
239 }
240 
248 {
249  return MatrixSymmetric3D(std::sqrt(A.XX), std::sqrt(A.XY), std::sqrt(A.XZ), std::sqrt(A.YY), std::sqrt(A.YZ), std::sqrt(A.ZZ));
250 }
251 
260 {
261  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);
262 }
263 
274 {
275  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);
276 }
static MatrixSymmetric3D square(const MatrixSymmetric3D &A)
Calculates the pointwise square.
Mdouble X
the vector components
Definition: Vector.h:52
MatrixSymmetric3D & operator-=(const MatrixSymmetric3D &A)
Matrix substraction.
std::istream & operator>>(std::istream &is, MatrixSymmetric3D &A)
double Mdouble
std::ostream & operator<<(std::ostream &os, const MatrixSymmetric3D &A)
T square(T val)
squares a number
Definition: ExtendedMath.h:91
MatrixSymmetric3D operator+(const MatrixSymmetric3D &A) const
Matrix addition.
Vec3D operator*(const MatrixSymmetric3D &A, const Vec3D &b)
MatrixSymmetric3D & operator/=(const Mdouble a)
Scalar division.
void setZero()
Sets all elements to zero.
MatrixSymmetric3D operator-(const MatrixSymmetric3D &A) const
Matrix substraction.
MatrixSymmetric3D & operator+=(const MatrixSymmetric3D &A)
Matrix addition.
Mdouble Y
Definition: Vector.h:52
static MatrixSymmetric3D symmetrisedDyadic(const Vec3D &a, const Vec3D &b)
Calculates the symmetrised dyadic product of two Vec3D: .
static MatrixSymmetric3D selfDyadic(const Vec3D &a)
Calculates the dyadic product of a Vec3D with itself: .
MatrixSymmetric3D operator/(const Mdouble a) const
Scalar division.
MatrixSymmetric3D()
Default constructor.
friend Vec3D operator*(const MatrixSymmetric3D &A, const Vec3D &b)
Vector multiplication.
Implementation of a 3D matrix.
Definition: Matrix.h:36
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble trace() const
Returns the MEAN of the diagonal elements (i.e. the trace divided by three).
static MatrixSymmetric3D sqrt(const MatrixSymmetric3D &A)
Calculates the pointwise square root.
Mdouble Z
Definition: Vector.h:52
Implementation of a 3D symmetric matrix.
Mdouble XX
The six distinctive matrix elements.