]> SALOME platform Git repositories - plugins/hybridplugin.git/blob - src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx
Salome HOME
Merge from V6_main (04/10/2012)
[plugins/hybridplugin.git] / src / GHS3DPlugin / GHS3DPlugin_Hypothesis.hxx
1 // Copyright (C) 2004-2012  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.
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 //  GHS3DPlugin : C++ implementation
21 // File      : GHS3DPlugin_Hypothesis.hxx
22 // Created   : Wed Apr  2 12:21:17 2008
23 // Author    : Edward AGAPOV (eap)
24 //
25 #ifndef GHS3DPlugin_Hypothesis_HeaderFile
26 #define GHS3DPlugin_Hypothesis_HeaderFile
27
28 #include "GHS3DPlugin_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 GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis
44 {
45 public:
46
47   GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen);
48
49   typedef std::map<std::vector<double>,double> TGHS3DEnforcedVertexCoordsValues;
50   typedef std::map<std::string,double> TGHS3DEnforcedVertexEntryValues;
51   
52   struct TGHS3DEnforcedVertex {
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 CompareGHS3DEnforcedVertex {
62     bool operator () (const TGHS3DEnforcedVertex* e1, const TGHS3DEnforcedVertex* 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< TGHS3DEnforcedVertex*, CompareGHS3DEnforcedVertex > TGHS3DEnforcedVertexList;
73   // Map Coords / Enforced node
74   typedef std::map< std::vector<double>, TGHS3DEnforcedVertex* > TCoordsGHS3DEnforcedVertexMap;
75   // Map geom entry / Enforced node
76   typedef std::map< std::string, TGHS3DEnforcedVertex* > TGeomEntryGHS3DEnforcedVertexMap;
77   // Map groupName / Enforced node
78   typedef std::map< std::string, TGHS3DEnforcedVertexList > TGroupNameGHS3DEnforcedVertexMap;
79   
80   ////////////////////
81   // Enforced meshes
82   ////////////////////
83   
84   struct TGHS3DEnforcedMesh {
85     std::string name;
86     std::string entry;
87     std::string groupName;
88     SMESH::ElementType elementType;
89   };
90   
91   struct CompareGHS3DEnforcedMesh {
92     bool operator () (const TGHS3DEnforcedMesh* e1, const TGHS3DEnforcedMesh* e2) const {
93       if (e1 && e2) {
94         if (e1->entry == e2->entry)
95           return (e1->elementType < e2->elementType);
96         else
97           return (e1->entry < e2->entry);
98       }
99       else
100         return false;
101     }
102   };
103   typedef std::set< TGHS3DEnforcedMesh*, CompareGHS3DEnforcedMesh > TGHS3DEnforcedMeshList;
104   // Map mesh entry / Enforced mesh list
105   // ex: 0:1:2:1 -> [ ("Mesh_1", "0:1:2:1", TopAbs_NODE, ""),
106   //                  ("Mesh_1", "0:1:2:1", TopAbs_EDGE, "edge group")]
107   typedef std::map< std::string, TGHS3DEnforcedMeshList > TEntryGHS3DEnforcedMeshListMap;
108   
109   typedef std::map<int,double> TID2SizeMap;
110
111   struct TIDMeshIDCompare {
112     bool operator () (const SMDS_MeshElement* e1, const SMDS_MeshElement* e2) const
113     { return e1->getMeshId() == e2->getMeshId() ? e1->GetID() < e2->GetID() : e1->getMeshId() < e2->getMeshId() ; }
114   };
115   
116   typedef std::map<const SMDS_MeshElement*, std::string, TIDMeshIDCompare > TIDSortedElemGroupMap;
117   typedef std::map<const SMDS_MeshNode*, std::string, TIDMeshIDCompare > TIDSortedNodeGroupMap;
118   typedef std::set<std::string> TSetStrings;
119
120   static const char* GetHypType() { return "GHS3D_Parameters"; }
121   /*!
122    * To mesh "holes" in a solid or not. Default is to mesh.
123    */
124   void SetToMeshHoles(bool toMesh);
125   bool GetToMeshHoles(bool checkFreeOption = false) const;
126   /*!
127    * Maximal size of memory to be used by the algorithm (in Megabytes)
128    */
129   void SetMaximumMemory(short MB);
130   short GetMaximumMemory() const;
131   /*!
132    * Initial size of memory to be used by the algorithm (in Megabytes) in
133    * automatic memory adjustment mode. Default is zero
134    */
135   void SetInitialMemory(short MB);
136   short GetInitialMemory() const;
137   /*!
138    * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
139    */
140   enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
141   void SetOptimizationLevel(OptimizationLevel level);
142   OptimizationLevel GetOptimizationLevel() const;
143   /*!
144    * Path to working directory
145    */
146   void SetWorkingDirectory(const std::string& path);
147   std::string GetWorkingDirectory() const;
148   /*!
149    * To keep working files or remove them. Log file remains in case of errors anyway.
150    */
151   void SetKeepFiles(bool toKeep);
152   bool GetKeepFiles() const;
153   /*!
154    * Verbose level [0-10]
155    *  0 - no standard output,
156    *  2 - prints the data, quality statistics of the skin and final meshes and
157    *     indicates when the final mesh is being saved. In addition the software
158    *     gives indication regarding the CPU time.
159    * 10 - same as 2 plus the main steps in the computation, quality statistics
160    *     histogram of the skin mesh, quality statistics histogram together with
161    *     the characteristics of the final mesh.
162    */
163   void SetVerboseLevel(short level);
164   short GetVerboseLevel() const;
165   /*!
166    * To create new nodes
167    */
168   void SetToCreateNewNodes(bool toCreate);
169   bool GetToCreateNewNodes() const;
170   /*!
171    * To use boundary recovery version which tries to create mesh on a very poor
172    * quality surface mesh
173    */
174   void SetToUseBoundaryRecoveryVersion(bool toUse);
175   bool GetToUseBoundaryRecoveryVersion() const;
176   /*!
177    * Applies finite-element correction by replacing overconstrained elements where
178    * it is possible. The process is cutting first the overconstrained edges and
179    * second the overconstrained facets. This insure that no edges have two boundary
180    * vertices and that no facets have three boundary vertices.
181    */
182   void SetFEMCorrection(bool toUseFem);
183   bool GetFEMCorrection() const;
184   /*!
185    * To removes initial central point.
186    */
187   void SetToRemoveCentralPoint(bool toRemove);
188   bool GetToRemoveCentralPoint() const;
189   /*!
190    * To set hiden/undocumented/advanced options
191    */
192   void SetTextOption(const std::string& option);
193   std::string GetTextOption() const;
194   /*!
195   * To define the volumic gradation
196   */
197   void SetGradation(double gradation);
198   double GetGradation() const ;
199     
200   
201 //   struct TEnforcedEdge {
202 //     long ID;
203 //     long node1;
204 //     long node2;
205 //     std::string groupName;
206 //   };
207   
208
209   /*!
210    * \brief Return command to run ghs3d mesher excluding file prefix (-f)
211    */
212   static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
213                                   const bool                    hasShapeToMesh=true);
214   /*!
215    * \brief Return a unique file name
216    */
217   static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp);
218
219   /*!
220    * To set an enforced vertex
221    */
222   bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
223                          double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
224   TGHS3DEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
225   TGHS3DEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
226   bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
227   const TGHS3DEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
228   const TGHS3DEnforcedVertexEntryValues  _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
229   const TGHS3DEnforcedVertexList         _GetEnforcedVertices() const { return _enfVertexList; }
230   const TCoordsGHS3DEnforcedVertexMap    _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
231   const TGeomEntryGHS3DEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
232   void ClearEnforcedVertices();
233
234   /*!
235    * To set enforced elements
236    */
237   bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
238   bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
239   bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
240   const TGHS3DEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
241   const TEntryGHS3DEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
242   void ClearEnforcedMeshes();
243   const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
244   const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
245   const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
246   const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
247   const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
248   /*!
249    * \brief Return the enforced vertices
250    */
251   static TGHS3DEnforcedVertexList GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp);
252   static TGHS3DEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const GHS3DPlugin_Hypothesis* hyp);
253   static TGHS3DEnforcedVertexEntryValues  GetEnforcedVerticesEntrySize(const GHS3DPlugin_Hypothesis* hyp);
254   static TCoordsGHS3DEnforcedVertexMap GetEnforcedVerticesByCoords(const GHS3DPlugin_Hypothesis* hyp);
255   static TGeomEntryGHS3DEnforcedVertexMap GetEnforcedVerticesByEntry(const GHS3DPlugin_Hypothesis* hyp);
256   
257   static TGHS3DEnforcedMeshList GetEnforcedMeshes(const GHS3DPlugin_Hypothesis* hyp);
258   static TEntryGHS3DEnforcedMeshListMap GetEnforcedMeshesByEntry(const GHS3DPlugin_Hypothesis* hyp);
259   static TIDSortedNodeGroupMap GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp);
260   static TIDSortedElemGroupMap GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp);
261   static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp);
262   static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp);
263   static TSetStrings GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp);
264   void ClearGroupsToRemove();
265   
266   static bool   DefaultMeshHoles();
267   static short  DefaultMaximumMemory();
268   static short  DefaultInitialMemory();
269   static short  DefaultOptimizationLevel();
270   static std::string DefaultWorkingDirectory();
271   static bool   DefaultKeepFiles();
272   static short  DefaultVerboseLevel();
273   static bool   DefaultToCreateNewNodes();
274   static bool   DefaultToUseBoundaryRecoveryVersion();
275   static bool   DefaultToUseFEMCorrection();
276   static bool   DefaultToRemoveCentralPoint();
277   static double DefaultGradation();
278   
279   static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();}
280   static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();}
281   static TGHS3DEnforcedVertexCoordsValues DefaultGHS3DEnforcedVertexCoordsValues() {return TGHS3DEnforcedVertexCoordsValues();}
282   static TGHS3DEnforcedVertexEntryValues DefaultGHS3DEnforcedVertexEntryValues() {return TGHS3DEnforcedVertexEntryValues();}
283   static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();}
284   static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();}
285   static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();}
286   
287   static TGHS3DEnforcedMesh         DefaultGHS3DEnforcedMesh() {return TGHS3DEnforcedMesh();}
288   static TGHS3DEnforcedMeshList     DefaultGHS3DEnforcedMeshList() {return TGHS3DEnforcedMeshList();}
289   static TEntryGHS3DEnforcedMeshListMap DefaultEntryGHS3DEnforcedMeshListMap() {return TEntryGHS3DEnforcedMeshListMap();}
290   static TIDSortedNodeGroupMap      DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
291   static TIDSortedElemGroupMap      DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
292   static TID2SizeMap                DefaultID2SizeMap() {return TID2SizeMap();}
293   static TSetStrings                DefaultGroupsToRemove() {return TSetStrings();}
294   
295   // Persistence
296   virtual std::ostream & SaveTo(std::ostream & save);
297   virtual std::istream & LoadFrom(std::istream & load);
298   friend GHS3DPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, GHS3DPlugin_Hypothesis & hyp);
299   friend GHS3DPLUGIN_EXPORT std::istream & operator >>(std::istream & load, GHS3DPlugin_Hypothesis & hyp);
300
301   /*!
302    * \brief Does nothing
303    */
304   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
305
306   /*!
307    * \brief Does nothing
308    */
309   virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
310
311 private:
312
313   bool   myToMeshHoles;
314   short  myMaximumMemory;
315   short  myInitialMemory;
316   short  myOptimizationLevel;
317   bool   myKeepFiles;
318   std::string myWorkingDirectory;
319   short  myVerboseLevel;
320   bool   myToCreateNewNodes;
321   bool   myToUseBoundaryRecoveryVersion;
322   bool   myToUseFemCorrection;
323   bool   myToRemoveCentralPoint;
324   std::string myTextOption;
325   double myGradation;
326   
327   TGHS3DEnforcedVertexList _enfVertexList;
328   TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
329   TGHS3DEnforcedVertexEntryValues _enfVertexEntrySizeList;
330   // map to get "manual" enf vertex (through the coordinates)
331   TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap;
332   // map to get "geom" enf vertex (through the geom entries)
333   TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap;
334   
335   
336   TGHS3DEnforcedMeshList _enfMeshList;
337   // map to get enf meshes through the entries
338   TEntryGHS3DEnforcedMeshListMap _entryEnfMeshMap;
339   TIDSortedNodeGroupMap _enfNodes;
340   TIDSortedElemGroupMap _enfEdges;
341   TIDSortedElemGroupMap _enfTriangles;
342   TID2SizeMap _nodeIDToSizeMap;
343   std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
344   
345   TSetStrings _groupsToRemove;
346 };
347
348
349 #endif