smesh/doc/examples/transforming_meshes_ex06.py

85 lines
2.7 KiB
Python
Raw Permalink Normal View History

2013-02-12 20:37:44 +06:00
# Merging Elements
import salome
salome.salome_init_without_session()
import SMESH
2022-04-11 18:28:01 +05:00
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 face to be meshed
2022-04-11 18:28:01 +05:00
px = geom_builder.MakeVertex(100., 0. , 0. )
py = geom_builder.MakeVertex(0. , 100., 0. )
pz = geom_builder.MakeVertex(0. , 0. , 100.)
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
vxy = geom_builder.MakeVector(px, py)
arc = geom_builder.MakeArc(py, pz, px)
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
wire = geom_builder.MakeWire([vxy, arc])
2013-02-12 20:37:44 +06:00
isPlanarFace = 1
2022-04-11 18:28:01 +05:00
face1 = geom_builder.MakeFace(wire, isPlanarFace)
id_face1 = geom_builder.addToStudy(face1, "Face1")
2013-02-12 20:37:44 +06:00
# create a circle to be an extrusion path
2022-04-11 18:28:01 +05:00
px1 = geom_builder.MakeVertex( 100., 100., 0.)
py1 = geom_builder.MakeVertex(-100., -100., 0.)
pz1 = geom_builder.MakeVertex( 0., 0., 50.)
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
circle = geom_builder.MakeCircleThreePnt(py1, pz1, px1)
id_circle = geom_builder.addToStudy(circle, "Path")
2013-02-12 20:37:44 +06:00
# create a 2D mesh on the face
2022-04-11 18:28:01 +05:00
trias = smesh_builder.Mesh(face1, "Face : 2D mesh")
2013-02-12 20:37:44 +06:00
algo1D = trias.Segment()
algo1D.NumberOfSegments(6)
algo2D = trias.Triangle()
algo2D.LengthFromEdges()
if not trias.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# create a group of all triangles currently present in the mesh
faceTriGroup = trias.Group( face1, "face triangles" )
2013-02-12 20:37:44 +06:00
# create a path mesh
2022-04-11 18:28:01 +05:00
circlemesh = smesh_builder.Mesh(circle, "Path mesh")
2013-02-12 20:37:44 +06:00
algo = circlemesh.Segment()
algo.NumberOfSegments(10)
if not circlemesh.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# extrusion of the mesh
trias.ExtrusionAlongPath([], circlemesh, circle, 1, MakeGroups=True )
# get a group "opposite" to faceTriGroup within the generated prismatic mesh
oppositeGroup = trias.GetGroupByName( faceTriGroup.GetName() + "_top" )[0]
# get edges of the groups
edgeGroup = trias.CreateDimGroup([ faceTriGroup, oppositeGroup ], SMESH.EDGE, "face edges")
2013-02-12 20:37:44 +06:00
# merge nodes of the groups only
2017-03-20 17:27:30 +05:00
print("Number of nodes before MergeNodes:", end=' ')
2013-02-12 20:37:44 +06:00
trias.NbNodes()
tolerance = 0.001
array_of_nodes_groups = trias.FindCoincidentNodesOnPart([faceTriGroup, oppositeGroup], tolerance)
2013-02-12 20:37:44 +06:00
trias.MergeNodes(array_of_nodes_groups)
2017-03-20 17:27:30 +05:00
print("Number of nodes after MergeNodes:", trias.NbNodes())
print("")
print("Number of elements before MergeEqualElements:")
print("Edges : ", trias.NbEdges())
print("Faces : ", trias.NbFaces())
2017-03-20 17:27:30 +05:00
print("Volumes : ", trias.NbVolumes())
2013-02-12 20:37:44 +06:00
# merge elements of the groups
equalFaces = trias.FindEqualElements( [faceTriGroup, oppositeGroup, edgeGroup] )
trias.MergeElements( equalFaces )
2017-03-20 17:27:30 +05:00
print("Number of elements after MergeEqualElements:")
print("Edges : ", trias.NbEdges())
print("Faces : ", trias.NbFaces())
2017-03-20 17:27:30 +05:00
print("Volumes : ", trias.NbVolumes())