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