]> SALOME platform Git repositories - plugins/hybridplugin.git/blob - src/HYBRIDPlugin/HYBRIDPluginBuilder.py
Salome HOME
Merge branch 'V9_13_BR'
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPluginBuilder.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2024  CEA, EDF
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 ##
22 # @package HYBRIDPluginBuilder
23 # Python API for the HYBRID meshing plug-in module.
24
25 from salome.smesh.smesh_algorithm import Mesh_Algorithm
26 from salome.smesh.smeshBuilder import AssureGeomPublished
27
28 # import HYBRIDPlugin module if possible
29 noHYBRIDPlugin = 0
30 try:
31     import HYBRIDPlugin
32 except ImportError:
33     noHYBRIDPlugin = 1
34     pass
35
36 # Optimization level of HYBRID
37 # V3.1
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
41
42 # Collision Mode
43 Decrease_Collision_Mode, Stop_Collision_Mode = 0,1
44
45 # Boundary Layers growing inward or outward.
46 Layer_Growth_Inward, Layer_Growth_Outward = 0,1
47
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
50
51 #----------------------------
52 # Mesh algo type identifiers
53 #----------------------------
54
55 ## Algorithm type: HYBRID tetra-hexahedron 3D algorithm, see HYBRID_Algorithm
56 MG_Hybrid = "HYBRID_3D"
57 HYBRID = MG_Hybrid
58
59 ## MG-Hybrid 3D algorithm
60 #  
61 #  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.HYBRID, geom=0 )
62 class HYBRID_Algorithm(Mesh_Algorithm):
63
64     ## name of the dynamic method in smeshBuilder.Mesh class
65     #  @internal
66     meshMethod = "Tetrahedron"
67     ## type of algorithm used with helper function in smeshBuilder.Mesh class
68     #  @internal
69     algoType   = MG_Hybrid
70     ## doc string of the method in smeshBuilder.Mesh class
71     #  @internal
72     docHelper  = "Creates tetrahedron 3D algorithm for volumes"
73
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")
82         self.params = None
83         pass
84
85     ## Defines hypothesis having several parameters
86     #  @return hypothesis object
87     def Parameters(self):
88         if not self.params:
89             self.params = self.Hypothesis("HYBRID_Parameters", [],
90                                           "libHYBRIDEngine.so", UseExisting=0)
91             pass
92         return self.params
93
94     ## To call MG-Hybrid by library. Default is no (i.e. by executable)
95     #  @param toUseLib "mesh layers on all wrap" flag value
96     def SetToUseLibrary(self, toUseLib):
97         self.Parameters().SetToUseLibrary(toUseLib)
98         pass
99
100     ## To mesh layers on all wrap. Default is to mesh.
101     #  @param toMesh "mesh layers on all wrap" flag value
102     def SetLayersOnAllWrap(self, toMesh):
103         self.Parameters().SetLayersOnAllWrap(toMesh)
104         pass
105
106     ## To mesh layers on given faces.
107     #  @param faceIDs faces or face IDs to construct boundary layers on
108     def SetFacesWithLayers(self, faceIDs):
109         import GEOM
110         ids = []
111         if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
112             faceIDs = [ faceIDs ]
113         for fid in faceIDs:
114             if isinstance( fid, int ):
115                 ids.append( fid )
116             elif isinstance( fid, GEOM._objref_GEOM_Object):
117                 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
118                 for f in faces:
119                     ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
120             else:
121                 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
122             pass
123         self.Parameters().SetFacesWithLayers(ids)
124         if ids:
125             self.SetLayersOnAllWrap( False )
126         pass
127
128     ## To imprint the layers on given faces.
129     #  @param faceIDs faces or face IDs to imprint the boundary layers on
130     def SetFacesWithImprinting(self, faceIDs):
131         import GEOM
132         ids = []
133         if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
134             faceIDs = [ faceIDs ]
135         for fid in faceIDs:
136             if isinstance( fid, int ):
137                 ids.append( fid )
138             elif isinstance( fid, GEOM._objref_GEOM_Object):
139                 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
140                 for f in faces:
141                     ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
142             else:
143                 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
144             pass
145         self.Parameters().SetFacesWithImprinting(ids)
146         if ids:
147             self.SetLayersOnAllWrap( False )
148         pass
149
150     ## To snap the layers on given surface (use existing surface layers as base for volume layers).
151     #  @param faceIDs faces or face IDs that already have surface layers
152     def SetFacesWithSnapping(self, faceIDs):
153         import GEOM
154         ids = []
155         if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
156             faceIDs = [ faceIDs ]
157         for fid in faceIDs:
158             if isinstance( fid, int ):
159                 ids.append( fid )
160             elif isinstance( fid, GEOM._objref_GEOM_Object):
161                 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
162                 for f in faces:
163                     ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
164             else:
165                 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
166             pass
167         self.Parameters().SetFacesWithSnapping(ids)
168         if ids:
169             self.SetLayersOnAllWrap( False )
170         pass
171
172     ## Set Collision Mode:
173     #  @param mode Collision Mode, one of the following values
174     #  - Decrease_Collision_Mode
175     #  - Stop_Collision_Mode
176     #  .
177     #  Default is Decrease_Collision_Mode
178     def SetCollisionMode(self, mode):
179         self.Parameters().SetCollisionMode(mode)
180         pass
181
182     ## To mesh Boundary Layers growing inward or outward.
183     #  @param mode, one of the following values
184     #  - Layer_Growth_Inward
185     #  - Layer_Growth_Outward
186     #  .
187     #  Default is Layer_Growth_Inward
188     def SetBoundaryLayersGrowth(self, mode):
189         self.Parameters().SetBoundaryLayersGrowth(mode)
190         pass
191
192     ## To mesh with element type Tetra Dominant or hexa Dominant in the remaining volume (outside layers).
193     #  @param mode, one of the following values
194     #  - Generation_Tetra_Dominant
195     #  - Generation_Hexa_Dominant
196     #  - Generation_Cartesian_Core
197     #  .
198     # Default is Generation_Tetra_Dominant
199     def SetElementGeneration(self, mode):
200         self.Parameters().SetElementGeneration(mode)
201         pass
202
203     ## To mesh adding extra normals at opening ridges and corners.
204     # Default is no.
205     # @param addMultinormals boolean value
206     def SetAddMultinormals(self, addMultinormals):
207         self.Parameters().SetAddMultinormals(addMultinormals)
208         pass
209
210     ## To mesh smoothing normals at closed ridges and corners.
211     # Default is no.
212     # @param smoothNormals boolean value
213     def SetSmoothNormals(self, smoothNormals):
214         self.Parameters().SetSmoothNormals(smoothNormals)
215         pass
216
217     ## To set height of the first layer.
218     # Default is 0.0
219     # @param heightFirstLayer double value
220     def SetHeightFirstLayer(self, heightFirstLayer):
221         self.Parameters().SetHeightFirstLayer(heightFirstLayer)
222         pass
223
224     ## Sizes of boundary layers are relative to the surface size. Default no
225     #  @param isRelative boolean flag
226     def SetHeightIsRelative(self, isRelative):
227         self.Parameters().SetHeightIsRelative( isRelative )
228         pass
229
230     ## To set boundary layers coefficient of geometric progression.
231     # Default is 1.0
232     # @param boundaryLayersProgression double value
233     def SetBoundaryLayersProgression(self, boundaryLayersProgression):
234         self.Parameters().SetBoundaryLayersProgression(boundaryLayersProgression)
235         pass
236
237     ## Set core elements size.
238     # Default is 0.0
239     # @param CoreSize double value
240     def SetCoreSize(self, CoreSize):
241         self.Parameters().SetCoreSize(CoreSize)
242         pass
243
244     ## To set multinormals angle threshold at opening ridges.
245     # Default is 30.0
246     # @param multinormalsAngle double value
247     def SetMultinormalsAngle(self, multinormalsAngle):
248         self.Parameters().SetMultinormalsAngle(multinormalsAngle)
249         pass
250
251     ## To set number of boundary layers.
252     # Default is 1
253     # @param nbOfBoundaryLayers int value
254     def SetNbOfBoundaryLayers(self, nbOfBoundaryLayers):
255         self.Parameters().SetNbOfBoundaryLayers(nbOfBoundaryLayers)
256         pass
257
258     ## Set maximum internal angles of boundary elements (in degree)
259     #  @param angle angle in degree
260     def SetBoundaryLayersMaxElemAngle(self, angle):
261         self.Parameters().SetBoundaryLayersMaxElemAngle( angle )
262         pass
263
264     ## Set path to working directory.
265     #  @param path working directory
266     def SetWorkingDirectory(self, path):
267         self.Parameters().SetWorkingDirectory(path)
268         pass
269
270     ## To keep working files or remove them.
271     #  @param toKeep "keep working files" flag value
272     def SetKeepFiles(self, toKeep):
273         self.Parameters().SetKeepFiles(toKeep)
274         pass
275     
276     ## Remove or not the log file (if any) in case of successful computation.
277     #  The log file remains in case of errors anyway. If 
278     #  the "keep working files" flag is set to true, this option
279     #  has no effect.
280     #  @param toRemove "remove log on success" flag value
281     def SetRemoveLogOnSuccess(self, toRemove):
282         self.Parameters().SetRemoveLogOnSuccess(toRemove)
283         pass
284     
285     ## Print the the log in a file. If set to false, the
286     # log is printed on the standard output
287     #  @param toPrintLogInFile "print log in a file" flag value
288     def SetPrintLogInFile(self, toPrintLogInFile):
289         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
290         pass
291
292     ## Set verbosity level [0-10].
293     #  @param level verbosity level
294     #  - 0 - no standard output,
295     #  - 2 - prints the data, quality statistics of the skin and final meshes and
296     #    indicates when the final mesh is being saved. In addition the software
297     #    gives indication regarding the CPU time.
298     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
299     #    histogram of the skin mesh, quality statistics histogram together with
300     #    the characteristics of the final mesh.
301     def SetVerboseLevel(self, level):
302         self.Parameters().SetVerboseLevel(level)
303         pass
304
305     ## To create new nodes.
306     #  @param toCreate "create new nodes" flag value
307     def SetToCreateNewNodes(self, toCreate):
308         self.Parameters().SetToCreateNewNodes(toCreate)
309         pass
310
311     ## To use boundary recovery version which tries to create mesh on a very poor
312     #  quality surface mesh.
313     #  @param toUse "use boundary recovery version" flag value
314     def SetToUseBoundaryRecoveryVersion(self, toUse):
315         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
316         pass
317
318     ## Applies finite-element correction by replacing overconstrained elements where
319     #  it is possible. The process is cutting first the overconstrained edges and
320     #  second the overconstrained facets. This insure that no edges have two boundary
321     #  vertices and that no facets have three boundary vertices.
322     #  @param toUseFem "apply finite-element correction" flag value
323     def SetFEMCorrection(self, toUseFem):
324         self.Parameters().SetFEMCorrection(toUseFem)
325         pass
326
327     ## To remove initial central point.
328     #  @param toRemove "remove initial central point" flag value
329     def SetToRemoveCentralPoint(self, toRemove):
330         self.Parameters().SetToRemoveCentralPoint(toRemove)
331         pass
332
333     ## To set an enforced vertex.
334     #  @param x            : x coordinate
335     #  @param y            : y coordinate
336     #  @param z            : z coordinate
337     #  @param size         : size of 1D element around enforced vertex
338     #  @param vertexName   : name of the enforced vertex
339     #  @param groupName    : name of the group
340     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
341         if vertexName == "":
342             if groupName == "":
343                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
344             else:
345                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
346             pass
347         else:
348             if groupName == "":
349                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
350             else:
351                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
352             pass
353         pass
354
355     ## To set an enforced vertex given a GEOM vertex, group or compound.
356     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
357     #  @param size         : size of 1D element around enforced vertex
358     #  @param groupName    : name of the group
359     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
360         AssureGeomPublished( self.mesh, theVertex )
361         if groupName == "":
362             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
363         else:
364             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
365         pass
366
367     ## To remove an enforced vertex.
368     #  @param x            : x coordinate
369     #  @param y            : y coordinate
370     #  @param z            : z coordinate
371     def RemoveEnforcedVertex(self, x, y, z):
372         return self.Parameters().RemoveEnforcedVertex(x, y, z)
373
374     ## To remove an enforced vertex given a GEOM vertex, group or compound.
375     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
376     def RemoveEnforcedVertexGeom(self, theVertex):
377         AssureGeomPublished( self.mesh, theVertex )
378         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
379
380     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
381     #  @param theSource    : source mesh which provides constraint elements/nodes
382     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
383     #  @param size         : size of elements around enforced elements. Unused if -1.
384     #  @param groupName    : group in which enforced elements will be added. Unused if "".
385     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
386         if size < 0:
387             if groupName == "":
388                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
389             else:
390                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
391             pass
392         else:
393             if groupName == "":
394                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
395             else:
396                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
397             pass
398         pass
399
400     ## Set advanced option value
401     #  @param optionName option name
402     #  @param optionValue option value
403     def SetOptionValue(self, optionName, optionValue):
404         self.Parameters().SetOptionValue( optionName, optionValue )
405         pass
406
407     ## Sets command line option as text.
408     #  @param optionAndValue command line option in a form "option value"
409     def SetAdvancedOption(self, optionAndValue):
410         self.Parameters().SetAdvancedOption(optionAndValue)
411         pass
412     
413     ## Sets command line option as text.
414     #
415     # OBSOLETE. Use SetAdvancedOption()
416     #  @param option command line option
417     def SetTextOption(self, option):
418         self.Parameters().SetAdvancedOption(option)
419         pass
420    
421     pass # end of HYBRID_Algorithm class