Salome HOME
a163d13f5891cd4f35f334b09c3c447d35c7e665
[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 aGroup1 = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
23
24 # create a group that contains all nodes from the mesh
25 aGroup2 = mesh.CreateEmptyGroup(smesh.NODE, "all nodes")
26 aGroup2.AddFrom(mesh.mesh)
27
28 salome.sg.updateObjBrowser(1)
29 \endcode
30
31 \image html create_group.png
32
33 <br>
34 \anchor tui_create_group_on_geometry
35 <h2>Create a Group on Geometry</h2>
36
37 \code
38 import salome
39 import geompy
40 import smesh
41
42 # create a box
43 box = geompy.MakeBox(0., 0., 0., 100., 100., 100.)
44 geompy.addToStudy(box, "box")
45
46 # add the first face of the box to the study
47 subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
48 face = subShapeList[0]
49 geompy.addToStudyInFather(box, face, "face 1") 
50
51 # create group of edges on the face
52 aGeomGroupE = geompy.CreateGroup(face, geompy.ShapeType["EDGE"])
53 geompy.AddObject(aGeomGroupE, 3)
54 geompy.AddObject(aGeomGroupE, 6)
55 geompy.AddObject(aGeomGroupE, 8)
56 geompy.AddObject(aGeomGroupE, 10)
57 geompy.addToStudyInFather(face, aGeomGroupE, "Group of Edges")
58
59 # create quadrangle 2D mesh on the box
60 quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")
61 algo1D = quadra.Segment()
62 quadra.Quadrangle()
63 algo1D.NumberOfSegments(7) 
64
65 # compute the mesh
66 quadra.Compute()
67
68 # create SMESH group on the face with name "SMESHGroup1"
69 aSmeshGroup1 = quadra.GroupOnGeom(face, "SMESHGroup1")
70
71 # create SMESH group on <aGeomGroupE> with default name
72 aSmeshGroup2 = quadra.GroupOnGeom(aGeomGroupE) 
73
74 salome.sg.updateObjBrowser(1)
75 \endcode
76
77 <br>
78 \anchor tui_create_group_on_filter
79
80 <h2>Create a Group on Filter</h2>
81
82 \code
83 from smesh import *
84 SetCurrentStudy(salome.myStudy)
85
86 box = geompy.MakeBoxDXDYDZ(10,10,10)
87
88 # make a mesh with quadrangles of different area in range [1,16]
89 mesh = Mesh(box,"Quad mesh")
90 hyp1D = mesh.Segment().StartEndLength( 1, 4 )
91 mesh.Quadrangle()
92 mesh.Compute()
93
94 # create a group on filter selecting faces of medium size
95 critaria = [ \
96     GetCriterion(FACE, FT_Area, ">", 1.1, BinaryOp=FT_LogicalAND ),
97     GetCriterion(FACE, FT_Area, "<", 15.0 )
98     ]
99 filt = GetFilterFromCriteria( critaria )
100 filtGroup = mesh.GroupOnFilter( FACE, "group on filter", filt )
101 print "Group on filter conatains %s elemens" % filtGroup.Size()
102
103 # group on filter is updated if the mesh is modified
104 hyp1D.SetStartLength( 2.5 )
105 hyp1D.SetEndLength( 2.5 )
106 mesh.Compute()
107 print "After mesh change, group on filter conatains %s elemens" % filtGroup.Size()
108
109 # set a new filter defining the group
110 filt2 = GetFilter( FACE, FT_RangeOfIds, "1-50" )
111 filtGroup.SetFilter( filt2 )
112 print "With a new filter, group on filter conatains %s elemens" % filtGroup.Size()
113
114 # group is updated at modification of the filter
115 filt2.SetCriteria( [ GetCriterion( FACE, FT_RangeOfIds, "1-70" )])
116 filtIDs3 = filtGroup.GetIDs()
117 print "After filter modification, group on filter conatains %s elemens" % filtGroup.Size()
118
119 salome.sg.updateObjBrowser(1)
120 \endcode
121
122 <br>
123 \anchor tui_edit_group
124 <h2>Edit a Group</h2>
125
126 \code
127 import SMESH_mechanic
128
129 smesh  = SMESH_mechanic.smesh
130 mesh   = SMESH_mechanic.mesh
131 salome = SMESH_mechanic.salome
132
133 # Get ids of all faces with area > 35
134 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 35.)
135
136 anIds = mesh.GetIdsFromFilter(aFilter) 
137
138 print "Criterion: Area > 35, Nb = ", len(anIds)
139
140 # create a group by adding elements with area > 35
141 aGroup = mesh.CreateEmptyGroup(smesh.FACE, "Area > 35")
142 aGroup.Add(anIds) 
143
144 # Get ids of all faces with area > 40
145 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 40.)
146
147 anIds = mesh.GetIdsFromFilter(aFilter)
148
149 print "Criterion: Area > 40, Nb = ", len(anIds) 
150
151 # create a group of elements with area [35; 40] by removing elements with area > 40 from group aGroup
152 aGroup.Remove(anIds) 
153
154 # print the result
155 aGroupElemIDs = aGroup.GetListOfID()
156
157 print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)
158
159 j = 1
160 for i in range(len(aGroupElemIDs)):
161   if j > 20: j = 1; print ""
162   print aGroupElemIDs[i],
163   j = j + 1
164   pass
165 print ""
166
167 salome.sg.updateObjBrowser(1)
168 \endcode
169
170 \image html editing_groups1.png
171
172 \image html editing_groups2.png
173
174 <br>
175 \anchor tui_union_of_groups
176 <h2>Union of groups</h2>
177
178 \code
179 import SMESH_mechanic
180
181 smesh  = SMESH_mechanic.smesh
182 mesh   = SMESH_mechanic.mesh
183 salome = SMESH_mechanic.salome
184
185 # Criterion : AREA > 20
186 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
187
188 anIds = mesh.GetIdsFromFilter(aFilter)
189
190 print "Criterion: Area > 20, Nb = ", len( anIds ) 
191
192 # create a group by adding elements with area > 20
193 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
194 aGroup1.Add(anIds)
195
196 # Criterion : AREA = 20
197 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_EqualTo, 20.)
198
199 anIds = mesh.GetIdsFromFilter(aFilter)
200
201 print "Criterion: Area = 20, Nb = ", len( anIds ) 
202
203 # create a group by adding elements with area = 20
204 aGroup2 = mesh.CreateEmptyGroup( smesh.FACE, "Area = 20" )
205
206 aGroup2.Add(anIds)
207
208 # create union group : area >= 20
209 aGroup3 = mesh.UnionListOfGroups([aGroup1, aGroup2], "Area >= 20")
210 print "Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID())
211 # Please note that also there is UnionGroups() method which works with two groups only
212
213 # Criterion : AREA < 20
214 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 20.)
215
216 anIds = mesh.GetIdsFromFilter(aFilter)
217
218 print "Criterion: Area < 20, Nb = ", len(anIds)
219
220 # create a group by adding elements with area < 20
221 aGroup4 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 20")
222 aGroup4.Add(anIds)
223
224 # create union group : area >= 20 and area < 20
225 aGroup5 = mesh.UnionListOfGroups([aGroup3, aGroup4], "Any Area")
226 print "Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID())
227
228 salome.sg.updateObjBrowser(1)
229 \endcode
230
231 \image html union_groups1.png
232
233 \image html union_groups2.png
234
235 \image html union_groups3.png
236
237 <br>
238 \anchor tui_intersection_of_groups
239 <h2>Intersection of groups</h2>
240
241 \code
242 import SMESH_mechanic
243
244 smesh  = SMESH_mechanic.smesh
245 mesh   = SMESH_mechanic.mesh
246 salome = SMESH_mechanic.salome
247
248 # Criterion : AREA > 20
249 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
250
251 anIds = mesh.GetIdsFromFilter(aFilter)
252
253 print "Criterion: Area > 20, Nb = ", len(anIds) 
254
255 # create a group by adding elements with area > 20
256 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
257 aGroup1.Add(anIds)
258
259 # Criterion : AREA < 60
260 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
261
262 anIds = mesh.GetIdsFromFilter(aFilter)
263
264 print "Criterion: Area < 60, Nb = ", len(anIds) 
265
266 # create a group by adding elements with area < 60
267 aGroup2 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 60")
268 aGroup2.Add(anIds)
269
270 # create an intersection of groups : 20 < area < 60
271 aGroup3 = mesh.IntersectListOfGroups([aGroup1, aGroup2], "20 < Area < 60")
272 print "Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID())
273 # Please note that also there is IntersectGroups() method which works with two groups only
274
275 salome.sg.updateObjBrowser(1)
276 \endcode
277
278 \image html intersect_groups1.png
279
280 \image html intersect_groups2.png
281
282 \image html intersect_groups3.png
283
284 <br>
285 \anchor tui_cut_of_groups
286 <h2>Cut of groups</h2>
287
288 \code
289 import SMESH_mechanic
290
291 smesh  = SMESH_mechanic.smesh
292 mesh   = SMESH_mechanic.mesh
293 salome = SMESH_mechanic.salome
294
295 # Criterion : AREA > 20
296 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
297
298 anIds = mesh.GetIdsFromFilter(aFilter)
299
300 print "Criterion: Area > 20, Nb = ", len(anIds) 
301
302 # create a group by adding elements with area > 20
303 aGroupMain = mesh.MakeGroupByIds("Area > 20", smesh.FACE, anIds)
304
305 # Criterion : AREA < 60
306 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
307
308 anIds = mesh.GetIdsFromFilter(aFilter)
309
310 print "Criterion: Area < 60, Nb = ", len(anIds) 
311
312 # create a group by adding elements with area < 60
313 aGroupTool = mesh.MakeGroupByIds("Area < 60", smesh.FACE, anIds)
314  
315 # create a cut of groups : area >= 60
316 aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")
317 print "Criterion: Area >= 60, Nb = ", len(aGroupRes.GetListOfID())
318 # Please note that also there is CutListOfGroups() method which works with lists of groups of any lengths
319
320 salome.sg.updateObjBrowser(1)
321 \endcode
322
323 \image html cut_groups1.png
324
325 \image html cut_groups2.png
326
327 \image html cut_groups3.png
328
329 <br>
330 \anchor tui_create_dim_group
331 <h2>Creating groups of entities from existing groups of superior dimensions</h2>
332
333 \code
334 import SMESH_mechanic
335
336 smesh  = SMESH_mechanic.smesh
337 mesh   = SMESH_mechanic.mesh
338 salome = SMESH_mechanic.salome
339
340 # Criterion : AREA > 100
341 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 100.)
342
343 anIds = mesh.GetIdsFromFilter(aFilter)
344
345 print "Criterion: Area > 100, Nb = ", len(anIds) 
346
347 # create a group by adding elements with area > 100
348 aSrcGroup1 = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
349
350 # Criterion : AREA < 30
351 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 30.)
352
353 anIds = mesh.GetIdsFromFilter(aFilter)
354
355 print "Criterion: Area < 30, Nb = ", len(anIds) 
356
357 # create a group by adding elements with area < 30
358 aSrcGroup2 = mesh.MakeGroupByIds("Area < 30", smesh.FACE, anIds)
359
360 # Create group of edges using source groups of faces
361 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.EDGE, "Edges" )
362
363 # Create group of nodes using source groups of faces
364 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.NODE, "Nodes" )
365
366 salome.sg.updateObjBrowser(1)
367 \endcode
368
369 \image html dimgroup_tui1.png
370 <center>Source groups of faces</center>
371
372 \image html dimgroup_tui2.png
373 <center>Result groups of edges and nodes</center>
374
375
376
377
378
379 */