Salome HOME
Restore some lost modifications.
[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 introduction_to_mesh_python_page "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 \anchor tui_editing_mesh
87 <h2>Editing of a mesh</h2>
88
89 \code
90 import geompy
91 import smesh
92
93 def PrintMeshInfo(theMesh):
94     aMesh = theMesh.GetMesh()
95     print "Information about mesh:"
96     print "Number of nodes       : ", aMesh.NbNodes()
97     print "Number of edges       : ", aMesh.NbEdges()
98     print "Number of faces       : ", aMesh.NbFaces()
99     print "Number of volumes     : ", aMesh.NbVolumes()
100     pass
101
102 # create a box
103 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
104 geompy.addToStudy(box, "box")
105
106 # select one edge of the box for definition of a local hypothesis
107 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
108 edge = subShapeList[0]
109 name = geompy.SubShapeName(edge, box)
110 geompy.addToStudyInFather(box, edge, name)
111
112 # create a mesh
113 tria = smesh.Mesh(box, "Mesh 2D")
114 algo1D = tria.Segment()
115 hyp1 = algo1D.NumberOfSegments(3)
116 algo2D = tria.Triangle()
117 hyp2 = algo2D.MaxElementArea(10.)
118
119 # create a sub-mesh
120 algo_local = tria.Segment(edge)
121 hyp3 = algo_local.Arithmetic1D(1, 6)
122 hyp4 = algo_local.Propagation()
123
124 # compute the mesh
125 tria.Compute()
126 PrintMeshInfo(tria)
127
128 # remove a local hypothesis
129 mesh = tria.GetMesh()
130 mesh.RemoveHypothesis(edge, hyp4)
131
132 # compute the mesh
133 tria.Compute()
134 PrintMeshInfo(tria)
135
136 # change the value of the 2D hypothesis
137 hyp2.SetMaxElementArea(2.)
138
139 # compute the mesh
140 tria.Compute()
141 PrintMeshInfo(tria)
142 \endcode
143
144 <br>
145 \anchor tui_export_mesh
146 <h2>Export of a Mesh</h2>
147
148 \code
149 import geompy
150 import smesh
151
152 # create a box
153 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
154 idbox = geompy.addToStudy(box, "box")
155
156 # create a mesh
157 tetra = smesh.Mesh(box, "MeshBox")
158
159 algo1D = tetra.Segment()
160 algo1D.NumberOfSegments(7)
161
162 algo2D = tetra.Triangle()
163 algo2D.MaxElementArea(800.)
164
165 algo3D = tetra.Tetrahedron(smesh.NETGEN)
166 algo3D.MaxElementVolume(900.)
167
168 # compute the mesh
169 tetra.Compute()
170
171 # export the mesh in a MED file
172 tetra.ExportMED("/tmp/meshMED.med", 0)
173 \endcode
174
175 <br>
176 <h2>How to mesh a cylinder with hexahedrons?</h2>
177 Here you can see an example of python script, creating a hexahedral
178 mesh on a cylinder. And a picture below the source code of the script,
179 demonstrating the resulting mesh.
180 \include /dn20/salome/jfa/V4/SRC/SMESH_SRC/src/SMESH_SWIG/ex24_cylinder.py
181
182 \image html mesh_cylinder_hexa.png
183
184 */