1 # Copyright (C) 2007-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
21 # @package GHS3DPluginBuilder
22 # Python API for the MG-Tetra meshing plug-in module.
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished
27 # import GHS3DPlugin module if possible
35 # Optimization level of MG-Tetra
37 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
38 # V4.1 (partialy redefines V3.1). Issue 0020574
39 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
41 # import items of enums
42 for e in GHS3DPlugin.Mode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
43 for e in GHS3DPlugin.PThreadsMode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
44 Mode_NO, Mode_YES, Mode_ONLY = GHS3DPlugin.Mode._items
45 Mode_SAFE, Mode_AGGRESSIVE, Mode_NONE = GHS3DPlugin.PThreadsMode._items
47 #----------------------------
48 # Mesh algo type identifiers
49 #----------------------------
51 ## Algorithm type: MG-Tetra tetrahedron 3D algorithm, see GHS3D_Algorithm
54 MG_Tetra_Optimization = "MG-Tetra Optimization"
56 ## Tetrahedron MG-Tetra 3D algorithm
58 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra, geom=0 )
59 class GHS3D_Algorithm(Mesh_Algorithm):
61 ## name of the dynamic method in smeshBuilder.Mesh class
63 meshMethod = "Tetrahedron"
64 ## type of algorithm used with helper function in smeshBuilder.Mesh class
67 ## doc string of the method in smeshBuilder.Mesh class
69 docHelper = "Creates tetrahedron 3D algorithm"
71 ## Private constructor.
72 # @param mesh parent mesh object algorithm is assigned to
73 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
74 # if it is @c 0 (default), the algorithm is assigned to the main shape
75 def __init__(self, mesh, geom=0):
76 Mesh_Algorithm.__init__(self)
77 if noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
78 self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
82 ## Defines hypothesis having several parameters
83 # @return hypothesis object
86 self.params = self.Hypothesis("MG-Tetra Parameters", [],
87 "libGHS3DEngine.so", UseExisting=0)
91 ## To mesh "holes" in a solid or not. Default is to mesh.
92 # @param toMesh "mesh holes" flag value
93 def SetToMeshHoles(self, toMesh):
94 self.Parameters().SetToMeshHoles(toMesh)
97 ## To make groups of volumes of different domains when mesh is generated from skin.
98 # Default is to make groups.
99 # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
100 # @param toMakeGroups "Make groups of domains" flag value
101 def SetToMakeGroupsOfDomains(self, toMakeGroups):
102 self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
105 ## Set Optimization level:
106 # @param level optimization level, one of the following values
107 # - None_Optimization
108 # - Light_Optimization
109 # - Standard_Optimization
110 # - StandardPlus_Optimization
111 # - Strong_Optimization.
113 # Default is Standard_Optimization
114 def SetOptimizationLevel(self, level):
115 self.Parameters().SetOptimizationLevel(level)
118 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
119 # @param MB maximal size of memory
120 def SetMaximumMemory(self, MB):
121 self.Parameters().SetMaximumMemory(MB)
124 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
125 # automatic memory adjustment mode.
126 # @param MB initial size of memory
127 def SetInitialMemory(self, MB):
128 self.Parameters().SetInitialMemory(MB)
131 ## Set path to working directory.
132 # @param path working directory
133 def SetWorkingDirectory(self, path):
134 self.Parameters().SetWorkingDirectory(path)
137 ## To keep working files or remove them.
138 # @param toKeep "keep working files" flag value
139 def SetKeepFiles(self, toKeep):
140 self.Parameters().SetKeepFiles(toKeep)
143 ## Remove or not the log file (if any) in case of successful computation.
144 # The log file remains in case of errors anyway. If
145 # the "keep working files" flag is set to true, this option
147 # @param toRemove "remove log on success" flag value
148 def SetRemoveLogOnSuccess(self, toRemove):
149 self.Parameters().SetRemoveLogOnSuccess(toRemove)
152 ## Print the the log in a file. If set to false, the
153 # log is printed on the standard output
154 # @param toPrintLogInFile "print log in a file" flag value
155 def SetPrintLogInFile(self, toPrintLogInFile):
156 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
159 ## Set verbosity level [0-10].
160 # @param level verbosity level
161 # - 0 - no standard output,
162 # - 2 - prints the data, quality statistics of the skin and final meshes and
163 # indicates when the final mesh is being saved. In addition the software
164 # gives indication regarding the CPU time.
165 # - 10 - same as 2 plus the main steps in the computation, quality statistics
166 # histogram of the skin mesh, quality statistics histogram together with
167 # the characteristics of the final mesh.
168 def SetVerboseLevel(self, level):
169 self.Parameters().SetVerboseLevel(level)
172 ## To create new nodes.
173 # @param toCreate "create new nodes" flag value
174 def SetToCreateNewNodes(self, toCreate):
175 self.Parameters().SetToCreateNewNodes(toCreate)
178 ## To use boundary recovery version which tries to create mesh on a very poor
179 # quality surface mesh.
180 # @param toUse "use boundary recovery version" flag value
181 def SetToUseBoundaryRecoveryVersion(self, toUse):
182 self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
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.
189 # @param toUseFem "apply finite-element correction" flag value
190 def SetFEMCorrection(self, toUseFem):
191 self.Parameters().SetFEMCorrection(toUseFem)
194 ## To remove initial central point.
195 # @param toRemove "remove initial central point" flag value
196 def SetToRemoveCentralPoint(self, toRemove):
197 self.Parameters().SetToRemoveCentralPoint(toRemove)
200 ## To set an enforced vertex.
201 # @param x : x coordinate
202 # @param y : y coordinate
203 # @param z : z coordinate
204 # @param size : size of 1D element around enforced vertex
205 # @param vertexName : name of the enforced vertex
206 # @param groupName : name of the group
207 def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
210 return self.Parameters().SetEnforcedVertex(x, y, z, size)
212 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
216 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
218 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
222 ## To set an enforced vertex given a GEOM vertex, group or compound.
223 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
224 # @param size : size of 1D element around enforced vertex
225 # @param groupName : name of the group
226 def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
227 AssureGeomPublished( self.mesh, theVertex )
229 return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
231 return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
234 ## To remove an enforced vertex.
235 # @param x : x coordinate
236 # @param y : y coordinate
237 # @param z : z coordinate
238 def RemoveEnforcedVertex(self, x, y, z):
239 return self.Parameters().RemoveEnforcedVertex(x, y, z)
241 ## To remove an enforced vertex given a GEOM vertex, group or compound.
242 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
243 def RemoveEnforcedVertexGeom(self, theVertex):
244 AssureGeomPublished( self.mesh, theVertex )
245 return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
247 ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
248 # @param theSource : source mesh which provides constraint elements/nodes
249 # @param elementType : SMESH.ElementType (NODE, EDGE or FACE)
250 # @param size : size of elements around enforced elements. Unused if -1.
251 # @param groupName : group in which enforced elements will be added. Unused if "".
252 def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
255 return self.Parameters().SetEnforcedMesh(theSource, elementType)
257 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
261 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
263 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
267 ## Sets command line option as text.
268 # @param option command line option
269 def SetTextOption(self, option):
270 self.Parameters().SetAdvancedOption(option)
273 ## Sets command line option as text.
274 # @param option command line option
275 def SetAdvancedOption(self, option):
276 self.Parameters().SetAdvancedOption(option)
279 pass # end of GHS3D_Algorithm class
282 ## MG-Tetra Optimization algorithm - optimizer of tetrahedral meshes
284 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
285 class GHS3D_Optimizer(GHS3D_Algorithm):
287 ## name of the dynamic method in smeshBuilder.Mesh class
289 meshMethod = "Tetrahedron"
290 ## type of algorithm used with helper function in smeshBuilder.Mesh class
292 algoType = MG_Tetra_Optimization
293 ## doc string of the method in smeshBuilder.Mesh class
295 docHelper = "Creates MG-Tetra optimizer of tetrahedral meshes"
297 ## Private constructor.
298 # @param mesh parent mesh object algorithm is assigned to
299 # @param geom - not used
300 def __init__(self, mesh, geom=0):
301 GHS3D_Algorithm.__init__(self, mesh)
303 # remove some inherited methods
304 # del self.SetToMeshHoles
305 # del self.SetToMakeGroupsOfDomains
306 # del self.SetToUseBoundaryRecoveryVersion
307 # del self.SetFEMCorrection
308 # del self.SetToRemoveCentralPoint
309 # del self.SetEnforcedVertex
310 # del self.SetEnforcedVertexGeom
311 # del self.RemoveEnforcedVertex
312 # del self.RemoveEnforcedVertexGeom
313 # del self.SetEnforcedMesh
314 # del self.SetTextOption
317 ## Defines hypothesis having several parameters
318 # @return hypothesis object
319 def Parameters(self):
321 self.params = self.Hypothesis("MG-Tetra Optimization Parameters", [],
322 "libGHS3DEngine.so", UseExisting=0)
326 ## Set Optimization mode
327 # @param optMode optimization mode, one of the following values:
328 # smeshBuilder.Mode_NO,
329 # smeshBuilder.Mode_YES (default),
330 # smeshBuilder.MODE_ONLY
331 def SetOptimizationOnly(self, optMode ):
332 self.Parameters().SetOptimizationOnly(optMode)
335 ## Set mode of splitting over-constrained elements
336 # @param ovcMode, one of the following values
337 # smeshBuilder.Mode_NO (default),
338 # smeshBuilder.Mode_YES,
339 # smeshBuilder.Mode_ONLY
340 def SetSplitOverConstrained(self, ovcMode ):
341 self.Parameters().SetSplitOverConstrained(ovcMode)
344 ## Activate smoothing sliver elements:
345 # @param toSmooth - Boolean flag
346 def SetSmoothOffSlivers(self, toSmooth ):
347 self.Parameters().SetSmoothOffSlivers(toSmooth)
350 ## Set multithread mode
351 # @param mode - the mode, one of the following values:
352 # smeshBuilder.Mode_SAFE,
353 # smeshBuilder.Mode_AGGRESSIVE,
354 # smeshBuilder.Mode_NONE (default)
355 def SetPThreadsMode(self, mode ):
356 self.Parameters().SetPThreadsMode(mode)
359 ## Set maximal number of threads
360 # @param nb - number of threads
361 def SetMaximalNumberOfThreads(self, nb ):
362 self.Parameters().SetMaximalNumberOfThreads(nb)
366 ## Set Optimization level:
367 # @param level optimization level, one of the following values
368 # - None_Optimization
369 # - Light_Optimization
370 # - Standard_Optimization
371 # - StandardPlus_Optimization
372 # - Strong_Optimization.
374 # Default is Standard_Optimization
375 def SetOptimizationLevel(self, level):
376 self.Parameters().SetOptimizationLevel(level)
379 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
380 # @param MB maximal size of memory
381 def SetMaximumMemory(self, MB):
382 self.Parameters().SetMaximumMemory(MB)
385 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
386 # automatic memory adjustment mode.
387 # @param MB initial size of memory
388 def SetInitialMemory(self, MB):
389 self.Parameters().SetInitialMemory(MB)
392 ## Set path to working directory.
393 # @param path working directory
394 def SetWorkingDirectory(self, path):
395 self.Parameters().SetWorkingDirectory(path)
398 ## To keep working files or remove them.
399 # @param toKeep "keep working files" flag value
400 def SetKeepFiles(self, toKeep):
401 self.Parameters().SetKeepFiles(toKeep)
404 ## Remove or not the log file (if any) in case of successful computation.
405 # The log file remains in case of errors anyway. If
406 # the "keep working files" flag is set to true, this option
408 # @param toRemove "remove log on success" flag value
409 def SetRemoveLogOnSuccess(self, toRemove):
410 self.Parameters().SetRemoveLogOnSuccess(toRemove)
413 ## Print the the log in a file. If set to false, the
414 # log is printed on the standard output
415 # @param toPrintLogInFile "print log in a file" flag value
416 def SetPrintLogInFile(self, toPrintLogInFile):
417 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
420 ## Set verbosity level [0-10].
421 # @param level verbosity level
422 # - 0 - no standard output,
423 # - 2 - prints the data, quality statistics of the skin and final meshes and
424 # indicates when the final mesh is being saved. In addition the software
425 # gives indication regarding the CPU time.
426 # - 10 - same as 2 plus the main steps in the computation, quality statistics
427 # histogram of the skin mesh, quality statistics histogram together with
428 # the characteristics of the final mesh.
429 def SetVerboseLevel(self, level):
430 self.Parameters().SetVerboseLevel(level)
433 ## To create new nodes.
434 # @param toCreate "create new nodes" flag value
435 def SetToCreateNewNodes(self, toCreate):
436 self.Parameters().SetToCreateNewNodes(toCreate)
439 ## Sets command line option as text.
440 # @param option command line option
441 def SetAdvancedOption(self, option):
442 self.Parameters().SetAdvancedOption(option)
445 pass # end of GHS3D_Optimizer class