smesh/doc/examples/viewing_meshes_ex01.py

83 lines
2.6 KiB
Python
Raw Permalink Normal View History

2013-02-12 20:37:44 +06:00
# Viewing Mesh Infos
import salome
salome.salome_init_without_session()
2022-04-11 18:28:01 +05:00
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
2022-04-11 18:28:01 +05:00
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
2013-02-12 20:37:44 +06:00
# create a box
2022-04-11 18:28:01 +05:00
box = geom_builder.MakeBox(0., 0., 0., 20., 20., 20.)
geom_builder.addToStudy(box, "box")
[Face_1,Face_2,Face_3,Face_4,Face_5,Face_5] = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
2013-02-12 20:37:44 +06:00
# create a mesh
2022-04-11 18:28:01 +05:00
tetra = smesh_builder.Mesh(box, "MeshBox")
2013-02-12 20:37:44 +06:00
algo1D = tetra.Segment()
algo1D.NumberOfSegments(3)
algo2D = tetra.Triangle()
algo2D.MaxElementArea(10.)
algo3D = tetra.Tetrahedron()
algo3D.MaxElementVolume(900.)
# Creation of SubMesh
Regular_1D_1_1 = tetra.Segment(geom=Face_1)
Nb_Segments_1 = Regular_1D_1_1.NumberOfSegments(5)
Nb_Segments_1.SetDistrType( 0 )
Quadrangle_2D = tetra.Quadrangle(geom=Face_1)
if not tetra.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
submesh = Regular_1D_1_1.GetSubMesh()
# compute the mesh
if not tetra.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# Creation of group
group = tetra.CreateEmptyGroup( SMESH.FACE, 'Group' )
nbAdd = group.Add( [ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76 ] )
# Print information about the mesh
2017-03-20 17:27:30 +05:00
print("Information about mesh:")
print("Number of nodes : ", tetra.NbNodes())
print("Number of edges : ", tetra.NbEdges())
print("Number of faces : ", tetra.NbFaces())
print(" triangles : ", tetra.NbTriangles())
print(" quadrangles : ", tetra.NbQuadrangles())
print(" polygons : ", tetra.NbPolygons())
print("Number of volumes : ", tetra.NbVolumes())
print(" tetrahedrons: ", tetra.NbTetras())
print(" hexahedrons : ", tetra.NbHexas())
print(" prisms : ", tetra.NbPrisms())
print(" pyramids : ", tetra.NbPyramids())
print(" polyhedrons : ", tetra.NbPolyhedrons())
2013-02-12 20:37:44 +06:00
# Get Information About Mesh by GetMeshInfo
2017-03-20 17:27:30 +05:00
print("\nInformation about mesh by GetMeshInfo:")
2022-04-11 18:28:01 +05:00
info = smesh_builder.GetMeshInfo(tetra)
2017-03-20 17:27:30 +05:00
keys = list(info.keys()); keys.sort()
2013-02-12 20:37:44 +06:00
for i in keys:
2017-03-20 17:27:30 +05:00
print(" %s : %d" % ( i, info[i] ))
2013-02-12 20:37:44 +06:00
pass
# Get Information About Group by GetMeshInfo
2017-03-20 17:27:30 +05:00
print("\nInformation about group by GetMeshInfo:")
2022-04-11 18:28:01 +05:00
info = smesh_builder.GetMeshInfo(group)
2017-03-20 17:27:30 +05:00
keys = list(info.keys()); keys.sort()
2013-02-12 20:37:44 +06:00
for i in keys:
2017-03-20 17:27:30 +05:00
print(" %s : %d" % ( i, info[i] ))
2013-02-12 20:37:44 +06:00
pass
# Get Information About SubMesh by GetMeshInfo
2017-03-20 17:27:30 +05:00
print("\nInformation about Submesh by GetMeshInfo:")
2022-04-11 18:28:01 +05:00
info = smesh_builder.GetMeshInfo(submesh)
2017-03-20 17:27:30 +05:00
keys = list(info.keys()); keys.sort()
2013-02-12 20:37:44 +06:00
for i in keys:
2017-03-20 17:27:30 +05:00
print(" %s : %d" % ( i, info[i] ))
2013-02-12 20:37:44 +06:00
pass