]> SALOME platform Git repositories - plugins/hybridplugin.git/blob - src/HYBRIDPlugin/HYBRIDPluginBuilder.py
Salome HOME
Merge remote-tracking branch 'origin/V8_3_BR' into gdd/python3_dev
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPluginBuilder.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D
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 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)
98         pass
99
100     ## To mesh layers on given faces.
101     #  @param faceIDs faces or face IDs to construct boundary layers on
102     def SetFacesWithLayers(self, faceIDs):
103         import GEOM
104         ids = []
105         if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
106             faceIDs = [ faceIDs ]
107         for fid in faceIDs:
108             if isinstance( fid, int ):
109                 ids.append( fid )
110             elif isinstance( fid, GEOM._objref_GEOM_Object):
111                 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
112                 for f in faces:
113                     ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
114             else:
115                 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
116             pass
117         self.Parameters().SetFacesWithLayers(ids)
118         if ids:
119             self.SetLayersOnAllWrap( False )
120         pass
121
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):
125         import GEOM
126         ids = []
127         if not isinstance( faceIDs, list ) and not isinstance( faceIDs, tuple ):
128             faceIDs = [ faceIDs ]
129         for fid in faceIDs:
130             if isinstance( fid, int ):
131                 ids.append( fid )
132             elif isinstance( fid, GEOM._objref_GEOM_Object):
133                 faces = self.mesh.geompyD.SubShapeAll( fid, self.mesh.geompyD.ShapeType["FACE"])
134                 for f in faces:
135                     ids.append( self.mesh.geompyD.GetSubShapeID( self.mesh.geom, f ))
136             else:
137                 raise TypeError("Face should be either ID or GEOM_Object, not %s" % type(fid))
138             pass
139         self.Parameters().SetFacesWithImprinting(ids)
140         if ids:
141             self.SetLayersOnAllWrap( False )
142         pass
143
144     """
145     obsolete
146     ## To mesh "holes" in a solid or not. Default is to mesh.
147     #  @param toMesh "mesh holes" flag value
148     def SetToMeshHoles(self, toMesh):
149         self.Parameters().SetToMeshHoles(toMesh)
150         pass
151
152     ## To make groups of volumes of different domains when mesh is generated from skin.
153     #  Default is to make groups.
154     # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
155     #  @param toMesh "mesh holes" flag value
156     def SetToMakeGroupsOfDomains(self, toMakeGroups):
157         self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
158         pass
159
160     ## Set Optimization level:
161     #  @param level optimization level, one of the following values
162     #  - None_Optimization
163     #  - Light_Optimization
164     #  - Standard_Optimization
165     #  - StandardPlus_Optimization
166     #  - Strong_Optimization.
167     #  .
168     #  Default is Standard_Optimization
169     def SetOptimizationLevel(self, level):
170         self.Parameters().SetOptimizationLevel(level)
171         pass
172
173     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
174     #  @param MB maximal size of memory
175     def SetMaximumMemory(self, MB):
176         self.Parameters().SetMaximumMemory(MB)
177         pass
178
179     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
180     #  automatic memory adjustment mode.
181     #  @param MB initial size of memory
182     def SetInitialMemory(self, MB):
183         self.Parameters().SetInitialMemory(MB)
184         pass
185     """
186
187     ## Set Collision Mode:
188     #  @param mode Collision Mode, one of the following values
189     #  - Decrease_Collision_Mode
190     #  - Stop_Collision_Mode
191     #  .
192     #  Default is Decrease_Collision_Mode
193     def SetCollisionMode(self, mode):
194         self.Parameters().SetCollisionMode(mode)
195         pass
196
197     ## To mesh Boundary Layers growing inward or outward.
198     #  @param mode, one of the following values
199     #  - Layer_Growth_Inward
200     #  - Layer_Growth_Outward
201     #  .
202     #  Default is Layer_Growth_Inward
203     def SetBoundaryLayersGrowth(self, mode):
204         self.Parameters().SetBoundaryLayersGrowth(mode)
205         pass
206
207     ## To mesh with element type Tetra Dominant or hexa Dominant in the remaining volume (outside layers).
208     #  @param mode, one of the following values
209     #  - Generation_Tetra_Dominant
210     #  - Generation_Hexa_Dominant
211     #  - Generation_Cartesian_Core
212     #  .
213     # Default is Generation_Tetra_Dominant
214     def SetElementGeneration(self, mode):
215         self.Parameters().SetElementGeneration(mode)
216         pass
217
218     ## To mesh adding extra normals at opening ridges and corners.
219     # Default is no.
220     # @param addMultinormals boolean value
221     def SetAddMultinormals(self, addMultinormals):
222         self.Parameters().SetAddMultinormals(addMultinormals)
223         pass
224
225     ## To mesh smoothing normals at closed ridges and corners.
226     # Default is no.
227     # @param smoothNormals boolean value
228     def SetSmoothNormals(self, smoothNormals):
229         self.Parameters().SetSmoothNormals(smoothNormals)
230         pass
231
232     ## To set height of the first layer.
233     # Default is 0.0
234     # @param heightFirstLayer double value
235     def SetHeightFirstLayer(self, heightFirstLayer):
236         self.Parameters().SetHeightFirstLayer(heightFirstLayer)
237         pass
238
239     ## To set boundary layers coefficient of geometric progression.
240     # Default is 1.0
241     # @param boundaryLayersProgression double value
242     def SetBoundaryLayersProgression(self, boundaryLayersProgression):
243         self.Parameters().SetBoundaryLayersProgression(boundaryLayersProgression)
244         pass
245
246     ## Set core elements size.
247     # Default is 0.0
248     # @param CoreSize double value
249     def SetCoreSize(self, CoreSize):
250         self.Parameters().SetCoreSize(CoreSize)
251         pass
252
253     ## To set multinormals angle threshold at opening ridges.
254     # Default is 30.0
255     # @param multinormalsAngle double value
256     def SetMultinormalsAngle(self, multinormalsAngle):
257         self.Parameters().SetMultinormalsAngle(multinormalsAngle)
258         pass
259
260     ## To set number of boundary layers.
261     # Default is 1
262     # @param nbOfBoundaryLayers int value
263     def SetNbOfBoundaryLayers(self, nbOfBoundaryLayers):
264         self.Parameters().SetNbOfBoundaryLayers(nbOfBoundaryLayers)
265         pass
266
267     ## Set path to working directory.
268     #  @param path working directory
269     def SetWorkingDirectory(self, path):
270         self.Parameters().SetWorkingDirectory(path)
271         pass
272
273     ## To keep working files or remove them.
274     #  @param toKeep "keep working files" flag value
275     def SetKeepFiles(self, toKeep):
276         self.Parameters().SetKeepFiles(toKeep)
277         pass
278     
279     ## Remove or not the log file (if any) in case of successful computation.
280     #  The log file remains in case of errors anyway. If 
281     #  the "keep working files" flag is set to true, this option
282     #  has no effect.
283     #  @param toRemove "remove log on success" flag value
284     def SetRemoveLogOnSuccess(self, toRemove):
285         self.Parameters().SetRemoveLogOnSuccess(toRemove)
286         pass
287     
288     ## Print the the log in a file. If set to false, the
289     # log is printed on the standard output
290     #  @param toPrintLogInFile "print log in a file" flag value
291     def SetPrintLogInFile(self, toPrintLogInFile):
292         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
293         pass
294
295     ## Set verbosity level [0-10].
296     #  @param level verbosity level
297     #  - 0 - no standard output,
298     #  - 2 - prints the data, quality statistics of the skin and final meshes and
299     #    indicates when the final mesh is being saved. In addition the software
300     #    gives indication regarding the CPU time.
301     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
302     #    histogram of the skin mesh, quality statistics histogram together with
303     #    the characteristics of the final mesh.
304     def SetVerboseLevel(self, level):
305         self.Parameters().SetVerboseLevel(level)
306         pass
307
308     ## To create new nodes.
309     #  @param toCreate "create new nodes" flag value
310     def SetToCreateNewNodes(self, toCreate):
311         self.Parameters().SetToCreateNewNodes(toCreate)
312         pass
313
314     ## To use boundary recovery version which tries to create mesh on a very poor
315     #  quality surface mesh.
316     #  @param toUse "use boundary recovery version" flag value
317     def SetToUseBoundaryRecoveryVersion(self, toUse):
318         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
319         pass
320
321     ## Applies finite-element correction by replacing overconstrained elements where
322     #  it is possible. The process is cutting first the overconstrained edges and
323     #  second the overconstrained facets. This insure that no edges have two boundary
324     #  vertices and that no facets have three boundary vertices.
325     #  @param toUseFem "apply finite-element correction" flag value
326     def SetFEMCorrection(self, toUseFem):
327         self.Parameters().SetFEMCorrection(toUseFem)
328         pass
329
330     ## To remove initial central point.
331     #  @param toRemove "remove initial central point" flag value
332     def SetToRemoveCentralPoint(self, toRemove):
333         self.Parameters().SetToRemoveCentralPoint(toRemove)
334         pass
335
336     ## To set an enforced vertex.
337     #  @param x            : x coordinate
338     #  @param y            : y coordinate
339     #  @param z            : z coordinate
340     #  @param size         : size of 1D element around enforced vertex
341     #  @param vertexName   : name of the enforced vertex
342     #  @param groupName    : name of the group
343     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
344         if vertexName == "":
345             if groupName == "":
346                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
347             else:
348                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
349             pass
350         else:
351             if groupName == "":
352                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
353             else:
354                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
355             pass
356         pass
357
358     ## To set an enforced vertex given a GEOM vertex, group or compound.
359     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
360     #  @param size         : size of 1D element around enforced vertex
361     #  @param groupName    : name of the group
362     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
363         AssureGeomPublished( self.mesh, theVertex )
364         if groupName == "":
365             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
366         else:
367             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
368         pass
369
370     ## To remove an enforced vertex.
371     #  @param x            : x coordinate
372     #  @param y            : y coordinate
373     #  @param z            : z coordinate
374     def RemoveEnforcedVertex(self, x, y, z):
375         return self.Parameters().RemoveEnforcedVertex(x, y, z)
376
377     ## To remove an enforced vertex given a GEOM vertex, group or compound.
378     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
379     def RemoveEnforcedVertexGeom(self, theVertex):
380         AssureGeomPublished( self.mesh, theVertex )
381         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
382
383     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
384     #  @param theSource    : source mesh which provides constraint elements/nodes
385     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
386     #  @param size         : size of elements around enforced elements. Unused if -1.
387     #  @param groupName    : group in which enforced elements will be added. Unused if "".
388     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
389         if size < 0:
390             if groupName == "":
391                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
392             else:
393                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
394             pass
395         else:
396             if groupName == "":
397                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
398             else:
399                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
400             pass
401         pass
402
403     ## Sets command line option as text.
404     #
405     # OBSOLETE. Use SetAdvancedOption()
406     #  @param option command line option
407     def SetTextOption(self, option):
408         self.Parameters().SetAdvancedOption(option)
409         pass
410     
411     ## Sets command line option as text.
412     #  @param option command line option
413     def SetAdvancedOption(self, option):
414         self.Parameters().SetAdvancedOption(option)
415         pass
416     
417     pass # end of HYBRID_Algorithm class