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