Salome HOME
e03433f1c7a02337adc5db6c5adfdcd2909d6037
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_grouping_elements.doc
1 /*!
2
3 \page tui_grouping_elements_page Grouping Elements
4
5 <br>
6 \anchor tui_create_standalone_group
7 <h2>Create a Standalone Group</h2>
8
9 \code
10 import SMESH_mechanic
11
12 smesh  = SMESH_mechanic.smesh
13 mesh   = SMESH_mechanic.mesh
14 salome = SMESH_mechanic.salome
15
16 # Get ids of all faces with area > 100 
17 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 100.)
18
19 anIds = mesh.GetIdsFromFilter(aFilter) 
20
21 # create a group consisting of faces with area > 100
22 aGroup = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
23
24 salome.sg.updateObjBrowser(1)
25 \endcode
26
27 \image html create_group.png
28
29 <br>
30 \anchor tui_create_group_on_geometry
31 <h2>Create a Group on Geometry</h2>
32
33 \code
34 import salome
35 import geompy
36 import smesh
37
38 # create a box
39 box = geompy.MakeBox(0., 0., 0., 100., 100., 100.)
40 geompy.addToStudy(box, "box")
41
42 # add the first face of the box to the study
43 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
44 face = subShapeList[0]
45 geompy.addToStudyInFather(box, face, "face 1") 
46
47 # create group of edges on the face
48 aGeomGroupE = geompy.CreateGroup(face, geompy.ShapeType["EDGE"])
49 geompy.AddObject(aGeomGroupE, 3)
50 geompy.AddObject(aGeomGroupE, 6)
51 geompy.AddObject(aGeomGroupE, 8)
52 geompy.AddObject(aGeomGroupE, 10)
53 geompy.addToStudyInFather(face, aGeomGroupE, "Group of Edges")
54
55 # create quadrangle 2D mesh on the box
56 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
57 algo1D = quadra.Segment()
58 quadra.Quadrangle()
59 algo1D.NumberOfSegments(7) 
60
61 # compute the mesh
62 quadra.Compute()
63
64 # create SMESH group on the face with name "SMESHGroup1"
65 aSmeshGroup1 = quadra.GroupOnGeom(face, "SMESHGroup1")
66
67 # create SMESH group on <aGeomGroupE> with default name
68 aSmeshGroup2 = quadra.GroupOnGeom(aGeomGroupE) 
69
70 salome.sg.updateObjBrowser(1)
71 \endcode
72
73 <br>
74 \anchor tui_edit_group
75 <h2>Edit a Group</h2>
76
77 \code
78 import SMESH_mechanic
79
80 smesh  = SMESH_mechanic.smesh
81 mesh   = SMESH_mechanic.mesh
82 salome = SMESH_mechanic.salome
83
84 # Get ids of all faces with area > 35
85 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 35.)
86
87 anIds = mesh.GetIdsFromFilter(aFilter) 
88
89 print "Criterion: Area > 35, Nb = ", len(anIds)
90
91 # create a group by adding elements with area > 35
92 aGroup = mesh.CreateEmptyGroup(smesh.FACE, "Area > 35")
93 aGroup.Add(anIds) 
94
95 # Get ids of all faces with area > 40
96 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 40.)
97
98 anIds = mesh.GetIdsFromFilter(aFilter)
99
100 print "Criterion: Area > 40, Nb = ", len(anIds) 
101
102 # create a group of elements with area [35; 40] by removing elements with area > 40 from group aGroup
103 aGroup.Remove(anIds) 
104
105 # print the result
106 aGroupElemIDs = aGroup.GetListOfID()
107
108 print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)
109
110 j = 1
111 for i in range(len(aGroupElemIDs)):
112   if j > 20: j = 1; print ""
113   print aGroupElemIDs[i],
114   j = j + 1
115   pass
116 print ""
117
118 salome.sg.updateObjBrowser(1)
119 \endcode
120
121 \image html editing_groups1.png
122
123 \image html editing_groups2.png
124
125 <br>
126 \anchor tui_union_of_groups
127 <h2>Union of groups</h2>
128
129 \code
130 import SMESH_mechanic
131
132 smesh  = SMESH_mechanic.smesh
133 mesh   = SMESH_mechanic.mesh
134 salome = SMESH_mechanic.salome
135
136 # Criterion : AREA > 20
137 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
138
139 anIds = mesh.GetIdsFromFilter(aFilter)
140
141 print "Criterion: Area > 20, Nb = ", len( anIds ) 
142
143 # create a group by adding elements with area > 20
144 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
145 aGroup1.Add(anIds)
146
147 # Criterion : AREA = 20
148 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_EqualTo, 20.)
149
150 anIds = mesh.GetIdsFromFilter(aFilter)
151
152 print "Criterion: Area = 20, Nb = ", len( anIds ) 
153
154 # create a group by adding elements with area = 20
155 aGroup2 = mesh.CreateEmptyGroup( smesh.FACE, "Area = 20" )
156
157 aGroup2.Add(anIds)
158
159 # create union group : area >= 20
160 aGroup3 = mesh.UnionListOfGroups([aGroup1, aGroup2], "Area >= 20")
161 print "Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID())
162 # Please note that also there is UnionGroups() method which works with two groups only
163
164 # Criterion : AREA < 20
165 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 20.)
166
167 anIds = mesh.GetIdsFromFilter(aFilter)
168
169 print "Criterion: Area < 20, Nb = ", len(anIds)
170
171 # create a group by adding elements with area < 20
172 aGroup4 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 20")
173 aGroup4.Add(anIds)
174
175 # create union group : area >= 20 and area < 20
176 aGroup5 = mesh.UnionListOfGroups([aGroup3, aGroup4], "Any Area")
177 print "Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID())
178
179 salome.sg.updateObjBrowser(1)
180 \endcode
181
182 \image html union_groups1.png
183
184 \image html union_groups2.png
185
186 \image html union_groups3.png
187
188 <br>
189 \anchor tui_intersection_of_groups
190 <h2>Intersection of groups</h2>
191
192 \code
193 import SMESH_mechanic
194
195 smesh  = SMESH_mechanic.smesh
196 mesh   = SMESH_mechanic.mesh
197 salome = SMESH_mechanic.salome
198
199 # Criterion : AREA > 20
200 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
201
202 anIds = mesh.GetIdsFromFilter(aFilter)
203
204 print "Criterion: Area > 20, Nb = ", len(anIds) 
205
206 # create a group by adding elements with area > 20
207 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
208 aGroup1.Add(anIds)
209
210 # Criterion : AREA < 60
211 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
212
213 anIds = mesh.GetIdsFromFilter(aFilter)
214
215 print "Criterion: Area < 60, Nb = ", len(anIds) 
216
217 # create a group by adding elements with area < 60
218 aGroup2 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 60")
219 aGroup2.Add(anIds)
220
221 # create an intersection of groups : 20 < area < 60
222 aGroup3 = mesh.IntersectListOfGroups([aGroup1, aGroup2], "20 < Area < 60")
223 print "Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID())
224 # Please note that also there is IntersectGroups() method which works with two groups only
225
226 salome.sg.updateObjBrowser(1)
227 \endcode
228
229 \image html intersect_groups1.png
230
231 \image html intersect_groups2.png
232
233 \image html intersect_groups3.png
234
235 <br>
236 \anchor tui_cut_of_groups
237 <h2>Cut of groups</h2>
238
239 \code
240 import SMESH_mechanic
241
242 smesh  = SMESH_mechanic.smesh
243 mesh   = SMESH_mechanic.mesh
244 salome = SMESH_mechanic.salome
245
246 # Criterion : AREA > 20
247 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
248
249 anIds = mesh.GetIdsFromFilter(aFilter)
250
251 print "Criterion: Area > 20, Nb = ", len(anIds) 
252
253 # create a group by adding elements with area > 20
254 aGroupMain = mesh.MakeGroupByIds("Area > 20", smesh.FACE, anIds)
255
256 # Criterion : AREA < 60
257 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
258
259 anIds = mesh.GetIdsFromFilter(aFilter)
260
261 print "Criterion: Area < 60, Nb = ", len(anIds) 
262
263 # create a group by adding elements with area < 60
264 aGroupTool = mesh.MakeGroupByIds("Area < 60", smesh.FACE, anIds)
265  
266 # create a cut of groups : area >= 60
267 aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")
268 print "Criterion: Area >= 60, Nb = ", len(aGroupRes.GetListOfID())
269 # Please note that also there is CutListOfGroups() method which works with lists of groups of any lengths
270
271 salome.sg.updateObjBrowser(1)
272 \endcode
273
274 \image html cut_groups1.png
275
276 \image html cut_groups2.png
277
278 \image html cut_groups3.png
279
280 <br>
281 \anchor tui_create_dim_group
282 <h2>Creating groups of entities from existing groups of superior dimensions</h2>
283
284 \code
285 import SMESH_mechanic
286
287 smesh  = SMESH_mechanic.smesh
288 mesh   = SMESH_mechanic.mesh
289 salome = SMESH_mechanic.salome
290
291 # Criterion : AREA > 100
292 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 100.)
293
294 anIds = mesh.GetIdsFromFilter(aFilter)
295
296 print "Criterion: Area > 100, Nb = ", len(anIds) 
297
298 # create a group by adding elements with area > 100
299 aSrcGroup1 = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
300
301 # Criterion : AREA < 30
302 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 30.)
303
304 anIds = mesh.GetIdsFromFilter(aFilter)
305
306 print "Criterion: Area < 30, Nb = ", len(anIds) 
307
308 # create a group by adding elements with area < 30
309 aSrcGroup2 = mesh.MakeGroupByIds("Area < 30", smesh.FACE, anIds)
310
311 # Create group of edges using source groups of faces
312 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.EDGE, "Edges" )
313
314 # Create group of nodes using source groups of faces
315 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.NODE, "Nodes" )
316
317 salome.sg.updateObjBrowser(1)
318 \endcode
319
320 \image html dimgroup_tui1.png
321 <center>Source groups of faces<\center>
322
323 \image html dimgroup_tui2.png
324 <center>Result groups of edges and nodes<\center>
325
326
327
328
329
330 */