FEDEM Solver  R8.0
Source code of the dynamics solver
FFa3DLocation.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_3D_LOCATION_H
14 #define FFA_3D_LOCATION_H
15 
16 #include <array>
17 
20 
21 class FaMat33;
22 class FaMat34;
23 
24 
34 {
35 public:
36 
38  enum PosType {
46  };
47 
49  enum RotType {
53  DIR_EX_EXY
54  };
55 
56 private:
57 
60  FFaEnumEntry(CART_X_Y_Z , "CART_X_Y_Z");
61  FFaEnumEntry(CYL_R_YR_X , "CYL_R_YR_X");
62  FFaEnumEntry(CYL_R_ZR_Y , "CYL_R_ZR_Y");
63  FFaEnumEntry(CYL_R_XR_Z , "CYL_R_XR_Z");
64  FFaEnumEntry(SPH_R_XR_YZ, "SPH_R_XR_YZ");
65  FFaEnumEntry(SPH_R_YR_ZX, "SPH_R_YR_ZX");
66  FFaEnumEntry(SPH_R_ZR_XY, "SPH_R_ZR_XY");
68  };
69 
71  FFaEnumEntry(EUL_Z_Y_X , "EUL_Z_Y_X" );
72  FFaEnumEntry(PNT_PZ_PXZ, "PNT_PZ_PXZ");
73  FFaEnumEntry(PNT_PX_PXY, "PNT_PX_PXY");
74  FFaEnumEntry(DIR_EX_EXY, "DIR_EX_EXY");
76  };
78 
79  PosTypeEnum myPosTyp = CART_X_Y_Z;
80  RotTypeEnum myRotTyp = EUL_Z_Y_X;
81 
82  std::array<FaVec3,3> myL;
83 
84  bool saveNumericalData = false;
85 
86 public:
90  FFa3DLocation(PosType t, const FaVec3& v0,
91  RotType r, const FaVec3& v1, const FaVec3& v2);
93  FFa3DLocation(PosType t, const FaVec3& v0, RotType r, const FaVec3& v1);
95  FFa3DLocation(const FaMat34& m);
97  FFa3DLocation(const FFa3DLocation& m) { *this = m; }
98 
101 
105  bool operator==(const FFa3DLocation& m) const;
106 
108  const FaVec3& operator[](int i) const;
110  FaVec3& operator[](int i);
111 
113  PosType getPosType() const { return myPosTyp; }
115  RotType getRotType() const { return myRotTyp; }
117  int getNumFields() const { return myRotTyp == EUL_Z_Y_X ? 6 : 9; }
118 
120  bool changePosType(PosType newType);
122  bool changeRotType(RotType newType);
123 
125  FFa3DLocation& changePosRefCS(const FaMat34& newRef, const FaMat34& oldRef);
127  FFa3DLocation& changeRotRefCS(const FaMat34& newRef, const FaMat34& oldRef);
128 
130  FFa3DLocation& set(PosType p, const FaMat34& posRelMx,
131  RotType r, const FaMat34& rotRelMx, const FaMat34& glbPos);
133  FFa3DLocation& set(PosType p, RotType r, const FaMat34& glbPos);
134 
136  FFa3DLocation& setPos(PosType p, const FaVec3& cartPos);
138  FFa3DLocation& setRot(RotType r, const FaMat33& rotMat);
139 
141  FaVec3 translation() const;
143  FaMat33 direction() const;
145  FaMat34 getMatrix() const;
147  FaMat34 getMatrix(const FaMat34& posRelMx, const FaMat34& rotRelMx) const;
148 
150  bool isValid() const;
151 
153  std::ostream& print(std::ostream& s, bool includeNumericalData = true) const;
154 
156  friend std::ostream& operator<<(std::ostream& s, const FFa3DLocation& m);
158  friend std::istream& operator>>(std::istream& s, FFa3DLocation& m);
159 };
160 
161 
162 inline const FaVec3& FFa3DLocation::operator[] (int i) const
163 {
164 #ifdef FFA_INDEXCHECK
165  if (i < 0 || i > 2)
166  std::cerr <<"FFa3DLocation::operator[]: index i="<< i
167  <<" is out of range [0,2]"<< std::endl;
168 #endif
169  return myL[i];
170 }
171 
173 {
174 #ifdef FFA_INDEXCHECK
175  if (i < 0 || i > 2)
176  std::cerr <<"FFa3DLocation::operator[]: index i="<< i
177  << " is out of range [0,2]"<< std::endl;
178 #endif
179  return myL[i];
180 }
181 
182 #endif
Enum variables with text representations.
#define FFaEnumEntryEnd
Defines the end of an enum mapping definition.
Definition: FFaEnum.H:237
#define FFaEnumMapping(EnumType)
Defines the start of an enum mapping definition.
Definition: FFaEnum.H:221
#define FFaEnumEntry(Value, Text)
Adds one entry to the current enum mapping definition.
Definition: FFaEnum.H:234
Point vectors in 3D space.
Class representing an object location in 3D space. This class is used to hold data describing the loc...
Definition: FFa3DLocation.H:34
FFa3DLocation & setPos(PosType p, const FaVec3 &cartPos)
Updates the position in *this.
Definition: FFa3DLocation.C:199
void saveMyNumericalData()
Let this instance save its numerical data.
Definition: FFa3DLocation.H:100
PosType getPosType() const
Returns the positioning type.
Definition: FFa3DLocation.H:113
std::array< FaVec3, 3 > myL
Vectors with position/orientation data.
Definition: FFa3DLocation.H:82
FFa3DLocation & set(PosType p, const FaMat34 &posRelMx, RotType r, const FaMat34 &rotRelMx, const FaMat34 &glbPos)
Updates the location based on the provided parameters.
Definition: FFa3DLocation.C:157
RotType
Enum for orientation representation.
Definition: FFa3DLocation.H:49
@ EUL_Z_Y_X
Euler ZYX-angles. Supposed to be entered [ X, Y, Z].
Definition: FFa3DLocation.H:50
@ PNT_PX_PXY
Point on X-axis and point in XY-plane.
Definition: FFa3DLocation.H:51
@ PNT_PZ_PXZ
Point on Z-axis and point in XZ-plane.
Definition: FFa3DLocation.H:52
@ DIR_EX_EXY
Direction vector along X-axis, direction vector in XY-plane.
Definition: FFa3DLocation.H:53
FaVec3 translation() const
Returns the cartesian position of *this.
Definition: FFa3DLocation.C:282
bool isValid() const
Checks that the current data represent a valid location.
Definition: FFa3DLocation.C:372
const FaVec3 & operator[](int i) const
Indexing operator, for read access.
Definition: FFa3DLocation.H:162
FFa3DLocation & changeRotRefCS(const FaMat34 &newRef, const FaMat34 &oldRef)
Changes the orientation reference CS from oldRef to newRef.
Definition: FFa3DLocation.C:130
std::ostream & print(std::ostream &s, bool includeNumericalData=true) const
Prints the content of *this to the provided output stream.
Definition: FFa3DLocation.C:411
FFa3DLocation & operator=(const FFa3DLocation &m)
Assignment operator.
Definition: FFa3DLocation.C:57
int getNumFields() const
Returns number of numerical fields for defining the orientation.
Definition: FFa3DLocation.H:117
FFa3DLocation()
Default constructor.
Definition: FFa3DLocation.H:88
FaMat33 direction() const
Returns the orientation of *this as a rotation matrix.
Definition: FFa3DLocation.C:319
friend std::ostream & operator<<(std::ostream &s, const FFa3DLocation &m)
Global printing operator.
bool operator==(const FFa3DLocation &m) const
Comparison operator.
Definition: FFa3DLocation.C:73
PosType
Enum for position representation.
Definition: FFa3DLocation.H:38
@ CART_X_Y_Z
Cartesian coordinates.
Definition: FFa3DLocation.H:39
@ CYL_R_YR_X
Cylindric coordinates, angle from Y-axis about X-axis.
Definition: FFa3DLocation.H:40
@ SPH_R_ZR_XY
Spherical coordinates, asimuth angle from Z-axis.
Definition: FFa3DLocation.H:45
@ CYL_R_ZR_Y
Cylindric coordinates, angle from Z-axis about Y-axis.
Definition: FFa3DLocation.H:41
@ SPH_R_XR_YZ
Spherical coordinates, asimuth angle from X-axis.
Definition: FFa3DLocation.H:43
@ CYL_R_XR_Z
Cylindric coordinates, angle from X-axis about Z-axis.
Definition: FFa3DLocation.H:42
@ SPH_R_YR_ZX
Spherical coordinates, asimuth angle from Y-axis.
Definition: FFa3DLocation.H:44
friend std::istream & operator>>(std::istream &s, FFa3DLocation &m)
Global reading operator.
FFa3DLocation(const FFa3DLocation &m)
Copy constructor.
Definition: FFa3DLocation.H:97
PosTypeEnum myPosTyp
Current positioning type.
Definition: FFa3DLocation.H:79
FaMat34 getMatrix() const
Returns a FaMat34 representation of *this.
Definition: FFa3DLocation.C:351
RotTypeEnum myRotTyp
Current orientation type.
Definition: FFa3DLocation.H:80
FFa3DLocation & setRot(RotType r, const FaMat33 &rotMat)
Updates the orientation in *this.
Definition: FFa3DLocation.C:242
bool changeRotType(RotType newType)
Converts the orientation representation in *this to newType.
Definition: FFa3DLocation.C:89
RotType getRotType() const
Returns the orientation type.
Definition: FFa3DLocation.H:115
bool saveNumericalData
If false, only the type enums are stored.
Definition: FFa3DLocation.H:84
FFa3DLocation & changePosRefCS(const FaMat34 &newRef, const FaMat34 &oldRef)
Changes the position reference CS from oldRef to newRef.
Definition: FFa3DLocation.C:104
bool changePosType(PosType newType)
Converts the position representation in *this to newType.
Definition: FFa3DLocation.C:79
Class for point transformations in 3D space.
Definition: FFaMat33.H:27
Class for positions in 3D space.
Definition: FFaMat34.H:32
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
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