Salome HOME
Copyrights update 2013
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPluginDC.py
1 # Copyright (C) 2007-2013  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.
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 GHS3DPluginDC
22 # Python API for the GHS3D meshing plug-in module.
23
24 from smesh_algorithm import Mesh_Algorithm
25 from smesh 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 GHS3D
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: GHS3D tetrahedron 3D algorithm, see GHS3D_Algorithm
46 GHS3D = "GHS3D_3D"
47
48 ## Tetrahedron GHS3D 3D algorithm
49 #  
50 #  It can be created by calling smesh.Mesh.Tetrahedron( smesh.GHS3D, geom=0 )
51 class GHS3D_Algorithm(Mesh_Algorithm):
52
53     ## name of the dynamic method in smesh.Mesh class
54     #  @internal
55     meshMethod = "Tetrahedron"
56     ## type of algorithm used with helper function in smesh.Mesh class
57     #  @internal
58     algoType   = GHS3D
59     ## doc string of the method in smesh.Mesh class
60     #  @internal
61     docHelper  = "Creates tetrahedron 3D algorithm for volumes"
62
63     ## Private constructor.
64     #  @param mesh parent mesh object algorithm is assigned to
65     #  @param geom geometry (shape/sub-shape) algorithm is assigned to;
66     #              if it is @c 0 (default), the algorithm is assigned to the main shape
67     def __init__(self, mesh, geom=0):
68         Mesh_Algorithm.__init__(self)
69         if noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
70         self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
71         self.params = None
72         pass
73
74     ## Defines hypothesis having several parameters
75     #  @return hypothesis object
76     def Parameters(self):
77         if not self.params:
78             self.params = self.Hypothesis("GHS3D_Parameters", [],
79                                           "libGHS3DEngine.so", UseExisting=0)
80             pass
81         return self.params
82
83     ## To mesh "holes" in a solid or not. Default is to mesh.
84     #  @param toMesh "mesh holes" flag value
85     def SetToMeshHoles(self, toMesh):
86         self.Parameters().SetToMeshHoles(toMesh)
87         pass
88
89     ## Set Optimization level:
90     #  @param level optimization level, one of the following values
91     #  - None_Optimization
92     #  - Light_Optimization
93     #  - Standard_Optimization
94     #  - StandardPlus_Optimization
95     #  - Strong_Optimization.
96     #  .
97     #  Default is Standard_Optimization
98     def SetOptimizationLevel(self, level):
99         self.Parameters().SetOptimizationLevel(level)
100         pass
101
102     ## Set maximal size of memory to be used by the algorithm (in Megabytes).
103     #  @param MB maximal size of memory
104     def SetMaximumMemory(self, MB):
105         self.Parameters().SetMaximumMemory(MB)
106         pass
107
108     ## Set initial size of memory to be used by the algorithm (in Megabytes) in
109     #  automatic memory adjustment mode.
110     #  @param MB initial size of memory
111     def SetInitialMemory(self, MB):
112         self.Parameters().SetInitialMemory(MB)
113         pass
114
115     ## Set path to working directory.
116     #  @param path working directory
117     def SetWorkingDirectory(self, path):
118         self.Parameters().SetWorkingDirectory(path)
119         pass
120
121     ## To keep working files or remove them. Log file remains in case of errors anyway.
122     #  @param toKeep "keep working files" flag value
123     def SetKeepFiles(self, toKeep):
124         self.Parameters().SetKeepFiles(toKeep)
125         pass
126
127     ## Set verbosity level [0-10].
128     #  @param level verbosity level
129     #  - 0 - no standard output,
130     #  - 2 - prints the data, quality statistics of the skin and final meshes and
131     #    indicates when the final mesh is being saved. In addition the software
132     #    gives indication regarding the CPU time.
133     #  - 10 - same as 2 plus the main steps in the computation, quality statistics
134     #    histogram of the skin mesh, quality statistics histogram together with
135     #    the characteristics of the final mesh.
136     def SetVerboseLevel(self, level):
137         self.Parameters().SetVerboseLevel(level)
138         pass
139
140     ## To create new nodes.
141     #  @param toCreate "create new nodes" flag value
142     def SetToCreateNewNodes(self, toCreate):
143         self.Parameters().SetToCreateNewNodes(toCreate)
144         pass
145
146     ## To use boundary recovery version which tries to create mesh on a very poor
147     #  quality surface mesh.
148     #  @param toUse "use boundary recovery version" flag value
149     def SetToUseBoundaryRecoveryVersion(self, toUse):
150         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
151         pass
152
153     ## Applies finite-element correction by replacing overconstrained elements where
154     #  it is possible. The process is cutting first the overconstrained edges and
155     #  second the overconstrained facets. This insure that no edges have two boundary
156     #  vertices and that no facets have three boundary vertices.
157     #  @param toUseFem "apply finite-element correction" flag value
158     def SetFEMCorrection(self, toUseFem):
159         self.Parameters().SetFEMCorrection(toUseFem)
160         pass
161
162     ## To remove initial central point.
163     #  @param toRemove "remove initial central point" flag value
164     def SetToRemoveCentralPoint(self, toRemove):
165         self.Parameters().SetToRemoveCentralPoint(toRemove)
166         pass
167
168     ## To set an enforced vertex.
169     #  @param x            : x coordinate
170     #  @param y            : y coordinate
171     #  @param z            : z coordinate
172     #  @param size         : size of 1D element around enforced vertex
173     #  @param vertexName   : name of the enforced vertex
174     #  @param groupName    : name of the group
175     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
176         if vertexName == "":
177             if groupName == "":
178                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
179             else:
180                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
181             pass
182         else:
183             if groupName == "":
184                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
185             else:
186                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
187             pass
188         pass
189
190     ## To set an enforced vertex given a GEOM vertex, group or compound.
191     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
192     #  @param size         : size of 1D element around enforced vertex
193     #  @param groupName    : name of the group
194     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
195         AssureGeomPublished( self.mesh, theVertex )
196         if groupName == "":
197             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
198         else:
199             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
200         pass
201
202     ## To remove an enforced vertex.
203     #  @param x            : x coordinate
204     #  @param y            : y coordinate
205     #  @param z            : z coordinate
206     def RemoveEnforcedVertex(self, x, y, z):
207         return self.Parameters().RemoveEnforcedVertex(x, y, z)
208
209     ## To remove an enforced vertex given a GEOM vertex, group or compound.
210     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
211     def RemoveEnforcedVertexGeom(self, theVertex):
212         AssureGeomPublished( self.mesh, theVertex )
213         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
214
215     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
216     #  @param theSource    : source mesh which provides constraint elements/nodes
217     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
218     #  @param size         : size of elements around enforced elements. Unused if -1.
219     #  @param groupName    : group in which enforced elements will be added. Unused if "".
220     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
221         if size < 0:
222             if groupName == "":
223                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
224             else:
225                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
226             pass
227         else:
228             if groupName == "":
229                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
230             else:
231                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
232             pass
233         pass
234
235     ## Sets command line option as text.
236     #  @param option command line option
237     def SetTextOption(self, option):
238         self.Parameters().SetTextOption(option)
239         pass
240     
241     pass # end of GHS3D_Algorithm class