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, 2-Generation_Cartesian_Core. Default is Generation_Tetra_Dominant
177 enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant, Generation_Cartesian_Core };
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 * Set core elements size.
207 void SetCoreSize(double CS);
208 double GetCoreSize() const;
210 * To set multinormals angle threshold at opening ridges.
213 void SetMultinormalsAngle(double MNA);
214 double GetMultinormalsAngle() const;
216 * To set number of boundary layers.
219 void SetNbOfBoundaryLayers(short NBL);
220 short GetNbOfBoundaryLayers() const;
224 * Path to working directory
226 void SetWorkingDirectory(const std::string& path);
227 std::string GetWorkingDirectory() const;
229 * To keep working files or remove them. Log file remains in case of errors anyway.
231 void SetKeepFiles(bool toKeep);
232 bool GetKeepFiles() const;
234 * Verbose level [0-10]
235 * 0 - no standard output,
236 * 2 - prints the data, quality statistics of the skin and final meshes and
237 * indicates when the final mesh is being saved. In addition the software
238 * gives indication regarding the CPU time.
239 * 10 - same as 2 plus the main steps in the computation, quality statistics
240 * histogram of the skin mesh, quality statistics histogram together with
241 * the characteristics of the final mesh.
243 void SetVerboseLevel(short level);
244 short GetVerboseLevel() const;
246 * To create new nodes
248 void SetToCreateNewNodes(bool toCreate);
249 bool GetToCreateNewNodes() const;
251 * To use boundary recovery version which tries to create mesh on a very poor
252 * quality surface mesh
254 void SetToUseBoundaryRecoveryVersion(bool toUse);
255 bool GetToUseBoundaryRecoveryVersion() const;
257 * Applies finite-element correction by replacing overconstrained elements where
258 * it is possible. The process is cutting first the overconstrained edges and
259 * second the overconstrained facets. This insure that no edges have two boundary
260 * vertices and that no facets have three boundary vertices.
262 void SetFEMCorrection(bool toUseFem);
263 bool GetFEMCorrection() const;
265 * To removes initial central point.
267 void SetToRemoveCentralPoint(bool toRemove);
268 bool GetToRemoveCentralPoint() const;
270 * To set hiden/undocumented/advanced options
272 void SetAdvancedOption(const std::string& option);
273 std::string GetAdvancedOption() const;
275 * To define the volumic gradation
277 void SetGradation(double gradation);
278 double GetGradation() const ;
280 * Print log in standard output
282 void SetStandardOutputLog(bool logInStandardOutput);
283 bool GetStandardOutputLog() const ;
285 * Remove log file on success
287 void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
288 bool GetRemoveLogOnSuccess() const ;
291 // struct TEnforcedEdge {
295 // std::string groupName;
300 * \brief Return command to run hybrid mesher excluding file prefix (-f)
302 static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp, SMESH_Mesh& mesh);
304 * \brief Return a unique file name
306 static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
308 * \brief Return the name of executable
310 static std::string GetExeName();
312 * \brief Return a tag of enforced triangles
314 static int EnforcedTag() { return -5; }
317 * To set an enforced vertex
319 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
320 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
321 THYBRIDEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
322 THYBRIDEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
323 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
324 const THYBRIDEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
325 const THYBRIDEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
326 const THYBRIDEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; }
327 const TCoordsHYBRIDEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
328 const TGeomEntryHYBRIDEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
329 void ClearEnforcedVertices();
332 * To set enforced elements
334 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
335 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
336 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
337 const THYBRIDEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
338 const TEntryHYBRIDEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
339 void ClearEnforcedMeshes();
340 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
341 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
342 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
343 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
344 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
345 void RestoreEnfElemsByMeshes(); // persistence
347 * \brief Return the enforced vertices
349 static THYBRIDEnforcedVertexList GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp);
350 static THYBRIDEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const HYBRIDPlugin_Hypothesis* hyp);
351 static THYBRIDEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const HYBRIDPlugin_Hypothesis* hyp);
352 static TCoordsHYBRIDEnforcedVertexMap GetEnforcedVerticesByCoords(const HYBRIDPlugin_Hypothesis* hyp);
353 static TGeomEntryHYBRIDEnforcedVertexMap GetEnforcedVerticesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
355 static THYBRIDEnforcedMeshList GetEnforcedMeshes(const HYBRIDPlugin_Hypothesis* hyp);
356 static TEntryHYBRIDEnforcedMeshListMap GetEnforcedMeshesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
357 static TIDSortedNodeGroupMap GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp);
358 static TIDSortedElemGroupMap GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp);
359 static TIDSortedElemGroupMap GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp);
360 static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp);
361 static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp);
362 static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp);
363 void ClearGroupsToRemove();
365 static bool DefaultMeshHoles();
366 static bool DefaultLayersOnAllWrap();
367 static bool DefaultToMakeGroupsOfDomains();
368 static double DefaultMaximumMemory();
369 static double DefaultInitialMemory();
370 static short DefaultOptimizationLevel();
371 static short DefaultCollisionMode();
372 static short DefaultBoundaryLayersGrowth();
373 static short DefaultElementGeneration();
374 static std::string DefaultWorkingDirectory();
375 static bool DefaultKeepFiles();
376 static short DefaultVerboseLevel();
377 static bool DefaultToCreateNewNodes();
378 static bool DefaultToUseBoundaryRecoveryVersion();
379 static bool DefaultToUseFEMCorrection();
380 static bool DefaultToRemoveCentralPoint();
381 static bool DefaultStandardOutputLog();
382 static bool DefaultRemoveLogOnSuccess();
383 static double DefaultGradation();
384 static bool DefaultAddMultinormals();
385 static bool DefaultSmoothNormals();
386 static short DefaultNbOfBoundaryLayers();
387 static double DefaultHeightFirstLayer();
388 static double DefaultBoundaryLayersProgression();
389 static double DefaultCoreSize();
390 static double DefaultMultinormalsAngle();
392 static THYBRIDEnforcedVertex DefaultHYBRIDEnforcedVertex() {return THYBRIDEnforcedVertex();}
393 static THYBRIDEnforcedVertexList DefaultHYBRIDEnforcedVertexList() {return THYBRIDEnforcedVertexList();}
394 static THYBRIDEnforcedVertexCoordsValues DefaultHYBRIDEnforcedVertexCoordsValues() {return THYBRIDEnforcedVertexCoordsValues();}
395 static THYBRIDEnforcedVertexEntryValues DefaultHYBRIDEnforcedVertexEntryValues() {return THYBRIDEnforcedVertexEntryValues();}
396 static TCoordsHYBRIDEnforcedVertexMap DefaultCoordsHYBRIDEnforcedVertexMap() {return TCoordsHYBRIDEnforcedVertexMap();}
397 static TGeomEntryHYBRIDEnforcedVertexMap DefaultGeomEntryHYBRIDEnforcedVertexMap() {return TGeomEntryHYBRIDEnforcedVertexMap();}
398 static TGroupNameHYBRIDEnforcedVertexMap DefaultGroupNameHYBRIDEnforcedVertexMap() {return TGroupNameHYBRIDEnforcedVertexMap();}
400 static THYBRIDEnforcedMesh DefaultHYBRIDEnforcedMesh() {return THYBRIDEnforcedMesh();}
401 static THYBRIDEnforcedMeshList DefaultHYBRIDEnforcedMeshList() {return THYBRIDEnforcedMeshList();}
402 static TEntryHYBRIDEnforcedMeshListMap DefaultEntryHYBRIDEnforcedMeshListMap() {return TEntryHYBRIDEnforcedMeshListMap();}
403 static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
404 static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
405 static TID2SizeMap DefaultID2SizeMap() {return TID2SizeMap();}
406 static TSetStrings DefaultGroupsToRemove() {return TSetStrings();}
409 virtual std::ostream & SaveTo(std::ostream & save);
410 virtual std::istream & LoadFrom(std::istream & load);
411 friend HYBRIDPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, HYBRIDPlugin_Hypothesis & hyp);
412 friend HYBRIDPLUGIN_EXPORT std::istream & operator >>(std::istream & load, HYBRIDPlugin_Hypothesis & hyp);
415 * \brief Does nothing
417 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
420 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
422 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
427 bool myLayersOnAllWrap;
428 std::vector<int> myFacesWithLayers;
429 bool myToMakeGroupsOfDomains;
430 double myMaximumMemory;
431 double myInitialMemory;
432 short myOptimizationLevel;
433 short myCollisionMode;
434 short myBoundaryLayersGrowth;
435 short myElementGeneration;
437 std::string myWorkingDirectory;
438 short myVerboseLevel;
439 bool myToCreateNewNodes;
440 bool myToUseBoundaryRecoveryVersion;
441 bool myToUseFemCorrection;
442 bool myToRemoveCentralPoint;
443 bool myLogInStandardOutput;
444 bool myRemoveLogOnSuccess;
445 std::string myTextOption;
448 bool myAddMultinormals;
449 bool mySmoothNormals;
450 double myHeightFirstLayer;
451 double myBoundaryLayersProgression;
453 double myMultinormalsAngle;
454 short myNbOfBoundaryLayers;
456 THYBRIDEnforcedVertexList _enfVertexList;
457 THYBRIDEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
458 THYBRIDEnforcedVertexEntryValues _enfVertexEntrySizeList;
459 // map to get "manual" enf vertex (through the coordinates)
460 TCoordsHYBRIDEnforcedVertexMap _coordsEnfVertexMap;
461 // map to get "geom" enf vertex (through the geom entries)
462 TGeomEntryHYBRIDEnforcedVertexMap _geomEntryEnfVertexMap;
465 THYBRIDEnforcedMeshList _enfMeshList;
466 // map to get enf meshes through the entries
467 TEntryHYBRIDEnforcedMeshListMap _entryEnfMeshMap;
468 TIDSortedNodeGroupMap _enfNodes;
469 TIDSortedElemGroupMap _enfEdges;
470 TIDSortedElemGroupMap _enfTriangles;
471 TID2SizeMap _nodeIDToSizeMap;
472 std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
474 TSetStrings _groupsToRemove;