FEDEM Solver  R8.0
Source code of the dynamics solver
FFaMat34.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_MAT34_H
9 #define FFA_MAT34_H
10 
13 
14 
15 class FaMat34
16 {
19 
20 public:
21 
22  // Constructors
23 
24  FaMat34() { this->setIdentity(); }
25  FaMat34(const float* mat) : r(mat), p(mat+9) {}
26  FaMat34(const double* mat) : r(mat), p(mat+9) {}
27  FaMat34(const FaVec3& pos) : p(pos) {}
28  FaMat34(const FaVec3& v0, const FaVec3& v1,
29  const FaVec3& v2, const FaVec3& v3) : r(v0,v1,v2), p(v3) {}
30  FaMat34(const FaMat33& m, const FaVec3& v) : r(m), p(v) {}
31  FaMat34(const FaMat34& m) : r(m.r), p(m.p) {}
32 
33  // Local operators
34 
35  FaMat34& operator= (const FaMat34& m) { r = m.r; p = m.p; return *this; }
36  FaMat34& operator= (const FaVec3& v) { p = v; return *this; }
37 
38  FaMat34& operator+= (const FaMat34& m);
39  FaMat34& operator+= (const FaVec3& v);
40  FaMat34& operator-= (const FaMat34& m);
41  FaMat34& operator-= (const FaVec3& v);
42  FaMat34& operator*= (double d);
43  FaMat34& operator/= (double d);
44 
45  // Indexing
46 
47  const FaVec3& operator[] (int i) const;
48  FaVec3& operator[] (int i);
49 
50  const double& operator() (int i, int j) const;
51  double& operator() (int i, int j);
52 
53  const FaMat33& direction() const { return r; }
54  const FaVec3& translation() const { return p; }
55 
56  // Special functions
57 
58  FaMat34 inverse() const;
60 
61  bool isCoincident(const FaMat34& m, double tolerance = 1.0e-10) const;
62 
63  FaMat34& eulerRotateZYX(const FaVec3& anglesXYZ, const FaMat34& fromMatrix);
64  FaMat34& eulerRotateZYX(const FaVec3& anglesXYZ);
65  FaMat34& eulerTransform(const FaVec3& offsetXYZ, const FaVec3& anglesXYZ,
66  const FaMat34& fromMatrix);
67  FaMat34& quatrTransform(const FaVec3& offsetXYZ, const FaVec3& anglesXYZ,
68  const FaMat34& fromMatrix);
69 
70  FaMat34& makeGlobalizedCS(const FaVec3& origin,
71  const FaVec3& p1);
72  FaMat34& makeGlobalizedCS(const FaVec3& origin,
73  const FaVec3& p1, const FaVec3& p2);
74  FaMat34& makeGlobalizedCS(const FaVec3& origin,
75  const FaVec3& p1, const FaVec3& p2,
76  const FaVec3& p3);
77 
78  FaMat34& makeCS_X_XY(const FaVec3& origin,
79  const FaVec3& xpt, const FaVec3& xypl);
80  FaMat34& makeCS_X_XZ(const FaVec3& origin,
81  const FaVec3& xpt, const FaVec3& xzpl);
82  FaMat34& makeCS_Z_XZ(const FaVec3& origin,
83  const FaVec3& zpt, const FaVec3& xzpl);
84 
85  FaVec3 projectOnXY(const FaVec3& x) const;
86  FaVec3 getEulerZYX() const;
87  double getEulerZYX(int i) const;
88  double getEulerZYX(int i, const FaMat34& from) const;
89  double getRotation(int i) const;
90  double getRotation(int i, const FaMat34& from) const;
91 
92  static FaVec3 getEulerZYX (const FaMat34& from, const FaMat34& to);
93  static FaMat34 makeZrotation(double angle);
94  static FaMat34 makeYrotation(double angle);
95  static FaMat34 makeXrotation(double angle);
96 
97  // Reading and writing
98 
99  std::ostream& printStd(std::ostream& os) const;
100  std::ostream& printRot(std::ostream& os) const;
101 
102  bool readStd(std::istream& s);
103  bool readRot(std::istream& s);
104 
105  // Global operators
106 
107  friend FaMat34 operator- (const FaMat34& a);
108  friend FaMat34 operator+ (const FaMat34& a, const FaMat34& b);
109  friend FaMat34 operator+ (const FaMat34& a, const FaMat33& b);
110  friend FaMat34 operator+ (const FaMat34& a, const FaVec3& b);
111  friend FaMat34 operator- (const FaMat34& a, const FaMat34& b);
112  friend FaMat34 operator- (const FaMat34& a, const FaMat33& b);
113  friend FaMat34 operator- (const FaMat34& a, const FaVec3& b);
114 
115  friend FaMat34 operator* (const FaMat34& a, const FaMat34& b);
116  friend FaMat34 operator* (const FaMat34& a, const FaMat33& b);
117  friend FaVec3 operator* (const FaMat34& a, const FaVec3& b);
118 
119  friend bool operator== (const FaMat34& a, const FaMat34& b);
120  friend bool operator!= (const FaMat34& a, const FaMat34& b);
121 
122  friend std::ostream& operator<< (std::ostream& s, const FaMat34& m);
123  friend std::istream& operator>> (std::istream& s, FaMat34& m);
124 };
125 
126 
127 // --- inline functions ---
128 
129 inline const FaVec3& FaMat34::operator[] (int i) const
130 {
131 #ifdef FFA_INDEXCHECK
132  if (i < 0 || i > 3)
133  std::cerr <<"FaMat34::operator[]: index i="<< i <<" is out of range [0,3]"
134  << std::endl;
135 #endif
136  return i == 3 ? p : r[i];
137 }
138 
140 {
141 #ifdef FFA_INDEXCHECK
142  if (i < 0 || i > 3)
143  std::cerr <<"FaMat34::operator[]: index i="<< i <<" is out of range [0,3]"
144  << std::endl;
145 #endif
146  return i == 3 ? p : r[i];
147 }
148 
149 // Fortran-like 1-based indexing operators.
150 // The first index is the row number, whereas the second is the column number.
151 
152 inline const double& FaMat34::operator() (int i, int j) const
153 {
154  return j == 4 ? p[i-1] : r[j-1][i-1];
155 }
156 
157 inline double& FaMat34::operator() (int i, int j)
158 {
159  return j == 4 ? p[i-1] : r[j-1][i-1];
160 }
161 
162 //TODO: Remove the symbol "makeCS_X_YX", use "makeCS_X_XY" instead
163 #define makeCS_X_YX makeCS_X_XY
164 #endif
Point vectors in 3D space.
Definition: FFaMat33.H:15
Definition: FFaMat34.H:16
friend FaMat34 operator+(const FaMat34 &a, const FaMat34 &b)
Definition: FFaMat34.C:343
FaMat34 & quatrTransform(const FaVec3 &offsetXYZ, const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Definition: FFaMat34.C:126
FaMat34 & makeCS_X_XY(const FaVec3 &origin, const FaVec3 &xpt, const FaVec3 &xypl)
Definition: FFaMat34.C:219
friend std::ostream & operator<<(std::ostream &s, const FaMat34 &m)
Definition: FFaMat34.C:383
friend bool operator!=(const FaMat34 &a, const FaMat34 &b)
Definition: FFaMat34.C:377
FaMat34 & operator+=(const FaMat34 &m)
Definition: FFaMat34.C:28
FaMat34()
Definition: FFaMat34.H:24
FaMat34(const double *mat)
Definition: FFaMat34.H:26
FaMat34(const FaVec3 &v0, const FaVec3 &v1, const FaVec3 &v2, const FaVec3 &v3)
Definition: FFaMat34.H:28
friend FaMat34 operator-(const FaMat34 &a)
Definition: FFaMat34.C:337
static FaMat34 makeYrotation(double angle)
Definition: FFaMat34.C:208
FaMat34 & operator-=(const FaMat34 &m)
Definition: FFaMat34.C:42
const FaMat33 & direction() const
Definition: FFaMat34.H:53
FaMat34 & makeCS_Z_XZ(const FaVec3 &origin, const FaVec3 &zpt, const FaVec3 &xzpl)
Definition: FFaMat34.C:245
FaMat34 & makeGlobalizedCS(const FaVec3 &origin, const FaVec3 &p1)
Definition: FFaMat34.C:136
double getRotation(int i) const
Definition: FFaMat34.C:186
FaMat34 & operator/=(double d)
Definition: FFaMat34.C:64
friend FaMat34 operator*(const FaMat34 &a, const FaMat34 &b)
Definition: FFaMat34.C:354
static FaMat34 makeXrotation(double angle)
Definition: FFaMat34.C:213
static FaMat34 makeZrotation(double angle)
Definition: FFaMat34.C:203
bool readStd(std::istream &s)
Definition: FFaMat34.C:307
FaMat34 & makeCS_X_XZ(const FaVec3 &origin, const FaVec3 &xpt, const FaVec3 &xzpl)
Definition: FFaMat34.C:232
FaMat34 & operator=(const FaMat34 &m)
Definition: FFaMat34.H:35
FaMat34 & eulerTransform(const FaVec3 &offsetXYZ, const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Definition: FFaMat34.C:116
friend std::istream & operator>>(std::istream &s, FaMat34 &m)
Definition: FFaMat34.C:388
FaMat34 & eulerRotateZYX(const FaVec3 &anglesXYZ, const FaMat34 &fromMatrix)
Definition: FFaMat34.C:108
FaMat34(const FaVec3 &pos)
Definition: FFaMat34.H:27
FaMat33 r
Definition: FFaMat34.H:17
const FaVec3 & operator[](int i) const
Definition: FFaMat34.H:129
const FaVec3 & translation() const
Definition: FFaMat34.H:54
FaMat34 inverse() const
Definition: FFaMat34.C:78
FaMat34(const FaMat34 &m)
Definition: FFaMat34.H:31
FaMat34 & setIdentity()
Definition: FFaMat34.C:85
FaVec3 p
Definition: FFaMat34.H:18
std::ostream & printRot(std::ostream &os) const
Definition: FFaMat34.C:294
FaVec3 projectOnXY(const FaVec3 &x) const
Definition: FFaMat34.C:162
FaVec3 getEulerZYX() const
Definition: FFaMat34.C:169
friend bool operator==(const FaMat34 &a, const FaMat34 &b)
Definition: FFaMat34.C:372
FaMat34 & operator*=(double d)
Definition: FFaMat34.C:56
std::ostream & printStd(std::ostream &os) const
Definition: FFaMat34.C:271
const double & operator()(int i, int j) const
Definition: FFaMat34.H:152
bool isCoincident(const FaMat34 &m, double tolerance=1.0e-10) const
Definition: FFaMat34.C:93
FaMat34(const float *mat)
Definition: FFaMat34.H:25
FaMat34(const FaMat33 &m, const FaVec3 &v)
Definition: FFaMat34.H:30
bool readRot(std::istream &s)
Definition: FFaMat34.C:324
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
integer(ptr), save, private x
Definition: extCtrlSysRoutinesModule.f90:16
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