Salome HOME
0020889: EDF 1433 SMESH: SplitHexaToTetra: add the 24 tetras mode
[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_edit_group
79 <h2>Edit a Group</h2>
80
81 \code
82 import SMESH_mechanic
83
84 smesh  = SMESH_mechanic.smesh
85 mesh   = SMESH_mechanic.mesh
86 salome = SMESH_mechanic.salome
87
88 # Get ids of all faces with area > 35
89 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 35.)
90
91 anIds = mesh.GetIdsFromFilter(aFilter) 
92
93 print "Criterion: Area > 35, Nb = ", len(anIds)
94
95 # create a group by adding elements with area > 35
96 aGroup = mesh.CreateEmptyGroup(smesh.FACE, "Area > 35")
97 aGroup.Add(anIds) 
98
99 # Get ids of all faces with area > 40
100 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 40.)
101
102 anIds = mesh.GetIdsFromFilter(aFilter)
103
104 print "Criterion: Area > 40, Nb = ", len(anIds) 
105
106 # create a group of elements with area [35; 40] by removing elements with area > 40 from group aGroup
107 aGroup.Remove(anIds) 
108
109 # print the result
110 aGroupElemIDs = aGroup.GetListOfID()
111
112 print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)
113
114 j = 1
115 for i in range(len(aGroupElemIDs)):
116   if j > 20: j = 1; print ""
117   print aGroupElemIDs[i],
118   j = j + 1
119   pass
120 print ""
121
122 salome.sg.updateObjBrowser(1)
123 \endcode
124
125 \image html editing_groups1.png
126
127 \image html editing_groups2.png
128
129 <br>
130 \anchor tui_union_of_groups
131 <h2>Union of groups</h2>
132
133 \code
134 import SMESH_mechanic
135
136 smesh  = SMESH_mechanic.smesh
137 mesh   = SMESH_mechanic.mesh
138 salome = SMESH_mechanic.salome
139
140 # Criterion : AREA > 20
141 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
142
143 anIds = mesh.GetIdsFromFilter(aFilter)
144
145 print "Criterion: Area > 20, Nb = ", len( anIds ) 
146
147 # create a group by adding elements with area > 20
148 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
149 aGroup1.Add(anIds)
150
151 # Criterion : AREA = 20
152 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_EqualTo, 20.)
153
154 anIds = mesh.GetIdsFromFilter(aFilter)
155
156 print "Criterion: Area = 20, Nb = ", len( anIds ) 
157
158 # create a group by adding elements with area = 20
159 aGroup2 = mesh.CreateEmptyGroup( smesh.FACE, "Area = 20" )
160
161 aGroup2.Add(anIds)
162
163 # create union group : area >= 20
164 aGroup3 = mesh.UnionListOfGroups([aGroup1, aGroup2], "Area >= 20")
165 print "Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID())
166 # Please note that also there is UnionGroups() method which works with two groups only
167
168 # Criterion : AREA < 20
169 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 20.)
170
171 anIds = mesh.GetIdsFromFilter(aFilter)
172
173 print "Criterion: Area < 20, Nb = ", len(anIds)
174
175 # create a group by adding elements with area < 20
176 aGroup4 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 20")
177 aGroup4.Add(anIds)
178
179 # create union group : area >= 20 and area < 20
180 aGroup5 = mesh.UnionListOfGroups([aGroup3, aGroup4], "Any Area")
181 print "Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID())
182
183 salome.sg.updateObjBrowser(1)
184 \endcode
185
186 \image html union_groups1.png
187
188 \image html union_groups2.png
189
190 \image html union_groups3.png
191
192 <br>
193 \anchor tui_intersection_of_groups
194 <h2>Intersection of groups</h2>
195
196 \code
197 import SMESH_mechanic
198
199 smesh  = SMESH_mechanic.smesh
200 mesh   = SMESH_mechanic.mesh
201 salome = SMESH_mechanic.salome
202
203 # Criterion : AREA > 20
204 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
205
206 anIds = mesh.GetIdsFromFilter(aFilter)
207
208 print "Criterion: Area > 20, Nb = ", len(anIds) 
209
210 # create a group by adding elements with area > 20
211 aGroup1 = mesh.CreateEmptyGroup(smesh.FACE, "Area > 20")
212 aGroup1.Add(anIds)
213
214 # Criterion : AREA < 60
215 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
216
217 anIds = mesh.GetIdsFromFilter(aFilter)
218
219 print "Criterion: Area < 60, Nb = ", len(anIds) 
220
221 # create a group by adding elements with area < 60
222 aGroup2 = mesh.CreateEmptyGroup(smesh.FACE, "Area < 60")
223 aGroup2.Add(anIds)
224
225 # create an intersection of groups : 20 < area < 60
226 aGroup3 = mesh.IntersectListOfGroups([aGroup1, aGroup2], "20 < Area < 60")
227 print "Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID())
228 # Please note that also there is IntersectGroups() method which works with two groups only
229
230 salome.sg.updateObjBrowser(1)
231 \endcode
232
233 \image html intersect_groups1.png
234
235 \image html intersect_groups2.png
236
237 \image html intersect_groups3.png
238
239 <br>
240 \anchor tui_cut_of_groups
241 <h2>Cut of groups</h2>
242
243 \code
244 import SMESH_mechanic
245
246 smesh  = SMESH_mechanic.smesh
247 mesh   = SMESH_mechanic.mesh
248 salome = SMESH_mechanic.salome
249
250 # Criterion : AREA > 20
251 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 20.)
252
253 anIds = mesh.GetIdsFromFilter(aFilter)
254
255 print "Criterion: Area > 20, Nb = ", len(anIds) 
256
257 # create a group by adding elements with area > 20
258 aGroupMain = mesh.MakeGroupByIds("Area > 20", smesh.FACE, anIds)
259
260 # Criterion : AREA < 60
261 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 60.)
262
263 anIds = mesh.GetIdsFromFilter(aFilter)
264
265 print "Criterion: Area < 60, Nb = ", len(anIds) 
266
267 # create a group by adding elements with area < 60
268 aGroupTool = mesh.MakeGroupByIds("Area < 60", smesh.FACE, anIds)
269  
270 # create a cut of groups : area >= 60
271 aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")
272 print "Criterion: Area >= 60, Nb = ", len(aGroupRes.GetListOfID())
273 # Please note that also there is CutListOfGroups() method which works with lists of groups of any lengths
274
275 salome.sg.updateObjBrowser(1)
276 \endcode
277
278 \image html cut_groups1.png
279
280 \image html cut_groups2.png
281
282 \image html cut_groups3.png
283
284 <br>
285 \anchor tui_create_dim_group
286 <h2>Creating groups of entities from existing groups of superior dimensions</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 > 100
296 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_MoreThan, 100.)
297
298 anIds = mesh.GetIdsFromFilter(aFilter)
299
300 print "Criterion: Area > 100, Nb = ", len(anIds) 
301
302 # create a group by adding elements with area > 100
303 aSrcGroup1 = mesh.MakeGroupByIds("Area > 100", smesh.FACE, anIds)
304
305 # Criterion : AREA < 30
306 aFilter = smesh.GetFilter(smesh.FACE, smesh.FT_Area, smesh.FT_LessThan, 30.)
307
308 anIds = mesh.GetIdsFromFilter(aFilter)
309
310 print "Criterion: Area < 30, Nb = ", len(anIds) 
311
312 # create a group by adding elements with area < 30
313 aSrcGroup2 = mesh.MakeGroupByIds("Area < 30", smesh.FACE, anIds)
314
315 # Create group of edges using source groups of faces
316 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.EDGE, "Edges" )
317
318 # Create group of nodes using source groups of faces
319 aGrp = mesh.CreateDimGroup( [aSrcGroup1, aSrcGroup2], smesh.NODE, "Nodes" )
320
321 salome.sg.updateObjBrowser(1)
322 \endcode
323
324 \image html dimgroup_tui1.png
325 <center>Source groups of faces</center>
326
327 \image html dimgroup_tui2.png
328 <center>Result groups of edges and nodes</center>
329
330
331
332
333
334 */