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