1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
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 mesh layers on all wrap. Default is yes.
137 void SetLayersOnAllWrap(bool toMesh);
138 bool GetLayersOnAllWrap(bool checkFreeOption = false) const;
140 * IDs of faces to grow the layers on
142 bool SetFacesWithLayers(const std::vector<int>& theVal);
143 const std::vector<int>& GetFacesWithLayers() const;
145 * IDs of faces to imprint the layers on
147 bool SetFacesWithImprinting(const std::vector<int>& theVal);
148 const std::vector<int>& GetFacesWithImprinting() const;
150 * IDs of faces with snapping (faces that already have surface layers)
152 bool SetFacesWithSnapping(const std::vector<int>& theVal);
153 const std::vector<int>& GetFacesWithSnapping() const;
155 * To make groups of volumes of different domains when mesh is generated from skin.
156 * Default is to make groups.
157 * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
159 void SetToMakeGroupsOfDomains(bool toMakeGroups);
160 bool GetToMakeGroupsOfDomains() const;
162 * Maximal size of memory to be used by the algorithm (in Megabytes)
164 void SetMaximumMemory(double MB);
165 double GetMaximumMemory() const;
167 * Initial size of memory to be used by the algorithm (in Megabytes) in
168 * automatic memory adjustment mode. Default is zero
170 void SetInitialMemory(double MB);
171 double GetInitialMemory() const;
173 * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
175 enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
176 void SetOptimizationLevel(OptimizationLevel level);
177 OptimizationLevel GetOptimizationLevel() const;
180 * Collision Mode: 0-decrease, 1-stop. Default is decrease
182 enum CollisionMode { Decrease = 0, Stop };
183 void SetCollisionMode(CollisionMode mode);
184 CollisionMode GetCollisionMode() const;
186 * BoundaryLayersGrowth: 0-Layer_Growth_Inward, 1-Layer_Growth_Outward. Default is Layer_Growth_Inward
188 enum BoundaryLayersGrowth { Layer_Growth_Inward = 0, Layer_Growth_Outward };
189 void SetBoundaryLayersGrowth(BoundaryLayersGrowth level);
190 BoundaryLayersGrowth GetBoundaryLayersGrowth() const;
192 * ElementGeneration: 0-Generation_Tetra_Dominant, 1-Generation_Hexa_Dominant, 2-Generation_Cartesian_Core. Default is Generation_Tetra_Dominant
194 enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant, Generation_Cartesian_Core, Generation_Extrusion_Only };
195 void SetElementGeneration(ElementGeneration level);
196 ElementGeneration GetElementGeneration() const;
198 * To mesh adding extra normals at opening ridges and corners.
201 void SetAddMultinormals(bool toAddMultinormals);
202 bool GetAddMultinormals() const;
204 * To mesh smoothing normals at closed ridges and corners.
207 void SetSmoothNormals(bool toSmoothNormals);
208 bool GetSmoothNormals() const;
210 * To set height of the first layer.
212 void SetHeightFirstLayer(double HFL);
213 double GetHeightFirstLayer() const;
215 * To set boundary layers coefficient of geometric progression.
218 void SetBoundaryLayersProgression(double BLP);
219 double GetBoundaryLayersProgression() const;
221 * Set core elements size.
224 void SetCoreSize(double CS);
225 double GetCoreSize() const;
227 * To set multinormals angle threshold at opening ridges.
230 void SetMultinormalsAngle(double MNA);
231 double GetMultinormalsAngle() const;
233 * To set number of boundary layers.
236 void SetNbOfBoundaryLayers(short NBL);
237 short GetNbOfBoundaryLayers() const;
241 * Path to working directory
243 void SetWorkingDirectory(const std::string& path);
244 std::string GetWorkingDirectory() const;
246 * To keep working files or remove them. Log file remains in case of errors anyway.
248 void SetKeepFiles(bool toKeep);
249 bool GetKeepFiles() const;
251 * Verbose level [0-10]
252 * 0 - no standard output,
253 * 2 - prints the data, quality statistics of the skin and final meshes and
254 * indicates when the final mesh is being saved. In addition the software
255 * gives indication regarding the CPU time.
256 * 10 - same as 2 plus the main steps in the computation, quality statistics
257 * histogram of the skin mesh, quality statistics histogram together with
258 * the characteristics of the final mesh.
260 void SetVerboseLevel(short level);
261 short GetVerboseLevel() const;
263 * To create new nodes
265 void SetToCreateNewNodes(bool toCreate);
266 bool GetToCreateNewNodes() const;
268 * To use boundary recovery version which tries to create mesh on a very poor
269 * quality surface mesh
271 void SetToUseBoundaryRecoveryVersion(bool toUse);
272 bool GetToUseBoundaryRecoveryVersion() const;
274 * Applies finite-element correction by replacing overconstrained elements where
275 * it is possible. The process is cutting first the overconstrained edges and
276 * second the overconstrained facets. This insure that no edges have two boundary
277 * vertices and that no facets have three boundary vertices.
279 void SetFEMCorrection(bool toUseFem);
280 bool GetFEMCorrection() const;
282 * To removes initial central point.
284 void SetToRemoveCentralPoint(bool toRemove);
285 bool GetToRemoveCentralPoint() const;
287 * To set hiden/undocumented/advanced options
289 void SetAdvancedOption(const std::string& option);
290 std::string GetAdvancedOption() const;
292 * To define the volumic gradation
294 void SetGradation(double gradation);
295 double GetGradation() const ;
297 * Print log in standard output
299 void SetStandardOutputLog(bool logInStandardOutput);
300 bool GetStandardOutputLog() const ;
302 * Remove log file on success
304 void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
305 bool GetRemoveLogOnSuccess() const ;
308 typedef std::map< std::string, std::string > TOptionValues;
309 typedef std::set< std::string > TOptionNames;
311 void SetOptionValue(const std::string& optionName,
312 const std::string& optionValue) throw (std::invalid_argument);
313 std::string GetOptionValue(const std::string& optionName,
314 bool* isDefault=0) const throw (std::invalid_argument);
315 bool HasOptionDefined( const std::string& optionName ) const;
316 void ClearOption(const std::string& optionName);
317 TOptionValues GetOptionValues() const;
318 const TOptionValues& GetCustomOptionValues() const { return _customOption2value; }
320 static bool ToBool(const std::string& str, bool* isOk=0) throw (std::invalid_argument);
321 static double ToDbl(const std::string& str, bool* isOk=0) throw (std::invalid_argument);
322 static int ToInt(const std::string& str, bool* isOk=0) throw (std::invalid_argument);
326 * \brief Return command to run hybrid mesher excluding file prefix (-f)
328 static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp);
330 * \brief Return a unique file name
332 static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
334 * \brief Return the name of executable
336 static std::string GetExeName();
338 * \brief Return a tag of enforced triangles
340 static int EnforcedTag() { return -5; }
343 * To set an enforced vertex
345 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
346 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
347 THYBRIDEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
348 THYBRIDEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
349 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
350 const THYBRIDEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
351 const THYBRIDEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
352 const THYBRIDEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; }
353 const TCoordsHYBRIDEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
354 const TGeomEntryHYBRIDEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
355 void ClearEnforcedVertices();
358 * To set enforced elements
360 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
361 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
362 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
363 const THYBRIDEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
364 const TEntryHYBRIDEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
365 void ClearEnforcedMeshes();
366 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
367 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
368 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
369 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
370 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
371 void RestoreEnfElemsByMeshes(); // persistence
373 * \brief Return the enforced vertices
375 static THYBRIDEnforcedVertexList GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp);
376 static THYBRIDEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const HYBRIDPlugin_Hypothesis* hyp);
377 static THYBRIDEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const HYBRIDPlugin_Hypothesis* hyp);
378 static TCoordsHYBRIDEnforcedVertexMap GetEnforcedVerticesByCoords(const HYBRIDPlugin_Hypothesis* hyp);
379 static TGeomEntryHYBRIDEnforcedVertexMap GetEnforcedVerticesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
381 static THYBRIDEnforcedMeshList GetEnforcedMeshes(const HYBRIDPlugin_Hypothesis* hyp);
382 static TEntryHYBRIDEnforcedMeshListMap GetEnforcedMeshesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
383 static TIDSortedNodeGroupMap GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp);
384 static TIDSortedElemGroupMap GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp);
385 static TIDSortedElemGroupMap GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp);
386 static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp);
387 static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp);
388 static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp);
389 void ClearGroupsToRemove();
391 static bool DefaultHeightIsRelative() { return false; }
392 static double DefaultBoundaryLayersMaxElemAngle() { return 165.0; }
393 static bool DefaultMeshHoles();
394 static bool DefaultLayersOnAllWrap();
395 static bool DefaultToMakeGroupsOfDomains();
396 static double DefaultMaximumMemory();
397 static double DefaultInitialMemory();
398 static short DefaultOptimizationLevel();
399 static short DefaultCollisionMode();
400 static short DefaultBoundaryLayersGrowth();
401 static short DefaultElementGeneration();
402 static std::string DefaultWorkingDirectory();
403 static bool DefaultKeepFiles();
404 static short DefaultVerboseLevel();
405 static bool DefaultToCreateNewNodes();
406 static bool DefaultToUseBoundaryRecoveryVersion();
407 static bool DefaultToUseFEMCorrection();
408 static bool DefaultToRemoveCentralPoint();
409 static bool DefaultStandardOutputLog();
410 static bool DefaultRemoveLogOnSuccess();
411 static double DefaultGradation();
412 static bool DefaultAddMultinormals();
413 static bool DefaultSmoothNormals();
414 static short DefaultNbOfBoundaryLayers();
415 static double DefaultHeightFirstLayer();
416 static double DefaultBoundaryLayersProgression();
417 static double DefaultCoreSize();
418 static double DefaultMultinormalsAngle();
421 * To mesh "holes" in a solid or not. Default is to mesh.
423 void SetToMeshHoles(bool toMesh);
424 bool GetToMeshHoles(bool checkFreeOption = false) const;
427 virtual std::ostream & SaveTo(std::ostream & save);
428 virtual std::istream & LoadFrom(std::istream & load);
431 * \brief Does nothing
433 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
436 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
438 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
442 short myNbOfBoundaryLayers;
443 double myHeightFirstLayer;
444 bool myHeightIsRelative;
445 short myBoundaryLayersGrowth;
446 double myBoundaryLayersMaxElemAngle;
447 double myBoundaryLayersProgression;
449 short myElementGeneration;
452 bool myLayersOnAllWrap;
453 std::vector<int> myFacesWithImprinting;
454 std::vector<int> myFacesWithSnapping;
455 std::vector<int> myFacesWithLayers;
457 // advanced (main params before redesign for 9.6.2)
458 short myCollisionMode;
459 bool myAddMultinormals;
460 bool mySmoothNormals;
461 double myMultinormalsAngle;
464 std::string myWorkingDirectory;
465 short myVerboseLevel;
466 bool myLogInStandardOutput;
467 bool myRemoveLogOnSuccess;
470 TOptionValues _option2value, _customOption2value; // user defined values
471 TOptionValues _defaultOptionValues; // default values
472 TOptionNames _doubleOptions, _charOptions, _boolOptions; // to find a type of option
474 short myOptimizationLevel; // missing from plugin
475 bool myToMakeGroupsOfDomains; // missing from plugin
477 bool myToMeshHoles; // missing from hybrid
478 double myMaximumMemory; // missing from hybrid
479 double myInitialMemory; // missing from hybrid
480 bool myToCreateNewNodes; // missing from hybrid
481 bool myToUseBoundaryRecoveryVersion; // missing from hybrid
482 bool myToUseFemCorrection; // missing from hybrid
483 bool myToRemoveCentralPoint; // missing from hybrid
486 THYBRIDEnforcedVertexList _enfVertexList;
487 THYBRIDEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
488 THYBRIDEnforcedVertexEntryValues _enfVertexEntrySizeList;
489 // map to get "manual" enf vertex (through the coordinates)
490 TCoordsHYBRIDEnforcedVertexMap _coordsEnfVertexMap;
491 // map to get "geom" enf vertex (through the geom entries)
492 TGeomEntryHYBRIDEnforcedVertexMap _geomEntryEnfVertexMap;
495 THYBRIDEnforcedMeshList _enfMeshList;
496 // map to get enf meshes through the entries
497 TEntryHYBRIDEnforcedMeshListMap _entryEnfMeshMap;
498 TIDSortedNodeGroupMap _enfNodes;
499 TIDSortedElemGroupMap _enfEdges;
500 TIDSortedElemGroupMap _enfTriangles;
501 TID2SizeMap _nodeIDToSizeMap;
502 std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
504 TSetStrings _groupsToRemove;