Salome HOME
new combo for element generation etc...
[plugins/hybridplugin.git] / src / HYBRIDPlugin / HYBRIDPluginBuilder.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013  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.
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 = 0,1
50
51 #----------------------------
52 # Mesh algo type identifiers
53 #----------------------------
54
55 ## Algorithm type: HYBRID tetrahedron 3D algorithm, see HYBRID_Algorithm
56 HYBRID = "HYBRID_3D"
57
58 ## Tetrahedron HYBRID 3D algorithm
59 #  
60 #  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.HYBRID, geom=0 )
61 class HYBRID_Algorithm(Mesh_Algorithm):
62
63     ## name of the dynamic method in smeshBuilder.Mesh class
64     #  @internal
65     meshMethod = "Tetrahedron"
66     ## type of algorithm used with helper function in smeshBuilder.Mesh class
67     #  @internal
68     algoType   = HYBRID
69     ## doc string of the method in smeshBuilder.Mesh class
70     #  @internal
71     docHelper  = "Creates tetrahedron 3D algorithm for volumes"
72
73     ## Private constructor.
74     #  @param mesh parent mesh object algorithm is assigned to
75     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
76     #              if it is @c 0 (default), the algorithm is assigned to the main shape
77     def __init__(self, mesh, geom=0):
78         Mesh_Algorithm.__init__(self)
79         if noHYBRIDPlugin: print "Warning: HYBRIDPlugin module unavailable"
80         self.Create(mesh, geom, self.algoType, "libHYBRIDEngine.so")
81         self.params = None
82         pass
83
84     ## Defines hypothesis having several parameters
85     #  @return hypothesis object
86     def Parameters(self):
87         if not self.params:
88             self.params = self.Hypothesis("HYBRID_Parameters", [],
89                                           "libHYBRIDEngine.so", UseExisting=0)
90             pass
91         return self.params
92
93     """
94     obsolete
95     ## To mesh "holes" in a solid or not. Default is to mesh.
96     #  @param toMesh "mesh holes" flag value
97     def SetToMeshHoles(self, toMesh):
98         self.Parameters().SetToMeshHoles(toMesh)
99         pass
100
101     ## To make groups of volumes of different domains when mesh is generated from skin.
102     #  Default is to make groups.
103     # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
104     #  @param toMesh "mesh holes" flag value
105     def SetToMakeGroupsOfDomains(self, toMakeGroups):
106         self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
107         pass
108
109     ## Set Optimization level:
110     #  @param level optimization level, one of the following values
111     #  - None_Optimization
112     #  - Light_Optimization
113     #  - Standard_Optimization
114     #  - StandardPlus_Optimization
115     #  - Strong_Optimization.
116     #  .
117     #  Default is Standard_Optimization
118     def SetOptimizationLevel(self, level):
119         self.Parameters().SetOptimizationLevel(level)
120         pass
121
122     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
123     #  @param MB maximal size of memory
124     def SetMaximumMemory(self, MB):
125         self.Parameters().SetMaximumMemory(MB)
126         pass
127
128     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
129     #  automatic memory adjustment mode.
130     #  @param MB initial size of memory
131     def SetInitialMemory(self, MB):
132         self.Parameters().SetInitialMemory(MB)
133         pass
134     """
135
136     ## Set Collision Mode:
137     #  @param mode Collision Mode, one of the following values
138     #  - Decrease_Collision_Mode
139     #  - Stop_Collision_Mode
140     #  .
141     #  Default is Decrease_Collision_Mode
142     def SetCollisionMode(self, mode):
143         self.Parameters().SetCollisionMode(mode)
144         pass
145
146     ## To mesh Boundary Layers growing inward or outward.
147     #  @param mode, one of the following values
148     #  - Layer_Growth_Inward
149     #  - Layer_Growth_Outward
150     #  .
151     #  Default is Layer_Growth_Inward
152     def SetBoundaryLayersGrowth(self, mode):
153         self.Parameters().SetBoundaryLayersGrowth(mode)
154         pass
155
156     ## To mesh with element type Tetra Dominant or hexa Dominant in the remaining volume (outside layers).
157     #  @param mode, one of the following values
158     #  - Generation_Tetra_Dominant
159     #  - Generation_Hexa_Dominant
160     #  .
161     # Default is Generation_Tetra_Dominant
162     def SetElementGeneration(self, mode);
163         self.Parameters().SetElementGeneration(mode)
164         pass
165
166     ## To mesh adding extra normals at opening ridges and corners.
167     # Default is no.
168     # @param addMultinormals boolean value
169     def SetAddMultinormals(self, addMultinormals);
170         self.Parameters().SetAddMultinormals(addMultinormals)
171         pass
172
173     ## To mesh smoothing normals at closed ridges and corners.
174     # Default is no.
175     # @param smoothNormals boolean value
176     def SetSmoothNormals(self, smoothNormals);
177         self.Parameters().SetSmoothNormals(smoothNormals)
178         pass
179
180     ## To set height of the first layer.
181     # Default is 0.0
182     # @param heightFirstLayer double value
183     def SetHeightFirstLayer(self, heightFirstLayer);
184         self.Parameters().SetHeightFirstLayer(heightFirstLayer)
185         pass
186
187     ## To set boundary layers coefficient of geometric progression.
188     # Default is 1.0
189     # @param boundaryLayersProgression double value
190     def SetBoundaryLayersProgression(self, boundaryLayersProgression);
191         self.Parameters().SetBoundaryLayersProgression(boundaryLayersProgression)
192         pass
193
194     ## To set multinormals angle threshold at opening ridges.
195     # Default is 30.0
196     # @param multinormalsAngle double value
197     def SetMultinormalsAngle(self, multinormalsAngle);
198         self.Parameters().SetMultinormalsAngle(multinormalsAngle)
199         pass
200
201     ## To set number of boundary layers.
202     # Default is 1
203     # @param nbOfBoundaryLayers int value
204     def SetNbOfBoundaryLayers(self, nbOfBoundaryLayers);
205         self.Parameters().SetNbOfBoundaryLayers(nbOfBoundaryLayers)
206         pass
207
208     ## Set path to working directory.
209     #  @param path working directory
210     def SetWorkingDirectory(self, path):
211         self.Parameters().SetWorkingDirectory(path)
212         pass
213
214     ## To keep working files or remove them.
215     #  @param toKeep "keep working files" flag value
216     def SetKeepFiles(self, toKeep):
217         self.Parameters().SetKeepFiles(toKeep)
218         pass
219     
220     ## Remove or not the log file (if any) in case of successful computation.
221     #  The log file remains in case of errors anyway. If 
222     #  the "keep working files" flag is set to true, this option
223     #  has no effect.
224     #  @param toRemove "remove log on success" flag value
225     def SetRemoveLogOnSuccess(self, toRemove):
226         self.Parameters().SetRemoveLogOnSuccess(toRemove)
227         pass
228     
229     ## Print the the log in a file. If set to false, the
230     # log is printed on the standard output
231     #  @param toPrintLogInFile "print log in a file" flag value
232     def SetPrintLogInFile(self, toPrintLogInFile):
233         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
234         pass
235
236     ## Set verbosity level [0-10].
237     #  @param level verbosity level
238     #  - 0 - no standard output,
239     #  - 2 - prints the data, quality statistics of the skin and final meshes and
240     #    indicates when the final mesh is being saved. In addition the software
241     #    gives indication regarding the CPU time.
242     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
243     #    histogram of the skin mesh, quality statistics histogram together with
244     #    the characteristics of the final mesh.
245     def SetVerboseLevel(self, level):
246         self.Parameters().SetVerboseLevel(level)
247         pass
248
249     ## To create new nodes.
250     #  @param toCreate "create new nodes" flag value
251     def SetToCreateNewNodes(self, toCreate):
252         self.Parameters().SetToCreateNewNodes(toCreate)
253         pass
254
255     ## To use boundary recovery version which tries to create mesh on a very poor
256     #  quality surface mesh.
257     #  @param toUse "use boundary recovery version" flag value
258     def SetToUseBoundaryRecoveryVersion(self, toUse):
259         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
260         pass
261
262     ## Applies finite-element correction by replacing overconstrained elements where
263     #  it is possible. The process is cutting first the overconstrained edges and
264     #  second the overconstrained facets. This insure that no edges have two boundary
265     #  vertices and that no facets have three boundary vertices.
266     #  @param toUseFem "apply finite-element correction" flag value
267     def SetFEMCorrection(self, toUseFem):
268         self.Parameters().SetFEMCorrection(toUseFem)
269         pass
270
271     ## To remove initial central point.
272     #  @param toRemove "remove initial central point" flag value
273     def SetToRemoveCentralPoint(self, toRemove):
274         self.Parameters().SetToRemoveCentralPoint(toRemove)
275         pass
276
277     ## To set an enforced vertex.
278     #  @param x            : x coordinate
279     #  @param y            : y coordinate
280     #  @param z            : z coordinate
281     #  @param size         : size of 1D element around enforced vertex
282     #  @param vertexName   : name of the enforced vertex
283     #  @param groupName    : name of the group
284     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
285         if vertexName == "":
286             if groupName == "":
287                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
288             else:
289                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
290             pass
291         else:
292             if groupName == "":
293                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
294             else:
295                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
296             pass
297         pass
298
299     ## To set an enforced vertex given a GEOM vertex, group or compound.
300     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
301     #  @param size         : size of 1D element around enforced vertex
302     #  @param groupName    : name of the group
303     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
304         AssureGeomPublished( self.mesh, theVertex )
305         if groupName == "":
306             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
307         else:
308             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
309         pass
310
311     ## To remove an enforced vertex.
312     #  @param x            : x coordinate
313     #  @param y            : y coordinate
314     #  @param z            : z coordinate
315     def RemoveEnforcedVertex(self, x, y, z):
316         return self.Parameters().RemoveEnforcedVertex(x, y, z)
317
318     ## To remove an enforced vertex given a GEOM vertex, group or compound.
319     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
320     def RemoveEnforcedVertexGeom(self, theVertex):
321         AssureGeomPublished( self.mesh, theVertex )
322         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
323
324     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
325     #  @param theSource    : source mesh which provides constraint elements/nodes
326     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
327     #  @param size         : size of elements around enforced elements. Unused if -1.
328     #  @param groupName    : group in which enforced elements will be added. Unused if "".
329     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
330         if size < 0:
331             if groupName == "":
332                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
333             else:
334                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
335             pass
336         else:
337             if groupName == "":
338                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
339             else:
340                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
341             pass
342         pass
343
344     ## Sets command line option as text.
345     #  @param option command line option
346     def SetTextOption(self, option):
347         self.Parameters().SetTextOption(option)
348         pass
349     
350     pass # end of HYBRID_Algorithm class