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