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 
13 #ifndef FFA_BODY_H
14 #define FFA_BODY_H
15 
16 #include <vector>
17 #include <string>
18 
21 
22 using FaEdge = std::pair<size_t,size_t>;
23 class FaFace;
24 class FaMat34;
25 
26 
35 class FFaBody
36 {
37 public:
39  FFaBody() : myVolume(0.0), startVx(0)
40  { isVolumeComputed = isBBoxComputed = false; }
41 
43  size_t getNoVertices() const { return myVertices.size(); }
45  size_t getNoFaces() const { return myFaces.size(); }
46 
48  bool computeBoundingBox(FaVec3& minX, FaVec3& maxX) const;
51  bool computeTotalVolume(double& Vb, FaVec3& C0b, FFaTensor3* Ib = NULL) const;
53  bool computeVolumeBelow(double& Vb, double& As, FaVec3& C0b, FaVec3& C0s,
54  const FaVec3& normal, double z0,
55  double zeroTol = 1.0e-16);
56 
58  bool saveIntersection(const FaMat34& cs);
60  bool computeIncArea(double& dAs, FaVec3& C0s,
61  const FaVec3& normal, const FaMat34& cs);
62 
64  size_t addFace(int v1, int v2, int v3, int v4 = -1);
66  size_t addVertex(const FaVec3& pos, double tol = -1.0);
68  const FaVec3& getVertex(size_t idx) const { return myVertices[idx]; }
70  int getFaceVtx(size_t idx, int i) const;
71 
73  static FFaBody* readFromCAD(std::istream& in, double duplTol = -1.0);
74 
76  bool writeCAD(const std::string& fileName, const FaMat34& partCS) const;
77 
78 protected:
80  static FFaBody* readSTL(std::istream& in, double duplTol);
82  static FFaBody* readCAD(std::istream& in);
84  static FFaBody* readWRL(std::istream& in, int version);
85 
87  static void readWRL1 (FFaBody*& body, std::istream& in);
88  static void readWRL2 (FFaBody*& body, std::istream& in);
89  static void readChildren (FFaBody*& body, const FaMat34& bodyCS,
90  std::istream& in);
91  static void readTransform(FFaBody*& body, const FaMat34& bodyCS,
92  std::istream& in);
93  static void readShape (FFaBody*& body, const FaMat34& bodyCS,
94  std::istream& in);
95 
96  void readIndexedFaceSet(std::istream& in, const FaMat34& partCS);
97  void readBody(std::istream& in, const FaMat34& partCS);
98  void readCoords(std::istream& in, const FaMat34& partCS, char endChar = '}');
99  void readFaces(std::istream& in, char endChar = '}');
100  void readFace(std::istream& in);
102 
103 public:
104  static std::string prefix;
105 
106 private:
107  mutable bool isBBoxComputed;
108  mutable FaVec3 myBBox[2];
109  std::vector<FaVec3> myVertices;
110  std::vector<FaFace> myFaces;
112  std::vector<FaVec3> myLoopVer;
113  std::vector<FaEdge> myIntLoop;
114  mutable char isVolumeComputed;
115  mutable double myVolume;
117  mutable FaVec3 myCentroid;
118  size_t startVx;
119 };
120 
121 
128 class FaFace
129 {
130 public:
132  FaFace();
134  FaFace(FFaBody* body, size_t i1, size_t i2, size_t i3, int i4 = -1);
135 
137  int intersect(const FaVec3& normal, double z0, double zeroTol = 1.0e-16);
139  bool isIntersected() const { return iEdge.first != iEdge.second; }
141  bool isBelow() const { return IAmBelow; }
142 
144  size_t size() const { return myVertices.size(); }
146  size_t operator[](int i) const { return myVertices[i]; }
148  const FaVec3& vertex(int i) const { return owner->getVertex(myVertices[i]); }
149 
151  double accumulateArea(const FaVec3& vn, const FaVec3& v0, FaVec3& X) const;
153  double accumulateVolume(const FaVec3& v0, FaVec3& X, FFaTensor3* I) const;
154 
156  const std::vector<FaFace>& getSubFaces() const { return mySubFaces; }
158  FaEdge getIntEdge() const { return iEdge; }
160  FaVec3 getIntEdgeCoord() const;
162  FFaBody* getBody() const { return owner; }
163 
164 protected:
166  int quad2Quads(const char* status, const double* dist);
168  int quad2QuadTria(const char* status, const double* dist, bool oneAbove);
169 
171  friend std::ostream& operator<<(std::ostream& s, const FaFace& f);
172 
173 private:
174  std::vector<size_t> myVertices;
176  std::vector<FaFace> mySubFaces;
177  bool IAmBelow;
178 
180 };
181 
182 
183 inline int FFaBody::getFaceVtx(size_t idx, int i) const
184 {
185  return i >= 0 && (size_t)i < myFaces[idx].size() ? myFaces[idx][i] : -1;
186 }
187 
188 #endif
std::pair< size_t, size_t > FaEdge
Vertex indices of an edge.
Definition: FFaBody.H:22
2nd order symmetric tensors in 3D space.
Point vectors in 3D space.
Class representing the surface geometry a volumetric object.
Definition: FFaBody.H:36
FaVec3 myCentroid
The volume centroid of this body.
Definition: FFaBody.H:117
FFaTensor3 myInertia
The volume intertia of this body.
Definition: FFaBody.H:116
std::vector< FaFace > myFaces
Face container of the body.
Definition: FFaBody.H:110
bool writeCAD(const std::string &fileName, const FaMat34 &partCS) const
Exports the body to specified CAD file.
Definition: FFaBodyParser.C:607
std::vector< FaEdge > myIntLoop
Edges of the intersection surface.
Definition: FFaBody.H:113
bool computeBoundingBox(FaVec3 &minX, FaVec3 &maxX) const
Computes the bounding box of the body.
Definition: FFaBody.C:445
int getFaceVtx(size_t idx, int i) const
Returns the global index of a face vertex.
Definition: FFaBody.H:183
static FFaBody * readWRL(std::istream &in, int version)
Creates a new body by parsing VRML content from an input stream.
Definition: FFaBodyParser.C:267
static FFaBody * readSTL(std::istream &in, double duplTol)
Creates a new body by parsing STL content from an input stream.
Definition: FFaBodyParser.C:159
static FFaBody * readFromCAD(std::istream &in, double duplTol=-1.0)
Creates a new body by parsing the given input stream.
Definition: FFaBodyParser.C:139
bool computeVolumeBelow(double &Vb, double &As, FaVec3 &C0b, FaVec3 &C0s, const FaVec3 &normal, double z0, double zeroTol=1.0e-16)
Computes the volume of a body portion below of given plane.
Definition: FFaBody.C:515
std::vector< FaVec3 > myVertices
Vertex container of the body.
Definition: FFaBody.H:109
const FaVec3 & getVertex(size_t idx) const
Returns the coordinates of a specified vertex.
Definition: FFaBody.H:68
std::vector< FaVec3 > myLoopVer
Vertices defining the intersection.
Definition: FFaBody.H:112
bool computeTotalVolume(double &Vb, FaVec3 &C0b, FFaTensor3 *Ib=NULL) const
Computes the total volume and volume centroid of the body.
Definition: FFaBody.C:461
size_t getNoVertices() const
Returns the total number of vertices in the body.
Definition: FFaBody.H:43
bool computeIncArea(double &dAs, FaVec3 &C0s, const FaVec3 &normal, const FaMat34 &cs)
Computes the intersection area increment.
Definition: FFaBody.C:637
size_t addFace(int v1, int v2, int v3, int v4=-1)
Adds a face to the body definition.
Definition: FFaBody.C:409
FFaBody()
Default constructor.
Definition: FFaBody.H:39
bool isBBoxComputed
If true, myBBox is defined.
Definition: FFaBody.H:107
double myVolume
The volume of this body.
Definition: FFaBody.H:115
char isVolumeComputed
If true, myVolume is computed.
Definition: FFaBody.H:114
size_t getNoFaces() const
Returns the total number of faces in the body.
Definition: FFaBody.H:45
size_t addVertex(const FaVec3 &pos, double tol=-1.0)
Adds a vertex to the body definition.
Definition: FFaBody.C:419
FaVec3 myBBox[2]
Bounding box of the body.
Definition: FFaBody.H:108
static std::string prefix
File prefix to use for included files.
Definition: FFaBody.H:104
size_t startVx
Number of vertices before intersected.
Definition: FFaBody.H:118
static FFaBody * readCAD(std::istream &in)
Creates a new body by parsing CAD content from an input stream.
Definition: FFaBodyParser.C:235
FaVec3 myX0s
Centroid of the plane intersection.
Definition: FFaBody.H:111
bool saveIntersection(const FaMat34 &cs)
Saves current plane intersection.
Definition: FFaBody.C:588
Class to represent a 3D symmetric tensor.
Definition: FFaTensor3.H:35
Class representing a surface segment of a FFaBody object.
Definition: FFaBody.H:129
std::vector< FaFace > mySubFaces
2 or 3 sub-triangles of intersected face
Definition: FFaBody.H:176
bool isIntersected() const
Returns true if face is intersected by the intersection plane.
Definition: FFaBody.H:139
FFaBody * owner
Pointer to the body object containing this face.
Definition: FFaBody.H:179
const std::vector< FaFace > & getSubFaces() const
Returns the sub-faces of the face when it is intersected.
Definition: FFaBody.H:156
int intersect(const FaVec3 &normal, double z0, double zeroTol=1.0e-16)
Calculates the intersection with a given plane.
Definition: FFaBody.C:110
const FaVec3 & vertex(int i) const
Returns the coordinates of the i'th vertex of this face.
Definition: FFaBody.H:148
size_t operator[](int i) const
Returns the global index of the i'th vertex of this face.
Definition: FFaBody.H:146
FFaBody * getBody() const
Returns the owner of this face.
Definition: FFaBody.H:162
size_t size() const
Returns the number of face vertices.
Definition: FFaBody.H:144
friend std::ostream & operator<<(std::ostream &s, const FaFace &f)
Global stream operator printing the face definition.
FaFace()
Default face constructor.
Definition: FFaBody.C:63
bool isBelow() const
Returns true if face is totally below the intersection plane.
Definition: FFaBody.H:141
int quad2Quads(const char *status, const double *dist)
Divides the face into two quadrilateral sub-faces.
Definition: FFaBody.C:270
FaVec3 getIntEdgeCoord() const
Returns the sum of the end points of the intersecting edge.
Definition: FFaBody.C:382
FaEdge iEdge
Vertices of the intersection edge, if any.
Definition: FFaBody.H:175
double accumulateArea(const FaVec3 &vn, const FaVec3 &v0, FaVec3 &X) const
Accumulates area of an intersection surface.
Definition: FFaBody.C:371
double accumulateVolume(const FaVec3 &v0, FaVec3 &X, FFaTensor3 *I) const
Accumulates volume with contribution from *this as surface segment.
Definition: FFaBody.C:394
std::vector< size_t > myVertices
Indices to the vertices defining the face.
Definition: FFaBody.H:174
FaEdge getIntEdge() const
Returns the index of the intersecting edge.
Definition: FFaBody.H:158
int quad2QuadTria(const char *status, const double *dist, bool oneAbove)
Divides the face into one triangle and two quadrilaterals.
Definition: FFaBody.C:327
bool IAmBelow
Is face below current intersection plane?
Definition: FFaBody.H:177
Class for positions in 3D space.
Definition: FFaMat34.H:32
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