FEDEM Solver  R8.0
Source code of the dynamics solver
FFaBody.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_BODY_H
9 #define FFA_BODY_H
10 
11 #include <vector>
12 #include <string>
13 
16 
17 using FaEdge = std::pair<size_t,size_t>;
18 class FaFace;
19 class FaMat34;
20 
21 
22 class FFaBody
23 {
24 public:
26 
27  size_t getNoVertices() const { return myVertices.size(); }
28  size_t getNoFaces() const { return myFaces.size(); }
29 
30  bool computeBoundingBox(FaVec3& minX, FaVec3& maxX) const;
31  bool computeTotalVolume(double& Vb, FaVec3& C0b, FFaTensor3* Ib = NULL) const;
32  bool computeVolumeBelow(double& Vb, double& As, FaVec3& C0b, FaVec3& C0s,
33  const FaVec3& normal, double z0,
34  double zeroTol = 1.0e-16);
35 
36  bool saveIntersection(const FaMat34& cs);
37  bool computeIncArea(double& dAs, FaVec3& C0s,
38  const FaVec3& normal, const FaMat34& cs);
39 
40  size_t addFace(int v1, int v2, int v3, int v4 = -1);
41  size_t addVertex(const FaVec3& pos, double tol = -1.0);
42  const FaVec3& getVertex(size_t idx) const { return myVertices[idx]; }
43  int getFaceVtx(size_t idx, int i) const;
44 
45  static FFaBody* readFromCAD(std::istream& in, double duplTol = -1.0);
46  bool writeCAD(const std::string& fileName, const FaMat34& partCS) const;
47 
48 protected:
49  static FFaBody* readSTL(std::istream& in, double duplTol);
50  static FFaBody* readCAD(std::istream& in);
51  static FFaBody* readWRL(std::istream& in, int version);
52 
53  static void readWRL1 (FFaBody*& body, std::istream& in);
54  static void readWRL2 (FFaBody*& body, std::istream& in);
55  static void readChildren (FFaBody*& body, const FaMat34& bodyCS,
56  std::istream& in);
57  static void readTransform(FFaBody*& body, const FaMat34& bodyCS,
58  std::istream& in);
59  static void readShape (FFaBody*& body, const FaMat34& bodyCS,
60  std::istream& in);
61 
62  void readIndexedFaceSet(std::istream& in, const FaMat34& partCS);
63  void readBody(std::istream& in, const FaMat34& partCS);
64  void readCoords(std::istream& in, const FaMat34& partCS, char endChar = '}');
65  void readFaces(std::istream& in, char endChar = '}');
66  void readFace(std::istream& in);
67 
68 public:
69  static std::string prefix;
70 
71 private:
72  mutable bool isBBoxComputed;
73  mutable FaVec3 myBBox[2];
74  std::vector<FaVec3> myVertices;
75  std::vector<FaFace> myFaces;
77  std::vector<FaVec3> myLoopVer;
78  std::vector<FaEdge> myIntLoop;
79  mutable char isVolumeComputed;
80  mutable double myVolume;
82  mutable FaVec3 myCentroid;
83  size_t startVx;
84 };
85 
86 
87 class FaFace
88 {
89 public:
90  FaFace();
91  FaFace(FFaBody* body, size_t i1, size_t i2, size_t i3, int i4 = -1);
92 
93  int intersect(const FaVec3& normal, double z0, double zeroTol = 1.0e-16);
94  bool isIntersected() const { return iEdge.first != iEdge.second; }
95  bool isBelow() const { return IAmBelow; }
96 
97  size_t size() const { return myVertices.size(); }
98  size_t operator[](int i) const { return myVertices[i]; }
99  const FaVec3& vertex(int i) const { return owner->getVertex(myVertices[i]); }
100 
101  double accumulateArea(const FaVec3& vn, const FaVec3& v0, FaVec3& X) const;
102  double accumulateVolume(const FaVec3& v0, FaVec3& X, FFaTensor3* I) const;
103 
104  const std::vector<FaFace>& getSubFaces() const { return mySubFaces; }
105  FaEdge getIntEdge() const { return iEdge; }
106  FaVec3 getIntEdgeCoord() const;
107  FFaBody* getBody() const { return owner; }
108 
109 protected:
110  int quad2Quads(const char* status, const double* dist);
111  int quad2QuadTria(const char* status, const double* dist, bool oneAbove);
112 
113  friend std::ostream& operator<<(std::ostream& s, const FaFace& f);
114 
115 private:
116  std::vector<size_t> myVertices;
118  std::vector<FaFace> mySubFaces;
119  bool IAmBelow;
120 
122 };
123 
124 
125 inline int FFaBody::getFaceVtx(size_t idx, int i) const
126 {
127  return i >= 0 && (size_t)i < myFaces[idx].size() ? myFaces[idx][i] : -1;
128 }
129 
130 #endif
std::pair< size_t, size_t > FaEdge
Vertex indices of an edge.
Definition: FFaBody.H:17
const double zeroTol
Definition: FFaMathOps.C:13
Point vectors in 3D space.
Definition: FFaBody.H:23
void readBody(std::istream &in, const FaMat34 &partCS)
Definition: FFaBodyParser.C:515
FaVec3 myCentroid
Definition: FFaBody.H:82
FFaTensor3 myInertia
Definition: FFaBody.H:81
static void readTransform(FFaBody *&body, const FaMat34 &bodyCS, std::istream &in)
Definition: FFaBodyParser.C:393
void readCoords(std::istream &in, const FaMat34 &partCS, char endChar='}')
Definition: FFaBodyParser.C:534
std::vector< FaFace > myFaces
Definition: FFaBody.H:75
bool writeCAD(const std::string &fileName, const FaMat34 &partCS) const
Definition: FFaBodyParser.C:606
std::vector< FaEdge > myIntLoop
Definition: FFaBody.H:78
bool computeBoundingBox(FaVec3 &minX, FaVec3 &maxX) const
Definition: FFaBody.C:464
int getFaceVtx(size_t idx, int i) const
Definition: FFaBody.H:125
static void readShape(FFaBody *&body, const FaMat34 &bodyCS, std::istream &in)
Definition: FFaBodyParser.C:440
static FFaBody * readWRL(std::istream &in, int version)
Definition: FFaBodyParser.C:266
static void readChildren(FFaBody *&body, const FaMat34 &bodyCS, std::istream &in)
Definition: FFaBodyParser.C:377
static FFaBody * readSTL(std::istream &in, double duplTol)
Definition: FFaBodyParser.C:158
static void readWRL1(FFaBody *&body, std::istream &in)
Definition: FFaBodyParser.C:279
static FFaBody * readFromCAD(std::istream &in, double duplTol=-1.0)
Definition: FFaBodyParser.C:138
bool computeVolumeBelow(double &Vb, double &As, FaVec3 &C0b, FaVec3 &C0s, const FaVec3 &normal, double z0, double zeroTol=1.0e-16)
Definition: FFaBody.C:537
std::vector< FaVec3 > myVertices
Definition: FFaBody.H:74
const FaVec3 & getVertex(size_t idx) const
Definition: FFaBody.H:42
std::vector< FaVec3 > myLoopVer
Definition: FFaBody.H:77
bool computeTotalVolume(double &Vb, FaVec3 &C0b, FFaTensor3 *Ib=NULL) const
Definition: FFaBody.C:484
size_t getNoVertices() const
Definition: FFaBody.H:27
void readFaces(std::istream &in, char endChar='}')
Definition: FFaBodyParser.C:571
bool computeIncArea(double &dAs, FaVec3 &C0s, const FaVec3 &normal, const FaMat34 &cs)
Definition: FFaBody.C:659
static void readWRL2(FFaBody *&body, std::istream &in)
Definition: FFaBodyParser.C:358
size_t addFace(int v1, int v2, int v3, int v4=-1)
Definition: FFaBody.C:420
FFaBody()
Definition: FFaBody.H:25
bool isBBoxComputed
Definition: FFaBody.H:72
double myVolume
Definition: FFaBody.H:80
char isVolumeComputed
Definition: FFaBody.H:79
void readFace(std::istream &in)
Definition: FFaBodyParser.C:554
size_t getNoFaces() const
Definition: FFaBody.H:28
size_t addVertex(const FaVec3 &pos, double tol=-1.0)
Definition: FFaBody.C:434
FaVec3 myBBox[2]
Definition: FFaBody.H:73
static std::string prefix
Definition: FFaBody.H:69
void readIndexedFaceSet(std::istream &in, const FaMat34 &partCS)
Definition: FFaBodyParser.C:469
size_t startVx
Definition: FFaBody.H:83
static FFaBody * readCAD(std::istream &in)
Definition: FFaBodyParser.C:234
FaVec3 myX0s
Definition: FFaBody.H:76
bool saveIntersection(const FaMat34 &cs)
Definition: FFaBody.C:610
Definition: FFaTensor3.H:27
Definition: FFaBody.H:88
std::vector< FaFace > mySubFaces
2 or 3 sub-triangles of intersected face
Definition: FFaBody.H:118
bool isIntersected() const
Definition: FFaBody.H:94
FFaBody * owner
Pointer to the body object containing this face.
Definition: FFaBody.H:121
const std::vector< FaFace > & getSubFaces() const
Definition: FFaBody.H:104
int intersect(const FaVec3 &normal, double z0, double zeroTol=1.0e-16)
Definition: FFaBody.C:90
const FaVec3 & vertex(int i) const
Definition: FFaBody.H:99
size_t operator[](int i) const
Definition: FFaBody.H:98
FFaBody * getBody() const
Definition: FFaBody.H:107
size_t size() const
Definition: FFaBody.H:97
friend std::ostream & operator<<(std::ostream &s, const FaFace &f)
Definition: FFaBody.C:69
FaFace()
Definition: FFaBody.C:37
bool isBelow() const
Definition: FFaBody.H:95
int quad2Quads(const char *status, const double *dist)
Definition: FFaBody.C:250
FaVec3 getIntEdgeCoord() const
Definition: FFaBody.C:362
FaEdge iEdge
Vertices of the intersection edge, if any.
Definition: FFaBody.H:117
double accumulateArea(const FaVec3 &vn, const FaVec3 &v0, FaVec3 &X) const
Definition: FFaBody.C:351
double accumulateVolume(const FaVec3 &v0, FaVec3 &X, FFaTensor3 *I) const
Definition: FFaBody.C:401
std::vector< size_t > myVertices
Indices to the vertices defining the face.
Definition: FFaBody.H:116
FaEdge getIntEdge() const
Definition: FFaBody.H:105
int quad2QuadTria(const char *status, const double *dist, bool oneAbove)
Definition: FFaBody.C:307
bool IAmBelow
Is face below current intersection plane?
Definition: FFaBody.H:119
Definition: FFaMat34.H:16
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
real(sp) version
Model file version.
Definition: headingNamelistModule.f90:22
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
integer, parameter i4
4-byte integer
Definition: kindModule.f90:18
real(dp) function dist(a, b, g)
Calculates the distance between the angles a,b,g and euler.
Definition: rotationModule.f90:274