1 # 3d mesh generation and mesh exploration
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New()
9 from salome.smesh import smeshBuilder
10 smesh = smeshBuilder.New()
13 # Geometry: an assembly of a box, a cylinder and a truncated cone
14 # to be meshed with tetrahedra
27 box = geompy.MakeBox(-cote, -cote, -cote, +cote, +cote, +cote)
30 pt1 = geompy.MakeVertex(0, 0, cote/3)
31 di1 = geompy.MakeVectorDXDYDZ(0, 0, 1)
32 cyl = geompy.MakeCylinder(pt1, di1, section, size)
34 # Build a truncated cone
35 pt2 = geompy.MakeVertex(0, 0, size)
36 cone = geompy.MakeCone(pt2, di1, radius_1, radius_2, height)
39 box_cyl = geompy.MakeFuse(box, cyl)
40 piece = geompy.MakeFuse(box_cyl, cone)
43 geompy.addToStudy(piece, name)
45 # Create a group of faces
46 faces_group = geompy.CreateGroup(piece, geompy.ShapeType["FACE"])
47 group_name = name + "_grp"
48 geompy.addToStudy(faces_group, group_name)
49 faces_group.SetName(group_name)
51 # Add faces to the group
52 faces = geompy.SubShapeAllIDs(piece, geompy.ShapeType["FACE"])
53 geompy.UnionIDs(faces_group, faces)
59 # Define a mesh on a geometry
60 tetra = smesh.Mesh(piece, name)
62 # Define 1D algorithm and hypothesis
63 algo1d = tetra.Segment()
64 algo1d.LocalLength(10)
66 # Define 2D algorithm and hypothesis
67 algo2d = tetra.Triangle()
68 algo2d.LengthFromEdges()
70 # Define 3D algorithm and hypothesis
71 algo3d = tetra.Tetrahedron()
72 algo3d.MaxElementVolume(100)
77 # Create a mesh group of all triangles generated on geom faces present in faces_group
78 group = tetra.Group(faces_group)
84 # Retrieve coordinates of nodes
86 for node in tetra.GetNodesId():
87 x,y,z = tetra.GetNodeXYZ( node )
88 coordStr += "%s (%s, %s, %s) " % ( node, x,y,z )
91 # Retrieve nodal connectivity of triangles
93 for tria in tetra.GetElementsByType( SMESH.FACE ):
94 nodes = tetra.GetElemNodes( tria )
95 triaStr += "%s (%s, %s, %s) " % ( tria, nodes[0], nodes[1], nodes[2] )
97 # Retrieve group contents
99 for group in tetra.GetGroups():
101 name = group.GetName()
102 eType = group.GetType()
103 groupStr += "'%s' %s: %s \n" % ( name, eType, ids )