1 # 3d mesh generation and mesh exploration
4 salome.salome_init_without_session()
7 from salome.geom import geomBuilder
8 from salome.smesh import smeshBuilder
10 geom_builder = geomBuilder.New()
11 smesh_builder = smeshBuilder.New()
14 # Geometry: an assembly of a box, a cylinder and a truncated cone
15 # to be meshed with tetrahedra
28 box = geom_builder.MakeBox(-cote, -cote, -cote, +cote, +cote, +cote)
31 pt1 = geom_builder.MakeVertex(0, 0, cote/3)
32 di1 = geom_builder.MakeVectorDXDYDZ(0, 0, 1)
33 cyl = geom_builder.MakeCylinder(pt1, di1, section, size)
35 # Build a truncated cone
36 pt2 = geom_builder.MakeVertex(0, 0, size)
37 cone = geom_builder.MakeCone(pt2, di1, radius_1, radius_2, height)
40 box_cyl = geom_builder.MakeFuse(box, cyl)
41 piece = geom_builder.MakeFuse(box_cyl, cone)
44 geom_builder.addToStudy(piece, name)
46 # Create a group of faces
47 faces_group = geom_builder.CreateGroup(piece, geom_builder.ShapeType["FACE"])
48 group_name = name + "_grp"
49 geom_builder.addToStudy(faces_group, group_name)
50 faces_group.SetName(group_name)
52 # Add faces to the group
53 faces = geom_builder.SubShapeAllIDs(piece, geom_builder.ShapeType["FACE"])
54 geom_builder.UnionIDs(faces_group, faces)
60 # Define a mesh on a geometry
61 tetra = smesh_builder.Mesh(piece, name)
63 # Define 1D algorithm and hypothesis
64 algo1d = tetra.Segment()
65 algo1d.LocalLength(10)
67 # Define 2D algorithm and hypothesis
68 algo2d = tetra.Triangle()
69 algo2d.LengthFromEdges()
71 # Define 3D algorithm and hypothesis
72 algo3d = tetra.Tetrahedron()
73 algo3d.MaxElementVolume(100)
76 if not tetra.Compute(): raise Exception("Error when computing Mesh")
78 # Create a mesh group of all triangles generated on geom faces present in faces_group
79 group = tetra.Group(faces_group)
85 # Retrieve coordinates of nodes
87 for node in tetra.GetNodesId():
88 x,y,z = tetra.GetNodeXYZ( node )
89 coordStr += "%s (%s, %s, %s) " % ( node, x,y,z )
92 # Retrieve nodal connectivity of triangles
94 for tria in tetra.GetElementsByType( SMESH.FACE ):
95 nodes = tetra.GetElemNodes( tria )
96 triaStr += "%s (%s, %s, %s) " % ( tria, nodes[0], nodes[1], nodes[2] )
98 # Retrieve group contents
100 for group in tetra.GetGroups():
102 name = group.GetName()
103 eType = group.GetType()
104 groupStr += "'%s' %s: %s \n" % ( name, eType, ids )