2013-02-12 20:37:44 +06:00
|
|
|
# Extrusion
|
|
|
|
|
2019-01-24 20:28:24 +05:00
|
|
|
# There is a series of Extrusion Along Line methods added at different times;
|
|
|
|
# a fully functional method is ExtrusionSweepObjects()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
2022-04-11 18:28:01 +05:00
|
|
|
import math
|
|
|
|
|
|
|
|
import salome
|
2021-08-12 14:38:10 +05:00
|
|
|
salome.salome_init_without_session()
|
2013-04-04 13:08:19 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
import SMESH
|
2013-04-04 13:08:19 +06:00
|
|
|
from salome.smesh import smeshBuilder
|
2022-04-11 18:28:01 +05:00
|
|
|
|
|
|
|
smesh_builder = smeshBuilder.New()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# create an empty mesh
|
2022-04-11 18:28:01 +05:00
|
|
|
mesh = smesh_builder.Mesh()
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# add a node
|
|
|
|
mesh.AddNode( 0.,0.,0. )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# extrude a node into a line of 10 segments along the X axis
|
|
|
|
ids = mesh.GetNodesId()
|
|
|
|
stepVector = [1.,0.,0.]
|
|
|
|
nbSteps = 10
|
|
|
|
mesh.ExtrusionSweep( ids, stepVector, nbSteps, IsNodes=True )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# create some groups
|
|
|
|
lastNode = mesh.GetNodesId()[-1]
|
|
|
|
lastNodeGroup = mesh.MakeGroupByIds( "node %s"% lastNode, SMESH.NODE, [lastNode])
|
|
|
|
lineGroup = mesh.MakeGroupByIds( "line", SMESH.EDGE, mesh.GetElementsId() )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# rotate the segments around the first node to get a mesh of a disk quarter
|
|
|
|
axisZ = [0.,0.,0., 0.,0.,1.]
|
|
|
|
groups = mesh.RotationSweepObject( lineGroup, axisZ, math.pi/2., 10, 1e-3, MakeGroups=True, TotalAngle=True )
|
2013-02-12 20:37:44 +06:00
|
|
|
|
2017-06-21 16:23:17 +05:00
|
|
|
# extrude all faces into volumes
|
|
|
|
obj = mesh
|
|
|
|
stepVector = [0.,0.,-1.]
|
|
|
|
nbSteps = 5
|
|
|
|
groups = mesh.ExtrusionSweepObject2D( obj, stepVector, nbSteps, MakeGroups=True )
|
|
|
|
|
|
|
|
# remove all segments created by the last command
|
|
|
|
for g in groups:
|
|
|
|
if g.GetType() == SMESH.EDGE:
|
|
|
|
mesh.RemoveGroupWithContents( g )
|
|
|
|
|
|
|
|
# extrude all segments into faces along Z
|
|
|
|
obj = mesh
|
|
|
|
stepVector = [0.,0.,1.]
|
|
|
|
mesh.ExtrusionSweepObject1D( obj, stepVector, nbSteps )
|
|
|
|
|
|
|
|
# extrude a group
|
2019-01-24 20:28:24 +05:00
|
|
|
obj = mesh.GetGroupByName( "line_extruded", SMESH.FACE )[0]
|
2017-06-21 16:23:17 +05:00
|
|
|
stepVector = [0,-5.,0.]
|
|
|
|
nbSteps = 1
|
|
|
|
mesh.ExtrusionSweepObject( obj, stepVector, nbSteps )
|
|
|
|
|
|
|
|
# extrude all nodes and triangle faces of the disk quarter, applying a scale factor
|
2019-01-24 20:28:24 +05:00
|
|
|
diskGroup = mesh.GetGroupByName( "line_rotated", SMESH.FACE )[0]
|
2022-04-11 18:28:01 +05:00
|
|
|
crit = [ smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=',SMESH.Geom_TRIANGLE ),
|
|
|
|
smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_BelongToMeshGroup,'=', diskGroup )]
|
|
|
|
trianglesFilter = smesh_builder.GetFilterFromCriteria( crit )
|
2017-06-21 16:23:17 +05:00
|
|
|
|
|
|
|
nodes = [ diskGroup ]
|
|
|
|
edges = []
|
|
|
|
faces = [ trianglesFilter ]
|
|
|
|
stepVector = [0,0,1]
|
|
|
|
nbSteps = 10
|
|
|
|
mesh.ExtrusionSweepObjects( nodes, edges, faces, stepVector, nbSteps, scaleFactors=[0.5], linearVariation=True )
|
|
|
|
|
|
|
|
# extrude a cylindrical group of faces by normal
|
|
|
|
cylGroup = None
|
|
|
|
for g in mesh.GetGroups( SMESH.FACE ):
|
|
|
|
if g.GetName().startswith("node "):
|
|
|
|
cylGroup = g
|
|
|
|
break
|
|
|
|
|
|
|
|
elements = cylGroup
|
|
|
|
stepSize = 5.
|
|
|
|
nbSteps = 2
|
|
|
|
mesh.ExtrusionByNormal( elements, stepSize, nbSteps )
|