Salome HOME
Merge multi-study removal branch.
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPluginBuilder.py
1 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 ##
21 # @package GHS3DPluginBuilder
22 # Python API for the MG-Tetra meshing plug-in module.
23
24 from salome.smesh.smesh_algorithm import Mesh_Algorithm
25 from salome.smesh.smeshBuilder import AssureGeomPublished
26
27 # import GHS3DPlugin module if possible
28 noGHS3DPlugin = 0
29 try:
30     import GHS3DPlugin
31 except ImportError:
32     noGHS3DPlugin = 1
33     pass
34
35 # Optimization level of MG-Tetra
36 # V3.1
37 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
38 # V4.1 (partialy redefines V3.1). Issue 0020574
39 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
40
41 # import items of enums
42 for e in GHS3DPlugin.Mode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
43 for e in GHS3DPlugin.PThreadsMode._items: exec('%s = GHS3DPlugin.%s'%(e,e))
44 Mode_NO, Mode_YES, Mode_ONLY = GHS3DPlugin.Mode._items
45 Mode_SAFE, Mode_AGGRESSIVE, Mode_NONE = GHS3DPlugin.PThreadsMode._items
46
47 #----------------------------
48 # Mesh algo type identifiers
49 #----------------------------
50
51 ## Algorithm type: MG-Tetra tetrahedron 3D algorithm, see GHS3D_Algorithm
52 MG_Tetra = "MG-Tetra"
53 GHS3D = MG_Tetra
54 MG_Tetra_Optimization = "MG-Tetra Optimization"
55
56 ## Tetrahedron MG-Tetra 3D algorithm
57 #  
58 #  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra, geom=0 )
59 class GHS3D_Algorithm(Mesh_Algorithm):
60
61     ## name of the dynamic method in smeshBuilder.Mesh class
62     #  @internal
63     meshMethod = "Tetrahedron"
64     ## type of algorithm used with helper function in smeshBuilder.Mesh class
65     #  @internal
66     algoType   = MG_Tetra
67     ## doc string of the method in smeshBuilder.Mesh class
68     #  @internal
69     docHelper  = "Creates tetrahedron 3D algorithm"
70
71     ## Private constructor.
72     #  @param mesh parent mesh object algorithm is assigned to
73     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
74     #              if it is @c 0 (default), the algorithm is assigned to the main shape
75     def __init__(self, mesh, geom=0):
76         Mesh_Algorithm.__init__(self)
77         if noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
78         self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
79         self.params = None
80         pass
81
82     ## Defines hypothesis having several parameters
83     #  @return hypothesis object
84     def Parameters(self):
85         if not self.params:
86             self.params = self.Hypothesis("MG-Tetra Parameters", [],
87                                           "libGHS3DEngine.so", UseExisting=0)
88             pass
89         return self.params
90
91     ## To mesh "holes" in a solid or not. Default is to mesh.
92     #  @param toMesh "mesh holes" flag value
93     def SetToMeshHoles(self, toMesh):
94         self.Parameters().SetToMeshHoles(toMesh)
95         pass
96
97     ## To make groups of volumes of different domains when mesh is generated from skin.
98     #  Default is to make groups.
99     # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
100     #  @param toMakeGroups "Make groups of domains" flag value
101     def SetToMakeGroupsOfDomains(self, toMakeGroups):
102         self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
103         pass
104
105     ## Set Optimization level:
106     #  @param level optimization level, one of the following values
107     #  - None_Optimization
108     #  - Light_Optimization
109     #  - Standard_Optimization
110     #  - StandardPlus_Optimization
111     #  - Strong_Optimization.
112     #  .
113     #  Default is Standard_Optimization
114     def SetOptimizationLevel(self, level):
115         self.Parameters().SetOptimizationLevel(level)
116         pass
117
118     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
119     #  @param MB maximal size of memory
120     def SetMaximumMemory(self, MB):
121         self.Parameters().SetMaximumMemory(MB)
122         pass
123
124     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
125     #  automatic memory adjustment mode.
126     #  @param MB initial size of memory
127     def SetInitialMemory(self, MB):
128         self.Parameters().SetInitialMemory(MB)
129         pass
130
131     ## Set path to working directory.
132     #  @param path working directory
133     def SetWorkingDirectory(self, path):
134         self.Parameters().SetWorkingDirectory(path)
135         pass
136
137     ## To keep working files or remove them.
138     #  @param toKeep "keep working files" flag value
139     def SetKeepFiles(self, toKeep):
140         self.Parameters().SetKeepFiles(toKeep)
141         pass
142     
143     ## Remove or not the log file (if any) in case of successful computation.
144     #  The log file remains in case of errors anyway. If 
145     #  the "keep working files" flag is set to true, this option
146     #  has no effect.
147     #  @param toRemove "remove log on success" flag value
148     def SetRemoveLogOnSuccess(self, toRemove):
149         self.Parameters().SetRemoveLogOnSuccess(toRemove)
150         pass
151     
152     ## Print the the log in a file. If set to false, the
153     # log is printed on the standard output
154     #  @param toPrintLogInFile "print log in a file" flag value
155     def SetPrintLogInFile(self, toPrintLogInFile):
156         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
157         pass
158
159     ## Set verbosity level [0-10].
160     #  @param level verbosity level
161     #  - 0 - no standard output,
162     #  - 2 - prints the data, quality statistics of the skin and final meshes and
163     #    indicates when the final mesh is being saved. In addition the software
164     #    gives indication regarding the CPU time.
165     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
166     #    histogram of the skin mesh, quality statistics histogram together with
167     #    the characteristics of the final mesh.
168     def SetVerboseLevel(self, level):
169         self.Parameters().SetVerboseLevel(level)
170         pass
171
172     ## To create new nodes.
173     #  @param toCreate "create new nodes" flag value
174     def SetToCreateNewNodes(self, toCreate):
175         self.Parameters().SetToCreateNewNodes(toCreate)
176         pass
177
178     ## To use boundary recovery version which tries to create mesh on a very poor
179     #  quality surface mesh.
180     #  @param toUse "use boundary recovery version" flag value
181     def SetToUseBoundaryRecoveryVersion(self, toUse):
182         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
183         pass
184
185     ## Applies finite-element correction by replacing overconstrained elements where
186     #  it is possible. The process is cutting first the overconstrained edges and
187     #  second the overconstrained facets. This insure that no edges have two boundary
188     #  vertices and that no facets have three boundary vertices.
189     #  @param toUseFem "apply finite-element correction" flag value
190     def SetFEMCorrection(self, toUseFem):
191         self.Parameters().SetFEMCorrection(toUseFem)
192         pass
193
194     ## To remove initial central point.
195     #  @param toRemove "remove initial central point" flag value
196     def SetToRemoveCentralPoint(self, toRemove):
197         self.Parameters().SetToRemoveCentralPoint(toRemove)
198         pass
199
200     ## To set an enforced vertex.
201     #  @param x            : x coordinate
202     #  @param y            : y coordinate
203     #  @param z            : z coordinate
204     #  @param size         : size of 1D element around enforced vertex
205     #  @param vertexName   : name of the enforced vertex
206     #  @param groupName    : name of the group
207     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
208         if vertexName == "":
209             if groupName == "":
210                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
211             else:
212                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
213             pass
214         else:
215             if groupName == "":
216                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
217             else:
218                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
219             pass
220         pass
221
222     ## To set an enforced vertex given a GEOM vertex, group or compound.
223     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
224     #  @param size         : size of 1D element around enforced vertex
225     #  @param groupName    : name of the group
226     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
227         AssureGeomPublished( self.mesh, theVertex )
228         if groupName == "":
229             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
230         else:
231             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
232         pass
233
234     ## To remove an enforced vertex.
235     #  @param x            : x coordinate
236     #  @param y            : y coordinate
237     #  @param z            : z coordinate
238     def RemoveEnforcedVertex(self, x, y, z):
239         return self.Parameters().RemoveEnforcedVertex(x, y, z)
240
241     ## To remove an enforced vertex given a GEOM vertex, group or compound.
242     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
243     def RemoveEnforcedVertexGeom(self, theVertex):
244         AssureGeomPublished( self.mesh, theVertex )
245         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
246
247     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
248     #  @param theSource    : source mesh which provides constraint elements/nodes
249     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
250     #  @param size         : size of elements around enforced elements. Unused if -1.
251     #  @param groupName    : group in which enforced elements will be added. Unused if "".
252     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
253         if size < 0:
254             if groupName == "":
255                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
256             else:
257                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
258             pass
259         else:
260             if groupName == "":
261                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
262             else:
263                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
264             pass
265         pass
266
267     ## Sets command line option as text.
268     #  @param option command line option
269     def SetTextOption(self, option):
270         self.Parameters().SetAdvancedOption(option)
271         pass
272     
273     ## Sets command line option as text.
274     #  @param option command line option
275     def SetAdvancedOption(self, option):
276         self.Parameters().SetAdvancedOption(option)
277         pass
278     
279     pass # end of GHS3D_Algorithm class
280
281
282 ## MG-Tetra Optimization algorithm - optimizer of tetrahedral meshes
283 #
284 #  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra_Optimization )
285 class GHS3D_Optimizer(GHS3D_Algorithm):
286
287     ## name of the dynamic method in smeshBuilder.Mesh class
288     #  @internal
289     meshMethod = "Tetrahedron"
290     ## type of algorithm used with helper function in smeshBuilder.Mesh class
291     #  @internal
292     algoType   = MG_Tetra_Optimization
293     ## doc string of the method in smeshBuilder.Mesh class
294     #  @internal
295     docHelper  = "Creates MG-Tetra optimizer of tetrahedral meshes"
296
297     ## Private constructor.
298     #  @param mesh parent mesh object algorithm is assigned to
299     #  @param geom - not used
300     def __init__(self, mesh, geom=0):
301         GHS3D_Algorithm.__init__(self, mesh)
302
303         # remove some inherited methods
304         # del self.SetToMeshHoles
305         # del self.SetToMakeGroupsOfDomains
306         # del self.SetToUseBoundaryRecoveryVersion
307         # del self.SetFEMCorrection
308         # del self.SetToRemoveCentralPoint
309         # del self.SetEnforcedVertex
310         # del self.SetEnforcedVertexGeom
311         # del self.RemoveEnforcedVertex
312         # del self.RemoveEnforcedVertexGeom
313         # del self.SetEnforcedMesh
314         # del self.SetTextOption
315         pass
316
317     ## Defines hypothesis having several parameters
318     #  @return hypothesis object
319     def Parameters(self):
320         if not self.params:
321             self.params = self.Hypothesis("MG-Tetra Optimization Parameters", [],
322                                           "libGHS3DEngine.so", UseExisting=0)
323             pass
324         return self.params
325
326     ## Set Optimization mode
327     #  @param optMode optimization mode, one of the following values:
328     #  smeshBuilder.Mode_NO,
329     #  smeshBuilder.Mode_YES (default),
330     #  smeshBuilder.MODE_ONLY
331     def SetOptimizationOnly(self, optMode ):
332         self.Parameters().SetOptimizationOnly(optMode)
333         pass
334
335     ## Set mode of splitting over-constrained elements
336     #  @param ovcMode, one of the following values
337     #  smeshBuilder.Mode_NO (default),
338     #  smeshBuilder.Mode_YES,
339     #  smeshBuilder.Mode_ONLY
340     def SetSplitOverConstrained(self, ovcMode ):
341         self.Parameters().SetSplitOverConstrained(ovcMode)
342         pass
343
344     ## Activate smoothing sliver elements:
345     #  @param toSmooth - Boolean flag
346     def SetSmoothOffSlivers(self, toSmooth ):
347         self.Parameters().SetSmoothOffSlivers(toSmooth)
348         pass
349
350     ## Set multithread mode
351     #  @param mode - the mode, one of the following values:
352     #  smeshBuilder.Mode_SAFE,
353     #  smeshBuilder.Mode_AGGRESSIVE,
354     #  smeshBuilder.Mode_NONE (default)
355     def SetPThreadsMode(self, mode ):
356         self.Parameters().SetPThreadsMode(mode)
357         pass
358
359     ## Set maximal number of threads
360     #  @param nb - number of threads
361     def SetMaximalNumberOfThreads(self, nb ):
362         self.Parameters().SetMaximalNumberOfThreads(nb)
363         pass
364
365
366     ## Set Optimization level:
367     #  @param level optimization level, one of the following values
368     #  - None_Optimization
369     #  - Light_Optimization
370     #  - Standard_Optimization
371     #  - StandardPlus_Optimization
372     #  - Strong_Optimization.
373     #  .
374     #  Default is Standard_Optimization
375     def SetOptimizationLevel(self, level):
376         self.Parameters().SetOptimizationLevel(level)
377         pass
378
379     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
380     #  @param MB maximal size of memory
381     def SetMaximumMemory(self, MB):
382         self.Parameters().SetMaximumMemory(MB)
383         pass
384
385     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
386     #  automatic memory adjustment mode.
387     #  @param MB initial size of memory
388     def SetInitialMemory(self, MB):
389         self.Parameters().SetInitialMemory(MB)
390         pass
391
392     ## Set path to working directory.
393     #  @param path working directory
394     def SetWorkingDirectory(self, path):
395         self.Parameters().SetWorkingDirectory(path)
396         pass
397
398     ## To keep working files or remove them.
399     #  @param toKeep "keep working files" flag value
400     def SetKeepFiles(self, toKeep):
401         self.Parameters().SetKeepFiles(toKeep)
402         pass
403
404     ## Remove or not the log file (if any) in case of successful computation.
405     #  The log file remains in case of errors anyway. If
406     #  the "keep working files" flag is set to true, this option
407     #  has no effect.
408     #  @param toRemove "remove log on success" flag value
409     def SetRemoveLogOnSuccess(self, toRemove):
410         self.Parameters().SetRemoveLogOnSuccess(toRemove)
411         pass
412
413     ## Print the the log in a file. If set to false, the
414     # log is printed on the standard output
415     #  @param toPrintLogInFile "print log in a file" flag value
416     def SetPrintLogInFile(self, toPrintLogInFile):
417         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
418         pass
419
420     ## Set verbosity level [0-10].
421     #  @param level verbosity level
422     #  - 0 - no standard output,
423     #  - 2 - prints the data, quality statistics of the skin and final meshes and
424     #    indicates when the final mesh is being saved. In addition the software
425     #    gives indication regarding the CPU time.
426     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
427     #    histogram of the skin mesh, quality statistics histogram together with
428     #    the characteristics of the final mesh.
429     def SetVerboseLevel(self, level):
430         self.Parameters().SetVerboseLevel(level)
431         pass
432
433     ## To create new nodes.
434     #  @param toCreate "create new nodes" flag value
435     def SetToCreateNewNodes(self, toCreate):
436         self.Parameters().SetToCreateNewNodes(toCreate)
437         pass
438
439     ## Sets command line option as text.
440     #  @param option command line option
441     def SetAdvancedOption(self, option):
442         self.Parameters().SetAdvancedOption(option)
443         pass
444
445     pass # end of GHS3D_Optimizer class