3 \page tui_creating_meshes_page Creating Meshes
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.
9 <h2>Construction of a Mesh</h2>
16 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
17 idbox = geompy.addToStudy(box, "box")
20 tetra = smesh.Mesh(box, "MeshBox")
22 algo1D = tetra.Segment()
23 algo1D.NumberOfSegments(7)
25 algo2D = tetra.Triangle()
26 algo2D.MaxElementArea(800.)
28 algo3D = tetra.Tetrahedron(smesh.NETGEN)
29 algo3D.MaxElementVolume(900.)
34 print "problem when computing the mesh"
41 \anchor tui_construction_submesh
42 <h2>Construction of a Submesh</h2>
49 box = MakeBoxDXDYDZ(10., 10., 10.)
50 addToStudy(box, "Box")
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]")
57 # create a hexahedral mesh on the box
58 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
60 # create a regular 1D algorithm for the faces
61 algo1D = quadra.Segment()
63 # define "NumberOfSegments" hypothesis to cut
64 # all the edges in a fixed number of segments
65 algo1D.NumberOfSegments(4)
67 # create a quadrangle 2D algorithm for the faces
70 # construct a submesh on the edge with a local hypothesis
71 algo_local = quadra.Segment(EdgeX)
73 # define "Arithmetic1D" hypothesis to cut the edge in several segments with increasing arithmetic length
74 algo_local.Arithmetic1D(1, 4)
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()
86 \anchor tui_editing_mesh
87 <h2>Editing of a mesh</h2>
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()
103 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
104 geompy.addToStudy(box, "box")
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)
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.)
120 algo_local = tria.Segment(edge)
121 hyp3 = algo_local.Arithmetic1D(1, 6)
122 hyp4 = algo_local.Propagation()
128 # remove a local hypothesis
129 mesh = tria.GetMesh()
130 mesh.RemoveHypothesis(edge, hyp4)
136 # change the value of the 2D hypothesis
137 hyp2.SetMaxElementArea(2.)
145 \anchor tui_export_mesh
146 <h2>Export of a Mesh</h2>
153 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
154 idbox = geompy.addToStudy(box, "box")
157 tetra = smesh.Mesh(box, "MeshBox")
159 algo1D = tetra.Segment()
160 algo1D.NumberOfSegments(7)
162 algo2D = tetra.Triangle()
163 algo2D.MaxElementArea(800.)
165 algo3D = tetra.Tetrahedron(smesh.NETGEN)
166 algo3D.MaxElementVolume(900.)
171 # export the mesh in a MED file
172 tetra.ExportMED("/tmp/meshMED.med", 0)
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 ex24_cylinder.py
182 \image html mesh_cylinder_hexa.png