1 // Copyright (C) 2004-2016 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, or (at your option) any later version.
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, 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 {
88 std::string groupName;
89 SMESH::ElementType elementType;
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, ""),
107 // ("Mesh_1", "0:1:2:1", TopAbs_EDGE, "edge group")]
108 typedef std::map< std::string, TGHS3DEnforcedMeshList > TEntryGHS3DEnforcedMeshListMap;
110 typedef std::map<int,double> TID2SizeMap;
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() ; }
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;
121 static const char* GetHypType() { return "MG-Tetra Parameters"; }
123 * To mesh "holes" in a solid or not. Default is to mesh.
125 void SetToMeshHoles(bool toMesh);
126 bool GetToMeshHoles(bool checkFreeOption = false) const;
128 * To make groups of volumes of different domains when mesh is generated from skin.
129 * Default is to make groups.
130 * This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
132 void SetToMakeGroupsOfDomains(bool toMakeGroups);
133 bool GetToMakeGroupsOfDomains() const;
135 * Maximal size of memory to be used by the algorithm (in Megabytes)
137 void SetMaximumMemory(float MB);
138 float GetMaximumMemory() const;
140 * Initial size of memory to be used by the algorithm (in Megabytes) in
141 * automatic memory adjustment mode. Default is zero
143 void SetInitialMemory(float MB);
144 float GetInitialMemory() const;
146 * Optimization level: 0-none, 1-light, 2-medium, 3-standard+, 4-strong. Default is medium
148 enum OptimizationLevel { None = 0, Light, Medium, StandardPlus, Strong };
149 void SetOptimizationLevel(OptimizationLevel level);
150 OptimizationLevel GetOptimizationLevel() const;
152 * Path to working directory
154 void SetWorkingDirectory(const std::string& path);
155 std::string GetWorkingDirectory() const;
157 * To keep working files or remove them. Log file remains in case of errors anyway.
159 void SetKeepFiles(bool toKeep);
160 bool GetKeepFiles() const;
162 * Verbose level [0-10]
163 * 0 - no standard output,
164 * 2 - prints the data, quality statistics of the skin and final meshes and
165 * indicates when the final mesh is being saved. In addition the software
166 * gives indication regarding the CPU time.
167 * 10 - same as 2 plus the main steps in the computation, quality statistics
168 * histogram of the skin mesh, quality statistics histogram together with
169 * the characteristics of the final mesh.
171 void SetVerboseLevel(short level);
172 short GetVerboseLevel() const;
174 * To create new nodes
176 void SetToCreateNewNodes(bool toCreate);
177 bool GetToCreateNewNodes() const;
179 * To use boundary recovery version which tries to create mesh on a very poor
180 * quality surface mesh
182 void SetToUseBoundaryRecoveryVersion(bool toUse);
183 bool GetToUseBoundaryRecoveryVersion() const;
185 * Applies finite-element correction by replacing overconstrained elements where
186 * it is possible. The process is cutting first the overconstrained edges and
187 * second the overconstrained facets. This insure that no edges have two boundary
188 * vertices and that no facets have three boundary vertices.
190 void SetFEMCorrection(bool toUseFem);
191 bool GetFEMCorrection() const;
193 * To removes initial central point.
195 void SetToRemoveCentralPoint(bool toRemove);
196 bool GetToRemoveCentralPoint() const;
198 * To set hiden/undocumented/advanced options
200 void SetAdvancedOption(const std::string& option);
201 std::string GetAdvancedOption() const;
203 * To define the volumic gradation
205 void SetGradation(double gradation);
206 double GetGradation() const ;
208 * Print log in standard output
210 void SetStandardOutputLog(bool logInStandardOutput);
211 bool GetStandardOutputLog() const ;
213 * Remove log file on success
215 void SetRemoveLogOnSuccess(bool removeLogOnSuccess);
216 bool GetRemoveLogOnSuccess() const ;
219 // struct TEnforcedEdge {
223 // std::string groupName;
228 * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
230 static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
231 const bool hasShapeToMesh,
232 const bool forExucutable);
234 * \brief Return a unique file name
236 static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp);
238 * \brief Return the name of executable
240 static std::string GetExeName();
243 * To set an enforced vertex
245 bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName,
246 double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false);
247 TGHS3DEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument);
248 TGHS3DEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument);
249 bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument);
250 const TGHS3DEnforcedVertexCoordsValues& _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; }
251 const TGHS3DEnforcedVertexEntryValues & _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; }
252 const TGHS3DEnforcedVertexList & _GetEnforcedVertices() const { return _enfVertexList; }
253 const TCoordsGHS3DEnforcedVertexMap & _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; }
254 const TGeomEntryGHS3DEnforcedVertexMap& _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; }
255 void ClearEnforcedVertices();
258 * To set enforced elements
260 bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
261 bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, std::string groupName = "");
262 bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, std::string groupName = "");
263 const TGHS3DEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; }
264 const TEntryGHS3DEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; }
265 void ClearEnforcedMeshes();
266 const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; }
267 const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; }
268 const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; }
269 const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; }
270 const TSetStrings _GetGroupsToRemove() const {return _groupsToRemove; }
271 void RestoreEnfElemsByMeshes(); // persistence
273 * \brief Return the enforced vertices
275 static TGHS3DEnforcedVertexList GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp);
276 static TGHS3DEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const GHS3DPlugin_Hypothesis* hyp);
277 static TGHS3DEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const GHS3DPlugin_Hypothesis* hyp);
278 static TCoordsGHS3DEnforcedVertexMap GetEnforcedVerticesByCoords(const GHS3DPlugin_Hypothesis* hyp);
279 static TGeomEntryGHS3DEnforcedVertexMap GetEnforcedVerticesByEntry(const GHS3DPlugin_Hypothesis* hyp);
281 static TGHS3DEnforcedMeshList GetEnforcedMeshes(const GHS3DPlugin_Hypothesis* hyp);
282 static TEntryGHS3DEnforcedMeshListMap GetEnforcedMeshesByEntry(const GHS3DPlugin_Hypothesis* hyp);
283 static TIDSortedNodeGroupMap GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp);
284 static TIDSortedElemGroupMap GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp);
285 static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp);
286 static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp);
287 static TSetStrings GetGroupsToRemove(const GHS3DPlugin_Hypothesis* hyp);
288 static bool GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp);
289 void ClearGroupsToRemove();
291 static bool DefaultMeshHoles();
292 static bool DefaultToMakeGroupsOfDomains();
293 static float DefaultMaximumMemory();
294 static float DefaultInitialMemory();
295 static short DefaultOptimizationLevel();
296 static std::string DefaultWorkingDirectory();
297 static bool DefaultKeepFiles();
298 static short DefaultVerboseLevel();
299 static bool DefaultToCreateNewNodes();
300 static bool DefaultToUseBoundaryRecoveryVersion();
301 static bool DefaultToUseFEMCorrection();
302 static bool DefaultToRemoveCentralPoint();
303 static bool DefaultStandardOutputLog();
304 static bool DefaultRemoveLogOnSuccess();
305 static double DefaultGradation();
307 static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();}
308 static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();}
309 static TGHS3DEnforcedVertexCoordsValues DefaultGHS3DEnforcedVertexCoordsValues() {return TGHS3DEnforcedVertexCoordsValues();}
310 static TGHS3DEnforcedVertexEntryValues DefaultGHS3DEnforcedVertexEntryValues() {return TGHS3DEnforcedVertexEntryValues();}
311 static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();}
312 static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();}
313 static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();}
315 static TGHS3DEnforcedMesh DefaultGHS3DEnforcedMesh() {return TGHS3DEnforcedMesh();}
316 static TGHS3DEnforcedMeshList DefaultGHS3DEnforcedMeshList() {return TGHS3DEnforcedMeshList();}
317 static TEntryGHS3DEnforcedMeshListMap DefaultEntryGHS3DEnforcedMeshListMap() {return TEntryGHS3DEnforcedMeshListMap();}
318 static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();}
319 static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();}
320 static TID2SizeMap DefaultID2SizeMap() {return TID2SizeMap();}
321 static TSetStrings DefaultGroupsToRemove() {return TSetStrings();}
324 virtual std::ostream & SaveTo(std::ostream & save);
325 virtual std::istream & LoadFrom(std::istream & load);
328 * \brief Does nothing
330 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape);
333 * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
335 virtual bool SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh=0);
340 bool myToMakeGroupsOfDomains;
341 float myMaximumMemory;
342 float myInitialMemory;
343 short myOptimizationLevel;
345 std::string myWorkingDirectory;
346 short myVerboseLevel;
347 bool myToCreateNewNodes;
348 bool myToUseBoundaryRecoveryVersion;
349 bool myToUseFemCorrection;
350 bool myToRemoveCentralPoint;
351 bool myLogInStandardOutput;
352 bool myRemoveLogOnSuccess;
353 std::string myTextOption;
356 TGHS3DEnforcedVertexList _enfVertexList;
357 TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList;
358 TGHS3DEnforcedVertexEntryValues _enfVertexEntrySizeList;
359 // map to get "manual" enf vertex (through the coordinates)
360 TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap;
361 // map to get "geom" enf vertex (through the geom entries)
362 TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap;
365 TGHS3DEnforcedMeshList _enfMeshList;
366 // map to get enf meshes through the entries
367 TEntryGHS3DEnforcedMeshListMap _entryEnfMeshMap;
368 TIDSortedNodeGroupMap _enfNodes;
369 TIDSortedElemGroupMap _enfEdges;
370 TIDSortedElemGroupMap _enfTriangles;
371 TID2SizeMap _nodeIDToSizeMap;
373 TSetStrings _groupsToRemove;