smesh/doc/examples/transforming_meshes_ex10.py

64 lines
2.2 KiB
Python
Raw Normal View History

2013-02-12 20:37:44 +06:00
# Sew Side Elements
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 two boxes
2022-04-11 18:28:01 +05:00
box1 = geom_builder.MakeBox(0., 0., 0., 10., 10., 10.)
box2 = geom_builder.MakeBox(0., 15., 0., 20., 25., 10.)
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
EdgesList = geom_builder.SubShapeAll(box2, geom_builder.ShapeType["EDGE"])
2013-02-12 20:37:44 +06:00
2022-04-11 18:28:01 +05:00
aComp = geom_builder.MakeCompound([box1, box2])
geom_builder.addToStudy(aComp, "Two boxes")
2013-02-12 20:37:44 +06:00
# create a mesh on two boxes
2022-04-11 18:28:01 +05:00
mesh = smesh_builder.Mesh(aComp, "Sew Side Elements")
2013-02-12 20:37:44 +06:00
algo1D = mesh.Segment()
algo1D.NumberOfSegments(2)
algo2D = mesh.Quadrangle()
algo_local = mesh.Segment(EdgesList[8])
algo_local.NumberOfSegments(4)
algo_local.Propagation()
if not mesh.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# sew side elements
# find elements to sew
2022-04-11 18:28:01 +05:00
face1 = geom_builder.GetFaceNearPoint( aComp, geom_builder.MakeVertex( 5, 10, 5 ))
IDsOfSide1Elements = mesh.GetSubMeshElementsId( face1 )
2017-03-20 17:27:30 +05:00
print("side faces 1:",IDsOfSide1Elements)
2022-04-11 18:28:01 +05:00
face1Translated = geom_builder.MakeTranslation( face1, 0,5,0 )
faceFilter = smesh_builder.GetFilter( SMESH.FACE, SMESH.FT_BelongToGeom,'=', face1Translated )
IDsOfSide2Elements = mesh.GetIdsFromFilter( faceFilter )
2017-03-20 17:27:30 +05:00
print("side faces 2:",IDsOfSide2Elements)
# find corresponding nodes on sides
2022-04-11 18:28:01 +05:00
edge1 = geom_builder.GetEdgeNearPoint( aComp, geom_builder.MakeVertex( 0, 10, 5 ))
segs1 = mesh.GetSubMeshElementsId( edge1 ) # mesh segments generated on edge1
NodeID1OfSide1ToMerge = mesh.GetElemNode( segs1[0], 0 )
NodeID2OfSide1ToMerge = mesh.GetElemNode( segs1[0], 1 )
2017-03-20 17:27:30 +05:00
print("nodes of side1:", [NodeID1OfSide1ToMerge,NodeID2OfSide1ToMerge])
2022-04-11 18:28:01 +05:00
edge2 = geom_builder.GetEdgeNearPoint( aComp, geom_builder.MakeVertex( 0, 15, 5 ))
segs2 = mesh.GetSubMeshElementsId( edge2 ) # mesh segments generated on edge2
NodeID1OfSide2ToMerge = mesh.GetElemNode( segs2[0], 0 )
NodeID2OfSide2ToMerge = mesh.GetElemNode( segs2[0], 1 )
2017-03-20 17:27:30 +05:00
print("nodes of side2:", [NodeID1OfSide2ToMerge,NodeID2OfSide2ToMerge])
res = mesh.SewSideElements(IDsOfSide1Elements, IDsOfSide2Elements,
NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge,
NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge)
2017-03-20 17:27:30 +05:00
print(res)