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