1 // Copyright (C) 2004-2011 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GHS3DPlugin : C++ implementation
21 // File : GHS3DPlugin_Hypothesis.hxx
22 // Created : Wed Apr 2 12:21:17 2008
23 // Author : Edward AGAPOV (eap)
25 #ifndef GHS3DPlugin_Hypothesis_HeaderFile
26 #define GHS3DPlugin_Hypothesis_HeaderFile
28 #include "GHS3DPlugin_Defs.hxx"
30 #include <SMDS_MeshNode.hxx>
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"
43 class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis: public SMESH_Hypothesis
47 GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen);
49 typedef std::map<std::vector<double>,double> TGHS3DEnforcedVertexCoordsValues;
50 typedef std::map<std::string,double> TGHS3DEnforcedVertexEntryValues;
52 struct TGHS3DEnforcedVertex {
54 std::string geomEntry;
56 std::vector<double> coords;
57 std::string groupName;
61 struct CompareGHS3DEnforcedVertex {
62 bool operator () (const TGHS3DEnforcedVertex* e1, const TGHS3DEnforcedVertex* e2) const {
64 if (e1->coords.size() && e2->coords.size())
65 return (e1->coords < e2->coords);
67 return (e1->geomEntry < e2->geomEntry);
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;
84 struct TGHS3DEnforcedMesh {
87 SMESH::ElementType elementType;
88 std::string groupName;
92 struct CompareGHS3DEnforcedMesh {
93 bool operator () (const TGHS3DEnforcedMesh* e1, const TGHS3DEnforcedMesh* e2) const {
95 if (e1->entry == e2->entry)
96 return (e1->elementType < e2->elementType);
98 return (e1->entry < e2->entry);
104 typedef std::set< TGHS3DEnforcedMesh*, CompareGHS3DEnforcedMesh > TGHS3DEnforcedMeshList;
105 // Map mesh entry / Enforced mesh list
106 // ex: 0:1:2:1 -> [ ("Mesh_1", "0:1:2:1", TopAbs_NODE, "", -1),
107 // ("Mesh_1", "0:1:2:1", TopAbs_EDGE, "edge group", 5)]
108 typedef std::map< std::string, TGHS3DEnforcedMeshList > TEntryGHS3DEnforcedMeshListMap;
110 typedef std::map<int,double> TID2SizeMap;
112 typedef std::map<const SMDS_MeshElement*, std::string, TIDCompare > TIDSortedElemGroupMap;
113 typedef std::map<const SMDS_MeshNode*, std::string, TIDCompare > TIDSortedNodeGroupMap;
114 typedef std::set<std::string> TSetStrings;
117 * To mesh "holes" in a solid or not. Default is to mesh.
119 void SetToMeshHoles(bool toMesh);
120 bool GetToMeshHoles(bool checkFreeOption = false) const;
122 * Maximal size of memory to be used by the algorithm (in Megabytes)
124 void SetMaximumMemory(short MB);
125 short GetMaximumMemory() const;
127 * Initial size of memory to be used by the algorithm (in Megabytes) in
128 * automatic memory adjustment mode. Default is zero
130 void SetInitialMemory(short MB);
131 short GetInitialMemory() const;
133 * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
135 enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
136 void SetOptimizationLevel(OptimizationLevel level);
137 OptimizationLevel GetOptimizationLevel() const;
139 * Path to working directory
141 void SetWorkingDirectory(const std::string& path);
142 std::string GetWorkingDirectory() const;
144 * To keep working files or remove them. Log file remains in case of errors anyway.
146 void SetKeepFiles(bool toKeep);
147 bool GetKeepFiles() const;
149 * Verbose level [0-10]
150 * 0 - no standard output,
151 * 2 - prints the data, quality statistics of the skin and final meshes and
152 * indicates when the final mesh is being saved. In addition the software
153 * gives indication regarding the CPU time.
154 * 10 - same as 2 plus the main steps in the computation, quality statistics
155 * histogram of the skin mesh, quality statistics histogram together with
156 * the characteristics of the final mesh.
158 void SetVerboseLevel(short level);
159 short GetVerboseLevel() const;
161 * To create new nodes
163 void SetToCreateNewNodes(bool toCreate);
164 bool GetToCreateNewNodes() const;
166 * To use boundary recovery version which tries to create mesh on a very poor
167 * quality surface mesh
169 void SetToUseBoundaryRecoveryVersion(bool toUse);
170 bool GetToUseBoundaryRecoveryVersion() const;
172 * Applies finite-element correction by replacing overconstrained elements where
173 * it is possible. The process is cutting first the overconstrained edges and
174 * second the overconstrained facets. This insure that no edges have two boundary
175 * vertices and that no facets have three boundary vertices.
177 void SetFEMCorrection(bool toUseFem);
178 bool GetFEMCorrection() const;
180 * To removes initial central point.
182 void SetToRemoveCentralPoint(bool toRemove);
183 bool GetToRemoveCentralPoint() const;
185 * To set hiden/undocumented/advanced options
187 void SetTextOption(const std::string& option);
188 std::string GetTextOption() const;
191 // struct TEnforcedEdge {
195 // std::string groupName;
200 * \brief Return command to run ghs3d mesher excluding file prefix (-f)
202 static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
203 const bool hasShapeToMesh=true);
205 * \brief Return a unique file name
207 static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp);
210 * To set an enforced vertex
212 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
213 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
214 TGHS3DEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
215 TGHS3DEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
216 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
217 const TGHS3DEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
218 const TGHS3DEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
219 const TGHS3DEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; }
220 const TCoordsGHS3DEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
221 const TGeomEntryGHS3DEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
222 void ClearEnforcedVertices();
225 * To set enforced elements
227 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName = "");
228 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName = "");
229 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size, std::string groupName = "");
230 const TGHS3DEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
231 const TEntryGHS3DEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
232 void ClearEnforcedMeshes();
233 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
234 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
235 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
236 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
237 const TID2SizeMap _GetElementIDToSizeMap() const {return _elementIDToSizeMap; }
238 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
240 * \brief Return the enforced vertices
242 static TGHS3DEnforcedVertexList GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp);
243 static TGHS3DEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const GHS3DPlugin_Hypothesis* hyp);
244 static TGHS3DEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const GHS3DPlugin_Hypothesis* hyp);
245 static TCoordsGHS3DEnforcedVertexMap GetEnforcedVerticesByCoords(const GHS3DPlugin_Hypothesis* hyp);
246 static TGeomEntryGHS3DEnforcedVertexMap GetEnforcedVerticesByEntry(const GHS3DPlugin_Hypothesis* hyp);
248 static TGHS3DEnforcedMeshList GetEnforcedMeshes(const GHS3DPlugin_Hypothesis* hyp);
249 static TEntryGHS3DEnforcedMeshListMap GetEnforcedMeshesByEntry(const GHS3DPlugin_Hypothesis* hyp);
250 static TIDSortedNodeGroupMap GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp);
251 static TIDSortedElemGroupMap GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp);
252 static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp);
253 static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp);
254 static TID2SizeMap GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp);
255 static TSetStrings GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp);
256 void ClearGroupsToRemove();
258 static bool DefaultMeshHoles();
259 static short DefaultMaximumMemory();
260 static short DefaultInitialMemory();
261 static short DefaultOptimizationLevel();
262 static std::string DefaultWorkingDirectory();
263 static bool DefaultKeepFiles();
264 static short DefaultVerboseLevel();
265 static bool DefaultToCreateNewNodes();
266 static bool DefaultToUseBoundaryRecoveryVersion();
267 static bool DefaultToUseFEMCorrection();
268 static bool DefaultToRemoveCentralPoint();
270 static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();}
271 static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();}
272 static TGHS3DEnforcedVertexCoordsValues DefaultGHS3DEnforcedVertexCoordsValues() {return TGHS3DEnforcedVertexCoordsValues();}
273 static TGHS3DEnforcedVertexEntryValues DefaultGHS3DEnforcedVertexEntryValues() {return TGHS3DEnforcedVertexEntryValues();}
274 static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();}
275 static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();}
276 static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();}
278 static TGHS3DEnforcedMesh DefaultGHS3DEnforcedMesh() {return TGHS3DEnforcedMesh();}
279 static TGHS3DEnforcedMeshList DefaultGHS3DEnforcedMeshList() {return TGHS3DEnforcedMeshList();}
280 static TEntryGHS3DEnforcedMeshListMap DefaultEntryGHS3DEnforcedMeshListMap() {return TEntryGHS3DEnforcedMeshListMap();}
281 static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
282 static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
283 static TID2SizeMap DefaultID2SizeMap() {return TID2SizeMap();}
284 static TSetStrings DefaultGroupsToRemove() {return TSetStrings();}
287 virtual std::ostream & SaveTo(std::ostream & save);
288 virtual std::istream & LoadFrom(std::istream & load);
289 friend GHS3DPLUGIN_EXPORT std::ostream & operator <<(std::ostream & save, GHS3DPlugin_Hypothesis & hyp);
290 friend GHS3DPLUGIN_EXPORT std::istream & operator >>(std::istream & load, GHS3DPlugin_Hypothesis & hyp);
293 * \brief Does nothing
295 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
298 * \brief Does nothing
300 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
305 short myMaximumMemory;
306 short myInitialMemory;
307 short myOptimizationLevel;
309 std::string myWorkingDirectory;
310 short myVerboseLevel;
311 bool myToCreateNewNodes;
312 bool myToUseBoundaryRecoveryVersion;
313 bool myToUseFemCorrection;
314 bool myToRemoveCentralPoint;
315 std::string myTextOption;
317 TGHS3DEnforcedVertexList _enfVertexList;
318 TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
319 TGHS3DEnforcedVertexEntryValues _enfVertexEntrySizeList;
320 // map to get "manual" enf vertex (through the coordinates)
321 TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap;
322 // map to get "geom" enf vertex (through the geom entries)
323 TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap;
326 TGHS3DEnforcedMeshList _enfMeshList;
327 // map to get enf meshes through the entries
328 TEntryGHS3DEnforcedMeshListMap _entryEnfMeshMap;
329 TIDSortedNodeGroupMap _enfNodes;
330 TIDSortedElemGroupMap _enfEdges;
331 TIDSortedElemGroupMap _enfTriangles;
332 TID2SizeMap _nodeIDToSizeMap;
333 TID2SizeMap _elementIDToSizeMap;
334 std::map<std::string, TIDSortedElemSet > _entryToElemsMap;
336 TSetStrings _groupsToRemove;