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 
8 #ifndef FFA_MAT33_H
9 #define FFA_MAT33_H
10 
12 
13 
14 class FaMat33
15 {
16  FaVec3 v[3];
17 
18 public:
19 
20  // Constructors
21 
22  FaMat33() { this->setIdentity(); }
23  FaMat33(const float* mat);
24  FaMat33(const double* mat);
25  FaMat33(const FaVec3& v0, const FaVec3& v1, const FaVec3& v2);
26  FaMat33(const FaMat33& m) { for (int i = 0; i < 3; i++) v[i] = m.v[i]; }
27 
28  // Local operators
29 
30  FaMat33& operator= (const FaMat33& m);
31  FaMat33& operator+= (const FaMat33& m);
32  FaMat33& operator-= (const FaMat33& m);
33  FaMat33& operator*= (double d);
34  FaMat33& operator/= (double d);
35 
36  // Indexing
37 
38  const FaVec3& operator[] (int i) const;
39  FaVec3& operator[] (int i);
40 
41  const double& operator() (int i, int j) const;
42  double& operator() (int i, int j);
43 
44  // Special functions
45 
46  FaMat33 inverse(double eps = 1.0e-16) const;
48  FaMat33 transpose() const;
49  FaMat33& shift(int delta);
50 
51  bool isCoincident(const FaMat33& m, double tolerance = 1.0e-10) const;
52 
54  FaMat33& makeGlobalizedCS(const FaVec3& v1, const FaVec3& v2);
56  const FaVec3& v1, const FaVec3& v2);
57  FaMat33& makeGlobalizedCS(const FaVec3& v1, const FaVec3& v2,
58  const FaVec3& v3, const FaVec3& v4);
59 
60  FaMat33& eulerRotateZYX(const FaVec3& angles);
61  FaMat33& incRotate(const FaVec3& angles);
62 
63  FaVec3 getEulerZYX() const;
64  FaVec3 getRotation() const;
65 
66  static FaMat33 makeZrotation(double angle);
67  static FaMat33 makeYrotation(double angle);
68  static FaMat33 makeXrotation(double angle);
69 
70  // Global operators
71 
72  friend FaMat33 operator- (const FaMat33& a);
73  friend FaMat33 operator+ (const FaMat33& a, const FaMat33& b);
74  friend FaMat33 operator- (const FaMat33& a, const FaMat33& b);
75 
76  friend FaMat33 operator* (const FaMat33& a, const FaMat33& b);
77  friend FaMat33 operator* (const FaMat33& a, double d);
78  friend FaMat33 operator* (double d, const FaMat33& a);
79  friend FaVec3 operator* (const FaMat33& a, const FaVec3& b);
80  friend FaVec3 operator* (const FaVec3& a, const FaMat33& b);
81  friend FaMat33 operator/ (const FaMat33& a, double d);
82 
83  friend int operator== (const FaMat33& a, const FaMat33& b);
84  friend int operator!= (const FaMat33& a, const FaMat33& b);
85 
86  friend std::ostream& operator<< (std::ostream& s, const FaMat33& m);
87  friend std::istream& operator>> (std::istream& s, FaMat33& m);
88 };
89 
90 
91 // --- inline functions ---
92 
93 inline const FaVec3& FaMat33::operator[] (int i) const
94 {
95 #ifdef FFA_INDEXCHECK
96  if (i < 0 || i > 2)
97  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
98  << std::endl;
99 #endif
100  return v[i];
101 }
102 
104 {
105 #ifdef FFA_INDEXCHECK
106  if (i < 0 || i > 2)
107  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
108  << std::endl;
109 #endif
110  return v[i];
111 }
112 
113 // Fortran-like 1-based indexing operators.
114 // The first index is the row number, whereas the second is the column number.
115 
116 inline const double& FaMat33::operator() (int i, int j) const
117 {
118 #ifdef FFA_INDEXCHECK
119  if (i < 1 || i > 3)
120  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
121  << std::endl;
122  if (j < 1 || j > 3)
123  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
124  << std::endl;
125 #endif
126  return v[j-1][i-1];
127 }
128 
129 inline double& FaMat33::operator() (int i, int j)
130 {
131 #ifdef FFA_INDEXCHECK
132  if (i < 1 || i > 3)
133  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
134  << std::endl;
135  if (j < 1 || j > 3)
136  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
137  << std::endl;
138 #endif
139  return v[j-1][i-1];
140 }
141 
142 #endif
Point vectors in 3D space.
Definition: FFaMat33.H:15
FaMat33 & makeGlobalizedCS(const FaVec3 &v1)
Definition: FFaMat33.C:204
friend std::ostream & operator<<(std::ostream &s, const FaMat33 &m)
Definition: FFaMat33.C:561
FaVec3 getEulerZYX() const
Definition: FFaMat33.C:327
friend FaMat33 operator*(const FaMat33 &a, const FaMat33 &b)
Definition: FFaMat33.C:504
const FaVec3 & operator[](int i) const
Definition: FFaMat33.H:93
static FaMat33 makeXrotation(double angle)
Definition: FFaMat33.C:464
FaMat33 & eulerRotateZYX(const FaVec3 &angles)
Definition: FFaMat33.C:299
bool isCoincident(const FaMat33 &m, double tolerance=1.0e-10) const
Definition: FFaMat33.C:189
const double & operator()(int i, int j) const
Definition: FFaMat33.H:116
friend FaMat33 operator-(const FaMat33 &a)
Definition: FFaMat33.C:486
FaMat33 & operator=(const FaMat33 &m)
Definition: FFaMat33.C:60
FaMat33 & operator-=(const FaMat33 &m)
Definition: FFaMat33.C:78
FaMat33 & setIdentity()
Definition: FFaMat33.C:155
FaMat33 & incRotate(const FaVec3 &angles)
Definition: FFaMat33.C:360
FaMat33 & operator/=(double d)
Definition: FFaMat33.C:96
FaMat33 transpose() const
Definition: FFaMat33.C:164
FaMat33()
Definition: FFaMat33.H:22
FaMat33 & shift(int delta)
Definition: FFaMat33.C:172
FaMat33 inverse(double eps=1.0e-16) const
Definition: FFaMat33.C:125
FaMat33 & operator*=(double d)
Definition: FFaMat33.C:87
friend int operator==(const FaMat33 &a, const FaMat33 &b)
Definition: FFaMat33.C:550
static FaMat33 makeZrotation(double angle)
Definition: FFaMat33.C:434
friend FaMat33 operator/(const FaMat33 &a, double d)
Definition: FFaMat33.C:534
FaVec3 getRotation() const
Definition: FFaMat33.C:393
friend int operator!=(const FaMat33 &a, const FaMat33 &b)
Definition: FFaMat33.C:555
FaVec3 v[3]
Definition: FFaMat33.H:16
FaMat33(const FaMat33 &m)
Definition: FFaMat33.H:26
static FaMat33 makeYrotation(double angle)
Definition: FFaMat33.C:449
FaMat33 & operator+=(const FaMat33 &m)
Definition: FFaMat33.C:69
friend std::istream & operator>>(std::istream &s, FaMat33 &m)
Definition: FFaMat33.C:568
friend FaMat33 operator+(const FaMat33 &a, const FaMat33 &b)
Definition: FFaMat33.C:492
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