Salome HOME
52976: Find Elements by Point - All does not find Ball element
[modules/smesh.git] / doc / salome / examples / filters_ex01.py
1 # Aspect ratio
2 # This script demonstrates various usages of filters
3
4 # create mesh
5 from SMESH_mechanic import *
6
7 # get faces with aspect ratio > 1.5
8 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, SMESH.FT_MoreThan, 1.5)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of faces with aspect ratio > 1.5:", len(ids)
11
12 # copy the faces with aspect ratio > 1.5 to another mesh;
13 # this demostrates that a filter can be used where usually a group or sub-mesh is acceptable
14 filter.SetMesh( mesh.GetMesh() )
15 mesh2 = smesh.CopyMesh( filter, "AR > 1.5" )
16 print "Number of copied faces with aspect ratio > 1.5:", mesh2.NbFaces()
17
18 # create a group (Group on Filter) of faces with Aspect Ratio < 1.5
19 group = mesh.MakeGroup("AR < 1.5", SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5)
20 print "Number of faces with aspect ratio < 1.5:", group.Size()
21
22 # combine several criteria to Create a Group of only Triangular faces with Aspect Ratio < 1.5;
23 # note that contents of a GroupOnFilter is dynamically updated as the mesh changes
24 crit = [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5, BinaryOp=SMESH.FT_LogicalAND ),
25          smesh.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=', SMESH.Geom_TRIANGLE ) ]
26 triaGroup = mesh.MakeGroupByCriteria( "Tria AR < 1.5", crit )
27 print "Number of triangles with aspect ratio < 1.5:", triaGroup.Size()
28
29 # get range of values of Aspect Ratio of all faces in the mesh
30 aspects = mesh.GetMinMax( SMESH.FT_AspectRatio )
31 print "MESH: Min aspect = %s, Max aspect = %s" % ( aspects[0], aspects[1] )
32
33 # get max value of Aspect Ratio of faces in triaGroup
34 grAspects = mesh.GetMinMax( SMESH.FT_AspectRatio, triaGroup )
35 print "GROUP: Max aspect = %s" % grAspects[1]