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