Salome HOME
Porting GUI documentation on Doxygen tool.
[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 tui_creating_meshes_page "Example of 3d mesh generation",
6  which is an example of good python script style for Mesh module.
7 \n Other examples of python scripts will be also updated soon to use
8  smesh package instead of direct usage of idl interface.
9
10 <br>
11 <h2>Construction of a Mesh</h2>
12
13 \code
14 import geompy
15 import smesh
16
17 # create a box
18 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
19 idbox = geompy.addToStudy(box, "box")
20
21 # create a mesh
22 tetra = smesh.Mesh(box, "MeshBox")
23
24 algo1D = tetra.Segment()
25 algo1D.NumberOfSegments(7)
26
27 algo2D = tetra.Triangle()
28 algo2D.MaxElementArea(800.)
29
30 algo3D = tetra.Tetrahedron(smesh.NETGEN)
31 algo3D.MaxElementVolume(900.)
32
33 # compute the mesh
34 ret = tetra.Compute()
35 if ret == 0:
36     print "problem when computing the mesh"
37 else:
38     print "mesh computed"
39     pass
40 \endcode
41
42 <br>
43 \anchor tui_construction_submesh
44 <h2>Construction of a Submesh</h2>
45
46 \code
47 from geompy import *
48 import smesh
49
50 # create a box
51 box = MakeBoxDXDYDZ(10., 10., 10.)
52 addToStudy(box, "Box")
53
54 # select one edge of the box for definition of a local hypothesis
55 p5 = MakeVertex(5., 0., 0.)
56 EdgeX = GetEdgeNearPoint(box, p5)
57 addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
58
59 # create a hexahedral mesh on the box
60 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
61
62 # create a regular 1D algorithm for the faces
63 algo1D = quadra.Segment()
64
65 # define "NumberOfSegments" hypothesis to cut
66 # all the edges in a fixed number of segments
67 algo1D.NumberOfSegments(4)
68
69 # create a quadrangle 2D algorithm for the faces
70 quadra.Quadrangle()
71
72 # construct a submesh on the edge with a local hypothesis
73 algo_local = quadra.Segment(EdgeX)
74
75 # define "Arithmetic1D" hypothesis to cut the edge in several segments with increasing arithmetic length
76 algo_local.Arithmetic1D(1, 4)
77
78 # define "Propagation" hypothesis that propagates all other hypotheses
79 # on all edges of the opposite side in case of quadrangular faces
80 algo_local.Propagation()
81
82 # compute the mesh
83 quadra.Compute()
84
85 \endcode
86
87 <br>
88 \anchor tui_editing_mesh
89 <h2>Editing of a mesh</h2>
90
91 \code
92 import geompy
93 import smesh
94
95 def PrintMeshInfo(theMesh):
96     aMesh = theMesh.GetMesh()
97     print "Information about mesh:"
98     print "Number of nodes       : ", aMesh.NbNodes()
99     print "Number of edges       : ", aMesh.NbEdges()
100     print "Number of faces       : ", aMesh.NbFaces()
101     print "Number of volumes     : ", aMesh.NbVolumes()
102     pass
103
104 # create a box
105 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
106 geompy.addToStudy(box, "box")
107
108 # select one edge of the box for definition of a local hypothesis
109 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
110 edge = subShapeList[0]
111 name = geompy.SubShapeName(edge, box)
112 geompy.addToStudyInFather(box, edge, name)
113
114 # create a mesh
115 tria = smesh.Mesh(box, "Mesh 2D")
116 algo1D = tria.Segment()
117 hyp1 = algo1D.NumberOfSegments(3)
118 algo2D = tria.Triangle()
119 hyp2 = algo2D.MaxElementArea(10.)
120
121 # create a sub-mesh
122 algo_local = tria.Segment(edge)
123 hyp3 = algo_local.Arithmetic1D(1, 6)
124 hyp4 = algo_local.Propagation()
125
126 # compute the mesh
127 tria.Compute()
128 PrintMeshInfo(tria)
129
130 # remove a local hypothesis
131 mesh = tria.GetMesh()
132 mesh.RemoveHypothesis(edge, hyp4)
133
134 # compute the mesh
135 tria.Compute()
136 PrintMeshInfo(tria)
137
138 # change the value of the 2D hypothesis
139 hyp2.SetMaxElementArea(2.)
140
141 # compute the mesh
142 tria.Compute()
143 PrintMeshInfo(tria)
144 \endcode
145
146 <br>
147 \anchor tui_export_mesh
148 <h2>Export of a Mesh</h2>
149
150 \code
151 import geompy
152 import smesh
153
154 # create a box
155 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
156 idbox = geompy.addToStudy(box, "box")
157
158 # create a mesh
159 tetra = smesh.Mesh(box, "MeshBox")
160
161 algo1D = tetra.Segment()
162 algo1D.NumberOfSegments(7)
163
164 algo2D = tetra.Triangle()
165 algo2D.MaxElementArea(800.)
166
167 algo3D = tetra.Tetrahedron(smesh.NETGEN)
168 algo3D.MaxElementVolume(900.)
169
170 # compute the mesh
171 tetra.Compute()
172
173 # export the mesh in a MED file
174 tetra.ExportMED("/tmp/meshMED.med", 0)
175 \endcode
176
177 */