FEDEM Solver  R8.0
Source code of the dynamics solver
FFaMat33.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_MAT33_H
14 #define FFA_MAT33_H
15 
17 
18 
26 class FaMat33
27 {
28 public:
30  FaMat33() { this->setIdentity(); }
32  FaMat33(const float* mat);
34  FaMat33(const double* mat);
36  FaMat33(const FaVec3& v0, const FaVec3& v1, const FaVec3& v2);
37 
39  FaMat33& operator+= (const FaMat33& m);
41  FaMat33& operator-= (const FaMat33& m);
43  FaMat33& operator*= (double d);
45  FaMat33& operator/= (double d);
46 
48  const FaVec3& operator[] (int i) const;
50  FaVec3& operator[] (int i);
51 
53  const double& operator() (int i, int j) const;
55  double& operator() (int i, int j);
56 
57  // Special functions
58 
61  FaMat33 inverse(double eps = 1.0e-16) const;
65  FaMat33 transpose() const;
67  FaMat33& shift(int delta);
68 
71  bool isCoincident(const FaMat33& m, double tolerance = 1.0e-10) const;
72 
76  FaMat33& makeGlobalizedCS(const FaVec3& v1, const FaVec3& v2);
79  const FaVec3& v1, const FaVec3& v2);
81  FaMat33& makeGlobalizedCS(const FaVec3& v1, const FaVec3& v2,
82  const FaVec3& v3, const FaVec3& v4);
83 
85  FaMat33& eulerRotateZYX(const FaVec3& angles);
87  FaMat33& incRotate(const FaVec3& angles);
88 
90  FaVec3 getEulerZYX() const;
92  FaVec3 getRotation() const;
93 
95  static FaMat33 makeZrotation(double angle);
97  static FaMat33 makeYrotation(double angle);
99  static FaMat33 makeXrotation(double angle);
100 
101  // Global operators
102 
104  friend FaMat33 operator- (const FaMat33& a);
106  friend FaMat33 operator+ (const FaMat33& a, const FaMat33& b);
108  friend FaMat33 operator- (const FaMat33& a, const FaMat33& b);
109 
111  friend FaMat33 operator* (const FaMat33& a, const FaMat33& b);
113  friend FaMat33 operator* (const FaMat33& a, double d);
115  friend FaMat33 operator* (double d, const FaMat33& a);
117  friend FaVec3 operator* (const FaMat33& a, const FaVec3& b);
119  friend FaVec3 operator* (const FaVec3& a, const FaMat33& b);
121  friend FaMat33 operator/ (const FaMat33& a, double d);
122 
124  friend int operator== (const FaMat33& a, const FaMat33& b);
126  friend int operator!= (const FaMat33& a, const FaMat33& b);
127 
129  friend std::ostream& operator<< (std::ostream& s, const FaMat33& m);
131  friend std::istream& operator>> (std::istream& s, FaMat33& m);
132 
133 private:
134  FaVec3 v[3];
135 };
136 
137 
138 // --- inline functions ---
139 
140 inline const FaVec3& FaMat33::operator[] (int i) const
141 {
142 #ifdef FFA_INDEXCHECK
143  if (i < 0 || i > 2)
144  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
145  << std::endl;
146 #endif
147  return v[i];
148 }
149 
151 {
152 #ifdef FFA_INDEXCHECK
153  if (i < 0 || i > 2)
154  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
155  << std::endl;
156 #endif
157  return v[i];
158 }
159 
160 // Fortran-like 1-based indexing operators.
161 // The first index is the row number, whereas the second is the column number.
162 
163 inline const double& FaMat33::operator() (int i, int j) const
164 {
165 #ifdef FFA_INDEXCHECK
166  if (i < 1 || i > 3)
167  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
168  << std::endl;
169  if (j < 1 || j > 3)
170  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
171  << std::endl;
172 #endif
173  return v[j-1][i-1];
174 }
175 
176 inline double& FaMat33::operator() (int i, int j)
177 {
178 #ifdef FFA_INDEXCHECK
179  if (i < 1 || i > 3)
180  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
181  << std::endl;
182  if (j < 1 || j > 3)
183  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
184  << std::endl;
185 #endif
186  return v[j-1][i-1];
187 }
188 
189 #endif
Point vectors in 3D space.
Class for point transformations in 3D space.
Definition: FFaMat33.H:27
FaMat33 & makeGlobalizedCS(const FaVec3 &v1)
Computes a globalized coordinate system from an X-axis vector.
Definition: FFaMat33.C:210
friend std::ostream & operator<<(std::ostream &s, const FaMat33 &m)
Printing operator.
FaVec3 getEulerZYX() const
Returns the Euler angles corresponding to an incremental rotation.
Definition: FFaMat33.C:325
friend FaMat33 operator*(const FaMat33 &a, const FaMat33 &b)
Multiplication of two matrices.
const FaVec3 & operator[](int i) const
Zero-based indexing operator accessing a matrix column (read only).
Definition: FFaMat33.H:140
static FaMat33 makeXrotation(double angle)
Returns the matrix representing a rotation about the X-axis.
Definition: FFaMat33.C:473
FaMat33 & eulerRotateZYX(const FaVec3 &angles)
Compute an incremental rotation tensor from the given Euler angles.
Definition: FFaMat33.C:301
bool isCoincident(const FaMat33 &m, double tolerance=1.0e-10) const
Returns true if the matrix m equals *this within the given tolerance.
Definition: FFaMat33.C:195
const double & operator()(int i, int j) const
One-based indexing operator accessing a matrix element (read only).
Definition: FFaMat33.H:163
friend FaMat33 operator-(const FaMat33 &a)
Unary negation operator.
FaMat33 & operator-=(const FaMat33 &m)
Subtraction operator.
Definition: FFaMat33.C:78
FaMat33 & setIdentity()
Initializes the matrix to the identity matrix.
Definition: FFaMat33.C:156
FaMat33 & incRotate(const FaVec3 &angles)
Computes an incremental rotation tensor from the given angles.
Definition: FFaMat33.C:364
FaMat33 & operator/=(double d)
Scaling operator (division by a scalar).
Definition: FFaMat33.C:96
FaMat33 transpose() const
Returns the transpose of matrix.
Definition: FFaMat33.C:165
FaMat33()
Default constructor creating an identity matrix.
Definition: FFaMat33.H:30
FaMat33 & shift(int delta)
Performs a cyclic permutation of the matrix columns.
Definition: FFaMat33.C:173
FaMat33 inverse(double eps=1.0e-16) const
Returns the inverse of the matrix.
Definition: FFaMat33.C:126
FaMat33 & operator*=(double d)
Scaling operator (multiplication by a scalar).
Definition: FFaMat33.C:87
friend int operator==(const FaMat33 &a, const FaMat33 &b)
Equality operator.
static FaMat33 makeZrotation(double angle)
Returns the matrix representing a rotation about the Z-axis.
Definition: FFaMat33.C:443
friend FaMat33 operator/(const FaMat33 &a, double d)
Scaling operator, division by a scalar.
FaVec3 getRotation() const
Returns the angles corresponding to an incremental rotation.
Definition: FFaMat33.C:402
friend int operator!=(const FaMat33 &a, const FaMat33 &b)
Inequality operator.
FaVec3 v[3]
Columns of the 3×3 matrix.
Definition: FFaMat33.H:134
static FaMat33 makeYrotation(double angle)
Returns the matrix representing a rotation about the Y-axis.
Definition: FFaMat33.C:458
FaMat33 & operator+=(const FaMat33 &m)
Addition operator.
Definition: FFaMat33.C:69
friend std::istream & operator>>(std::istream &s, FaMat33 &m)
Reading operator.
friend FaMat33 operator+(const FaMat33 &a, const FaMat33 &b)
Global addition operator.
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(sp), dimension(:,:,:), pointer b
Definition: diffractionModule.f90:22
real(sp), dimension(:,:,:), pointer a
Definition: diffractionModule.f90:21
real(dp), dimension(:,:), allocatable m
Definition: inverseModule.f90:38
real(dp), dimension(:), allocatable v0
Definition: inverseModule.f90:26
real(dp), dimension(:), allocatable v1
Definition: inverseModule.f90:27
real(dp), dimension(:), allocatable v2
Definition: inverseModule.f90:28