Version: 8.3.0
 All Classes Namespaces Files Functions Variables Groups Pages
Viewing Meshes


Viewing Mesh Infos

1 # Viewing Mesh Infos
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 # create a box
15 box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
16 geompy.addToStudy(box, "box")
17 [Face_1,Face_2,Face_3,Face_4,Face_5,Face_5] = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
18 
19 # create a mesh
20 tetra = smesh.Mesh(box, "MeshBox")
21 
22 algo1D = tetra.Segment()
23 algo1D.NumberOfSegments(3)
24 
25 algo2D = tetra.Triangle()
26 algo2D.MaxElementArea(10.)
27 
28 algo3D = tetra.Tetrahedron()
29 algo3D.MaxElementVolume(900.)
30 
31 # Creation of SubMesh
32 Regular_1D_1_1 = tetra.Segment(geom=Face_1)
33 Nb_Segments_1 = Regular_1D_1_1.NumberOfSegments(5)
34 Nb_Segments_1.SetDistrType( 0 )
35 Quadrangle_2D = tetra.Quadrangle(geom=Face_1)
36 isDone = tetra.Compute()
37 submesh = Regular_1D_1_1.GetSubMesh()
38 
39 # compute the mesh
40 tetra.Compute()
41 
42 # Creation of group
43 group = tetra.CreateEmptyGroup( SMESH.FACE, 'Group' )
44 nbAdd = group.Add( [ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76 ] )
45 
46 # Print information about the mesh
47 print "Information about mesh:"
48 print "Number of nodes : ", tetra.NbNodes()
49 print "Number of edges : ", tetra.NbEdges()
50 print "Number of faces : ", tetra.NbFaces()
51 print " triangles : ", tetra.NbTriangles()
52 print " quadrangles : ", tetra.NbQuadrangles()
53 print " polygons : ", tetra.NbPolygons()
54 print "Number of volumes : ", tetra.NbVolumes()
55 print " tetrahedrons: ", tetra.NbTetras()
56 print " hexahedrons : ", tetra.NbHexas()
57 print " prisms : ", tetra.NbPrisms()
58 print " pyramids : ", tetra.NbPyramids()
59 print " polyhedrons : ", tetra.NbPolyhedrons()
60 
61 # Get Information About Mesh by GetMeshInfo
62 print "\nInformation about mesh by GetMeshInfo:"
63 info = smesh.GetMeshInfo(tetra)
64 keys = info.keys(); keys.sort()
65 for i in keys:
66  print " %s : %d" % ( i, info[i] )
67  pass
68 
69 # Get Information About Group by GetMeshInfo
70 print "\nInformation about group by GetMeshInfo:"
71 info = smesh.GetMeshInfo(group)
72 keys = info.keys(); keys.sort()
73 for i in keys:
74  print " %s : %d" % ( i, info[i] )
75  pass
76 
77 # Get Information About SubMesh by GetMeshInfo
78 print "\nInformation about Submesh by GetMeshInfo:"
79 info = smesh.GetMeshInfo(submesh)
80 keys = info.keys(); keys.sort()
81 for i in keys:
82  print " %s : %d" % ( i, info[i] )
83  pass

Download this script


Find Element by Point

1 # Find Element by Point
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 # Create a geometry to mesh
15 box = geompy.MakeBoxDXDYDZ(100,100,100)
16 
17 # Create a mesh
18 mesh = smesh.Mesh(box,"Mesh")
19 mesh.AutomaticHexahedralization()
20 mesh.Compute()
21 
22 # Create a point
23 x,y,z = 0, 0, 1
24 
25 # Find all elements (except 0D ones) located at the point
26 all_elems_except_0D = mesh.FindElementsByPoint(x,y,z)
27 assert( len(all_elems_except_0D) == 4)
28 
29 # Find nodes at the point
30 nodes = mesh.FindElementsByPoint(x,y,z, SMESH.NODE )
31 assert( len(nodes) == 0)
32 assert( len( mesh.FindElementsByPoint(x,y,0, SMESH.NODE)) == 1)
33 
34 # Find an edge at the point
35 edges = mesh.FindElementsByPoint(x,y,z, SMESH.EDGE )
36 assert( len(edges) == 1)
37 
38 # Find faces at the point
39 edges = mesh.FindElementsByPoint(x,y,z, SMESH.FACE )
40 assert( len(edges) == 2)
41 
42 # Find a volume at the point
43 vols = mesh.FindElementsByPoint(x,y,z, SMESH.VOLUME )
44 assert( len(vols) == 1)
45 
46 # Find 0D elements at the point
47 elems0d = mesh.FindElementsByPoint(x,y,z, SMESH.ELEM0D )
48 assert( len(elems0d) == 0)
49 
50 # Find edges within a group
51 group1D = mesh.MakeGroupByIds("1D", SMESH.EDGE, [1,2] )
52 edges = mesh.FindElementsByPoint(x,y,z, SMESH.EDGE, group1D )

Download this script