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 FaMat33 operator/ (const FaMat33& a, double d);
81 
82  friend int operator== (const FaMat33& a, const FaMat33& b);
83  friend int operator!= (const FaMat33& a, const FaMat33& b);
84 
85  friend std::ostream& operator<< (std::ostream& s, const FaMat33& m);
86  friend std::istream& operator>> (std::istream& s, FaMat33& m);
87 };
88 
89 
90 // --- inline functions ---
91 
92 inline const FaVec3& FaMat33::operator[] (int i) const
93 {
94 #ifdef FFA_INDEXCHECK
95  if (i < 0 || i > 2)
96  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
97  << std::endl;
98 #endif
99  return v[i];
100 }
101 
103 {
104 #ifdef FFA_INDEXCHECK
105  if (i < 0 || i > 2)
106  std::cerr <<"FaMat33::operator[]: index i="<< i <<" is out of range [0,2]"
107  << std::endl;
108 #endif
109  return v[i];
110 }
111 
112 // Fortran-like 1-based indexing operators.
113 // The first index is the row number, whereas the second is the column number.
114 
115 inline const double& FaMat33::operator() (int i, int j) const
116 {
117 #ifdef FFA_INDEXCHECK
118  if (i < 1 || i > 3)
119  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
120  << std::endl;
121  if (j < 1 || j > 3)
122  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
123  << std::endl;
124 #endif
125  return v[j-1][i-1];
126 }
127 
128 inline double& FaMat33::operator() (int i, int j)
129 {
130 #ifdef FFA_INDEXCHECK
131  if (i < 1 || i > 3)
132  std::cerr <<"FaMat33::operator(): index i="<< i <<" is out of range [1,3]"
133  << std::endl;
134  if (j < 1 || j > 3)
135  std::cerr <<"FaMat33::operator(): index j="<< j <<" is out of range [1,3]"
136  << std::endl;
137 #endif
138  return v[j-1][i-1];
139 }
140 
141 #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:555
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:92
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:115
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:544
static FaMat33 makeZrotation(double angle)
Definition: FFaMat33.C:434
friend FaMat33 operator/(const FaMat33 &a, double d)
Definition: FFaMat33.C:528
FaVec3 getRotation() const
Definition: FFaMat33.C:393
friend int operator!=(const FaMat33 &a, const FaMat33 &b)
Definition: FFaMat33.C:549
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:562
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