Salome HOME
0bbd71861be6e1441669883ac60c8d52536ce7e8
[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, int studyId, 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->getMeshId() == e2->getMeshId() ? e1->GetID() < e2->GetID() : e1->getMeshId() < e2->getMeshId() ; }
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    * 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
141    */
142   void SetToMakeGroupsOfDomains(bool toMakeGroups);
143   bool GetToMakeGroupsOfDomains() const;
144   /*!
145    * Maximal size of memory to be used by the algorithm (in Megabytes)
146    */
147   void SetMaximumMemory(double MB);
148   double GetMaximumMemory() const;
149   /*!
150    * Initial size of memory to be used by the algorithm (in Megabytes) in
151    * automatic memory adjustment mode. Default is zero
152    */
153   void SetInitialMemory(double MB);
154   double GetInitialMemory() const;
155   /*!
156    * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
157    */
158   enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
159   void SetOptimizationLevel(OptimizationLevel level);
160   OptimizationLevel GetOptimizationLevel() const;
161
162   /*!
163    * Collision Mode: 0-decrease, 1-stop. Default is decrease
164    */
165   enum CollisionMode { Decrease = 0, Stop };
166   void SetCollisionMode(CollisionMode level);
167   CollisionMode GetCollisionMode() const;
168   /*!
169    * BoundaryLayersGrowth: 0-Layer_Growth_Inward, 1-Layer_Growth_Outward. Default is Layer_Growth_Inward
170    */
171   enum BoundaryLayersGrowth { Layer_Growth_Inward = 0, Layer_Growth_Outward };
172   void SetBoundaryLayersGrowth(BoundaryLayersGrowth level);
173   BoundaryLayersGrowth GetBoundaryLayersGrowth() const;
174   /*!
175    * ElementGeneration: 0-Generation_Tetra_Dominant, 1-Generation_Hexa_Dominant. Default is Generation_Tetra_Dominant
176    */
177   enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant };
178   void SetElementGeneration(ElementGeneration level);
179   ElementGeneration GetElementGeneration() const;
180     /*!
181      * To mesh adding extra normals at opening ridges and corners.
182      * Default is no.
183      */
184     void SetAddMultinormals(bool toAddMultinormals);
185     bool GetAddMultinormals() const;
186     /*!
187      * To mesh smoothing normals at closed ridges and corners.
188      * Default is no.
189      */
190     void SetSmoothNormals(bool toSmoothNormals);
191     bool GetSmoothNormals() const;
192     /*!
193      * To set height of the first layer.
194      */
195     void SetHeightFirstLayer(double HFL);
196     double GetHeightFirstLayer() const;
197     /*!
198      * To set boundary layers coefficient of geometric progression.
199      * Default is 1.0
200      */
201     void SetBoundaryLayersProgression(double BLP);
202     double GetBoundaryLayersProgression() const;
203     /*!
204      * To set multinormals angle threshold at opening ridges.
205      * Default is 30.0
206      */
207     void SetMultinormalsAngle(double MNA);
208     double GetMultinormalsAngle() const;
209     /*!
210      * To set number of boundary layers.
211      * Default is 1
212      */
213     void SetNbOfBoundaryLayers(short NBL);
214     short GetNbOfBoundaryLayers() const;
215
216
217   /*!
218    * Path to working directory
219    */
220   void SetWorkingDirectory(const std::string& path);
221   std::string GetWorkingDirectory() const;
222   /*!
223    * To keep working files or remove them. Log file remains in case of errors anyway.
224    */
225   void SetKeepFiles(bool toKeep);
226   bool GetKeepFiles() const;
227   /*!
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.
236    */
237   void SetVerboseLevel(short level);
238   short GetVerboseLevel() const;
239   /*!
240    * To create new nodes
241    */
242   void SetToCreateNewNodes(bool toCreate);
243   bool GetToCreateNewNodes() const;
244   /*!
245    * To use boundary recovery version which tries to create mesh on a very poor
246    * quality surface mesh
247    */
248   void SetToUseBoundaryRecoveryVersion(bool toUse);
249   bool GetToUseBoundaryRecoveryVersion() const;
250   /*!
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.
255    */
256   void SetFEMCorrection(bool toUseFem);
257   bool GetFEMCorrection() const;
258   /*!
259    * To removes initial central point.
260    */
261   void SetToRemoveCentralPoint(bool toRemove);
262   bool GetToRemoveCentralPoint() const;
263   /*!
264    * To set hiden/undocumented/advanced options
265    */
266   void SetAdvancedOption(const std::string& option);
267   std::string GetAdvancedOption() const;
268   /*!
269   * To define the volumic gradation
270   */
271   void SetGradation(double gradation);
272   double GetGradation() const ;
273   /*!
274   * Print log in standard output
275   */
276   void SetStandardOutputLog(bool logInStandardOutput);
277   bool GetStandardOutputLog() const ;
278   /*!
279   * Remove log file on success
280   */
281   void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
282   bool GetRemoveLogOnSuccess() const ;
283     
284   
285 //   struct TEnforcedEdge {
286 //     long ID;
287 //     long node1;
288 //     long node2;
289 //     std::string groupName;
290 //   };
291   
292
293   /*!
294    * \brief Return command to run hybrid mesher excluding file prefix (-f)
295    */
296   static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp, SMESH_Mesh& mesh);
297   /*!
298    * \brief Return a unique file name
299    */
300   static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
301   /*!
302    * \brief Return the name of executable
303    */
304   static std::string GetExeName();
305   /*!
306    * \brief Return a tag of enforced triangles
307    */
308   static int EnforcedTag() { return -5; }
309
310   /*!
311    * To set an enforced vertex
312    */
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();
324
325   /*!
326    * To set enforced elements
327    */
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
340   /*!
341    * \brief Return the enforced vertices
342    */
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);
348   
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();
358   
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();
384     
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();}
392   
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();}
400   
401   // Persistence
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);
406
407   /*!
408    * \brief Does nothing
409    */
410   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
411
412   /*!
413    * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
414    */
415   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
416
417 private:
418
419   bool             myToMeshHoles;
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;
429   bool             myKeepFiles;
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;
439   double           myGradation;
440
441   bool             myAddMultinormals;
442   bool             mySmoothNormals;
443   double           myHeightFirstLayer;
444   double           myBoundaryLayersProgression;
445   double           myMultinormalsAngle;
446   short            myNbOfBoundaryLayers;
447    
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;
455   
456   
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;
465   
466   TSetStrings _groupsToRemove;
467 };
468
469
470 #endif