1 # Copyright (C) 2007-2023 CEA, EDF
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 the algorithm id
226 # @param algorithm ID 0 MGTetra HPC - 1 MGTetra
227 def SetAlgorithm(self,algoId):
228 self.Parameters().SetAlgorithm(algoId)
231 ## To use parallel mode
232 # @param toUseNumOfThreads "use max number of threads" flag value
233 def SetUseNumOfThreads(self,useThreads):
234 self.Parameters().SetUseNumOfThreads(useThreads)
237 ## To set the number of threads to be used
238 # @param numberOfThreads define max_num_threads for MGTetra and MGTetra HPC
239 def SetNumOfThreads(self,numThreads):
240 self.Parameters().SetNumOfThreads(numThreads)
243 ## Set SetPthreadMode.
244 # @param pthreadMode for parallel algorithm in MGTetra
248 def SetPthreadMode(self,pthreadMode):
249 self.Parameters().SetPthreadMode(pthreadMode)
252 ## Set SetParallelMode.
253 # @param parallelMode for parallel algorithm in MGTetra HPC
255 # - 1 - reproducible_given_max_number_of_threads
258 def SetPthreadMode(self,parallelMode):
259 self.Parameters().SetParallelMode(parallelMode)
262 ## To set an enforced vertex.
263 # @param x : x coordinate
264 # @param y : y coordinate
265 # @param z : z coordinate
266 # @param size : size of 1D element around enforced vertex
267 # @param vertexName : name of the enforced vertex
268 # @param groupName : name of the group
269 def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
272 return self.Parameters().SetEnforcedVertex(x, y, z, size)
274 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
278 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
280 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
284 ## To set an enforced vertex given a GEOM vertex, group or compound.
285 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
286 # @param size : size of 1D element around enforced vertex
287 # @param groupName : name of the group
288 def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
289 AssureGeomPublished( self.mesh, theVertex )
291 return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
293 return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
296 ## To remove an enforced vertex.
297 # @param x : x coordinate
298 # @param y : y coordinate
299 # @param z : z coordinate
300 def RemoveEnforcedVertex(self, x, y, z):
301 return self.Parameters().RemoveEnforcedVertex(x, y, z)
303 ## To remove an enforced vertex given a GEOM vertex, group or compound.
304 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
305 def RemoveEnforcedVertexGeom(self, theVertex):
306 AssureGeomPublished( self.mesh, theVertex )
307 return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
309 ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
310 # @param theSource : source mesh which provides constraint elements/nodes
311 # @param elementType : SMESH.ElementType (NODE, EDGE or FACE)
312 # @param size : size of elements around enforced elements. Unused if -1.
313 # @param groupName : group in which enforced elements will be added. Unused if "".
314 def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
317 return self.Parameters().SetEnforcedMesh(theSource, elementType)
319 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
323 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
325 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
329 ## Set advanced option value
330 # @param optionName option name
331 # @param optionValue option value
332 def SetOptionValue(self, optionName, optionValue):
333 self.Parameters().SetOptionValue( optionName, optionValue )
336 ## Sets command line option as text.
337 # @param optionAndValue command line option in a form "option value"
338 def SetAdvancedOption(self, optionAndValue):
339 self.Parameters().SetAdvancedOption(optionAndValue)
342 ## OBSOLETE Sets command line option as text.
343 # @param option command line option
344 def SetTextOption(self, option):
345 self.Parameters().SetAdvancedOption(option)
348 pass # end of GHS3D_Algorithm class
351 ## MG-Tetra Optimization algorithm - optimizer of tetrahedral meshes
353 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
354 class GHS3D_Optimizer(GHS3D_Algorithm):
356 ## name of the dynamic method in smeshBuilder.Mesh class
358 meshMethod = "Tetrahedron"
359 ## type of algorithm used with helper function in smeshBuilder.Mesh class
361 algoType = MG_Tetra_Optimization
362 ## doc string of the method in smeshBuilder.Mesh class
364 docHelper = "Creates MG-Tetra optimizer of tetrahedral meshes"
366 ## Private constructor.
367 # @param mesh parent mesh object algorithm is assigned to
368 # @param geom - not used
369 def __init__(self, mesh, geom=0):
370 GHS3D_Algorithm.__init__(self, mesh)
372 # remove some inherited methods
373 # del self.SetToMeshHoles
374 # del self.SetToMakeGroupsOfDomains
375 # del self.SetToUseBoundaryRecoveryVersion
376 # del self.SetFEMCorrection
377 # del self.SetToRemoveCentralPoint
378 # del self.SetEnforcedVertex
379 # del self.SetEnforcedVertexGeom
380 # del self.RemoveEnforcedVertex
381 # del self.RemoveEnforcedVertexGeom
382 # del self.SetEnforcedMesh
383 # del self.SetTextOption
386 ## Defines hypothesis having several parameters
387 # @return hypothesis object
388 def Parameters(self):
390 self.params = self.Hypothesis("MG-Tetra Optimization Parameters", [],
391 "libGHS3DEngine.so", UseExisting=0)
395 ## Set Optimization mode
396 # @param optMode optimization mode, one of the following values:
397 # smeshBuilder.Mode_NO,
398 # smeshBuilder.Mode_YES (default),
399 # smeshBuilder.MODE_ONLY
400 def SetOptimizationOnly(self, optMode ):
401 self.Parameters().SetOptimizationOnly(optMode)
404 ## Set mode of splitting over-constrained elements
405 # @param ovcMode, one of the following values
406 # smeshBuilder.Mode_NO (default),
407 # smeshBuilder.Mode_YES,
408 # smeshBuilder.Mode_ONLY
409 def SetSplitOverConstrained(self, ovcMode ):
410 self.Parameters().SetSplitOverConstrained(ovcMode)
413 ## Activate smoothing sliver elements:
414 # @param toSmooth - Boolean flag
415 def SetSmoothOffSlivers(self, toSmooth ):
416 self.Parameters().SetSmoothOffSlivers(toSmooth)
419 ## Set multithread mode
420 # @param mode - the mode, one of the following values:
421 # smeshBuilder.Mode_SAFE,
422 # smeshBuilder.Mode_AGGRESSIVE,
423 # smeshBuilder.Mode_NONE (default)
424 def SetPThreadsMode(self, mode ):
425 self.Parameters().SetPThreadsMode(mode)
428 ## Set maximal number of threads
429 # @param nb - number of threads
430 def SetMaximalNumberOfThreads(self, nb ):
431 self.Parameters().SetMaximalNumberOfThreads(nb)
435 ## Set Optimization level:
436 # @param level optimization level, one of the following values
437 # - None_Optimization
438 # - Light_Optimization
439 # - Standard_Optimization
440 # - StandardPlus_Optimization
441 # - Strong_Optimization.
443 # Default is Standard_Optimization
444 def SetOptimizationLevel(self, level):
445 self.Parameters().SetOptimizationLevel(level)
448 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
449 # @param MB maximal size of memory
450 def SetMaximumMemory(self, MB):
451 self.Parameters().SetMaximumMemory(MB)
454 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
455 # automatic memory adjustment mode.
456 # @param MB initial size of memory
457 def SetInitialMemory(self, MB):
458 self.Parameters().SetInitialMemory(MB)
461 ## Set path to working directory.
462 # @param path working directory
463 def SetWorkingDirectory(self, path):
464 self.Parameters().SetWorkingDirectory(path)
467 ## To keep working files or remove them.
468 # @param toKeep "keep working files" flag value
469 def SetKeepFiles(self, toKeep):
470 self.Parameters().SetKeepFiles(toKeep)
473 ## Remove or not the log file (if any) in case of successful computation.
474 # The log file remains in case of errors anyway. If
475 # the "keep working files" flag is set to true, this option
477 # @param toRemove "remove log on success" flag value
478 def SetRemoveLogOnSuccess(self, toRemove):
479 self.Parameters().SetRemoveLogOnSuccess(toRemove)
482 ## Print the the log in a file. If set to false, the
483 # log is printed on the standard output
484 # @param toPrintLogInFile "print log in a file" flag value
485 def SetPrintLogInFile(self, toPrintLogInFile):
486 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
489 ## Set verbosity level [0-10].
490 # @param level verbosity level
491 # - 0 - no standard output,
492 # - 2 - prints the data, quality statistics of the skin and final meshes and
493 # indicates when the final mesh is being saved. In addition the software
494 # gives indication regarding the CPU time.
495 # - 10 - same as 2 plus the main steps in the computation, quality statistics
496 # histogram of the skin mesh, quality statistics histogram together with
497 # the characteristics of the final mesh.
498 def SetVerboseLevel(self, level):
499 self.Parameters().SetVerboseLevel(level)
502 ## To create new nodes.
503 # @param toCreate "create new nodes" flag value
504 def SetToCreateNewNodes(self, toCreate):
505 self.Parameters().SetToCreateNewNodes(toCreate)
508 ## Sets command line option as text.
509 # @param option command line option
510 def SetAdvancedOption(self, option):
511 self.Parameters().SetAdvancedOption(option)
514 pass # end of GHS3D_Optimizer class
516 class hypoProxy(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis):
518 Private class wrapping to provide backward compatibility with deprecated API.
520 def __init__(self, *args):
521 GHS3DPlugin._objref_GHS3DPlugin_Hypothesis.__init__(self, *args)
522 def __deepcopy__(self, memo=None):
523 new = self.__class__(self)
525 def SetPrintLogInFile(self, value):
526 self.SetStandardOutputLog(not value)
527 omniORB.registerObjref(GHS3DPlugin._objref_GHS3DPlugin_Hypothesis._NP_RepositoryId, hypoProxy)