1 # Copyright (C) 2007-2020 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.
25 from salome.smesh.smesh_algorithm import Mesh_Algorithm
26 from salome.smesh.smeshBuilder import AssureGeomPublished
28 # import GHS3DPlugin module if possible
36 # Optimization level of MG-Tetra
38 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
39 # V4.1 (partialy redefines V3.1). Issue 0020574
40 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
42 # import items of enums
43 for e in GHS3DPlugin.Mode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
44 for e in GHS3DPlugin.PThreadsMode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
45 Mode_NO, Mode_YES, Mode_ONLY = GHS3DPlugin.Mode._items
46 Mode_SAFE, Mode_AGGRESSIVE, Mode_NONE = GHS3DPlugin.PThreadsMode._items
48 #----------------------------
49 # Mesh algo type identifiers
50 #----------------------------
52 ## Algorithm type: MG-Tetra tetrahedron 3D algorithm, see GHS3D_Algorithm
55 MG_Tetra_Optimization = "MG-Tetra Optimization"
57 ## Tetrahedron MG-Tetra 3D algorithm
59 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra, geom=0 )
60 class GHS3D_Algorithm(Mesh_Algorithm):
62 ## name of the dynamic method in smeshBuilder.Mesh class
64 meshMethod = "Tetrahedron"
65 ## type of algorithm used with helper function in smeshBuilder.Mesh class
68 ## doc string of the method in smeshBuilder.Mesh class
70 docHelper = "Creates tetrahedron 3D algorithm"
72 ## Private constructor.
73 # @param mesh parent mesh object algorithm is assigned to
74 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
75 # if it is @c 0 (default), the algorithm is assigned to the main shape
76 def __init__(self, mesh, geom=0):
77 Mesh_Algorithm.__init__(self)
78 if noGHS3DPlugin: print("Warning: GHS3DPlugin module unavailable")
79 self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
83 ## Defines hypothesis having several parameters
84 # @return hypothesis object
87 self.params = self.Hypothesis("MG-Tetra Parameters", [],
88 "libGHS3DEngine.so", UseExisting=0)
92 ## Set lower boundary of mesh element size
93 # Set it to zero to deactivate this option
94 def SetMinSize(self, theMinSize):
95 self.Parameters().SetMinSize(theMinSize)
98 ## Set upper boundary of mesh element size
99 # Set it to zero to deactivate this option
100 def SetMaxSize(self, theMaxSize):
101 self.Parameters().SetMaxSize(theMaxSize)
104 ## Activate/deactivate volume proximity computation
106 def SetVolumeProximity(self, toUse ):
107 self.Parameters().SetVolumeProximity(toUse)
110 ## Set number of surface element layers to be generated due to volume proximity
112 def SetNbVolumeProximityLayers(self, nbLayers ):
113 self.Parameters().SetNbVolumeProximityLayers(nbLayers)
116 ## To mesh "holes" in a solid or not. Default is to mesh.
117 # @param toMesh "mesh holes" flag value
118 def SetToMeshHoles(self, toMesh):
119 self.Parameters().SetToMeshHoles(toMesh)
122 ## To make groups of volumes of different domains when mesh is generated from skin.
123 # Default is to make groups.
124 # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
125 # @param toMakeGroups "Make groups of domains" flag value
126 def SetToMakeGroupsOfDomains(self, toMakeGroups):
127 self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
130 ## Set Optimization level:
131 # @param level optimization level, one of the following values
132 # - None_Optimization
133 # - Light_Optimization
134 # - Standard_Optimization
135 # - StandardPlus_Optimization
136 # - Strong_Optimization.
138 # Default is Standard_Optimization
139 def SetOptimizationLevel(self, level):
140 self.Parameters().SetOptimizationLevel(level)
143 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
144 # @param MB maximal size of memory
145 def SetMaximumMemory(self, MB):
146 self.Parameters().SetMaximumMemory(MB)
149 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
150 # automatic memory adjustment mode.
151 # @param MB initial size of memory
152 def SetInitialMemory(self, MB):
153 self.Parameters().SetInitialMemory(MB)
156 ## Set path to working directory.
157 # @param path working directory
158 def SetWorkingDirectory(self, path):
159 self.Parameters().SetWorkingDirectory(path)
162 ## To keep working files or remove them.
163 # @param toKeep "keep working files" flag value
164 def SetKeepFiles(self, toKeep):
165 self.Parameters().SetKeepFiles(toKeep)
168 ## Remove or not the log file (if any) in case of successful computation.
169 # The log file remains in case of errors anyway. If
170 # the "keep working files" flag is set to true, this option
172 # @param toRemove "remove log on success" flag value
173 def SetRemoveLogOnSuccess(self, toRemove):
174 self.Parameters().SetRemoveLogOnSuccess(toRemove)
177 ## Print the the log in a file. If set to false, the
178 # log is printed on the standard output
179 # @param toPrintLogInFile "print log in a file" flag value
180 def SetPrintLogInFile(self, toPrintLogInFile):
181 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
184 ## Set verbosity level [0-10].
185 # @param level verbosity level
186 # - 0 - no standard output,
187 # - 2 - prints the data, quality statistics of the skin and final meshes and
188 # indicates when the final mesh is being saved. In addition the software
189 # gives indication regarding the CPU time.
190 # - 10 - same as 2 plus the main steps in the computation, quality statistics
191 # histogram of the skin mesh, quality statistics histogram together with
192 # the characteristics of the final mesh.
193 def SetVerboseLevel(self, level):
194 self.Parameters().SetVerboseLevel(level)
197 ## To create new nodes.
198 # @param toCreate "create new nodes" flag value
199 def SetToCreateNewNodes(self, toCreate):
200 self.Parameters().SetToCreateNewNodes(toCreate)
203 ## To use boundary recovery version which tries to create mesh on a very poor
204 # quality surface mesh.
205 # @param toUse "use boundary recovery version" flag value
206 def SetToUseBoundaryRecoveryVersion(self, toUse):
207 self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
210 ## Applies finite-element correction by replacing overconstrained elements where
211 # it is possible. The process is cutting first the overconstrained edges and
212 # second the overconstrained facets. This insure that no edges have two boundary
213 # vertices and that no facets have three boundary vertices.
214 # @param toUseFem "apply finite-element correction" flag value
215 def SetFEMCorrection(self, toUseFem):
216 self.Parameters().SetFEMCorrection(toUseFem)
219 ## To remove initial central point.
220 # @param toRemove "remove initial central point" flag value
221 def SetToRemoveCentralPoint(self, toRemove):
222 self.Parameters().SetToRemoveCentralPoint(toRemove)
225 ## To set an enforced vertex.
226 # @param x : x coordinate
227 # @param y : y coordinate
228 # @param z : z coordinate
229 # @param size : size of 1D element around enforced vertex
230 # @param vertexName : name of the enforced vertex
231 # @param groupName : name of the group
232 def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
235 return self.Parameters().SetEnforcedVertex(x, y, z, size)
237 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
241 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
243 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
247 ## To set an enforced vertex given a GEOM vertex, group or compound.
248 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
249 # @param size : size of 1D element around enforced vertex
250 # @param groupName : name of the group
251 def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
252 AssureGeomPublished( self.mesh, theVertex )
254 return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
256 return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
259 ## To remove an enforced vertex.
260 # @param x : x coordinate
261 # @param y : y coordinate
262 # @param z : z coordinate
263 def RemoveEnforcedVertex(self, x, y, z):
264 return self.Parameters().RemoveEnforcedVertex(x, y, z)
266 ## To remove an enforced vertex given a GEOM vertex, group or compound.
267 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
268 def RemoveEnforcedVertexGeom(self, theVertex):
269 AssureGeomPublished( self.mesh, theVertex )
270 return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
272 ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
273 # @param theSource : source mesh which provides constraint elements/nodes
274 # @param elementType : SMESH.ElementType (NODE, EDGE or FACE)
275 # @param size : size of elements around enforced elements. Unused if -1.
276 # @param groupName : group in which enforced elements will be added. Unused if "".
277 def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
280 return self.Parameters().SetEnforcedMesh(theSource, elementType)
282 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
286 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
288 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
292 ## Set advanced option value
293 # @param optionName option name
294 # @param optionValue option value
295 def SetOptionValue(self, optionName, optionValue):
296 self.Parameters().SetOptionValue( optionName, optionValue )
299 ## Sets command line option as text.
300 # @param optionAndValue command line option in a form "option value"
301 def SetAdvancedOption(self, optionAndValue):
302 self.Parameters().SetAdvancedOption(optionAndValue)
305 ## OBSOLETE Sets command line option as text.
306 # @param option command line option
307 def SetTextOption(self, option):
308 self.Parameters().SetAdvancedOption(option)
311 pass # end of GHS3D_Algorithm class
314 ## MG-Tetra Optimization algorithm - optimizer of tetrahedral meshes
316 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
317 class GHS3D_Optimizer(GHS3D_Algorithm):
319 ## name of the dynamic method in smeshBuilder.Mesh class
321 meshMethod = "Tetrahedron"
322 ## type of algorithm used with helper function in smeshBuilder.Mesh class
324 algoType = MG_Tetra_Optimization
325 ## doc string of the method in smeshBuilder.Mesh class
327 docHelper = "Creates MG-Tetra optimizer of tetrahedral meshes"
329 ## Private constructor.
330 # @param mesh parent mesh object algorithm is assigned to
331 # @param geom - not used
332 def __init__(self, mesh, geom=0):
333 GHS3D_Algorithm.__init__(self, mesh)
335 # remove some inherited methods
336 # del self.SetToMeshHoles
337 # del self.SetToMakeGroupsOfDomains
338 # del self.SetToUseBoundaryRecoveryVersion
339 # del self.SetFEMCorrection
340 # del self.SetToRemoveCentralPoint
341 # del self.SetEnforcedVertex
342 # del self.SetEnforcedVertexGeom
343 # del self.RemoveEnforcedVertex
344 # del self.RemoveEnforcedVertexGeom
345 # del self.SetEnforcedMesh
346 # del self.SetTextOption
349 ## Defines hypothesis having several parameters
350 # @return hypothesis object
351 def Parameters(self):
353 self.params = self.Hypothesis("MG-Tetra Optimization Parameters", [],
354 "libGHS3DEngine.so", UseExisting=0)
358 ## Set Optimization mode
359 # @param optMode optimization mode, one of the following values:
360 # smeshBuilder.Mode_NO,
361 # smeshBuilder.Mode_YES (default),
362 # smeshBuilder.MODE_ONLY
363 def SetOptimizationOnly(self, optMode ):
364 self.Parameters().SetOptimizationOnly(optMode)
367 ## Set mode of splitting over-constrained elements
368 # @param ovcMode, one of the following values
369 # smeshBuilder.Mode_NO (default),
370 # smeshBuilder.Mode_YES,
371 # smeshBuilder.Mode_ONLY
372 def SetSplitOverConstrained(self, ovcMode ):
373 self.Parameters().SetSplitOverConstrained(ovcMode)
376 ## Activate smoothing sliver elements:
377 # @param toSmooth - Boolean flag
378 def SetSmoothOffSlivers(self, toSmooth ):
379 self.Parameters().SetSmoothOffSlivers(toSmooth)
382 ## Set multithread mode
383 # @param mode - the mode, one of the following values:
384 # smeshBuilder.Mode_SAFE,
385 # smeshBuilder.Mode_AGGRESSIVE,
386 # smeshBuilder.Mode_NONE (default)
387 def SetPThreadsMode(self, mode ):
388 self.Parameters().SetPThreadsMode(mode)
391 ## Set maximal number of threads
392 # @param nb - number of threads
393 def SetMaximalNumberOfThreads(self, nb ):
394 self.Parameters().SetMaximalNumberOfThreads(nb)
398 ## Set Optimization level:
399 # @param level optimization level, one of the following values
400 # - None_Optimization
401 # - Light_Optimization
402 # - Standard_Optimization
403 # - StandardPlus_Optimization
404 # - Strong_Optimization.
406 # Default is Standard_Optimization
407 def SetOptimizationLevel(self, level):
408 self.Parameters().SetOptimizationLevel(level)
411 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
412 # @param MB maximal size of memory
413 def SetMaximumMemory(self, MB):
414 self.Parameters().SetMaximumMemory(MB)
417 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
418 # automatic memory adjustment mode.
419 # @param MB initial size of memory
420 def SetInitialMemory(self, MB):
421 self.Parameters().SetInitialMemory(MB)
424 ## Set path to working directory.
425 # @param path working directory
426 def SetWorkingDirectory(self, path):
427 self.Parameters().SetWorkingDirectory(path)
430 ## To keep working files or remove them.
431 # @param toKeep "keep working files" flag value
432 def SetKeepFiles(self, toKeep):
433 self.Parameters().SetKeepFiles(toKeep)
436 ## Remove or not the log file (if any) in case of successful computation.
437 # The log file remains in case of errors anyway. If
438 # the "keep working files" flag is set to true, this option
440 # @param toRemove "remove log on success" flag value
441 def SetRemoveLogOnSuccess(self, toRemove):
442 self.Parameters().SetRemoveLogOnSuccess(toRemove)
445 ## Print the the log in a file. If set to false, the
446 # log is printed on the standard output
447 # @param toPrintLogInFile "print log in a file" flag value
448 def SetPrintLogInFile(self, toPrintLogInFile):
449 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
452 ## Set verbosity level [0-10].
453 # @param level verbosity level
454 # - 0 - no standard output,
455 # - 2 - prints the data, quality statistics of the skin and final meshes and
456 # indicates when the final mesh is being saved. In addition the software
457 # gives indication regarding the CPU time.
458 # - 10 - same as 2 plus the main steps in the computation, quality statistics
459 # histogram of the skin mesh, quality statistics histogram together with
460 # the characteristics of the final mesh.
461 def SetVerboseLevel(self, level):
462 self.Parameters().SetVerboseLevel(level)
465 ## To create new nodes.
466 # @param toCreate "create new nodes" flag value
467 def SetToCreateNewNodes(self, toCreate):
468 self.Parameters().SetToCreateNewNodes(toCreate)
471 ## Sets command line option as text.
472 # @param option command line option
473 def SetAdvancedOption(self, option):
474 self.Parameters().SetAdvancedOption(option)
477 pass # end of GHS3D_Optimizer class
479 class hypoProxy(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis):
481 Private class wrapping to provide backward compatibility with deprecated API.
483 def __init__(self, *args):
484 GHS3DPlugin._objref_GHS3DPlugin_Hypothesis.__init__(self, *args)
485 def __deepcopy__(self, memo=None):
486 new = self.__class__(self)
488 def SetPrintLogInFile(self, value):
489 self.SetStandardOutputLog(not value)
490 omniORB.registerObjref(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis._NP_RepositoryId, hypoProxy)