1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 # @package HYBRIDPluginBuilder
23 # Python API for the HYBRID meshing plug-in module.
25 from salome.smesh.smesh_algorithm import Mesh_Algorithm
26 from salome.smesh.smeshBuilder import AssureGeomPublished
28 # import HYBRIDPlugin module if possible
36 # Optimization level of HYBRID
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
43 Decrease_Collision_Mode, Stop_Collision_Mode = 0,1
45 # Boundary Layers growing inward or outward.
46 Layer_Growth_Inward, Layer_Growth_Outward = 0,1
48 # Mesh with element type Tetra Dominant or hexa Dominant in the remaining volume (outside layers).
49 Generation_Tetra_Dominant, Generation_Hexa_Dominant, Generation_Cartesian_Core = 0,1,2
51 #----------------------------
52 # Mesh algo type identifiers
53 #----------------------------
55 ## Algorithm type: HYBRID tetra-hexahedron 3D algorithm, see HYBRID_Algorithm
56 MG_Hybrid = "HYBRID_3D"
59 ## MG-Hybrid 3D algorithm
61 # It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.HYBRID, geom=0 )
62 class HYBRID_Algorithm(Mesh_Algorithm):
64 ## name of the dynamic method in smeshBuilder.Mesh class
66 meshMethod = "Tetrahedron"
67 ## type of algorithm used with helper function in smeshBuilder.Mesh class
70 ## doc string of the method in smeshBuilder.Mesh class
72 docHelper = "Creates tetrahedron 3D algorithm for volumes"
74 ## Private constructor.
75 # @param mesh parent mesh object algorithm is assigned to
76 # @param geom geometry (shape/sub-shape) algorithm is assigned to;
77 # if it is @c 0 (default), the algorithm is assigned to the main shape
78 def __init__(self, mesh, geom=0):
79 Mesh_Algorithm.__init__(self)
80 if noHYBRIDPlugin: print("Warning: HYBRIDPlugin module unavailable")
81 self.Create(mesh, geom, self.algoType, "libHYBRIDEngine.so")
85 ## Defines hypothesis having several parameters
86 # @return hypothesis object
89 self.params = self.Hypothesis("HYBRID_Parameters", [],
90 "libHYBRIDEngine.so", UseExisting=0)
94 ## To mesh layers on all wrap. Default is to mesh.
95 # @param toMesh "mesh layers on all wrap" flag value
96 def SetLayersOnAllWrap(self, toMesh):
97 self.Parameters().SetLayersOnAllWrap(toMesh)
100 ## To mesh layers on given faces.
101 # @param faceIDs faces or face IDs to construct boundary layers on
102 def SetFacesWithLayers(self, faceIDs):
105 if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
106 faceIDs = [ faceIDs ]
108 if isinstance( fid, int ):
110 elif isinstance( fid, GEOM._objref_GEOM_Object):
111 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
113 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
115 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
117 self.Parameters().SetFacesWithLayers(ids)
119 self.SetLayersOnAllWrap( False )
122 ## To imprint the layers on given faces.
123 # @param faceIDs faces or face IDs to imprint the boundary layers on
124 def SetFacesWithImprinting(self, faceIDs):
127 if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
128 faceIDs = [ faceIDs ]
130 if isinstance( fid, int ):
132 elif isinstance( fid, GEOM._objref_GEOM_Object):
133 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
135 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
137 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
139 self.Parameters().SetFacesWithImprinting(ids)
141 self.SetLayersOnAllWrap( False )
144 ## To snap the layers on given surface (use existing surface layers as base for volume layers).
145 # @param faceIDs faces or face IDs that already have surface layers
146 def SetFacesWithSnapping(self, faceIDs):
149 if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
150 faceIDs = [ faceIDs ]
152 if isinstance( fid, int ):
154 elif isinstance( fid, GEOM._objref_GEOM_Object):
155 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
157 ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
159 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
161 self.Parameters().SetFacesWithSnapping(ids)
163 self.SetLayersOnAllWrap( False )
168 ## To mesh "holes" in a solid or not. Default is to mesh.
169 # @param toMesh "mesh holes" flag value
170 def SetToMeshHoles(self, toMesh):
171 self.Parameters().SetToMeshHoles(toMesh)
174 ## To make groups of volumes of different domains when mesh is generated from skin.
175 # Default is to make groups.
176 # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
177 # @param toMesh "mesh holes" flag value
178 def SetToMakeGroupsOfDomains(self, toMakeGroups):
179 self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
182 ## Set Optimization level:
183 # @param level optimization level, one of the following values
184 # - None_Optimization
185 # - Light_Optimization
186 # - Standard_Optimization
187 # - StandardPlus_Optimization
188 # - Strong_Optimization.
190 # Default is Standard_Optimization
191 def SetOptimizationLevel(self, level):
192 self.Parameters().SetOptimizationLevel(level)
195 ## Set maximal size of memory to be used by the algorithm (in Megabytes).
196 # @param MB maximal size of memory
197 def SetMaximumMemory(self, MB):
198 self.Parameters().SetMaximumMemory(MB)
201 ## Set initial size of memory to be used by the algorithm (in Megabytes) in
202 # automatic memory adjustment mode.
203 # @param MB initial size of memory
204 def SetInitialMemory(self, MB):
205 self.Parameters().SetInitialMemory(MB)
209 ## Set Collision Mode:
210 # @param mode Collision Mode, one of the following values
211 # - Decrease_Collision_Mode
212 # - Stop_Collision_Mode
214 # Default is Decrease_Collision_Mode
215 def SetCollisionMode(self, mode):
216 self.Parameters().SetCollisionMode(mode)
219 ## To mesh Boundary Layers growing inward or outward.
220 # @param mode, one of the following values
221 # - Layer_Growth_Inward
222 # - Layer_Growth_Outward
224 # Default is Layer_Growth_Inward
225 def SetBoundaryLayersGrowth(self, mode):
226 self.Parameters().SetBoundaryLayersGrowth(mode)
229 ## To mesh with element type Tetra Dominant or hexa Dominant in the remaining volume (outside layers).
230 # @param mode, one of the following values
231 # - Generation_Tetra_Dominant
232 # - Generation_Hexa_Dominant
233 # - Generation_Cartesian_Core
235 # Default is Generation_Tetra_Dominant
236 def SetElementGeneration(self, mode):
237 self.Parameters().SetElementGeneration(mode)
240 ## To mesh adding extra normals at opening ridges and corners.
242 # @param addMultinormals boolean value
243 def SetAddMultinormals(self, addMultinormals):
244 self.Parameters().SetAddMultinormals(addMultinormals)
247 ## To mesh smoothing normals at closed ridges and corners.
249 # @param smoothNormals boolean value
250 def SetSmoothNormals(self, smoothNormals):
251 self.Parameters().SetSmoothNormals(smoothNormals)
254 ## To set height of the first layer.
256 # @param heightFirstLayer double value
257 def SetHeightFirstLayer(self, heightFirstLayer):
258 self.Parameters().SetHeightFirstLayer(heightFirstLayer)
261 ## To set boundary layers coefficient of geometric progression.
263 # @param boundaryLayersProgression double value
264 def SetBoundaryLayersProgression(self, boundaryLayersProgression):
265 self.Parameters().SetBoundaryLayersProgression(boundaryLayersProgression)
268 ## Set core elements size.
270 # @param CoreSize double value
271 def SetCoreSize(self, CoreSize):
272 self.Parameters().SetCoreSize(CoreSize)
275 ## To set multinormals angle threshold at opening ridges.
277 # @param multinormalsAngle double value
278 def SetMultinormalsAngle(self, multinormalsAngle):
279 self.Parameters().SetMultinormalsAngle(multinormalsAngle)
282 ## To set number of boundary layers.
284 # @param nbOfBoundaryLayers int value
285 def SetNbOfBoundaryLayers(self, nbOfBoundaryLayers):
286 self.Parameters().SetNbOfBoundaryLayers(nbOfBoundaryLayers)
289 ## Set path to working directory.
290 # @param path working directory
291 def SetWorkingDirectory(self, path):
292 self.Parameters().SetWorkingDirectory(path)
295 ## To keep working files or remove them.
296 # @param toKeep "keep working files" flag value
297 def SetKeepFiles(self, toKeep):
298 self.Parameters().SetKeepFiles(toKeep)
301 ## Remove or not the log file (if any) in case of successful computation.
302 # The log file remains in case of errors anyway. If
303 # the "keep working files" flag is set to true, this option
305 # @param toRemove "remove log on success" flag value
306 def SetRemoveLogOnSuccess(self, toRemove):
307 self.Parameters().SetRemoveLogOnSuccess(toRemove)
310 ## Print the the log in a file. If set to false, the
311 # log is printed on the standard output
312 # @param toPrintLogInFile "print log in a file" flag value
313 def SetPrintLogInFile(self, toPrintLogInFile):
314 self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
317 ## Set verbosity level [0-10].
318 # @param level verbosity level
319 # - 0 - no standard output,
320 # - 2 - prints the data, quality statistics of the skin and final meshes and
321 # indicates when the final mesh is being saved. In addition the software
322 # gives indication regarding the CPU time.
323 # - 10 - same as 2 plus the main steps in the computation, quality statistics
324 # histogram of the skin mesh, quality statistics histogram together with
325 # the characteristics of the final mesh.
326 def SetVerboseLevel(self, level):
327 self.Parameters().SetVerboseLevel(level)
330 ## To create new nodes.
331 # @param toCreate "create new nodes" flag value
332 def SetToCreateNewNodes(self, toCreate):
333 self.Parameters().SetToCreateNewNodes(toCreate)
336 ## To use boundary recovery version which tries to create mesh on a very poor
337 # quality surface mesh.
338 # @param toUse "use boundary recovery version" flag value
339 def SetToUseBoundaryRecoveryVersion(self, toUse):
340 self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
343 ## Applies finite-element correction by replacing overconstrained elements where
344 # it is possible. The process is cutting first the overconstrained edges and
345 # second the overconstrained facets. This insure that no edges have two boundary
346 # vertices and that no facets have three boundary vertices.
347 # @param toUseFem "apply finite-element correction" flag value
348 def SetFEMCorrection(self, toUseFem):
349 self.Parameters().SetFEMCorrection(toUseFem)
352 ## To remove initial central point.
353 # @param toRemove "remove initial central point" flag value
354 def SetToRemoveCentralPoint(self, toRemove):
355 self.Parameters().SetToRemoveCentralPoint(toRemove)
358 ## To set an enforced vertex.
359 # @param x : x coordinate
360 # @param y : y coordinate
361 # @param z : z coordinate
362 # @param size : size of 1D element around enforced vertex
363 # @param vertexName : name of the enforced vertex
364 # @param groupName : name of the group
365 def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
368 return self.Parameters().SetEnforcedVertex(x, y, z, size)
370 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
374 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
376 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
380 ## To set an enforced vertex given a GEOM vertex, group or compound.
381 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
382 # @param size : size of 1D element around enforced vertex
383 # @param groupName : name of the group
384 def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
385 AssureGeomPublished( self.mesh, theVertex )
387 return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
389 return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
392 ## To remove an enforced vertex.
393 # @param x : x coordinate
394 # @param y : y coordinate
395 # @param z : z coordinate
396 def RemoveEnforcedVertex(self, x, y, z):
397 return self.Parameters().RemoveEnforcedVertex(x, y, z)
399 ## To remove an enforced vertex given a GEOM vertex, group or compound.
400 # @param theVertex : GEOM vertex (or group, compound) to be projected on theFace.
401 def RemoveEnforcedVertexGeom(self, theVertex):
402 AssureGeomPublished( self.mesh, theVertex )
403 return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
405 ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
406 # @param theSource : source mesh which provides constraint elements/nodes
407 # @param elementType : SMESH.ElementType (NODE, EDGE or FACE)
408 # @param size : size of elements around enforced elements. Unused if -1.
409 # @param groupName : group in which enforced elements will be added. Unused if "".
410 def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
413 return self.Parameters().SetEnforcedMesh(theSource, elementType)
415 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
419 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
421 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
425 ## Sets command line option as text.
427 # OBSOLETE. Use SetAdvancedOption()
428 # @param option command line option
429 def SetTextOption(self, option):
430 self.Parameters().SetAdvancedOption(option)
433 ## Sets command line option as text.
434 # @param option command line option
435 def SetAdvancedOption(self, option):
436 self.Parameters().SetAdvancedOption(option)
439 pass # end of HYBRID_Algorithm class