Version: 8.3.0
 All Classes Namespaces Files Functions Variables Groups Pages
Grouping Elements


Create a Standalone Group

1 # Create a Standalone Group
2 
3 import SMESH_mechanic
4 import SMESH
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Get ids of all faces with area > 100
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
12 
13 anIds = mesh.GetIdsFromFilter(aFilter)
14 
15 # create a group consisting of faces with area > 100
16 aGroup1 = mesh.MakeGroupByIds("Area > 100", SMESH.FACE, anIds)
17 
18 # create a group that contains all nodes from the mesh
19 aGroup2 = mesh.CreateEmptyGroup(SMESH.NODE, "all nodes")
20 aGroup2.AddFrom(mesh.mesh)
21 
22 
23 # ====================================
24 # Various methods of the Group object
25 # ====================================
26 
27 aGroup = mesh.CreateEmptyGroup(SMESH.NODE, "aGroup")
28 
29 # set/get group name
30 aGroup.SetName( "new name" )
31 print "name", aGroup.GetName()
32 
33 # get group type (type of entities in the group, SMESH.NODE in our case)
34 print "type", aGroup.GetType()
35 
36 # get number of entities (nodes in our case) in the group
37 print "size", aGroup.Size()
38 
39 # check of emptiness
40 print "is empty", aGroup.IsEmpty()
41 
42 # check of presence of an entity in the group
43 aGroup.Add([1,2]) # Add() method is specific to the standalone group
44 print "contains node 2", aGroup.Contains(2)
45 
46 # get an entity by index
47 print "1st node", aGroup.GetID(1)
48 
49 # get all entities
50 print "all", aGroup.GetIDs()
51 
52 # get number of nodes (actual for groups of elements)
53 print "nb nodes", aGroup.GetNumberOfNodes()
54 
55 # get underlying nodes (actual for groups of elements)
56 print "nodes", aGroup.GetNodeIDs()
57 
58 # set/get color
59 import SALOMEDS
60 aGroup.SetColor( SALOMEDS.Color(1.,1.,0.));
61 print "color", aGroup.GetColor()
62 
63 # ----------------------------------------------------------------------------
64 # methods specific to the standalone group and not present in GroupOnGeometry
65 # and GroupOnFilter
66 # ----------------------------------------------------------------------------
67 
68 # clear the group's contents
69 aGroup.Clear()
70 
71 # add contents of other object (group, sub-mesh, filter)
72 aGroup.AddFrom( aGroup2 )
73 
74 # removes entities
75 aGroup.Remove( [2,3,4] )
76 
77 
78 
79 
80 salome.sg.updateObjBrowser(True)

Download this script

create_group.png


Create a Group on Geometry

1 # Create a Group on Geometry
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 
14 # create a box
15 box = geompy.MakeBox(0., 0., 0., 100., 100., 100.)
16 geompy.addToStudy(box, "box")
17 
18 # add the first face of the box to the study
19 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
20 face = subShapeList[0]
21 geompy.addToStudyInFather(box, face, "face 1")
22 
23 # create group of edges on the face
24 aGeomGroupE = geompy.CreateGroup(face, geompy.ShapeType["EDGE"])
25 geompy.AddObject(aGeomGroupE, 3)
26 geompy.AddObject(aGeomGroupE, 6)
27 geompy.AddObject(aGeomGroupE, 8)
28 geompy.AddObject(aGeomGroupE, 10)
29 geompy.addToStudyInFather(face, aGeomGroupE, "Group of Edges")
30 
31 # create quadrangle 2D mesh on the box
32 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
33 algo1D = quadra.Segment()
34 quadra.Quadrangle()
35 algo1D.NumberOfSegments(7)
36 
37 # compute the mesh
38 quadra.Compute()
39 
40 # create SMESH group on the face with name "SMESHGroup1"
41 aSmeshGroup1 = quadra.GroupOnGeom(face, "SMESHGroup1")
42 
43 # create SMESH group on <aGeomGroupE> with default name
44 aSmeshGroup2 = quadra.GroupOnGeom(aGeomGroupE)
45 
46 salome.sg.updateObjBrowser(True)

Download this script


Create a Group on Filter

1 # Create a Group on Filter
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 
16 box = geompy.MakeBoxDXDYDZ(10,10,10)
17 
18 # make a mesh with quadrangles of different area in range [1,16]
19 mesh = smesh.Mesh(box,"Quad mesh")
20 hyp1D = mesh.Segment().StartEndLength( 1, 4 )
21 mesh.Quadrangle()
22 mesh.Compute()
23 
24 # create a group on filter selecting faces of medium size
25 critaria = [ \
26  smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, ">", 1.1, BinaryOp=SMESH.FT_LogicalAND ),
27  smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, "<", 15.0 )
28  ]
29 filt = smesh.GetFilterFromCriteria( critaria )
30 filtGroup = mesh.GroupOnFilter( SMESH.FACE, "group on filter", filt )
31 print "Group on filter contains %s elemens" % filtGroup.Size()
32 
33 # group on filter is updated if the mesh is modified
34 hyp1D.SetStartLength( 2.5 )
35 hyp1D.SetEndLength( 2.5 )
36 mesh.Compute()
37 print "After mesh change, group on filter contains %s elemens" % filtGroup.Size()
38 
39 # set a new filter defining the group
40 filt2 = smesh.GetFilter( SMESH.FACE, SMESH.FT_RangeOfIds, "1-50" )
41 filtGroup.SetFilter( filt2 )
42 print "With a new filter, group on filter contains %s elemens" % filtGroup.Size()
43 
44 # group is updated at modification of the filter
45 filt2.SetCriteria( [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_RangeOfIds, "1-70" )])
46 filtIDs3 = filtGroup.GetIDs()
47 print "After filter modification, group on filter contains %s elemens" % filtGroup.Size()
48 
49 salome.sg.updateObjBrowser(True)

Download this script


Edit a Group

1 # Edit a Group
2 
3 import SMESH_mechanic
4 import SMESH
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Get ids of all faces with area > 35
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 35.)
12 
13 anIds = mesh.GetIdsFromFilter(aFilter)
14 
15 print "Criterion: Area > 35, Nb = ", len(anIds)
16 
17 # create a group by adding elements with area > 35
18 aGroup = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 35")
19 aGroup.Add(anIds)
20 
21 # Get ids of all faces with area > 40
22 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 40.)
23 
24 anIds = mesh.GetIdsFromFilter(aFilter)
25 
26 print "Criterion: Area > 40, Nb = ", len(anIds)
27 
28 # create a group of elements with area [35; 40] by removing elements with area > 40 from group aGroup
29 aGroup.Remove(anIds)
30 aGroup.SetName("35 < Area < 40")
31 
32 # print the result
33 aGroupElemIDs = aGroup.GetListOfID()
34 
35 print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)
36 
37 j = 1
38 for i in range(len(aGroupElemIDs)):
39  if j > 20: j = 1; print ""
40  print aGroupElemIDs[i],
41  j = j + 1
42  pass
43 print ""
44 
45 salome.sg.updateObjBrowser(True)

Download this script

editing_groups1.png


Union of groups

1 # Union of groups
2 
3 import SMESH_mechanic
4 import SMESH, SALOMEDS
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Criterion : AREA > 20
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
12 
13 anIds = mesh.GetIdsFromFilter(aFilter)
14 
15 print "Criterion: Area > 20, Nb = ", len( anIds )
16 
17 # create a group by adding elements with area > 20
18 aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
19 aGroup1.Add(anIds)
20 
21 # Criterion : AREA = 20
22 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_EqualTo, 20.)
23 
24 anIds = mesh.GetIdsFromFilter(aFilter)
25 
26 print "Criterion: Area = 20, Nb = ", len( anIds )
27 
28 # create a group by adding elements with area = 20
29 aGroup2 = mesh.CreateEmptyGroup( SMESH.FACE, "Area = 20" )
30 
31 aGroup2.Add(anIds)
32 
33 # create union group : area >= 20
34 aGroup3 = mesh.UnionListOfGroups([aGroup1, aGroup2], "Area >= 20")
35 aGroup3.SetColor( SALOMEDS.Color(1.,1.,0.));
36 print "Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID())
37 # Please note that also there is UnionGroups() method which works with two groups only
38 
39 # Criterion : AREA < 20
40 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 20.)
41 
42 anIds = mesh.GetIdsFromFilter(aFilter)
43 
44 print "Criterion: Area < 20, Nb = ", len(anIds)
45 
46 # create a group by adding elements with area < 20
47 aGroup4 = mesh.CreateEmptyGroup(SMESH.FACE, "Area < 20")
48 aGroup4.Add(anIds)
49 aGroup4.SetColor( SALOMEDS.Color(1.,0.,0.));
50 
51 # create union group : area >= 20 and area < 20
52 aGroup5 = mesh.UnionListOfGroups([aGroup3, aGroup4], "Any Area")
53 print "Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID())
54 
55 salome.sg.updateObjBrowser(True)

Download this script

union_groups1.png


Intersection of groups

1 # Intersection of groups
2 
3 import SMESH_mechanic
4 import SMESH
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Criterion : AREA > 20
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
12 
13 anIds = mesh.GetIdsFromFilter(aFilter)
14 
15 print "Criterion: Area > 20, Nb = ", len(anIds)
16 
17 # create a group by adding elements with area > 20
18 aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
19 aGroup1.Add(anIds)
20 
21 # Criterion : AREA < 60
22 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 60.)
23 
24 anIds = mesh.GetIdsFromFilter(aFilter)
25 
26 print "Criterion: Area < 60, Nb = ", len(anIds)
27 
28 # create a group by adding elements with area < 60
29 aGroup2 = mesh.CreateEmptyGroup(SMESH.FACE, "Area < 60")
30 aGroup2.Add(anIds)
31 
32 # create an intersection of groups : 20 < area < 60
33 aGroup3 = mesh.IntersectListOfGroups([aGroup1, aGroup2], "20 < Area < 60")
34 print "Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID())
35 # Please note that also there is IntersectGroups() method which works with two groups only
36 
37 salome.sg.updateObjBrowser(True)

Download this script

intersect_groups1.png


Cut of groups

1 # Cut of groups
2 
3 import SMESH_mechanic
4 import SMESH
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Criterion : AREA > 20
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
12 
13 anIds = mesh.GetIdsFromFilter(aFilter)
14 
15 print "Criterion: Area > 20, Nb = ", len(anIds)
16 
17 # create a group by adding elements with area > 20
18 aGroupMain = mesh.MakeGroupByIds("Area > 20", SMESH.FACE, anIds)
19 
20 # Criterion : AREA < 60
21 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 60.)
22 
23 anIds = mesh.GetIdsFromFilter(aFilter)
24 
25 print "Criterion: Area < 60, Nb = ", len(anIds)
26 
27 # create a group by adding elements with area < 60
28 aGroupTool = mesh.MakeGroupByIds("Area < 60", SMESH.FACE, anIds)
29 
30 # create a cut of groups : area >= 60
31 aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")
32 print "Criterion: Area >= 60, Nb = ", len(aGroupRes.GetListOfID())
33 # Please note that also there is CutListOfGroups() method which works with lists of groups of any lengths
34 
35 salome.sg.updateObjBrowser(True)

Download this script

cut_groups1.png


Creating groups of entities basing on nodes of other groups

1 # Creating groups of entities basing on nodes of other groups
2 
3 import SMESH_mechanic
4 import SMESH, SALOMEDS
5 
6 smesh = SMESH_mechanic.smesh
7 mesh = SMESH_mechanic.mesh
8 salome = SMESH_mechanic.salome
9 
10 # Criterion : AREA > 100
11 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
12 
13 # create a group by adding elements with area > 100
14 aSrcGroup1 = mesh.GroupOnFilter(SMESH.FACE, "Area > 100", aFilter)
15 aSrcGroup1.SetColor( SALOMEDS.Color(1.,1.,0.))
16 print "Criterion: Area > 100, Nb = ", aSrcGroup1.Size()
17 
18 # Criterion : AREA < 30
19 aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 30.)
20 
21 # create a group by adding elements with area < 30
22 aSrcGroup2 = mesh.GroupOnFilter(SMESH.FACE, "Area < 30", aFilter)
23 aSrcGroup2.SetColor( SALOMEDS.Color(1.,0.,0.))
24 print "Criterion: Area < 30, Nb = ", aSrcGroup2.Size()
25 
26 
27 # Create group of edges using source groups of faces
28 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], SMESH.EDGE, "Edges" )
29 
30 # Create group of nodes using source groups of faces
31 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], SMESH.NODE, "Nodes" )
32 
33 salome.sg.updateObjBrowser(True)

Download this script

dimgroup_tui1.png