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()
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 = Mesh_1.Tetrahedron()
107 Max_Element_Volume_1 = Tetrahedron.MaxElementVolume(40000)
109 # create submesh and assign algorithms on Face_1
110 Regular_1D_1 = Mesh_1.Segment(geom=Face_1)
111 Nb_Segments_2 = Regular_1D_1.NumberOfSegments(4)
112 Nb_Segments_2.SetDistrType( 0 )
113 MEFISTO_2D_1 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_1)
114 Length_From_Edges_2D = MEFISTO_2D_1.LengthFromEdges()
115 SubMesh_1 = MEFISTO_2D_1.GetSubMesh()
117 # create submesh and assign algorithms on Face_2
118 Regular_1D_2 = Mesh_1.Segment(geom=Face_2)
119 Nb_Segments_3 = Regular_1D_2.NumberOfSegments(8)
120 Nb_Segments_3.SetDistrType( 0 )
121 MEFISTO_2D_2 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_2)
122 Length_From_Edges_2D_1 = MEFISTO_2D_2.LengthFromEdges()
123 SubMesh_2 = MEFISTO_2D_2.GetSubMesh()
125 # create submesh and assign algorithms on Face_3
126 Regular_1D_3 = Mesh_1.Segment(geom=Face_3)
127 Nb_Segments_4 = Regular_1D_3.NumberOfSegments(12)
128 Nb_Segments_4.SetDistrType( 0 )
129 MEFISTO_2D_3 = Mesh_1.Triangle(algo=smesh.MEFISTO,geom=Face_3)
130 Length_From_Edges_2D_2 = MEFISTO_2D_3.LengthFromEdges()
131 SubMesh_3 = MEFISTO_2D_3.GetSubMesh()
133 # check exisiting submesh priority order
134 [ [ SubMesh_1, SubMesh_3, SubMesh_2 ] ] = Mesh_1.GetMeshOrder()
135 # set new submesh order
136 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_1, SubMesh_2, SubMesh_3 ] ])
138 isDone = Mesh_1.Compute()
140 # clear mesh result and compute with other submesh order
142 isDone = Mesh_1.SetMeshOrder( [ [ SubMesh_2, SubMesh_1, SubMesh_3 ] ])
143 isDone = Mesh_1.Compute()
148 \anchor tui_editing_mesh
149 <h2>Editing of a mesh</h2>
155 def PrintMeshInfo(theMesh):
156 aMesh = theMesh.GetMesh()
157 print "Information about mesh:"
158 print "Number of nodes : ", aMesh.NbNodes()
159 print "Number of edges : ", aMesh.NbEdges()
160 print "Number of faces : ", aMesh.NbFaces()
161 print "Number of volumes : ", aMesh.NbVolumes()
165 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
166 geompy.addToStudy(box, "box")
168 # select one edge of the box for definition of a local hypothesis
169 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
170 edge = subShapeList[0]
171 name = geompy.SubShapeName(edge, box)
172 geompy.addToStudyInFather(box, edge, name)
175 tria = smesh.Mesh(box, "Mesh 2D")
176 algo1D = tria.Segment()
177 hyp1 = algo1D.NumberOfSegments(3)
178 algo2D = tria.Triangle()
179 hyp2 = algo2D.MaxElementArea(10.)
182 algo_local = tria.Segment(edge)
183 hyp3 = algo_local.Arithmetic1D(1, 6)
184 hyp4 = algo_local.Propagation()
190 # remove a local hypothesis
191 mesh = tria.GetMesh()
192 mesh.RemoveHypothesis(edge, hyp4)
198 # change the value of the 2D hypothesis
199 hyp2.SetMaxElementArea(2.)
207 \anchor tui_export_mesh
208 <h2>Export of a Mesh</h2>
215 box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
216 idbox = geompy.addToStudy(box, "box")
219 tetra = smesh.Mesh(box, "MeshBox")
221 algo1D = tetra.Segment()
222 algo1D.NumberOfSegments(7)
224 algo2D = tetra.Triangle()
225 algo2D.MaxElementArea(800.)
227 algo3D = tetra.Tetrahedron()
228 algo3D.MaxElementVolume(900.)
233 # export the mesh in a MED file
234 tetra.ExportMED("/tmp/meshMED.med", 0)
236 # export a group in a MED file
237 face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0] # a box side
238 group = tetra.GroupOnGeom( face, "face group" ) # group of 2D elements on the <face>
239 tetra.ExportMED("/tmp/groupMED.med", meshPart=group)
243 <h2>How to mesh a cylinder with hexahedrons?</h2>
244 Here you can see an example of python script, creating a hexahedral
245 mesh on a cylinder. And a picture below the source code of the script,
246 demonstrating the resulting mesh.
247 \include ex24_cylinder.py
249 \image html mesh_cylinder_hexa.png
252 \anchor tui_building_compound
253 <h2>Building a compound of meshes</h2>
254 \dontinclude SMESH_BuildCompound.py
255 \skipline import geompy
259 \anchor tui_copy_mesh
260 <h2>Mesh Copying</h2>
263 SetCurrentStudy(salome.myStudy)
265 # make geometry of a box
266 box = geompy.MakeBoxDXDYDZ(100,100,100)
267 face = geompy.SubShapeAllSorted(box, geompy.ShapeType["FACE"])[0]
271 localAlgo = mesh.Triangle(face)
272 mesh.AutomaticHexahedralization()
275 fGroup = mesh.GroupOnGeom( face, "2D on face")
276 nGroup = mesh.GroupOnGeom( face, "nodes on face", NODE)
277 subMesh = localAlgo.GetSubMesh()
279 # make a new mesh by copying different parts of the mesh
281 # 1. copy the whole mesh
282 newMesh = CopyMesh( mesh, "whole mesh copy")
284 # 2. copy a group of 2D elements along with groups
285 newMesh = CopyMesh( fGroup, "face group copy with groups",toCopyGroups=True)
287 # 3. copy a group of nodes with preseving their ids
288 newMesh = CopyMesh( nGroup, "node group copy", toKeepIDs=True)
291 faceIds = fGroup.GetIDs()[-10:]
292 newMesh = CopyMesh( mesh.GetIDSource( faceIds, FACE ), "some faces copy")
295 nodeIds = nGroup.GetIDs()[-10:]
296 newMesh = CopyMesh( mesh.GetIDSource( nodeIds, NODE), "some nodes copy")
299 newMesh = CopyMesh( subMesh, "submesh copy" )