1 // Copyright (C) 2007-2016 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, int studyId, 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->getMeshId() == e2->getMeshId() ? e1->GetID() < e2->GetID() : e1->getMeshId() < e2->getMeshId() ; }
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"; }
123 * To mesh "holes" in a solid or not. Default is to mesh.
125 void SetToMeshHoles(bool toMesh);
126 bool GetToMeshHoles(bool checkFreeOption = false) const;
128 * To mesh layers on all wrap. Default is yes.
130 void SetLayersOnAllWrap(bool toMesh);
131 bool GetLayersOnAllWrap(bool checkFreeOption = false) const;
133 * IDs of faces to grow the layers on
135 bool SetFacesWithLayers(const std::vector<int>& theVal);
136 const std::vector<int>& GetFacesWithLayers() const;
138 * To make groups of volumes of different domains when mesh is generated from skin.
139 * Default is to make groups.
140 * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
142 void SetToMakeGroupsOfDomains(bool toMakeGroups);
143 bool GetToMakeGroupsOfDomains() const;
145 * Maximal size of memory to be used by the algorithm (in Megabytes)
147 void SetMaximumMemory(double MB);
148 double GetMaximumMemory() const;
150 * Initial size of memory to be used by the algorithm (in Megabytes) in
151 * automatic memory adjustment mode. Default is zero
153 void SetInitialMemory(double MB);
154 double GetInitialMemory() const;
156 * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
158 enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
159 void SetOptimizationLevel(OptimizationLevel level);
160 OptimizationLevel GetOptimizationLevel() const;
163 * Collision Mode: 0-decrease, 1-stop. Default is decrease
165 enum CollisionMode { Decrease = 0, Stop };
166 void SetCollisionMode(CollisionMode level);
167 CollisionMode GetCollisionMode() const;
169 * BoundaryLayersGrowth: 0-Layer_Growth_Inward, 1-Layer_Growth_Outward. Default is Layer_Growth_Inward
171 enum BoundaryLayersGrowth { Layer_Growth_Inward = 0, Layer_Growth_Outward };
172 void SetBoundaryLayersGrowth(BoundaryLayersGrowth level);
173 BoundaryLayersGrowth GetBoundaryLayersGrowth() const;
175 * ElementGeneration: 0-Generation_Tetra_Dominant, 1-Generation_Hexa_Dominant. Default is Generation_Tetra_Dominant
177 enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant };
178 void SetElementGeneration(ElementGeneration level);
179 ElementGeneration GetElementGeneration() const;
181 * To mesh adding extra normals at opening ridges and corners.
184 void SetAddMultinormals(bool toAddMultinormals);
185 bool GetAddMultinormals() const;
187 * To mesh smoothing normals at closed ridges and corners.
190 void SetSmoothNormals(bool toSmoothNormals);
191 bool GetSmoothNormals() const;
193 * To set height of the first layer.
195 void SetHeightFirstLayer(double HFL);
196 double GetHeightFirstLayer() const;
198 * To set boundary layers coefficient of geometric progression.
201 void SetBoundaryLayersProgression(double BLP);
202 double GetBoundaryLayersProgression() const;
204 * To set multinormals angle threshold at opening ridges.
207 void SetMultinormalsAngle(double MNA);
208 double GetMultinormalsAngle() const;
210 * To set number of boundary layers.
213 void SetNbOfBoundaryLayers(short NBL);
214 short GetNbOfBoundaryLayers() const;
218 * Path to working directory
220 void SetWorkingDirectory(const std::string& path);
221 std::string GetWorkingDirectory() const;
223 * To keep working files or remove them. Log file remains in case of errors anyway.
225 void SetKeepFiles(bool toKeep);
226 bool GetKeepFiles() const;
228 * Verbose level [0-10]
229 * 0 - no standard output,
230 * 2 - prints the data, quality statistics of the skin and final meshes and
231 * indicates when the final mesh is being saved. In addition the software
232 * gives indication regarding the CPU time.
233 * 10 - same as 2 plus the main steps in the computation, quality statistics
234 * histogram of the skin mesh, quality statistics histogram together with
235 * the characteristics of the final mesh.
237 void SetVerboseLevel(short level);
238 short GetVerboseLevel() const;
240 * To create new nodes
242 void SetToCreateNewNodes(bool toCreate);
243 bool GetToCreateNewNodes() const;
245 * To use boundary recovery version which tries to create mesh on a very poor
246 * quality surface mesh
248 void SetToUseBoundaryRecoveryVersion(bool toUse);
249 bool GetToUseBoundaryRecoveryVersion() const;
251 * Applies finite-element correction by replacing overconstrained elements where
252 * it is possible. The process is cutting first the overconstrained edges and
253 * second the overconstrained facets. This insure that no edges have two boundary
254 * vertices and that no facets have three boundary vertices.
256 void SetFEMCorrection(bool toUseFem);
257 bool GetFEMCorrection() const;
259 * To removes initial central point.
261 void SetToRemoveCentralPoint(bool toRemove);
262 bool GetToRemoveCentralPoint() const;
264 * To set hiden/undocumented/advanced options
266 void SetAdvancedOption(const std::string& option);
267 std::string GetAdvancedOption() const;
269 * To define the volumic gradation
271 void SetGradation(double gradation);
272 double GetGradation() const ;
274 * Print log in standard output
276 void SetStandardOutputLog(bool logInStandardOutput);
277 bool GetStandardOutputLog() const ;
279 * Remove log file on success
281 void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
282 bool GetRemoveLogOnSuccess() const ;
285 // struct TEnforcedEdge {
289 // std::string groupName;
294 * \brief Return command to run hybrid mesher excluding file prefix (-f)
296 static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp, SMESH_Mesh& mesh);
298 * \brief Return a unique file name
300 static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
302 * \brief Return the name of executable
304 static std::string GetExeName();
306 * \brief Return a tag of enforced triangles
308 static int EnforcedTag() { return -5; }
311 * To set an enforced vertex
313 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
314 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
315 THYBRIDEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
316 THYBRIDEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
317 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
318 const THYBRIDEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
319 const THYBRIDEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
320 const THYBRIDEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; }
321 const TCoordsHYBRIDEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
322 const TGeomEntryHYBRIDEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
323 void ClearEnforcedVertices();
326 * To set enforced elements
328 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
329 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
330 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
331 const THYBRIDEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
332 const TEntryHYBRIDEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
333 void ClearEnforcedMeshes();
334 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
335 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
336 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
337 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
338 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
339 void RestoreEnfElemsByMeshes(); // persistence
341 * \brief Return the enforced vertices
343 static THYBRIDEnforcedVertexList GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp);
344 static THYBRIDEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const HYBRIDPlugin_Hypothesis* hyp);
345 static THYBRIDEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const HYBRIDPlugin_Hypothesis* hyp);
346 static TCoordsHYBRIDEnforcedVertexMap GetEnforcedVerticesByCoords(const HYBRIDPlugin_Hypothesis* hyp);
347 static TGeomEntryHYBRIDEnforcedVertexMap GetEnforcedVerticesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
349 static THYBRIDEnforcedMeshList GetEnforcedMeshes(const HYBRIDPlugin_Hypothesis* hyp);
350 static TEntryHYBRIDEnforcedMeshListMap GetEnforcedMeshesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
351 static TIDSortedNodeGroupMap GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp);
352 static TIDSortedElemGroupMap GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp);
353 static TIDSortedElemGroupMap GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp);
354 static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp);
355 static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp);
356 static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp);
357 void ClearGroupsToRemove();
359 static bool DefaultMeshHoles();
360 static bool DefaultLayersOnAllWrap();
361 static bool DefaultToMakeGroupsOfDomains();
362 static double DefaultMaximumMemory();
363 static double DefaultInitialMemory();
364 static short DefaultOptimizationLevel();
365 static short DefaultCollisionMode();
366 static short DefaultBoundaryLayersGrowth();
367 static short DefaultElementGeneration();
368 static std::string DefaultWorkingDirectory();
369 static bool DefaultKeepFiles();
370 static short DefaultVerboseLevel();
371 static bool DefaultToCreateNewNodes();
372 static bool DefaultToUseBoundaryRecoveryVersion();
373 static bool DefaultToUseFEMCorrection();
374 static bool DefaultToRemoveCentralPoint();
375 static bool DefaultStandardOutputLog();
376 static bool DefaultRemoveLogOnSuccess();
377 static double DefaultGradation();
378 static bool DefaultAddMultinormals();
379 static bool DefaultSmoothNormals();
380 static short DefaultNbOfBoundaryLayers();
381 static double DefaultHeightFirstLayer();
382 static double DefaultBoundaryLayersProgression();
383 static double DefaultMultinormalsAngle();
385 static THYBRIDEnforcedVertex DefaultHYBRIDEnforcedVertex() {return THYBRIDEnforcedVertex();}
386 static THYBRIDEnforcedVertexList DefaultHYBRIDEnforcedVertexList() {return THYBRIDEnforcedVertexList();}
387 static THYBRIDEnforcedVertexCoordsValues DefaultHYBRIDEnforcedVertexCoordsValues() {return THYBRIDEnforcedVertexCoordsValues();}
388 static THYBRIDEnforcedVertexEntryValues DefaultHYBRIDEnforcedVertexEntryValues() {return THYBRIDEnforcedVertexEntryValues();}
389 static TCoordsHYBRIDEnforcedVertexMap DefaultCoordsHYBRIDEnforcedVertexMap() {return TCoordsHYBRIDEnforcedVertexMap();}
390 static TGeomEntryHYBRIDEnforcedVertexMap DefaultGeomEntryHYBRIDEnforcedVertexMap() {return TGeomEntryHYBRIDEnforcedVertexMap();}
391 static TGroupNameHYBRIDEnforcedVertexMap DefaultGroupNameHYBRIDEnforcedVertexMap() {return TGroupNameHYBRIDEnforcedVertexMap();}
393 static THYBRIDEnforcedMesh DefaultHYBRIDEnforcedMesh() {return THYBRIDEnforcedMesh();}
394 static THYBRIDEnforcedMeshList DefaultHYBRIDEnforcedMeshList() {return THYBRIDEnforcedMeshList();}
395 static TEntryHYBRIDEnforcedMeshListMap DefaultEntryHYBRIDEnforcedMeshListMap() {return TEntryHYBRIDEnforcedMeshListMap();}
396 static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
397 static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
398 static TID2SizeMap DefaultID2SizeMap() {return TID2SizeMap();}
399 static TSetStrings DefaultGroupsToRemove() {return TSetStrings();}
402 virtual std::ostream & SaveTo(std::ostream & save);
403 virtual std::istream & LoadFrom(std::istream & load);
404 friend HYBRIDPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, HYBRIDPlugin_Hypothesis & hyp);
405 friend HYBRIDPLUGIN_EXPORT std::istream & operator >>(std::istream & load, HYBRIDPlugin_Hypothesis & hyp);
408 * \brief Does nothing
410 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
413 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
415 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
420 bool myLayersOnAllWrap;
421 std::vector<int> myFacesWithLayers;
422 bool myToMakeGroupsOfDomains;
423 double myMaximumMemory;
424 double myInitialMemory;
425 short myOptimizationLevel;
426 short myCollisionMode;
427 short myBoundaryLayersGrowth;
428 short myElementGeneration;
430 std::string myWorkingDirectory;
431 short myVerboseLevel;
432 bool myToCreateNewNodes;
433 bool myToUseBoundaryRecoveryVersion;
434 bool myToUseFemCorrection;
435 bool myToRemoveCentralPoint;
436 bool myLogInStandardOutput;
437 bool myRemoveLogOnSuccess;
438 std::string myTextOption;
441 bool myAddMultinormals;
442 bool mySmoothNormals;
443 double myHeightFirstLayer;
444 double myBoundaryLayersProgression;
445 double myMultinormalsAngle;
446 short myNbOfBoundaryLayers;
448 THYBRIDEnforcedVertexList _enfVertexList;
449 THYBRIDEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
450 THYBRIDEnforcedVertexEntryValues _enfVertexEntrySizeList;
451 // map to get "manual" enf vertex (through the coordinates)
452 TCoordsHYBRIDEnforcedVertexMap _coordsEnfVertexMap;
453 // map to get "geom" enf vertex (through the geom entries)
454 TGeomEntryHYBRIDEnforcedVertexMap _geomEntryEnfVertexMap;
457 THYBRIDEnforcedMeshList _enfMeshList;
458 // map to get enf meshes through the entries
459 TEntryHYBRIDEnforcedMeshListMap _entryEnfMeshMap;
460 TIDSortedNodeGroupMap _enfNodes;
461 TIDSortedElemGroupMap _enfEdges;
462 TIDSortedElemGroupMap _enfTriangles;
463 TID2SizeMap _nodeIDToSizeMap;
464 std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
466 TSetStrings _groupsToRemove;