Salome HOME
Merge from V6_main (04/10/2012)
[plugins/ghs3dplugin.git] / doc / salome / gui / GHS3DPLUGIN / input / ghs3dplugin_python_interface.doc
1 /*!
2
3 \page ghs3dplugin_python_interface_page Python Interface
4
5 Python package GHS3DPluginDC defines several classes, destined for creation of the 3D meshes.
6
7 GHS3D meshing plugin dynamically adds several methods to the smesh.Mesh class to create meshing algorithms.
8
9 Below you can see an example of usage of the GHS3DPlugin Python API for mesh generation:
10
11 \anchor tui_ghs3d
12
13 -# \ref tui_ghs3d_basic
14 -# \ref tui_ghs3d_enforced_vertices
15 -# \ref tui_ghs3d_enforced_meshes
16
17 \section tui_ghs3d_basic Construction of Mesh using Ghs3D algorithm
18
19 \code
20 import geompy
21 import smesh
22 import BLSURFPlugin
23 import GHS3DPlugin
24
25 # create a box
26 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
27 geompy.addToStudy(box, "box")
28
29 # create a mesh on the box
30 ghs3dMesh = smesh.Mesh(box,"box: Ghs3D and BLSurf mesh")
31
32 # create a BLSurf algorithm for faces
33 BLSURF = ghs3dMesh.Triangle(algo=smesh.BLSURF)
34 GHS3D = ghs3dMesh.Tetrahedron(algo=smesh.GHS3D)
35
36 # compute the mesh
37 ghs3dMesh.Compute()
38
39 # End of script
40 \endcode
41
42 \image html ghs3d_screenshot.png Ghs3d mesh without hypothesis
43
44 \ref tui_ghs3d "Back to top"
45
46 \section tui_ghs3d_enforced_vertices Adding enforced vertices
47
48 \code
49
50 # An enforced vertex can be added via:
51 # - the coordinates x,y,z
52 # - a GEOM vertex or compound (No geometry, TUI only)
53 #
54 # The created enforced nodes can also be stored in
55 # a group.
56 #
57 # This feature is available only on meshes without geometry.
58
59 # Ex1: Add one enforced vertex with coordinates (50,50,100) 
60 #      and physical size 2.
61
62 import geompy
63 import smesh
64 import BLSURFPlugin
65 import GHS3DPlugin
66
67 # create a box
68 box = geompy.MakeBoxDXDYDZ(200., 200., 200.)
69 geompy.addToStudy(box, "box")
70 # create a mesh on the box
71 ghs3dMesh = smesh.Mesh(box,"box: Ghs3D and BLSurf mesh")
72 # create a BLSurf algorithm for faces
73 ghs3dMesh.Triangle(algo=smesh.BLSURF)
74 # compute the mesh
75 ghs3dMesh.Compute()
76
77 # Make a copy of the 2D mesh
78 ghs3dMesh_wo_geometry = smesh.CopyMesh( ghs3dMesh, 'Ghs3D wo geometry', 0, 0)
79
80 # create a Ghs3D algorithm and hypothesis and assign them to the mesh
81 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
82 GHS3D_Parameters = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
83 ghs3dMesh.AddHypothesis( GHS3D )
84 ghs3dMesh.AddHypothesis( GHS3D_Parameters )
85 # Create the enforced vertex
86 GHS3D_Parameters.SetEnforcedVertex( 50, 50, 100, 2) # no group
87 # Compute the mesh
88 ghs3dMesh.Compute()
89
90
91 # Ex2: Add one vertex enforced by a GEOM vertex at (50,50,100) 
92 #      with physical size 5 and add it to a group called "My special nodes"
93
94 # Create another GHS3D hypothesis and assign it to the mesh without geometry
95 GHS3D_Parameters_wo_geometry = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
96 ghs3dMesh_wo_geometry.AddHypothesis( GHS3D )
97 ghs3dMesh_wo_geometry.AddHypothesis( GHS3D_Parameters_wo_geometry )
98
99 # Create the enforced vertex
100 p1 = geompy.MakeVertex(150, 150, 100)
101 geompy.addToStudy(p1, "p1")
102 GHS3D_Parameters_wo_geometry.SetEnforcedVertexGeomWithGroup( p1, 5 , "My special nodes")
103 #GHS3D_Parameters.SetEnforcedVertexGeom( p1, 5 ) # no group
104
105 # compute the mesh
106 ghs3dMesh_wo_geometry.Compute()
107
108 # Erase all enforced vertices
109 GHS3D_Parameters.ClearEnforcedVertices()
110
111 # End of script
112
113 \endcode
114
115 \image html ghs3d_screenshot_enf1.png Ghs3d mesh with enforced vertex
116 \image html ghs3d_screenshot_enf2.png Ghs3d mesh with enforced vertex from GEOM vertex
117
118 \ref tui_ghs3d "Back to top"
119
120 \section tui_ghs3d_enforced_meshes Adding enforced mesh
121
122 \code
123
124 # It is possible to constrain GHS3D with another mesh or group.
125 # The constraint can refer to the nodes, edges or faces.
126 # This feature is available only on 2D meshes without geometry.
127 # The constraining elements are called enforced elements for the mesh.
128 # They can be recovered using groups if necessary.
129
130 # In the following examples, a box and a cylinder are meshed in 2D.
131 # The mesh of the cylinder will be used as a constraint for the 
132 # 3D mesh of the box.
133
134 import geompy
135 import smesh
136 import BLSURFPlugin
137 import GHS3DPlugin
138
139 box = geompy.MakeBoxDXDYDZ(200, 200, 200)
140 geompy.addToStudy( box, "box" )
141 cylindre = geompy.MakeCylinderRH(50, 50)
142 geompy.TranslateDXDYDZ(cylindre, 100, 100, 30)
143 face_cyl = geompy.ExtractShapes(cylindre, geompy.ShapeType["FACE"], True)[1]
144 geompy.addToStudy( cylindre, 'cylindre' )
145 geompy.addToStudyInFather( cylindre, face_cyl, 'face_cyl' )
146 p1 = geompy.MakeVertex(20, 20, 20)
147 p2 = geompy.MakeVertex(180, 180, 20)
148 c = geompy.MakeCompound([p1,p2])
149 geompy.addToStudy( p1, "p1" )
150 geompy.addToStudy( p2, "p2" )
151 geompy.addToStudy( c, "c" )
152
153 # Create the 2D algorithm and hypothesis
154 BLSURF = smesh.CreateHypothesis('BLSURF', 'BLSURFEngine')
155 # For the box
156 BLSURF_Parameters = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
157 BLSURF_Parameters.SetPhysicalMesh( 1 )
158 BLSURF_Parameters.SetPhySize( 200 )
159 # For the cylinder
160 BLSURF_Parameters2 = smesh.CreateHypothesis('BLSURF_Parameters', 'BLSURFEngine')
161 BLSURF_Parameters2.SetGeometricMesh( 1 )
162
163 # Create the 3D algorithm and hypothesis
164 GHS3D = smesh.CreateHypothesis('GHS3D_3D', 'GHS3DEngine')
165 GHS3D_Parameters_node = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
166 #GHS3D_Parameters_node.SetToMeshHoles( 1 )
167 GHS3D_Parameters_edge = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
168 #GHS3D_Parameters_edge.SetToMeshHoles( 1 )
169 GHS3D_Parameters_face = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
170 GHS3D_Parameters_face.SetToMeshHoles( 1 ) # to mesh inside the cylinder
171 GHS3D_Parameters_mesh = smesh.CreateHypothesis('GHS3D_Parameters', 'GHS3DEngine')
172 GHS3D_Parameters_mesh.SetToMeshHoles( 1 ) # to mesh inside the cylinder
173
174 # Create the mesh on the cylinder
175 Mesh_cylindre = smesh.Mesh(cylindre)
176 smesh.SetName(Mesh_cylindre,"Mesh_cylindre")
177 Mesh_cylindre.AddHypothesis( BLSURF )
178 Mesh_cylindre.AddHypothesis( BLSURF_Parameters2 )
179 # Create some groups
180 face_cyl_faces = Mesh_cylindre.GroupOnGeom(face_cyl,'group_face_cyl', smesh.FACE)
181 face_cyl_edges = Mesh_cylindre.GroupOnGeom(face_cyl,'group_edge_cyl', smesh.EDGE)
182 face_cyl_nodes = Mesh_cylindre.GroupOnGeom(face_cyl,'group_node_cyl', smesh.NODE)
183 Mesh_cylindre.Compute()
184
185 # Create the mesh on the cylinder
186 Mesh_box_tri = smesh.Mesh(box)
187 smesh.SetName(Mesh_box_tri,"Mesh_box_tri")
188 Mesh_box_tri.AddHypothesis( BLSURF )
189 Mesh_box_tri.AddHypothesis( BLSURF_Parameters )
190 Mesh_box_tri.Compute()
191
192 # Create 4 copies of the 2D mesh to test the 3 types of contraints (NODE, EDGE, FACE)
193 # from the whole mesh and from groups of elements.
194 # Then the 3D algo and hypothesis are assigned to them.
195
196 mesh_mesh = smesh.CopyMesh( Mesh_box_tri, 'Enforced by faces of mesh', 0, 0)
197 mesh_mesh.AddHypothesis( GHS3D )
198 mesh_mesh.AddHypothesis( GHS3D_Parameters_mesh)
199
200 mesh_node = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of nodes', 0, 0)
201 mesh_node.AddHypothesis( GHS3D )
202 mesh_node.AddHypothesis( GHS3D_Parameters_node)
203
204 mesh_edge = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of edges', 0, 0)
205 mesh_edge.AddHypothesis( GHS3D )
206 mesh_edge.AddHypothesis( GHS3D_Parameters_edge)
207
208 mesh_face = smesh.CopyMesh( Mesh_box_tri, 'Enforced by group of faces', 0, 0)
209 mesh_face.AddHypothesis( GHS3D )
210 mesh_face.AddHypothesis( GHS3D_Parameters_face)
211
212 # Add the enforced elements
213 GHS3D_Parameters_mesh.SetEnforcedMeshWithGroup(Mesh_cylindre.GetMesh(),smesh.FACE,"faces from cylinder")
214 GHS3D_Parameters_node.SetEnforcedMeshWithGroup(face_cyl_nodes,smesh.NODE,"nodes from face_cyl_nodes")
215 GHS3D_Parameters_edge.SetEnforcedMeshWithGroup(face_cyl_edges,smesh.EDGE,"edges from face_cyl_edges")
216 GHS3D_Parameters_face.SetEnforcedMeshWithGroup(face_cyl_faces,smesh.FACE,"faces from face_cyl_faces")
217
218 #Compute the meshes
219 mesh_node.Compute()
220 mesh_edge.Compute()
221 mesh_face.Compute()
222 mesh_mesh.Compute()
223
224 # End of script
225
226 \endcode
227
228 \image html ghs3d_screenshot_enf3.png
229 \image html ghs3d_screenshot_enf4.png
230 \image html ghs3d_screenshot_enf5.png
231 \image html ghs3d_screenshot_enf6.png
232
233 \ref tui_ghs3d "Back to top"
234
235 */