Salome HOME
Merge branch 'V7_dev'
[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 #----------------------------
42 # Mesh algo type identifiers
43 #----------------------------
44
45 ## Algorithm type: MG-Tetra tetrahedron 3D algorithm, see GHS3D_Algorithm
46 MG_Tetra = "MG-Tetra"
47 GHS3D = MG_Tetra
48
49 ## Tetrahedron MG-Tetra 3D algorithm
50 #  
51 #  It can be created by calling smeshBuilder.Mesh.Tetrahedron( smeshBuilder.MG_Tetra, geom=0 )
52 class GHS3D_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   = MG_Tetra
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 noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
71         self.Create(mesh, geom, self.algoType, "libGHS3DEngine.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("MG-Tetra Parameters", [],
80                                           "libGHS3DEngine.so", UseExisting=0)
81             pass
82         return self.params
83
84     ## To mesh "holes" in a solid or not. Default is to mesh.
85     #  @param toMesh "mesh holes" flag value
86     def SetToMeshHoles(self, toMesh):
87         self.Parameters().SetToMeshHoles(toMesh)
88         pass
89
90     ## To make groups of volumes of different domains when mesh is generated from skin.
91     #  Default is to make groups.
92     # This option works only (1) for the mesh w/o shape and (2) if GetToMeshHoles() == true
93     #  @param toMakeGroups "Make groups of domains" flag value
94     def SetToMakeGroupsOfDomains(self, toMakeGroups):
95         self.Parameters().SetToMakeGroupsOfDomains(toMakeGroups)
96         pass
97
98     ## Set Optimization level:
99     #  @param level optimization level, one of the following values
100     #  - None_Optimization
101     #  - Light_Optimization
102     #  - Standard_Optimization
103     #  - StandardPlus_Optimization
104     #  - Strong_Optimization.
105     #  .
106     #  Default is Standard_Optimization
107     def SetOptimizationLevel(self, level):
108         self.Parameters().SetOptimizationLevel(level)
109         pass
110
111     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
112     #  @param MB maximal size of memory
113     def SetMaximumMemory(self, MB):
114         self.Parameters().SetMaximumMemory(MB)
115         pass
116
117     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
118     #  automatic memory adjustment mode.
119     #  @param MB initial size of memory
120     def SetInitialMemory(self, MB):
121         self.Parameters().SetInitialMemory(MB)
122         pass
123
124     ## Set path to working directory.
125     #  @param path working directory
126     def SetWorkingDirectory(self, path):
127         self.Parameters().SetWorkingDirectory(path)
128         pass
129
130     ## To keep working files or remove them.
131     #  @param toKeep "keep working files" flag value
132     def SetKeepFiles(self, toKeep):
133         self.Parameters().SetKeepFiles(toKeep)
134         pass
135     
136     ## Remove or not the log file (if any) in case of successful computation.
137     #  The log file remains in case of errors anyway. If 
138     #  the "keep working files" flag is set to true, this option
139     #  has no effect.
140     #  @param toRemove "remove log on success" flag value
141     def SetRemoveLogOnSuccess(self, toRemove):
142         self.Parameters().SetRemoveLogOnSuccess(toRemove)
143         pass
144     
145     ## Print the the log in a file. If set to false, the
146     # log is printed on the standard output
147     #  @param toPrintLogInFile "print log in a file" flag value
148     def SetPrintLogInFile(self, toPrintLogInFile):
149         self.Parameters().SetStandardOutputLog(not toPrintLogInFile)
150         pass
151
152     ## Set verbosity level [0-10].
153     #  @param level verbosity level
154     #  - 0 - no standard output,
155     #  - 2 - prints the data, quality statistics of the skin and final meshes and
156     #    indicates when the final mesh is being saved. In addition the software
157     #    gives indication regarding the CPU time.
158     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
159     #    histogram of the skin mesh, quality statistics histogram together with
160     #    the characteristics of the final mesh.
161     def SetVerboseLevel(self, level):
162         self.Parameters().SetVerboseLevel(level)
163         pass
164
165     ## To create new nodes.
166     #  @param toCreate "create new nodes" flag value
167     def SetToCreateNewNodes(self, toCreate):
168         self.Parameters().SetToCreateNewNodes(toCreate)
169         pass
170
171     ## To use boundary recovery version which tries to create mesh on a very poor
172     #  quality surface mesh.
173     #  @param toUse "use boundary recovery version" flag value
174     def SetToUseBoundaryRecoveryVersion(self, toUse):
175         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
176         pass
177
178     ## Applies finite-element correction by replacing overconstrained elements where
179     #  it is possible. The process is cutting first the overconstrained edges and
180     #  second the overconstrained facets. This insure that no edges have two boundary
181     #  vertices and that no facets have three boundary vertices.
182     #  @param toUseFem "apply finite-element correction" flag value
183     def SetFEMCorrection(self, toUseFem):
184         self.Parameters().SetFEMCorrection(toUseFem)
185         pass
186
187     ## To remove initial central point.
188     #  @param toRemove "remove initial central point" flag value
189     def SetToRemoveCentralPoint(self, toRemove):
190         self.Parameters().SetToRemoveCentralPoint(toRemove)
191         pass
192
193     ## To set an enforced vertex.
194     #  @param x            : x coordinate
195     #  @param y            : y coordinate
196     #  @param z            : z coordinate
197     #  @param size         : size of 1D element around enforced vertex
198     #  @param vertexName   : name of the enforced vertex
199     #  @param groupName    : name of the group
200     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
201         if vertexName == "":
202             if groupName == "":
203                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
204             else:
205                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
206             pass
207         else:
208             if groupName == "":
209                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
210             else:
211                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
212             pass
213         pass
214
215     ## To set an enforced vertex given a GEOM vertex, group or compound.
216     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
217     #  @param size         : size of 1D element around enforced vertex
218     #  @param groupName    : name of the group
219     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
220         AssureGeomPublished( self.mesh, theVertex )
221         if groupName == "":
222             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
223         else:
224             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
225         pass
226
227     ## To remove an enforced vertex.
228     #  @param x            : x coordinate
229     #  @param y            : y coordinate
230     #  @param z            : z coordinate
231     def RemoveEnforcedVertex(self, x, y, z):
232         return self.Parameters().RemoveEnforcedVertex(x, y, z)
233
234     ## To remove an enforced vertex given a GEOM vertex, group or compound.
235     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
236     def RemoveEnforcedVertexGeom(self, theVertex):
237         AssureGeomPublished( self.mesh, theVertex )
238         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
239
240     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
241     #  @param theSource    : source mesh which provides constraint elements/nodes
242     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
243     #  @param size         : size of elements around enforced elements. Unused if -1.
244     #  @param groupName    : group in which enforced elements will be added. Unused if "".
245     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
246         if size < 0:
247             if groupName == "":
248                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
249             else:
250                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
251             pass
252         else:
253             if groupName == "":
254                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
255             else:
256                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
257             pass
258         pass
259
260     ## Sets command line option as text.
261     #  @param option command line option
262     def SetTextOption(self, option):
263         self.Parameters().SetTextOption(option)
264         pass
265     
266     pass # end of GHS3D_Algorithm class