Salome HOME
Merge branch 'V8_3_BR' into V8_4_BR
[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 > 2.5
8 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, SMESH.FT_MoreThan, 2.5)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of faces with aspect ratio > 2.5:", len(ids)
11
12 # get faces with aspect ratio > 1.5
13 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, '>', 1.5, mesh=mesh)
14 ids = filter.GetIDs()
15 print "Number of faces with aspect ratio > 1.5:", len(ids)
16
17 # copy the faces with aspect ratio > 1.5 to another mesh;
18 # this demostrates that a filter can be used where usually a group or sub-mesh is acceptable
19 filter.SetMesh( mesh.GetMesh() ) # - actually non necessary as mesh is set at filter creation
20 mesh2 = smesh.CopyMesh( filter, "AR > 1.5" )
21 print "Number of copied faces with aspect ratio > 1.5:", mesh2.NbFaces()
22
23 # create a group (Group on Filter) of faces with Aspect Ratio < 1.5
24 group = mesh.MakeGroup("AR < 1.5", SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5)
25 print "Number of faces with aspect ratio < 1.5:", group.Size()
26
27 # combine several criteria to Create a Group of only Triangular faces with Aspect Ratio < 1.5;
28 # note that contents of a GroupOnFilter is dynamically updated as the mesh changes
29 crit = [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5, BinaryOp=SMESH.FT_LogicalAND ),
30          smesh.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=', SMESH.Geom_TRIANGLE ) ]
31 triaGroup = mesh.MakeGroupByCriteria( "Tria AR < 1.5", crit )
32 print "Number of triangles with aspect ratio < 1.5:", triaGroup.Size()
33
34 # get range of values of Aspect Ratio of all faces in the mesh
35 aspects = mesh.GetMinMax( SMESH.FT_AspectRatio )
36 print "MESH: Min aspect = %s, Max aspect = %s" % ( aspects[0], aspects[1] )
37
38 # get max value of Aspect Ratio of faces in triaGroup
39 grAspects = mesh.GetMinMax( SMESH.FT_AspectRatio, triaGroup )
40 print "GROUP: Max aspect = %s" % grAspects[1]
41
42 # get Aspect Ratio of an element
43 aspect = mesh.FunctorValue( SMESH.FT_AspectRatio, ids[0] )
44 print "Aspect ratio of the face %s = %s" % ( ids[0], aspect )