1 // Copyright (C) 2007-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 // File : HYBRIDPlugin_Hypothesis.hxx
22 // Author : Christian VAN WAMBEKE (CEA)
25 #ifndef HYBRIDPlugin_Hypothesis_HeaderFile
26 #define HYBRIDPlugin_Hypothesis_HeaderFile
28 #include "HYBRIDPlugin_Defs.hxx"
30 #include <SMDS_MeshNode.hxx>
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_Mesh_i.hxx"
34 #include "SMESH_Gen_i.hxx"
35 #include "SMESH_TypeDefs.hxx"
36 #include "utilities.h"
43 class HYBRIDPLUGIN_EXPORT HYBRIDPlugin_Hypothesis: public SMESH_Hypothesis
47 HYBRIDPlugin_Hypothesis(int hypId, SMESH_Gen * gen);
49 typedef std::map<std::vector<double>,double> THYBRIDEnforcedVertexCoordsValues;
50 typedef std::map<std::string,double> THYBRIDEnforcedVertexEntryValues;
52 struct THYBRIDEnforcedVertex {
54 std::string geomEntry;
56 std::vector<double> coords;
57 std::string groupName;
61 struct CompareHYBRIDEnforcedVertex {
62 bool operator () (const THYBRIDEnforcedVertex* e1, const THYBRIDEnforcedVertex* e2) const {
64 if (e1->coords.size() && e2->coords.size())
65 return (e1->coords < e2->coords);
67 return (e1->geomEntry < e2->geomEntry);
72 typedef std::set< THYBRIDEnforcedVertex*, CompareHYBRIDEnforcedVertex > THYBRIDEnforcedVertexList;
73 // Map Coords / Enforced node
74 typedef std::map< std::vector<double>, THYBRIDEnforcedVertex* > TCoordsHYBRIDEnforcedVertexMap;
75 // Map geom entry / Enforced node
76 typedef std::map< std::string, THYBRIDEnforcedVertex* > TGeomEntryHYBRIDEnforcedVertexMap;
77 // Map groupName / Enforced node
78 typedef std::map< std::string, THYBRIDEnforcedVertexList > TGroupNameHYBRIDEnforcedVertexMap;
84 struct THYBRIDEnforcedMesh {
88 std::string groupName;
89 SMESH::ElementType elementType;
92 struct CompareHYBRIDEnforcedMesh {
93 bool operator () (const THYBRIDEnforcedMesh* e1, const THYBRIDEnforcedMesh* e2) const {
95 if (e1->entry == e2->entry)
96 return (e1->elementType < e2->elementType);
98 return (e1->entry < e2->entry);
104 typedef std::set< THYBRIDEnforcedMesh*, CompareHYBRIDEnforcedMesh > THYBRIDEnforcedMeshList;
105 // Map mesh entry / Enforced mesh list
106 // ex: 0:1:2:1 -> [ ("Mesh_1", "0:1:2:1", TopAbs_NODE, ""),
107 // ("Mesh_1", "0:1:2:1", TopAbs_EDGE, "edge group")]
108 typedef std::map< std::string, THYBRIDEnforcedMeshList > TEntryHYBRIDEnforcedMeshListMap;
110 typedef std::map<int,double> TID2SizeMap;
112 struct TIDMeshIDCompare {
113 bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
114 { return e1->GetMesh() == e2->GetMesh() ? e1->GetID() < e2->GetID() : e1->GetMesh() < e2->GetMesh(); }
117 typedef std::map<const SMDS_MeshElement*, std::string, TIDMeshIDCompare > TIDSortedElemGroupMap;
118 typedef std::map<const SMDS_MeshNode*, std::string, TIDMeshIDCompare > TIDSortedNodeGroupMap;
119 typedef std::set<std::string> TSetStrings;
121 static const char* GetHypType() { return "HYBRID_Parameters"; }
125 * Sizes of boundary layers are relative to the surface size. Default no
127 void SetHeightIsRelative( bool isRelative );
128 bool GetHeightIsRelative() const { return myHeightIsRelative; }
130 * Maximum internal angles of boundary elements (in degree)
132 void SetBoundaryLayersMaxElemAngle( double angle );
133 double GetBoundaryLayersMaxElemAngle() const { return myBoundaryLayersMaxElemAngle; }
135 * To call MG-Hybrid by library. Default is no (i.e. by executable)
137 void SetToUseLibrary(bool toUseLib);
138 bool GetToUseLibrary() const;
140 * To mesh layers on all wrap. Default is yes.
142 void SetLayersOnAllWrap(bool toMesh);
143 bool GetLayersOnAllWrap(bool checkFreeOption = false) const;
145 * IDs of faces to grow the layers on
147 bool SetFacesWithLayers(const std::vector<int>& theVal);
148 const std::vector<int>& GetFacesWithLayers() const;
150 * IDs of faces to imprint the layers on
152 bool SetFacesWithImprinting(const std::vector<int>& theVal);
153 const std::vector<int>& GetFacesWithImprinting() const;
155 * IDs of faces with snapping (faces that already have surface layers)
157 bool SetFacesWithSnapping(const std::vector<int>& theVal);
158 const std::vector<int>& GetFacesWithSnapping() const;
160 * To make groups of volumes of different domains when mesh is generated from skin.
161 * Default is to make groups.
162 * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
164 void SetToMakeGroupsOfDomains(bool toMakeGroups);
165 bool GetToMakeGroupsOfDomains() const;
167 * Maximal size of memory to be used by the algorithm (in Megabytes)
169 void SetMaximumMemory(double MB);
170 double GetMaximumMemory() const;
172 * Initial size of memory to be used by the algorithm (in Megabytes) in
173 * automatic memory adjustment mode. Default is zero
175 void SetInitialMemory(double MB);
176 double GetInitialMemory() const;
178 * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
180 enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
181 void SetOptimizationLevel(OptimizationLevel level);
182 OptimizationLevel GetOptimizationLevel() const;
185 * Collision Mode: 0-decrease, 1-stop. Default is decrease
187 enum CollisionMode { Decrease = 0, Stop };
188 void SetCollisionMode(CollisionMode mode);
189 CollisionMode GetCollisionMode() const;
191 * BoundaryLayersGrowth: 0-Layer_Growth_Inward, 1-Layer_Growth_Outward. Default is Layer_Growth_Inward
193 enum BoundaryLayersGrowth { Layer_Growth_Inward = 0, Layer_Growth_Outward };
194 void SetBoundaryLayersGrowth(BoundaryLayersGrowth level);
195 BoundaryLayersGrowth GetBoundaryLayersGrowth() const;
197 * ElementGeneration: 0-Generation_Tetra_Dominant, 1-Generation_Hexa_Dominant, 2-Generation_Cartesian_Core. Default is Generation_Tetra_Dominant
199 enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant, Generation_Cartesian_Core, Generation_Extrusion_Only };
200 void SetElementGeneration(ElementGeneration level);
201 ElementGeneration GetElementGeneration() const;
203 * To mesh adding extra normals at opening ridges and corners.
206 void SetAddMultinormals(bool toAddMultinormals);
207 bool GetAddMultinormals() const;
209 * To mesh smoothing normals at closed ridges and corners.
212 void SetSmoothNormals(bool toSmoothNormals);
213 bool GetSmoothNormals() const;
215 * To set height of the first layer.
217 void SetHeightFirstLayer(double HFL);
218 double GetHeightFirstLayer() const;
220 * To set boundary layers coefficient of geometric progression.
223 void SetBoundaryLayersProgression(double BLP);
224 double GetBoundaryLayersProgression() const;
226 * Set core elements size.
229 void SetCoreSize(double CS);
230 double GetCoreSize() const;
232 * To set multinormals angle threshold at opening ridges.
235 void SetMultinormalsAngle(double MNA);
236 double GetMultinormalsAngle() const;
238 * To set number of boundary layers.
241 void SetNbOfBoundaryLayers(short NBL);
242 short GetNbOfBoundaryLayers() const;
246 * Path to working directory
248 void SetWorkingDirectory(const std::string& path);
249 std::string GetWorkingDirectory() const;
251 * To keep working files or remove them. Log file remains in case of errors anyway.
253 void SetKeepFiles(bool toKeep);
254 bool GetKeepFiles() const;
256 * Verbose level [0-10]
257 * 0 - no standard output,
258 * 2 - prints the data, quality statistics of the skin and final meshes and
259 * indicates when the final mesh is being saved. In addition the software
260 * gives indication regarding the CPU time.
261 * 10 - same as 2 plus the main steps in the computation, quality statistics
262 * histogram of the skin mesh, quality statistics histogram together with
263 * the characteristics of the final mesh.
265 void SetVerboseLevel(short level);
266 short GetVerboseLevel() const;
268 * To create new nodes
270 void SetToCreateNewNodes(bool toCreate);
271 bool GetToCreateNewNodes() const;
273 * To use boundary recovery version which tries to create mesh on a very poor
274 * quality surface mesh
276 void SetToUseBoundaryRecoveryVersion(bool toUse);
277 bool GetToUseBoundaryRecoveryVersion() const;
279 * Applies finite-element correction by replacing overconstrained elements where
280 * it is possible. The process is cutting first the overconstrained edges and
281 * second the overconstrained facets. This insure that no edges have two boundary
282 * vertices and that no facets have three boundary vertices.
284 void SetFEMCorrection(bool toUseFem);
285 bool GetFEMCorrection() const;
287 * To removes initial central point.
289 void SetToRemoveCentralPoint(bool toRemove);
290 bool GetToRemoveCentralPoint() const;
292 * To set hiden/undocumented/advanced options
294 void SetAdvancedOption(const std::string& option);
295 std::string GetAdvancedOption() const;
297 * To define the volumic gradation
299 void SetGradation(double gradation);
300 double GetGradation() const ;
302 * Print log in standard output
304 void SetStandardOutputLog(bool logInStandardOutput);
305 bool GetStandardOutputLog() const ;
307 * Remove log file on success
309 void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
310 bool GetRemoveLogOnSuccess() const ;
313 typedef std::map< std::string, std::string > TOptionValues;
314 typedef std::set< std::string > TOptionNames;
316 void SetOptionValue(const std::string& optionName,
317 const std::string& optionValue);
318 std::string GetOptionValue(const std::string& optionName,
319 bool* isDefault=0) const;
320 bool HasOptionDefined( const std::string& optionName ) const;
321 void ClearOption(const std::string& optionName);
322 TOptionValues GetOptionValues() const;
323 const TOptionValues& GetCustomOptionValues() const { return _customOption2value; }
325 static bool ToBool(const std::string& str, bool* isOk=0);
326 static double ToDbl(const std::string& str, bool* isOk=0);
327 static int ToInt(const std::string& str, bool* isOk=0);
331 * \brief Return command to run hybrid mesher excluding file prefix (-f)
333 static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp);
335 * \brief Return a unique file name
337 static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
339 * \brief Return the name of executable
341 static std::string GetExeName();
343 * \brief Return a tag of enforced triangles
345 static int EnforcedTag() { return -5; }
348 * To set an enforced vertex
350 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
351 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
352 THYBRIDEnforcedVertex* GetEnforcedVertex(double x, double y, double z);
353 THYBRIDEnforcedVertex* GetEnforcedVertex(const std::string anEntry);
354 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" );
355 const THYBRIDEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
356 const THYBRIDEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
357 const THYBRIDEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; }
358 const TCoordsHYBRIDEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
359 const TGeomEntryHYBRIDEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
360 void ClearEnforcedVertices();
363 * To set enforced elements
365 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
366 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::smIdType_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
367 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
368 const THYBRIDEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
369 const TEntryHYBRIDEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
370 void ClearEnforcedMeshes();
371 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
372 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
373 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
374 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
375 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
376 void RestoreEnfElemsByMeshes(); // persistence
378 * \brief Return the enforced vertices
380 static THYBRIDEnforcedVertexList GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp);
381 static THYBRIDEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const HYBRIDPlugin_Hypothesis* hyp);
382 static THYBRIDEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const HYBRIDPlugin_Hypothesis* hyp);
383 static TCoordsHYBRIDEnforcedVertexMap GetEnforcedVerticesByCoords(const HYBRIDPlugin_Hypothesis* hyp);
384 static TGeomEntryHYBRIDEnforcedVertexMap GetEnforcedVerticesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
386 static THYBRIDEnforcedMeshList GetEnforcedMeshes(const HYBRIDPlugin_Hypothesis* hyp);
387 static TEntryHYBRIDEnforcedMeshListMap GetEnforcedMeshesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
388 static TIDSortedNodeGroupMap GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp);
389 static TIDSortedElemGroupMap GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp);
390 static TIDSortedElemGroupMap GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp);
391 static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp);
392 static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp);
393 static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp);
394 static bool GetToUseLibrary(const HYBRIDPlugin_Hypothesis* hyp);
395 void ClearGroupsToRemove();
397 static bool DefaultHeightIsRelative() { return false; }
398 static double DefaultBoundaryLayersMaxElemAngle() { return 165.0; }
399 static bool DefaultMeshHoles();
400 static bool DefaultToUseLib();
401 static bool DefaultLayersOnAllWrap();
402 static bool DefaultToMakeGroupsOfDomains();
403 static double DefaultMaximumMemory();
404 static double DefaultInitialMemory();
405 static short DefaultOptimizationLevel();
406 static short DefaultCollisionMode();
407 static short DefaultBoundaryLayersGrowth();
408 static short DefaultElementGeneration();
409 static std::string DefaultWorkingDirectory();
410 static bool DefaultKeepFiles();
411 static short DefaultVerboseLevel();
412 static bool DefaultToCreateNewNodes();
413 static bool DefaultToUseBoundaryRecoveryVersion();
414 static bool DefaultToUseFEMCorrection();
415 static bool DefaultToRemoveCentralPoint();
416 static bool DefaultStandardOutputLog();
417 static bool DefaultRemoveLogOnSuccess();
418 static double DefaultGradation();
419 static bool DefaultAddMultinormals();
420 static bool DefaultSmoothNormals();
421 static short DefaultNbOfBoundaryLayers();
422 static double DefaultHeightFirstLayer();
423 static double DefaultBoundaryLayersProgression();
424 static double DefaultCoreSize();
425 static double DefaultMultinormalsAngle();
428 * To mesh "holes" in a solid or not. Default is to mesh.
430 void SetToMeshHoles(bool toMesh);
431 bool GetToMeshHoles(bool checkFreeOption = false) const;
434 virtual std::ostream & SaveTo(std::ostream & save);
435 virtual std::istream & LoadFrom(std::istream & load);
438 * \brief Does nothing
440 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
443 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
445 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
449 short myNbOfBoundaryLayers;
450 double myHeightFirstLayer;
451 bool myHeightIsRelative;
452 short myBoundaryLayersGrowth;
453 double myBoundaryLayersMaxElemAngle;
454 double myBoundaryLayersProgression;
456 short myElementGeneration;
459 bool myLayersOnAllWrap;
460 std::vector<int> myFacesWithImprinting;
461 std::vector<int> myFacesWithSnapping;
462 std::vector<int> myFacesWithLayers;
464 // advanced (main params before redesign for 9.6.2)
465 short myCollisionMode;
466 bool myAddMultinormals;
467 bool mySmoothNormals;
468 double myMultinormalsAngle;
471 std::string myWorkingDirectory;
472 short myVerboseLevel;
473 bool myLogInStandardOutput;
474 bool myRemoveLogOnSuccess;
477 TOptionValues _option2value, _customOption2value; // user defined values
478 TOptionValues _defaultOptionValues; // default values
479 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
481 short myOptimizationLevel; // missing from plugin
482 bool myToMakeGroupsOfDomains; // missing from plugin
484 bool myToMeshHoles; // missing from hybrid
485 double myMaximumMemory; // missing from hybrid
486 double myInitialMemory; // missing from hybrid
487 bool myToCreateNewNodes; // missing from hybrid
488 bool myToUseBoundaryRecoveryVersion; // missing from hybrid
489 bool myToUseFemCorrection; // missing from hybrid
490 bool myToRemoveCentralPoint; // missing from hybrid
494 THYBRIDEnforcedVertexList _enfVertexList;
495 THYBRIDEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
496 THYBRIDEnforcedVertexEntryValues _enfVertexEntrySizeList;
497 // map to get "manual" enf vertex (through the coordinates)
498 TCoordsHYBRIDEnforcedVertexMap _coordsEnfVertexMap;
499 // map to get "geom" enf vertex (through the geom entries)
500 TGeomEntryHYBRIDEnforcedVertexMap _geomEntryEnfVertexMap;
503 THYBRIDEnforcedMeshList _enfMeshList;
504 // map to get enf meshes through the entries
505 TEntryHYBRIDEnforcedMeshListMap _entryEnfMeshMap;
506 TIDSortedNodeGroupMap _enfNodes;
507 TIDSortedElemGroupMap _enfEdges;
508 TIDSortedElemGroupMap _enfTriangles;
509 TID2SizeMap _nodeIDToSizeMap;
510 std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
512 TSetStrings _groupsToRemove;