Salome HOME
PR: merged from V5_1_4rc1
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_creating_meshes.doc
1 /*!
2
3 \page tui_creating_meshes_page Creating Meshes
4
5 \n First of all see \ref example_3d_mesh "Example of 3d mesh generation",
6  which is an example of good python script style for Mesh module.
7
8 <br>
9 <h2>Construction of a Mesh</h2>
10
11 \code
12 import geompy
13 import smesh
14
15 # create a box
16 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
17 idbox = geompy.addToStudy(box, "box")
18
19 # create a mesh
20 tetra = smesh.Mesh(box, "MeshBox")
21
22 algo1D = tetra.Segment()
23 algo1D.NumberOfSegments(7)
24
25 algo2D = tetra.Triangle()
26 algo2D.MaxElementArea(800.)
27
28 algo3D = tetra.Tetrahedron(smesh.NETGEN)
29 algo3D.MaxElementVolume(900.)
30
31 # compute the mesh
32 ret = tetra.Compute()
33 if ret == 0:
34     print "problem when computing the mesh"
35 else:
36     print "mesh computed"
37     pass
38 \endcode
39
40 <br>
41 \anchor tui_construction_submesh
42 <h2>Construction of a Submesh</h2>
43
44 \code
45 from geompy import *
46 import smesh
47
48 # create a box
49 box = MakeBoxDXDYDZ(10., 10., 10.)
50 addToStudy(box, "Box")
51
52 # select one edge of the box for definition of a local hypothesis
53 p5 = MakeVertex(5., 0., 0.)
54 EdgeX = GetEdgeNearPoint(box, p5)
55 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
56
57 # create a hexahedral mesh on the box
58 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
59
60 # create a regular 1D algorithm for the faces
61 algo1D = quadra.Segment()
62
63 # define "NumberOfSegments" hypothesis to cut
64 # all the edges in a fixed number of segments
65 algo1D.NumberOfSegments(4)
66
67 # create a quadrangle 2D algorithm for the faces
68 quadra.Quadrangle()
69
70 # construct a submesh on the edge with a local hypothesis
71 algo_local = quadra.Segment(EdgeX)
72
73 # define "Arithmetic1D" hypothesis to cut the edge in several segments with increasing arithmetic length
74 algo_local.Arithmetic1D(1, 4)
75
76 # define "Propagation" hypothesis that propagates all other hypotheses
77 # on all edges of the opposite side in case of quadrangular faces
78 algo_local.Propagation()
79
80 # compute the mesh
81 quadra.Compute()
82
83 \endcode
84
85 <br>
86 <h2>Change priority of submeshes in Mesh</h2>
87
88 \code
89 import salome
90 import geompy
91 import smesh
92 import SMESH
93
94 Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
95 [Face_1,Face_2,Face_3,Face_4,Face_5,Face_6] = geompy.SubShapeAllSorted(Box_1, geompy.ShapeType["FACE"])
96
97 # create Mesh object on Box shape
98 Mesh_1 = smesh.Mesh(Box_1)
99
100 # assign mesh algorithms
101 Regular_1D = Mesh_1.Segment()
102 Nb_Segments_1 = Regular_1D.NumberOfSegments(20)
103 Nb_Segments_1.SetDistrType( 0 )
104 MEFISTO_2D = Mesh_1.Triangle()
105 Max_Element_Area_1 = MEFISTO_2D.MaxElementArea(1200)
106 Tetrahedron_Netgen = Mesh_1.Tetrahedron(algo=smesh.NETGEN)
107 Max_Element_Volume_1 = Tetrahedron_Netgen.MaxElementVolume(40000)
108
109 # create submesh and assign algorithms on Face_1
110 Netgen_1D_2D = Mesh_1.Triangle(algo=smesh.NETGEN,geom=Face_1)
111 SubMesh_1 = Netgen_1D_2D.GetSubMesh()
112 NETGEN_2D_Simple_Parameters_1 = Netgen_1D_2D.Parameters(which=smesh.SIMPLE)
113 NETGEN_2D_Simple_Parameters_1.SetNumberOfSegments( 4 )
114 NETGEN_2D_Simple_Parameters_1.LengthFromEdges()
115
116 # create submesh and assign algorithms on Face_2
117 Netgen_1D_2D_1 = Mesh_1.Triangle(algo=smesh.NETGEN,geom=Face_2)
118 SubMesh_2 = Netgen_1D_2D_1.GetSubMesh()
119 NETGEN_2D_Simple_Parameters_2 = Netgen_1D_2D_1.Parameters(which=smesh.SIMPLE)
120 NETGEN_2D_Simple_Parameters_2.SetNumberOfSegments( 8 )
121 NETGEN_2D_Simple_Parameters_2.LengthFromEdges()
122 smeshObj_1 = smesh.CreateHypothesis('NETGEN_SimpleParameters_2D',
123 'NETGENEngine')
124
125 # create submesh and assign algorithms on Face_3
126 Netgen_1D_2D_2 = Mesh_1.Triangle(algo=smesh.NETGEN,geom=Face_3)
127 SubMesh_3 = Netgen_1D_2D_2.GetSubMesh()
128 NETGEN_2D_Simple_Parameters_3 = Netgen_1D_2D_2.Parameters(which=smesh.SIMPLE)
129 NETGEN_2D_Simple_Parameters_3.SetNumberOfSegments( 12 )
130 NETGEN_2D_Simple_Parameters_3.LengthFromEdges()
131
132 # check exisiting submesh priority order
133 [ [ SubMesh_1, SubMesh_3, SubMesh_2 ] ] = Mesh_1.GetMeshOrder()
134 # set new submesh order
135 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_1, SubMesh_2, SubMesh_3 ] ])
136 # compute mesh
137 isDone = Mesh_1.Compute()
138
139 # clear mesh result and compute with other submesh order
140 Mesh_1.Clear()
141 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_2, SubMesh_1, SubMesh_3 ] ])
142 isDone = Mesh_1.Compute()
143
144 \endcode
145
146 <br>
147 \anchor tui_editing_mesh
148 <h2>Editing of a mesh</h2>
149
150 \code
151 import geompy
152 import smesh
153
154 def PrintMeshInfo(theMesh):
155     aMesh = theMesh.GetMesh()
156     print "Information about mesh:"
157     print "Number of nodes       : ", aMesh.NbNodes()
158     print "Number of edges       : ", aMesh.NbEdges()
159     print "Number of faces       : ", aMesh.NbFaces()
160     print "Number of volumes     : ", aMesh.NbVolumes()
161     pass
162
163 # create a box
164 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
165 geompy.addToStudy(box, "box")
166
167 # select one edge of the box for definition of a local hypothesis
168 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
169 edge = subShapeList[0]
170 name = geompy.SubShapeName(edge, box)
171 geompy.addToStudyInFather(box, edge, name)
172
173 # create a mesh
174 tria = smesh.Mesh(box, "Mesh 2D")
175 algo1D = tria.Segment()
176 hyp1 = algo1D.NumberOfSegments(3)
177 algo2D = tria.Triangle()
178 hyp2 = algo2D.MaxElementArea(10.)
179
180 # create a sub-mesh
181 algo_local = tria.Segment(edge)
182 hyp3 = algo_local.Arithmetic1D(1, 6)
183 hyp4 = algo_local.Propagation()
184
185 # compute the mesh
186 tria.Compute()
187 PrintMeshInfo(tria)
188
189 # remove a local hypothesis
190 mesh = tria.GetMesh()
191 mesh.RemoveHypothesis(edge, hyp4)
192
193 # compute the mesh
194 tria.Compute()
195 PrintMeshInfo(tria)
196
197 # change the value of the 2D hypothesis
198 hyp2.SetMaxElementArea(2.)
199
200 # compute the mesh
201 tria.Compute()
202 PrintMeshInfo(tria)
203 \endcode
204
205 <br>
206 \anchor tui_export_mesh
207 <h2>Export of a Mesh</h2>
208
209 \code
210 import geompy
211 import smesh
212
213 # create a box
214 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
215 idbox = geompy.addToStudy(box, "box")
216
217 # create a mesh
218 tetra = smesh.Mesh(box, "MeshBox")
219
220 algo1D = tetra.Segment()
221 algo1D.NumberOfSegments(7)
222
223 algo2D = tetra.Triangle()
224 algo2D.MaxElementArea(800.)
225
226 algo3D = tetra.Tetrahedron(smesh.NETGEN)
227 algo3D.MaxElementVolume(900.)
228
229 # compute the mesh
230 tetra.Compute()
231
232 # export the mesh in a MED file
233 tetra.ExportMED("/tmp/meshMED.med", 0)
234 \endcode
235
236 <br>
237 <h2>How to mesh a cylinder with hexahedrons?</h2>
238 Here you can see an example of python script, creating a hexahedral
239 mesh on a cylinder. And a picture below the source code of the script,
240 demonstrating the resulting mesh.
241 \include ex24_cylinder.py
242
243 \image html mesh_cylinder_hexa.png
244
245 <br>
246 \anchor tui_building_compound
247 <h2>Building a compound of meshes</h2>
248 \dontinclude SMESH_BuildCompound.py
249 \skipline import geompy
250 \until #end
251
252 */