Salome HOME
f4953fa019af14b126c3425792c90a0e0b9eef7f
[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, 2-Generation_Cartesian_Core. Default is Generation_Tetra_Dominant
176    */
177   enum ElementGeneration { Generation_Tetra_Dominant = 0, Generation_Hexa_Dominant, Generation_Cartesian_Core };
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      * Set core elements size.
205      * Default is 0.0
206      */
207     void SetCoreSize(double CS);
208     double GetCoreSize() const;
209     /*!
210      * To set multinormals angle threshold at opening ridges.
211      * Default is 30.0
212      */
213     void SetMultinormalsAngle(double MNA);
214     double GetMultinormalsAngle() const;
215     /*!
216      * To set number of boundary layers.
217      * Default is 1
218      */
219     void SetNbOfBoundaryLayers(short NBL);
220     short GetNbOfBoundaryLayers() const;
221
222
223   /*!
224    * Path to working directory
225    */
226   void SetWorkingDirectory(const std::string& path);
227   std::string GetWorkingDirectory() const;
228   /*!
229    * To keep working files or remove them. Log file remains in case of errors anyway.
230    */
231   void SetKeepFiles(bool toKeep);
232   bool GetKeepFiles() const;
233   /*!
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.
242    */
243   void SetVerboseLevel(short level);
244   short GetVerboseLevel() const;
245   /*!
246    * To create new nodes
247    */
248   void SetToCreateNewNodes(bool toCreate);
249   bool GetToCreateNewNodes() const;
250   /*!
251    * To use boundary recovery version which tries to create mesh on a very poor
252    * quality surface mesh
253    */
254   void SetToUseBoundaryRecoveryVersion(bool toUse);
255   bool GetToUseBoundaryRecoveryVersion() const;
256   /*!
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.
261    */
262   void SetFEMCorrection(bool toUseFem);
263   bool GetFEMCorrection() const;
264   /*!
265    * To removes initial central point.
266    */
267   void SetToRemoveCentralPoint(bool toRemove);
268   bool GetToRemoveCentralPoint() const;
269   /*!
270    * To set hiden/undocumented/advanced options
271    */
272   void SetAdvancedOption(const std::string& option);
273   std::string GetAdvancedOption() const;
274   /*!
275   * To define the volumic gradation
276   */
277   void SetGradation(double gradation);
278   double GetGradation() const ;
279   /*!
280   * Print log in standard output
281   */
282   void SetStandardOutputLog(bool logInStandardOutput);
283   bool GetStandardOutputLog() const ;
284   /*!
285   * Remove log file on success
286   */
287   void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
288   bool GetRemoveLogOnSuccess() const ;
289     
290   
291 //   struct TEnforcedEdge {
292 //     long ID;
293 //     long node1;
294 //     long node2;
295 //     std::string groupName;
296 //   };
297   
298
299   /*!
300    * \brief Return command to run hybrid mesher excluding file prefix (-f)
301    */
302   static std::string CommandToRun(const HYBRIDPlugin_Hypothesis* hyp, SMESH_Mesh& mesh);
303   /*!
304    * \brief Return a unique file name
305    */
306   static std::string GetFileName(const HYBRIDPlugin_Hypothesis* hyp);
307   /*!
308    * \brief Return the name of executable
309    */
310   static std::string GetExeName();
311   /*!
312    * \brief Return a tag of enforced triangles
313    */
314   static int EnforcedTag() { return -5; }
315
316   /*!
317    * To set an enforced vertex
318    */
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();
330
331   /*!
332    * To set enforced elements
333    */
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
346   /*!
347    * \brief Return the enforced vertices
348    */
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);
354   
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();
364   
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();
391     
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();}
399   
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();}
407   
408   // Persistence
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);
413
414   /*!
415    * \brief Does nothing
416    */
417   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
418
419   /*!
420    * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
421    */
422   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
423
424 private:
425
426   bool             myToMeshHoles;
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;
436   bool             myKeepFiles;
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;
446   double           myGradation;
447
448   bool             myAddMultinormals;
449   bool             mySmoothNormals;
450   double           myHeightFirstLayer;
451   double           myBoundaryLayersProgression;
452   double           myCoreSize;
453   double           myMultinormalsAngle;
454   short            myNbOfBoundaryLayers;
455    
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;
463   
464   
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;
473   
474   TSetStrings _groupsToRemove;
475 };
476
477
478 #endif