Salome HOME
Merge V9_dev branch into master
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPlugin_Hypothesis.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File   : HYBRIDPlugin_Hypothesis.hxx
22 // Author : Christian VAN WAMBEKE (CEA)
23 // ---
24 //
25 #ifndef HYBRIDPlugin_Hypothesis_HeaderFile
26 #define HYBRIDPlugin_Hypothesis_HeaderFile
27
28 #include "HYBRIDPlugin_Defs.hxx"
29
30 #include <SMDS_MeshNode.hxx>
31
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"
37
38 #include <stdexcept>
39 #include <map>
40 #include <vector>
41 #include <cstdio>
42
43 class HYBRIDPLUGIN_EXPORT HYBRIDPlugin_Hypothesis: public SMESH_Hypothesis
44 {
45 public:
46
47   HYBRIDPlugin_Hypothesis(int hypId, SMESH_Gen * gen);
48
49   typedef std::map<std::vector<double>,double> THYBRIDEnforcedVertexCoordsValues;
50   typedef std::map<std::string,double> THYBRIDEnforcedVertexEntryValues;
51   
52   struct THYBRIDEnforcedVertex {
53     std::string name;
54     std::string geomEntry;
55     bool isCompound;
56     std::vector<double> coords;
57     std::string groupName;
58     double size;
59   };
60   
61   struct CompareHYBRIDEnforcedVertex {
62     bool operator () (const THYBRIDEnforcedVertex* e1, const THYBRIDEnforcedVertex* e2) const {
63       if (e1 && e2) {
64         if (e1->coords.size() && e2->coords.size())
65           return (e1->coords < e2->coords);
66         else
67           return (e1->geomEntry < e2->geomEntry);
68       }
69       return false;
70     }
71   };
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;
79   
80   ////////////////////
81   // Enforced meshes
82   ////////////////////
83   
84   struct THYBRIDEnforcedMesh {
85     int         persistID;
86     std::string name;
87     std::string entry;
88     std::string groupName;
89     SMESH::ElementType elementType;
90   };
91   
92   struct CompareHYBRIDEnforcedMesh {
93     bool operator () (const THYBRIDEnforcedMesh* e1, const THYBRIDEnforcedMesh* e2) const {
94       if (e1 && e2) {
95         if (e1->entry == e2->entry)
96           return (e1->elementType < e2->elementType);
97         else
98           return (e1->entry < e2->entry);
99       }
100       else
101         return false;
102     }
103   };
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;
109   
110   typedef std::map<int,double> TID2SizeMap;
111
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(); }
115   };
116   
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;
120
121   static const char* GetHypType() { return "HYBRID_Parameters"; }
122   /*!
123    * To mesh "holes" in a solid or not. Default is to mesh.
124    */
125   void SetToMeshHoles(bool toMesh);
126   bool GetToMeshHoles(bool checkFreeOption = false) const;
127   /*!
128    * To mesh layers on all wrap. Default is yes.
129    */
130   void SetLayersOnAllWrap(bool toMesh);
131   bool GetLayersOnAllWrap(bool checkFreeOption = false) const;
132   /*!
133    * IDs of faces to grow the layers on
134    */
135   bool SetFacesWithLayers(const std::vector<int>& theVal);
136   const std::vector<int>& GetFacesWithLayers() const;
137   /*!
138    * IDs of faces to imprint the layers on
139    */
140   bool SetFacesWithImprinting(const std::vector<int>& theVal);
141   const std::vector<int>& GetFacesWithImprinting() const;
142   /*!
143    * To make groups of volumes of different domains when mesh is generated from skin.
144    * Default is to make groups.
145    * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
146    */
147   void SetToMakeGroupsOfDomains(bool toMakeGroups);
148   bool GetToMakeGroupsOfDomains() const;
149   /*!
150    * Maximal size of memory to be used by the algorithm (in Megabytes)
151    */
152   void SetMaximumMemory(double MB);
153   double GetMaximumMemory() const;
154   /*!
155    * Initial size of memory to be used by the algorithm (in Megabytes) in
156    * automatic memory adjustment mode. Default is zero
157    */
158   void SetInitialMemory(double MB);
159   double GetInitialMemory() const;
160   /*!
161    * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
162    */
163   enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
164   void SetOptimizationLevel(OptimizationLevel level);
165   OptimizationLevel GetOptimizationLevel() const;
166
167   /*!
168    * Collision Mode: 0-decrease, 1-stop. Default is decrease
169    */
170   enum CollisionMode { Decrease = 0, Stop };
171   void SetCollisionMode(CollisionMode level);
172   CollisionMode GetCollisionMode() const;
173   /*!
174    * BoundaryLayersGrowth: 0-Layer_Growth_Inward, 1-Layer_Growth_Outward. Default is Layer_Growth_Inward
175    */
176   enum BoundaryLayersGrowth { Layer_Growth_Inward = 0, Layer_Growth_Outward };
177   void SetBoundaryLayersGrowth(BoundaryLayersGrowth level);
178   BoundaryLayersGrowth GetBoundaryLayersGrowth() const;
179   /*!
180    * ElementGeneration: 0-Generation_Tetra_Dominant, 1-Generation_Hexa_Dominant, 2-Generation_Cartesian_Core. Default is Generation_Tetra_Dominant
181    */
182   enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant, Generation_Cartesian_Core };
183   void SetElementGeneration(ElementGeneration level);
184   ElementGeneration GetElementGeneration() const;
185     /*!
186      * To mesh adding extra normals at opening ridges and corners.
187      * Default is no.
188      */
189     void SetAddMultinormals(bool toAddMultinormals);
190     bool GetAddMultinormals() const;
191     /*!
192      * To mesh smoothing normals at closed ridges and corners.
193      * Default is no.
194      */
195     void SetSmoothNormals(bool toSmoothNormals);
196     bool GetSmoothNormals() const;
197     /*!
198      * To set height of the first layer.
199      */
200     void SetHeightFirstLayer(double HFL);
201     double GetHeightFirstLayer() const;
202     /*!
203      * To set boundary layers coefficient of geometric progression.
204      * Default is 1.0
205      */
206     void SetBoundaryLayersProgression(double BLP);
207     double GetBoundaryLayersProgression() const;
208     /*!
209      * Set core elements size.
210      * Default is 0.0
211      */
212     void SetCoreSize(double CS);
213     double GetCoreSize() const;
214     /*!
215      * To set multinormals angle threshold at opening ridges.
216      * Default is 30.0
217      */
218     void SetMultinormalsAngle(double MNA);
219     double GetMultinormalsAngle() const;
220     /*!
221      * To set number of boundary layers.
222      * Default is 1
223      */
224     void SetNbOfBoundaryLayers(short NBL);
225     short GetNbOfBoundaryLayers() const;
226
227
228   /*!
229    * Path to working directory
230    */
231   void SetWorkingDirectory(const std::string& path);
232   std::string GetWorkingDirectory() const;
233   /*!
234    * To keep working files or remove them. Log file remains in case of errors anyway.
235    */
236   void SetKeepFiles(bool toKeep);
237   bool GetKeepFiles() const;
238   /*!
239    * Verbose level [0-10]
240    *  0 - no standard output,
241    *  2 - prints the data, quality statistics of the skin and final meshes and
242    *     indicates when the final mesh is being saved. In addition the software
243    *     gives indication regarding the CPU time.
244    * 10 - same as 2 plus the main steps in the computation, quality statistics
245    *     histogram of the skin mesh, quality statistics histogram together with
246    *     the characteristics of the final mesh.
247    */
248   void SetVerboseLevel(short level);
249   short GetVerboseLevel() const;
250   /*!
251    * To create new nodes
252    */
253   void SetToCreateNewNodes(bool toCreate);
254   bool GetToCreateNewNodes() const;
255   /*!
256    * To use boundary recovery version which tries to create mesh on a very poor
257    * quality surface mesh
258    */
259   void SetToUseBoundaryRecoveryVersion(bool toUse);
260   bool GetToUseBoundaryRecoveryVersion() const;
261   /*!
262    * Applies finite-element correction by replacing overconstrained elements where
263    * it is possible. The process is cutting first the overconstrained edges and
264    * second the overconstrained facets. This insure that no edges have two boundary
265    * vertices and that no facets have three boundary vertices.
266    */
267   void SetFEMCorrection(bool toUseFem);
268   bool GetFEMCorrection() const;
269   /*!
270    * To removes initial central point.
271    */
272   void SetToRemoveCentralPoint(bool toRemove);
273   bool GetToRemoveCentralPoint() const;
274   /*!
275    * To set hiden/undocumented/advanced options
276    */
277   void SetAdvancedOption(const std::string& option);
278   std::string GetAdvancedOption() const;
279   /*!
280   * To define the volumic gradation
281   */
282   void SetGradation(double gradation);
283   double GetGradation() const ;
284   /*!
285   * Print log in standard output
286   */
287   void SetStandardOutputLog(bool logInStandardOutput);
288   bool GetStandardOutputLog() const ;
289   /*!
290   * Remove log file on success
291   */
292   void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
293   bool GetRemoveLogOnSuccess() const ;
294     
295   
296 //   struct TEnforcedEdge {
297 //     long ID;
298 //     long node1;
299 //     long node2;
300 //     std::string groupName;
301 //   };
302   
303
304   /*!
305    * \brief Return command to run hybrid mesher excluding file prefix (-f)
306    */
307   static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp, SMESH_Mesh& mesh);
308   /*!
309    * \brief Return a unique file name
310    */
311   static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
312   /*!
313    * \brief Return the name of executable
314    */
315   static std::string GetExeName();
316   /*!
317    * \brief Return a tag of enforced triangles
318    */
319   static int EnforcedTag() { return -5; }
320
321   /*!
322    * To set an enforced vertex
323    */
324   bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
325                          double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
326   THYBRIDEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
327   THYBRIDEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
328   bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
329   const THYBRIDEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
330   const THYBRIDEnforcedVertexEntryValues  _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
331   const THYBRIDEnforcedVertexList         _GetEnforcedVertices() const { return _enfVertexList; }
332   const TCoordsHYBRIDEnforcedVertexMap    _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
333   const TGeomEntryHYBRIDEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
334   void ClearEnforcedVertices();
335
336   /*!
337    * To set enforced elements
338    */
339   bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
340   bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
341   bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
342   const THYBRIDEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
343   const TEntryHYBRIDEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
344   void ClearEnforcedMeshes();
345   const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
346   const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
347   const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
348   const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
349   const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
350   void RestoreEnfElemsByMeshes(); // persistence
351   /*!
352    * \brief Return the enforced vertices
353    */
354   static THYBRIDEnforcedVertexList GetEnforcedVertices(const HYBRIDPlugin_Hypothesis* hyp);
355   static THYBRIDEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const HYBRIDPlugin_Hypothesis* hyp);
356   static THYBRIDEnforcedVertexEntryValues  GetEnforcedVerticesEntrySize(const HYBRIDPlugin_Hypothesis* hyp);
357   static TCoordsHYBRIDEnforcedVertexMap GetEnforcedVerticesByCoords(const HYBRIDPlugin_Hypothesis* hyp);
358   static TGeomEntryHYBRIDEnforcedVertexMap GetEnforcedVerticesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
359   
360   static THYBRIDEnforcedMeshList GetEnforcedMeshes(const HYBRIDPlugin_Hypothesis* hyp);
361   static TEntryHYBRIDEnforcedMeshListMap GetEnforcedMeshesByEntry(const HYBRIDPlugin_Hypothesis* hyp);
362   static TIDSortedNodeGroupMap GetEnforcedNodes(const HYBRIDPlugin_Hypothesis* hyp);
363   static TIDSortedElemGroupMap GetEnforcedEdges(const HYBRIDPlugin_Hypothesis* hyp);
364   static TIDSortedElemGroupMap GetEnforcedTriangles(const HYBRIDPlugin_Hypothesis* hyp);
365   static TID2SizeMap GetNodeIDToSizeMap(const HYBRIDPlugin_Hypothesis* hyp);
366   static TSetStrings GetGroupsToRemove(const HYBRIDPlugin_Hypothesis* hyp);
367   static bool GetToMakeGroupsOfDomains(const HYBRIDPlugin_Hypothesis* hyp);
368   void ClearGroupsToRemove();
369   
370   static bool   DefaultMeshHoles();
371   static bool   DefaultLayersOnAllWrap();
372   static bool   DefaultToMakeGroupsOfDomains();
373   static double DefaultMaximumMemory();
374   static double DefaultInitialMemory();
375   static short  DefaultOptimizationLevel();
376   static short  DefaultCollisionMode();
377   static short  DefaultBoundaryLayersGrowth();
378   static short  DefaultElementGeneration();
379   static std::string DefaultWorkingDirectory();
380   static bool   DefaultKeepFiles();
381   static short  DefaultVerboseLevel();
382   static bool   DefaultToCreateNewNodes();
383   static bool   DefaultToUseBoundaryRecoveryVersion();
384   static bool   DefaultToUseFEMCorrection();
385   static bool   DefaultToRemoveCentralPoint();
386   static bool   DefaultStandardOutputLog();
387   static bool   DefaultRemoveLogOnSuccess();
388   static double DefaultGradation();
389   static bool   DefaultAddMultinormals();
390   static bool   DefaultSmoothNormals();
391   static short  DefaultNbOfBoundaryLayers();
392   static double DefaultHeightFirstLayer();
393   static double DefaultBoundaryLayersProgression();
394   static double DefaultCoreSize();
395   static double DefaultMultinormalsAngle();
396     
397   static THYBRIDEnforcedVertex DefaultHYBRIDEnforcedVertex() {return THYBRIDEnforcedVertex();}
398   static THYBRIDEnforcedVertexList DefaultHYBRIDEnforcedVertexList() {return THYBRIDEnforcedVertexList();}
399   static THYBRIDEnforcedVertexCoordsValues DefaultHYBRIDEnforcedVertexCoordsValues() {return THYBRIDEnforcedVertexCoordsValues();}
400   static THYBRIDEnforcedVertexEntryValues DefaultHYBRIDEnforcedVertexEntryValues() {return THYBRIDEnforcedVertexEntryValues();}
401   static TCoordsHYBRIDEnforcedVertexMap DefaultCoordsHYBRIDEnforcedVertexMap() {return TCoordsHYBRIDEnforcedVertexMap();}
402   static TGeomEntryHYBRIDEnforcedVertexMap DefaultGeomEntryHYBRIDEnforcedVertexMap() {return TGeomEntryHYBRIDEnforcedVertexMap();}
403   static TGroupNameHYBRIDEnforcedVertexMap DefaultGroupNameHYBRIDEnforcedVertexMap() {return TGroupNameHYBRIDEnforcedVertexMap();}
404   
405   static THYBRIDEnforcedMesh        DefaultHYBRIDEnforcedMesh() {return THYBRIDEnforcedMesh();}
406   static THYBRIDEnforcedMeshList    DefaultHYBRIDEnforcedMeshList() {return THYBRIDEnforcedMeshList();}
407   static TEntryHYBRIDEnforcedMeshListMap DefaultEntryHYBRIDEnforcedMeshListMap() {return TEntryHYBRIDEnforcedMeshListMap();}
408   static TIDSortedNodeGroupMap      DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
409   static TIDSortedElemGroupMap      DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
410   static TID2SizeMap                DefaultID2SizeMap() {return TID2SizeMap();}
411   static TSetStrings                DefaultGroupsToRemove() {return TSetStrings();}
412   
413   // Persistence
414   virtual std::ostream & SaveTo(std::ostream & save);
415   virtual std::istream & LoadFrom(std::istream & load);
416   friend HYBRIDPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, HYBRIDPlugin_Hypothesis & hyp);
417   friend HYBRIDPLUGIN_EXPORT std::istream & operator >>(std::istream & load, HYBRIDPlugin_Hypothesis & hyp);
418
419   /*!
420    * \brief Does nothing
421    */
422   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
423
424   /*!
425    * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
426    */
427   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
428
429 private:
430
431   bool             myToMeshHoles;
432   bool             myLayersOnAllWrap;
433   std::vector<int> myFacesWithLayers;
434   std::vector<int> myFacesWithImprinting;
435   bool             myToMakeGroupsOfDomains;
436   double           myMaximumMemory;
437   double           myInitialMemory;
438   short            myOptimizationLevel;
439   short            myCollisionMode;
440   short            myBoundaryLayersGrowth;
441   short            myElementGeneration;
442   bool             myKeepFiles;
443   std::string      myWorkingDirectory;
444   short            myVerboseLevel;
445   bool             myToCreateNewNodes;
446   bool             myToUseBoundaryRecoveryVersion;
447   bool             myToUseFemCorrection;
448   bool             myToRemoveCentralPoint;
449   bool             myLogInStandardOutput;
450   bool             myRemoveLogOnSuccess;
451   std::string      myTextOption;
452   double           myGradation;
453
454   bool             myAddMultinormals;
455   bool             mySmoothNormals;
456   double           myHeightFirstLayer;
457   double           myBoundaryLayersProgression;
458   double           myCoreSize;
459   double           myMultinormalsAngle;
460   short            myNbOfBoundaryLayers;
461    
462   THYBRIDEnforcedVertexList _enfVertexList;
463   THYBRIDEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
464   THYBRIDEnforcedVertexEntryValues _enfVertexEntrySizeList;
465   // map to get "manual" enf vertex (through the coordinates)
466   TCoordsHYBRIDEnforcedVertexMap _coordsEnfVertexMap;
467   // map to get "geom" enf vertex (through the geom entries)
468   TGeomEntryHYBRIDEnforcedVertexMap _geomEntryEnfVertexMap;
469   
470   
471   THYBRIDEnforcedMeshList _enfMeshList;
472   // map to get enf meshes through the entries
473   TEntryHYBRIDEnforcedMeshListMap _entryEnfMeshMap;
474   TIDSortedNodeGroupMap _enfNodes;
475   TIDSortedElemGroupMap _enfEdges;
476   TIDSortedElemGroupMap _enfTriangles;
477   TID2SizeMap _nodeIDToSizeMap;
478   std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
479   
480   TSetStrings _groupsToRemove;
481 };
482
483
484 #endif