Salome HOME
Merge from V6_main_20120808 08Aug12
[plugins/hybridplugin.git] / src / GHS3DPlugin / GHS3DPluginDC.py
1 # Copyright (C) 2007-2012  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 from smesh import Mesh_Algorithm, AssureGeomPublished
21
22 # import GHS3DPlugin module if possible
23 noGHS3DPlugin = 0
24 try:
25     import GHS3DPlugin
26 except ImportError:
27     noGHS3DPlugin = 1
28     pass
29
30 # Optimization level of GHS3D
31 # V3.1
32 None_Optimization, Light_Optimization, Medium_Optimization, Strong_Optimization = 0,1,2,3
33 # V4.1 (partialy redefines V3.1). Issue 0020574
34 None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization, Strong_Optimization = 0,1,2,3,4
35
36 GHS3D = "GHS3D_3D"
37
38 ## Tetrahedron GHS3D 3D algorithm
39 #  It is created by calling Mesh.Tetrahedron( GHS3D, geom=0 )
40 #
41 class GHS3D_Algorithm(Mesh_Algorithm):
42
43     meshMethod = "Tetrahedron"
44     algoType   = GHS3D
45
46     ## Private constructor.
47     def __init__(self, mesh, geom=0):
48         Mesh_Algorithm.__init__(self)
49         if noGHS3DPlugin: print "Warning: GHS3DPlugin module unavailable"
50         self.Create(mesh, geom, self.algoType, "libGHS3DEngine.so")
51         self.params = None
52
53     ## Defines hypothesis having several parameters
54     #
55     def Parameters(self):
56         if not self.params:
57             self.params = self.Hypothesis("GHS3D_Parameters", [],
58                                           "libGHS3DEngine.so", UseExisting=0)
59         return self.params
60
61     ## To mesh "holes" in a solid or not. Default is to mesh.
62     #
63     def SetToMeshHoles(self, toMesh):
64         self.Parameters().SetToMeshHoles(toMesh)
65
66     ## Set Optimization level:
67     #   None_Optimization, Light_Optimization, Standard_Optimization, StandardPlus_Optimization,
68     #   Strong_Optimization.
69     # Default is Standard_Optimization
70     def SetOptimizationLevel(self, level):
71         self.Parameters().SetOptimizationLevel(level)
72
73     ## Maximal size of memory to be used by the algorithm (in Megabytes).
74     #    
75     def SetMaximumMemory(self, MB):
76         self.Parameters().SetMaximumMemory(MB)
77
78     ## Initial size of memory to be used by the algorithm (in Megabytes) in
79     #  automatic memory adjustment mode.
80     def SetInitialMemory(self, MB):
81         self.Parameters().SetInitialMemory(MB)
82
83     ## Path to working directory.
84     #    
85     def SetWorkingDirectory(self, path):
86         self.Parameters().SetWorkingDirectory(path)
87
88     ## To keep working files or remove them. Log file remains in case of errors anyway.
89     def SetKeepFiles(self, toKeep):
90         self.Parameters().SetKeepFiles(toKeep)
91
92     ## To set verbose level [0-10]. <ul>
93     #<li> 0 - no standard output,
94     #<li> 2 - prints the data, quality statistics of the skin and final meshes and
95     #     indicates when the final mesh is being saved. In addition the software
96     #     gives indication regarding the CPU time.
97     #<li>10 - same as 2 plus the main steps in the computation, quality statistics
98     #     histogram of the skin mesh, quality statistics histogram together with
99     #     the characteristics of the final mesh.</ul>
100     def SetVerboseLevel(self, level):
101         self.Parameters().SetVerboseLevel(level)
102
103     ## To create new nodes.
104     def SetToCreateNewNodes(self, toCreate):
105         self.Parameters().SetToCreateNewNodes(toCreate)
106
107     ## To use boundary recovery version which tries to create mesh on a very poor
108     #  quality surface mesh.
109     def SetToUseBoundaryRecoveryVersion(self, toUse):
110         self.Parameters().SetToUseBoundaryRecoveryVersion(toUse)
111
112     ## Applies finite-element correction by replacing overconstrained elements where
113     #  it is possible. The process is cutting first the overconstrained edges and
114     #  second the overconstrained facets. This insure that no edges have two boundary
115     #  vertices and that no facets have three boundary vertices.
116     def SetFEMCorrection(self, toUseFem):
117         self.Parameters().SetFEMCorrection(toUseFem)
118
119     ## To removes initial central point.
120     def SetToRemoveCentralPoint(self, toRemove):
121         self.Parameters().SetToRemoveCentralPoint(toRemove)
122
123     ## To set an enforced vertex.
124     #  @param x            : x coordinate
125     #  @param y            : y coordinate
126     #  @param z            : z coordinate
127     #  @param size         : size of 1D element around enforced vertex
128     #  @param vertexName   : name of the enforced vertex
129     #  @param groupName    : name of the group
130     def SetEnforcedVertex(self, x, y, z, size, vertexName = "", groupName = ""):
131         if vertexName == "":
132             if groupName == "":
133                 return self.Parameters().SetEnforcedVertex(x, y, z, size)
134             else:
135                 return self.Parameters().SetEnforcedVertexWithGroup(x, y, z, size, groupName)
136         else:
137             if groupName == "":
138                 return self.Parameters().SetEnforcedVertexNamed(x, y, z, size, vertexName)
139             else:
140                 return self.Parameters().SetEnforcedVertexNamedWithGroup(x, y, z, size, vertexName, groupName)
141
142     ## To set an enforced vertex given a GEOM vertex, group or compound.
143     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
144     #  @param size         : size of 1D element around enforced vertex
145     #  @param groupName    : name of the group
146     def SetEnforcedVertexGeom(self, theVertex, size, groupName = ""):
147         AssureGeomPublished( self.mesh, theVertex )
148         if groupName == "":
149             return self.Parameters().SetEnforcedVertexGeom(theVertex, size)
150         else:
151             return self.Parameters().SetEnforcedVertexGeomWithGroup(theVertex, size, groupName)
152
153     ## To remove an enforced vertex.
154     #  @param x            : x coordinate
155     #  @param y            : y coordinate
156     #  @param z            : z coordinate
157     def RemoveEnforcedVertex(self, x, y, z):
158         return self.Parameters().RemoveEnforcedVertex(x, y, z)
159
160     ## To remove an enforced vertex given a GEOM vertex, group or compound.
161     #  @param theVertex    : GEOM vertex (or group, compound) to be projected on theFace.
162     def RemoveEnforcedVertexGeom(self, theVertex):
163         AssureGeomPublished( self.mesh, theVertex )
164         return self.Parameters().RemoveEnforcedVertexGeom(theVertex)
165
166     ## To set an enforced mesh with given size and add the enforced elements in the group "groupName".
167     #  @param theSource    : source mesh which provides constraint elements/nodes
168     #  @param elementType  : SMESH.ElementType (NODE, EDGE or FACE)
169     #  @param size         : size of elements around enforced elements. Unused if -1.
170     #  @param groupName    : group in which enforced elements will be added. Unused if "".
171     def SetEnforcedMesh(self, theSource, elementType, size = -1, groupName = ""):
172         if size < 0:
173             if groupName == "":
174                 return self.Parameters().SetEnforcedMesh(theSource, elementType)
175             else:
176                 return self.Parameters().SetEnforcedMeshWithGroup(theSource, elementType, groupName)
177         else:
178             if groupName == "":
179                 return self.Parameters().SetEnforcedMeshSize(theSource, elementType, size)
180             else:
181                 return self.Parameters().SetEnforcedMeshSizeWithGroup(theSource, elementType, size, groupName)
182
183     ## Sets command line option as text.
184     def SetTextOption(self, option):
185         self.Parameters().SetTextOption(option)
186