Salome HOME
bos #29171 Refactor testing procedure
[modules/smesh.git] / doc / examples / modifying_meshes_ex22.py
1 # Extrusion
2
3 # There is a series of Extrusion Along Line methods added at different times;
4 # a fully functional method is ExtrusionSweepObjects()
5
6 import math
7
8 import salome
9 salome.salome_init_without_session()
10
11 import SMESH
12 from salome.smesh import smeshBuilder
13
14 smesh_builder = smeshBuilder.New()
15
16 # create an empty mesh
17 mesh = smesh_builder.Mesh() 
18
19 # add a node
20 mesh.AddNode( 0.,0.,0. )
21
22 # extrude a node into a line of 10 segments along the X axis
23 ids = mesh.GetNodesId()
24 stepVector = [1.,0.,0.]
25 nbSteps = 10
26 mesh.ExtrusionSweep( ids, stepVector, nbSteps, IsNodes=True )
27
28 # create some groups
29 lastNode      = mesh.GetNodesId()[-1]
30 lastNodeGroup = mesh.MakeGroupByIds( "node %s"% lastNode, SMESH.NODE, [lastNode])
31 lineGroup     = mesh.MakeGroupByIds( "line", SMESH.EDGE, mesh.GetElementsId() )
32
33 # rotate the segments around the first node to get a mesh of a disk quarter
34 axisZ  = [0.,0.,0., 0.,0.,1.]
35 groups = mesh.RotationSweepObject( lineGroup, axisZ, math.pi/2., 10, 1e-3, MakeGroups=True, TotalAngle=True )
36
37 # extrude all faces into volumes
38 obj        = mesh
39 stepVector = [0.,0.,-1.]
40 nbSteps    = 5
41 groups = mesh.ExtrusionSweepObject2D( obj, stepVector, nbSteps, MakeGroups=True )
42
43 # remove all segments created by the last command
44 for g in groups:
45     if g.GetType() == SMESH.EDGE:
46         mesh.RemoveGroupWithContents( g )
47
48 # extrude all segments into faces along Z
49 obj = mesh
50 stepVector = [0.,0.,1.]
51 mesh.ExtrusionSweepObject1D( obj, stepVector, nbSteps )
52
53 # extrude a group
54 obj        = mesh.GetGroupByName( "line_extruded", SMESH.FACE )[0]
55 stepVector = [0,-5.,0.]
56 nbSteps    = 1
57 mesh.ExtrusionSweepObject( obj, stepVector, nbSteps )
58
59 # extrude all nodes and triangle faces of the disk quarter, applying a scale factor
60 diskGroup = mesh.GetGroupByName( "line_rotated", SMESH.FACE )[0]
61 crit = [ smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=',SMESH.Geom_TRIANGLE ),
62          smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_BelongToMeshGroup,'=', diskGroup )]
63 trianglesFilter = smesh_builder.GetFilterFromCriteria( crit )
64
65 nodes      = [ diskGroup ]
66 edges      = []
67 faces      = [ trianglesFilter ]
68 stepVector = [0,0,1]
69 nbSteps    = 10
70 mesh.ExtrusionSweepObjects( nodes, edges, faces, stepVector, nbSteps, scaleFactors=[0.5], linearVariation=True )
71
72 # extrude a cylindrical group of faces by normal
73 cylGroup = None
74 for g in mesh.GetGroups( SMESH.FACE ):
75     if g.GetName().startswith("node "):
76         cylGroup = g
77         break
78
79 elements = cylGroup
80 stepSize = 5.
81 nbSteps  = 2
82 mesh.ExtrusionByNormal( elements, stepSize, nbSteps )