smesh/doc/examples/modifying_meshes_ex15.py

50 lines
1.4 KiB
Python
Raw Permalink Normal View History

2013-02-12 20:37:44 +06:00
# Moving Nodes
import salome
salome.salome_init_without_session()
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()
2022-04-11 18:28:01 +05:00
box = geom_builder.MakeBoxDXDYDZ(200, 200, 200)
2022-04-11 18:28:01 +05:00
mesh = smesh_builder.Mesh( box )
2013-02-12 20:37:44 +06:00
mesh.Segment().AutomaticLength(0.1)
mesh.Quadrangle()
if not mesh.Compute(): raise Exception("Error when computing Mesh")
2013-02-12 20:37:44 +06:00
# find node at (0,0,0) which is located on a geom vertex
2013-02-12 20:37:44 +06:00
node000 = None
2022-04-11 18:28:01 +05:00
for vId in geom_builder.SubShapeAllIDs( box, geom_builder.ShapeType["VERTEX"]):
2013-02-12 20:37:44 +06:00
if node000: break
nodeIds = mesh.GetSubMeshNodesId( vId, True )
for node in nodeIds:
xyz = mesh.GetNodeXYZ( node )
if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
node000 = node
pass
pass
pass
if not node000:
raise Exception("node000 not found")
2013-02-12 20:37:44 +06:00
# find node000 using a dedicated function
2013-02-12 20:37:44 +06:00
n = mesh.FindNodeClosestTo( -1,-1,-1 )
if not n == node000:
2017-03-20 17:27:30 +05:00
raise Exception("FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 ))
2013-02-12 20:37:44 +06:00
# move node000 to a new location
x,y,z = -10, -10, -10
n = mesh.MoveNode( n,x,y,z )
if not n:
2017-03-20 17:27:30 +05:00
raise Exception("MoveNode() returns " + n)
2013-02-12 20:37:44 +06:00
# check the coordinates of the node000
xyz = mesh.GetNodeXYZ( node000 )
if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
2017-03-20 17:27:30 +05:00
raise Exception("Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] ))