FEDEM Model Database  R8.0
Source code of the FEDEM model database
FFlLinkHandler.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 FFL_LINK_HANDLER_H
14 #define FFL_LINK_HANDLER_H
15 
16 #include <map>
17 #include <set>
18 #include <vector>
19 #include <string>
20 
21 #include "FFlLib/FFlTypeInfoSpec.H"
22 #include "FFlLib/FFlLinkCSMask.H"
23 
24 class FFlFEResultBase;
25 class FFlrFELinkResult;
26 class FFlFaceGenerator;
27 class FFlConnectorItems;
28 class FFaCompoundGeometry;
29 class FFaUnitCalculator;
30 class FFaProfiler;
31 class FFaCheckSum;
32 class FFaTensor3;
33 class FaMat34;
34 class FaVec3;
35 
36 using ElmTypeCount = std::map<std::string,size_t>;
37 using CathegoryVec = std::vector<FFlTypeInfoSpec::Cathegory>;
38 
39 
40 #ifdef FF_NAMESPACE
41 namespace FF_NAMESPACE {
42 #endif
43 
44 class FFlNode;
45 class FFlVertex;
46 class FFlPartBase;
47 class FFlNamedPartBase;
48 class FFlElementBase;
49 class FFlAttributeBase;
50 class FFlLoadBase;
51 class FFlVisualBase;
52 class FFlVDetail;
53 class FFlVAppearance;
54 class FFlGroup;
55 
56 using NodesVec = std::vector<FFlNode*>;
57 using NodesCIter = NodesVec::const_iterator;
58 
59 using ElementsSet = std::set<FFlElementBase*>;
60 using ElementsVec = std::vector<FFlElementBase*>;
61 using ElementsCIter = ElementsVec::const_iterator;
62 
63 using AttributeMap = std::map<int,FFlAttributeBase*>;
64 using AttributeTypeMap = std::map<std::string,AttributeMap>;
65 using AttributeTypeCIter = AttributeTypeMap::const_iterator;
66 
67 using LoadsVec = std::vector<FFlLoadBase*>;
68 using LoadsCIter = LoadsVec::const_iterator;
69 
70 using GroupMap = std::map<int,FFlGroup*>;
71 using GroupCIter = GroupMap::const_iterator;
72 
73 #ifdef FT_USE_VERTEX
74 using VertexVec = std::vector<FaVec3*>;
75 using VertexCIter = VertexVec::const_iterator;
76 
77 using FFlrElement = std::pair<FFlElementBase*,int>;
78 using FFlrElementVec = std::vector<FFlrElement>;
79 using FFlrVxToElmMap = std::vector<FFlrElementVec>;
80 #endif
81 
82 #ifdef FT_USE_VISUALS
83 using VisualsVec = std::vector<FFlVisualBase*>;
84 using VisualsCIter = VisualsVec::const_iterator;
85 #endif
86 
87 
95 {
96 public:
98  FFlLinkHandler(size_t maxNodes = 0, size_t maxElms = 0);
100  FFlLinkHandler(const FFlLinkHandler& otherLink);
102  FFlLinkHandler(const FFlGroup& fromGroup);
104  ~FFlLinkHandler();
105 
108 
109  // Adding entities
110 
111  bool addElement(FFlElementBase* anElem, bool sortOnInsert = false);
112  bool addNode(FFlNode* aNode, bool sortOnInsert = false);
113  bool addGroup(FFlGroup* group, bool silence = false);
114  void addLoad(FFlLoadBase* load, bool sortOnInsert = false);
115  bool addAttribute(FFlAttributeBase* attr, bool silence = false);
116  bool addAttribute(FFlAttributeBase* attr, bool silence,
117  const std::string& name);
118  int addUniqueAttribute(FFlAttributeBase* attr, bool silence = false);
119  int addUniqueAttributeCS(FFlAttributeBase*& attr);
120  bool removeAttribute(const std::string& name, int ID, bool silence = false);
121 #ifdef FT_USE_VISUALS
122  void addVisual(FFlVisualBase* visual, bool sortOnInsert = false);
123  void setRunningIdxOnAppearances();
124 #endif
125 
127  int sortElementsAndNodes(bool deleteDuplicates = false) const;
128 
130  enum Types {
133  FFL_STRC = FFlTypeInfoSpec::STRC_ELM
134  };
135 
137  const ElmTypeCount& getElmTypeCount() const;
139  int getElementCount(const std::string& type) const;
141  int getElementCount(int types = FFL_ALL, bool checkCF = false) const;
143  int getNodeCount(int types = FFL_ALL) const;
145  int getDofCount(bool includeExternalDofs = true) const;
147  int getAttributeCount(const std::string& type) const;
149  int buildFiniteElementVec(bool allFElements = true) const;
150 
151  // Looking up entities by ID (external or internal)
152 
154  FFlElementBase* getElement(int ID, bool internalID = false) const;
156  FFlElementBase* getFiniteElement(int iel) const;
158  FFlNode* getNode(int ID) const;
160  FFlNode* getFENode(int inod) const;
162  FFlGroup* getGroup(int ID) const;
165  FFlAttributeBase* getAttribute(const std::string& type, int ID) const;
166 #ifdef FT_USE_VISUALS
167  FFlVDetail* getDetail(int ID) const;
168  FFlVAppearance* getAppearance(int ID) const;
169 #endif
170 
175  size_t getRefNodes(NodesVec& refNodes, NodesVec& mstNodes) const;
176 
178  bool getLoads(int ID, LoadsVec& loads) const;
180  void getLoadCases(std::set<int>& IDs) const;
181 
183  int getIntNodeID(int extID) const;
185  int getIntElementID(int extID) const;
186 
188  void removeElements(const ElementsVec& elms);
189 
190  int getNewElmID() const;
191  int getNewNodeID() const;
192  int getNewGroupID() const;
193  int getNewAttribID(const std::string& type) const;
194 #ifdef FT_USE_VISUALS
195  int getNewVisualID() const;
196 #endif
197 
198  // Begin iterators to the containers
199 
200  ElementsCIter elementsBegin() const { return myElements.begin(); }
201  ElementsCIter fElementsBegin() const { return myFElements.begin(); }
202  NodesCIter nodesBegin() const { return myNodes.begin(); }
203 #ifdef FT_USE_VERTEX
204  VertexCIter verticesBegin() const { return myVertices.begin(); }
205 #endif
206  GroupCIter groupsBegin() const { return myGroupMap.begin(); }
207  LoadsCIter loadsBegin() const { return myLoads.begin(); }
208 #ifdef FT_USE_VISUALS
209  VisualsCIter visualsBegin() const { return myVisuals.begin(); }
210 #endif
211  AttributeTypeCIter attributeTypesBegin() const { return myAttributes.begin(); }
212 
213  // End iterators to the containers
214 
215  ElementsCIter elementsEnd() const { return myElements.end(); }
216  ElementsCIter fElementsEnd() const { return myFElements.end(); }
217  NodesCIter nodesEnd() const { return myNodes.end(); }
218 #ifdef FT_USE_VERTEX
219  VertexCIter verticesEnd() const { return myVertices.end(); }
220 #endif
221  GroupCIter groupsEnd() const { return myGroupMap.end(); }
222  LoadsCIter loadsEnd() const { return myLoads.end(); }
223 #ifdef FT_USE_VISUALS
224  VisualsCIter visualsEnd() const { return myVisuals.end(); }
225 #endif
226  AttributeTypeCIter attributeTypesEnd() const { return myAttributes.end(); }
227 
229  const AttributeMap& getAttributes(const std::string& name) const;
230 
231  // Special vertex management access
232 
233 #ifdef FT_USE_VERTEX
234  size_t getVertexCount() const { return myVertices.size(); }
235  const VertexVec& getVertexes() const { return myVertices; }
236  bool coLinearVertices(size_t i1, size_t i2, size_t i3,
237  double tolerance = 1.0e-8) const;
238  FFlVertex* getVertex(size_t idx) const;
240  void addVertex(FFlVertex* aVertex);
241 
243  const FFlrVxToElmMap& getVxToElementMapping();
244 
245  using WindowTester = bool(*)(const FaVec3&);
246  void findWindowedNodes(std::map<int,FaVec3>& nodes,
247  const std::vector<int>& indices,
248  const FaMat34& lCS, bool lFirst,
249  WindowTester isInsideWindow) const;
250 #endif
251 
253  void getAllInternalCoordSys(std::vector<FaMat34>& mxes) const;
254 
255  // Utilities :
256 
257  bool getExtents(FaVec3& max, FaVec3& min) const;
258  double getMeanElementSize() const;
259 
261  void getMassProperties(double& M, FaVec3& Xcg, FFaTensor3& I) const;
262 
264  int findNode(FaVec3& nodePos, const FaMat34* Tlg = NULL) const;
265 
267  FFlNode* findFreeNodeAtPoint(const FaVec3& point, double tol,
268  int dofFilter = -1) const;
270  FFlNode* findClosestNode(const FaVec3& point) const;
271 
273  FFlNode* createAttachableNode(FFlNode* fromNode, const FaVec3& nodePos,
274  FFlConnectorItems* cItems = NULL,
275  double Ktra = 0.0, double Krot = 0.0,
276  double Mass = 0.0);
277 
279  FFlElementBase* findClosestElement(const FaVec3& point,
280  const CathegoryVec& wantedTypes) const;
282  FFlElementBase* findClosestElement(const FaVec3& point,
283  const FFlGroup& group) const;
285  FFlElementBase* findClosestElement(const FaVec3& point,
286  FFlGroup* group = NULL) const;
287 
288  FFlElementBase* findPoint(const FFlGroup& group, const FaVec3& point,
289  double* xi) const;
290  FFlElementBase* findPoint(const FaVec3& point,
291  double* xi, int groupID = 0) const;
292 
293  using Strings = std::vector<std::string>;
295  FFlNode* getNodeConnectivity(int ID, Strings& elmList) const;
296 
297  // Strain coat creation (these methods are defined in FFlStrainCoatCreator.C)
298 
299  bool makeStrainCoat(FFlFaceGenerator* geometry,
300  FFlNamedPartBase* group = NULL);
301  bool assignFatigueProperty(int stdIndx, int curveIndx, double sCF,
302  FFlNamedPartBase* group = NULL);
303 
304  static bool isStrainCoat(FFlElementBase* elm);
305 
306  // Result management :
307 
308  void deleteResults();
309  bool hasResults() const { return myResults != NULL; }
310  FFlrFELinkResult* getResults();
311 
312  void convertUnits(const FFaUnitCalculator* convCal);
313 
314  // Admin :
315 
316  bool resolve(bool subdivParabolic = false, bool fromSESAM = false);
317  bool verify(bool fixNegElms = false);
318  void deleteGeometry();
319  bool hasGeometry() const { return this->getNodeCount() > 0; }
320  bool isTooLarge() const { return tooLarge; }
321 
323  unsigned int calculateChecksum(int csType = FFl::CS_NOEXTINFO,
324  bool rndOff = true) const;
326  void calculateChecksum(FFaCheckSum* cs, bool rndOff = true) const;
328  void calculateChecksum(FFaCheckSum* cs, int csType, bool rndOff) const;
329 
330  void initiateCalculationFlag(bool status = false);
331  bool updateCalculationFlag(int groupId, bool status = true);
332  bool updateCalculationFlag(FFlPartBase* part, bool status = true);
333  bool updateCalculationFlag(const std::string& attType, int id,
334  bool status = true);
335 
336 #ifdef FT_USE_VISUALS
337  // Visual settings
338  bool setVisDetail(const FFlVDetail* det); // on all elements
339  bool setVisDetail(FFlPartBase* part, const FFlVDetail* det);
340  bool setVisDetail(const std::vector<FFlPartBase*>& parts,
341  const FFlVDetail* det);
342  bool setVisAppearance(FFlPartBase* partSpec, const FFlVAppearance* app);
343  void updateGroupVisibilityStatus();
344 
346  FFlVDetail* getPredefDetail(int detailType);
347  FFlVDetail* getOnDetail();
348  FFlVDetail* getOffDetail();
349 #endif
350 
351  // For external Nastran files
352  void addComponentModes(int nGen) { nGenDofs += nGen; }
353  void addOP2file(const std::string& fname) { myOP2files.push_back(fname); }
354  void clearOP2files() { myOP2files.clear(); }
355  const Strings& getOP2files() const { return myOP2files; }
356  size_t getNumberOfGenDofs() const { return nGenDofs; }
357 
358  void dump(const std::string& heading = "") const;
359 
360 #ifdef FT_USE_CONNECTORS
362  int createConnector(const FFaCompoundGeometry& compound,
363  const FaVec3& nodePos, int spiderType,
364  FFlConnectorItems& cItems);
366  int deleteConnector(const FFlConnectorItems& cItems);
367 #endif
368 
369 protected:
370  using NodesIter = NodesVec::const_iterator;
371  NodesIter getNodeIter(int ID) const;
372 
373  using ElementsIter = ElementsVec::const_iterator;
374  ElementsIter getElementIter(int ID) const;
375 
377  void countElements() const;
378 
380  bool areBUSHconnected(FFlNode* n1, FFlNode* n2) const;
381  int buildBUSHelementSet() const;
382 
384  int splitElement(FFlElementBase* elm);
385 
386  // Sorting quickies :
387 
388  int sortElements(bool deleteDuplicates = false) const;
389  int sortNodes(bool deleteDuplicates = false) const;
390  void sortLoads() const;
391 #ifdef FT_USE_VISUALS
392  void sortVisuals() const;
393 #endif
394 
395  // Model size limits :
396 
397  bool tooLarge;
398  size_t nodeLimit;
399  size_t elmLimit;
400 
401  // Containers :
402 
404  mutable bool areElementsSorted;
405  mutable NodesVec myNodes;
406  mutable bool areNodesSorted;
407  mutable LoadsVec myLoads;
408  mutable bool areLoadsSorted;
409 #ifdef FT_USE_VISUALS
410  mutable VisualsVec myVisuals;
411  mutable bool areVisualsSorted;
412 #endif
413 #ifdef FT_USE_VERTEX
414  VertexVec myVertices;
415  FFlrVxToElmMap myVxMapping;
416 #endif
419 
420  std::map<unsigned int,FFlAttributeBase*> uniqueAtts;
421  mutable std::map<FFlNode*,ElementsSet> myNodeMapping;
422 
423  bool isResolved;
425 
427  mutable std::map<int,int> ext2intNode;
439  size_t nGenDofs;
440 
443  FFaProfiler* myProfiler;
444 };
445 
446 #ifdef FF_NAMESPACE
447 } // namespace
448 #endif
449 #endif
const double * M
Definition: ChainShape.H:16
std::map< int, FFlAttributeBase * > AttributeMap
Definition: FFlFEAttributeRefs.H:29
GroupMap::const_iterator GroupCIter
Definition: FFlLinkHandler.H:71
std::vector< FFlTypeInfoSpec::Cathegory > CathegoryVec
Definition: FFlLinkHandler.H:37
LoadsVec::const_iterator LoadsCIter
Definition: FFlLinkHandler.H:68
ElementsVec::const_iterator ElementsCIter
Definition: FFlLinkHandler.H:61
NodesVec::const_iterator NodesCIter
Definition: FFlLinkHandler.H:57
AttributeTypeMap::const_iterator AttributeTypeCIter
Definition: FFlLinkHandler.H:65
std::vector< FFlElementBase * > ElementsVec
Definition: FFlLinkHandler.H:60
std::map< int, FFlGroup * > GroupMap
Definition: FFlLinkHandler.H:70
std::map< std::string, AttributeMap > AttributeTypeMap
Definition: FFlLinkHandler.H:64
std::set< FFlElementBase * > ElementsSet
Definition: FFlLinkHandler.H:59
std::map< std::string, size_t > ElmTypeCount
Definition: FFlLinkHandler.H:36
std::vector< FFlLoadBase * > LoadsVec
Definition: FFlLinkHandler.H:67
std::vector< FFlNode * > NodesVec
Definition: FFlLinkHandler.H:56
Class for holding and calculation of checksum value of objects.
Definition: FFaCheckSum.H:30
Class to represent a 3D symmetric tensor.
Definition: FFaTensor3.H:35
Class holding a set of unit conversions for physical properties.
Definition: FFaUnitCalculator.H:28
Definition: FFlAttributeBase.H:26
Storage of spider connector properties for Triads.
Definition: FFlConnectorItems.H:20
Definition: FFlElementBase.H:43
Definition: FFlFEResultBase.H:13
Class for grouping of elements.
Definition: FFlGroup.H:28
Container class for finite element models.
Definition: FFlLinkHandler.H:95
ElementsVec myElements
Definition: FFlLinkHandler.H:403
LoadsCIter loadsBegin() const
Definition: FFlLinkHandler.H:207
FFaProfiler * myProfiler
Definition: FFlLinkHandler.H:443
bool makeStrainCoat(FFlFaceGenerator *geometry, FFlNamedPartBase *group=NULL)
LoadsCIter loadsEnd() const
Definition: FFlLinkHandler.H:222
NodesVec::const_iterator NodesIter
Definition: FFlLinkHandler.H:370
Strings myOP2files
List of files with externally reduced matrices for this model.
Definition: FFlLinkHandler.H:437
ElementsVec::const_iterator ElementsIter
Definition: FFlLinkHandler.H:373
bool isTooLarge() const
Definition: FFlLinkHandler.H:320
GroupCIter groupsBegin() const
Definition: FFlLinkHandler.H:206
NodesCIter nodesEnd() const
Definition: FFlLinkHandler.H:217
bool areLoadsSorted
Definition: FFlLinkHandler.H:408
bool isResolved
Flag to avoid resolving the topology more than once.
Definition: FFlLinkHandler.H:423
ElementsCIter elementsEnd() const
Definition: FFlLinkHandler.H:215
bool hasResults() const
Definition: FFlLinkHandler.H:309
void addComponentModes(int nGen)
Definition: FFlLinkHandler.H:352
GroupMap myGroupMap
Definition: FFlLinkHandler.H:417
ElementsSet myBushElements
Vector of pointers to all BUSH elements in the model.
Definition: FFlLinkHandler.H:435
AttributeTypeMap myAttributes
Definition: FFlLinkHandler.H:418
size_t elmLimit
Max number of elements allowed.
Definition: FFlLinkHandler.H:399
std::map< int, int > ext2intNode
External-to-internal node number mapping.
Definition: FFlLinkHandler.H:427
void addOP2file(const std::string &fname)
Definition: FFlLinkHandler.H:353
Types
Enumerator for getting counts of different element cathegories.
Definition: FFlLinkHandler.H:130
ElementsCIter fElementsBegin() const
Definition: FFlLinkHandler.H:201
bool hasGeometry() const
Definition: FFlLinkHandler.H:319
ElementsVec myFElements
Vector of pointers to the Finite Elements only.
Definition: FFlLinkHandler.H:433
FFlFEResultBase * myResults
Definition: FFlLinkHandler.H:442
std::map< FFlNode *, ElementsSet > myNodeMapping
Definition: FFlLinkHandler.H:421
size_t nodeLimit
Max number of nodes allowed.
Definition: FFlLinkHandler.H:398
NodesVec myFEnodes
Vector or pointers to the Finite Element nodes only.
Definition: FFlLinkHandler.H:429
bool areNodesSorted
Definition: FFlLinkHandler.H:406
FFlLinkHandler & operator=(const FFlLinkHandler &)=delete
Deleted assignement operator.
NodesCIter nodesBegin() const
Definition: FFlLinkHandler.H:202
LoadsVec myLoads
Definition: FFlLinkHandler.H:407
FFlrFELinkResult * getResults()
NodesVec myNodes
Definition: FFlLinkHandler.H:405
std::vector< std::string > Strings
Definition: FFlLinkHandler.H:293
size_t nGenDofs
Number of component modes, as read from Nastran bulk data file.
Definition: FFlLinkHandler.H:439
ElementsCIter fElementsEnd() const
Definition: FFlLinkHandler.H:216
AttributeTypeCIter attributeTypesEnd() const
Definition: FFlLinkHandler.H:226
ElementsCIter elementsBegin() const
Definition: FFlLinkHandler.H:200
bool assignFatigueProperty(int stdIndx, int curveIndx, double sCF, FFlNamedPartBase *group=NULL)
bool areElementsSorted
Definition: FFlLinkHandler.H:404
bool tooLarge
Set by addNode() and addElement()
Definition: FFlLinkHandler.H:397
std::map< unsigned int, FFlAttributeBase * > uniqueAtts
Definition: FFlLinkHandler.H:420
AttributeTypeCIter attributeTypesBegin() const
Definition: FFlLinkHandler.H:211
GroupCIter groupsEnd() const
Definition: FFlLinkHandler.H:221
ElmTypeCount myNumElements
Map of element type name to the number of elements of that type.
Definition: FFlLinkHandler.H:431
FFaCheckSum * myChkSum
Definition: FFlLinkHandler.H:441
void clearOP2files()
Definition: FFlLinkHandler.H:354
size_t getNumberOfGenDofs() const
Definition: FFlLinkHandler.H:356
const Strings & getOP2files() const
Definition: FFlLinkHandler.H:355
bool hasLooseNodes
If true, the FE model contains unconnected nodes.
Definition: FFlLinkHandler.H:424
Definition: FFlLoadBase.H:31
Definition: FFlNamedPartBase.H:21
FE node class. Stores node position and additional data for the node.
Definition: FFlNode.H:39
Base class for all object types of a FE model.
Definition: FFlPartBase.H:27
@ STRC_ELM
Definition: FFlTypeInfoSpec.H:33
@ OTHER_ELM
Definition: FFlTypeInfoSpec.H:33
Definition: FFlVAppearance.H:22
Definition: FFlVDetail.H:21
Definition: FFlVertex.H:24
Definition: FFlVisualBase.H:25
Class for positions in 3D space.
Definition: FFaMat34.H:32
Class for point vectors in 3D space.
Definition: FFaVec3.H:40
@ CS_NOEXTINFO
Definition: FFlLinkCSMask.H:14