3 \page tui_creating_meshes_page Creating Meshes
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.
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 <h2>Change priority of submeshes in Mesh</h2>
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"])
97 # create Mesh object on Box shape
98 Mesh_1 = smesh.Mesh(Box_1)
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)
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()
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',
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()
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 ] ])
137 isDone = Mesh_1.Compute()
139 # clear mesh result and compute with other submesh order
141 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_2, SubMesh_1, SubMesh_3 ] ])
142 isDone = Mesh_1.Compute()
147 \anchor tui_editing_mesh
148 <h2>Editing of a mesh</h2>
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()
164 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
165 geompy.addToStudy(box, "box")
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)
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.)
181 algo_local = tria.Segment(edge)
182 hyp3 = algo_local.Arithmetic1D(1, 6)
183 hyp4 = algo_local.Propagation()
189 # remove a local hypothesis
190 mesh = tria.GetMesh()
191 mesh.RemoveHypothesis(edge, hyp4)
197 # change the value of the 2D hypothesis
198 hyp2.SetMaxElementArea(2.)
206 \anchor tui_export_mesh
207 <h2>Export of a Mesh</h2>
214 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
215 idbox = geompy.addToStudy(box, "box")
218 tetra = smesh.Mesh(box, "MeshBox")
220 algo1D = tetra.Segment()
221 algo1D.NumberOfSegments(7)
223 algo2D = tetra.Triangle()
224 algo2D.MaxElementArea(800.)
226 algo3D = tetra.Tetrahedron(smesh.NETGEN)
227 algo3D.MaxElementVolume(900.)
232 # export the mesh in a MED file
233 tetra.ExportMED("/tmp/meshMED.med", 0)
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
243 \image html mesh_cylinder_hexa.png
246 \anchor tui_building_compound
247 <h2>Building a compound of meshes</h2>
248 \dontinclude SMESH_BuildCompound.py
249 \skipline import geompy