Version: 8.3.0
 All Classes Namespaces Files Functions Variables Groups Pages
Filters usage

Filters allow picking only the mesh elements satisfying to a specific condition or a set of conditions. Filters can be used to create or edit mesh groups, remove elements from the mesh, control mesh quality by different parameters, etc.

Several filtering criteria can be combined together by using logical operators AND and OR. In addition, a filtering criterion can be reverted using logical operator NOT.

Mesh filters can use the functionality of mesh quality controls to filter mesh nodes / elements by a specific characteristic (Area, Length, etc).

This page provides a short description of the existing mesh filters, describes required parameters and gives simple examples of usage in Python scripts.

See Also
Quality Controls

Aspect ratio

filters 2D mesh elements (faces) according to the aspect ratio value:

  • element type should be SMESH.FACE
  • functor type should be SMESH.FT_AspectRatio
  • threshold is floating point value (aspect ratio)
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 )

Download this script

See Also
Aspect Ratio

Aspect ratio 3D

filters 3D mesh elements (volumes) according to the aspect ratio value:

  • element type is SMESH.VOLUME
  • functor type is SMESH.FT_AspectRatio3D
  • threshold is floating point value (aspect ratio)
1 # Aspect ratio 3D
2 
3 # create mesh with volumes
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get volumes with aspect ratio < 2.0
8 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_AspectRatio3D, SMESH.FT_LessThan, 2.0)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of volumes with aspect ratio < 2.0:", len(ids)

Download this script

See Also
Aspect Ratio 3D

Warping angle

filters 2D mesh elements (faces) according to the warping angle value:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_Warping
  • threshold is floating point value (warping angle)
1 # Warping angle
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces with warping angle = 2.0e-13 with tolerance 5.0e-14
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Warping, "=", 2.0e-13, Tolerance=5.0e-14)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with warping angle = 2.0e-13 (tolerance 5.0e-14):", len(ids)

Download this script

See Also
Warping

Minimum angle

filters 2D mesh elements (faces) according to the minimum angle value:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_MinimumAngle
  • threshold is floating point value (minimum angle)
1 # Minimum angle
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces with minimum angle > 75
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MinimumAngle,">", 75)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with minimum angle > 75:", len(ids)

Download this script

See Also
Minimum Angle

Taper

filters 2D mesh elements (faces) according to the taper value:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_Taper
  • threshold is floating point value (taper)
1 # Taper
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces with taper < 1.e-15
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Taper, SMESH.FT_LessThan, 1.e-15)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with taper < 1.e-15:", len(ids)

Download this script

See Also
Taper

Skew

filters 2D mesh elements (faces) according to the skew value:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_Skew
  • threshold is floating point value (skew)
1 # Skew
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces with skew > 50
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Skew, SMESH.FT_MoreThan, 50)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with skew > 50:", len(ids)

Download this script

See Also
Skew

Area

filters 2D mesh elements (faces) according to the area value:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_Area
  • threshold is floating point value (area)
1 # Area
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces with area > 60 and < 90
6 criterion1 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 60)
7 criterion2 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 90)
8 filter = smesh.GetFilterFromCriteria([criterion1,criterion2], SMESH.FT_LogicalAND)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of faces with area in range (60,90):", len(ids)

Download this script

See Also
Area

Volume

filters 3D mesh elements (volumes) according to the volume value:

  • element type is SMESH.VOLUME
  • functor type is SMESH.FT_Volume3D
  • threshold is floating point value (volume)
1 # Volume
2 
3 # create mesh with volumes
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get volumes faces with volume > 100
8 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_Volume3D, SMESH.FT_MoreThan, 100)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of volumes with volume > 100:", len(ids)

Download this script

See Also
Volume

Free borders

filters 1D mesh elements (edges) which represent free borders of a mesh:

  • element type is SMESH.EDGE
  • functor type is SMESH.FT_FreeBorders
  • threshold value is not required
1 # Free borders
2 
3 # initialize SALOME and modules
4 import salome, SMESH
5 salome.salome_init()
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 from salome.smesh import smeshBuilder
9 smesh = smeshBuilder.New(salome.myStudy)
10 
11 # create mesh
12 face = geompy.MakeFaceHW(100, 100, 1, theName="quadrangle")
13 mesh = smesh.Mesh(face)
14 mesh.Segment().NumberOfSegments(10)
15 mesh.Triangle().MaxElementArea(25)
16 mesh.Compute()
17 
18 # get all free borders
19 filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_FreeBorders)
20 ids = mesh.GetIdsFromFilter(filter)
21 print "Number of edges on free borders:", len(ids)

Download this script

See Also
Free Borders

Free edges

filters 2D mesh elements (faces) having edges (i.e. links between nodes, not mesh segments) belonging to one face of mesh only:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_FreeEdges
  • threshold value is not required
1 # Free edges
2 
3 # initialize SALOME and modules
4 import salome, SMESH
5 salome.salome_init()
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New(salome.myStudy)
8 from salome.smesh import smeshBuilder
9 smesh = smeshBuilder.New(salome.myStudy)
10 
11 # create mesh
12 face = geompy.MakeFaceHW(100, 100, 1)
13 geompy.addToStudy( face, "quadrangle" )
14 mesh = smesh.Mesh(face)
15 mesh.Segment().NumberOfSegments(10)
16 mesh.Triangle().MaxElementArea(25)
17 mesh.Compute()
18 
19 # get all faces with free edges
20 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_FreeEdges)
21 ids = mesh.GetIdsFromFilter(filter)
22 print "Number of faces with free edges:", len(ids)

Download this script

See Also
Free Edges

Free nodes

filters free nodes:

  • element type is SMESH.NODE
  • functor type is SMESH.FT_FreeNodes
  • threshold value is not required
1 # Free nodes
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # add node
6 mesh.AddNode(0,0,0)
7 # get all free nodes
8 filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_FreeNodes)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of free nodes:", len(ids)

Download this script

See Also
Free Nodes

Free faces

filters free faces:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_FreeFaces
  • threshold value is not required
1 # Free faces
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all free faces
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_FreeFaces)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of free faces:", len(ids)

Download this script

See Also
Free Faces

Bare border faces

filters faces with bare borders:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_BareBorderFace
  • threshold value is not required
1 # Bare border faces
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # remove some faces to have faces with bare borders
6 mesh.RemoveElements( mesh.GetElementsByType(SMESH.FACE)[0:5] )
7 # get all faces with bare borders
8 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BareBorderFace)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Faces with bare borders:", ids

Download this script

See Also
Bare border faces

Coplanar faces

filters coplanar faces:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_CoplanarFaces
  • threshold value is the face ID
  • tolerance is in degrees
1 # Coplanar faces
2 
3 # create mesh
4 from SMESH_mechanic import *
5 faceID = mesh.GetElementsByType(SMESH.FACE)[0]
6 # get all faces co-planar to the first face with tolerance 5 degrees
7 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_CoplanarFaces,faceID,Tolerance=5.0)
8 ids = mesh.GetIdsFromFilter(filter)
9 print "Number of faces coplanar with the first one:", len(ids)

Download this script

Over-constrained faces

filters over-constrained faces:

  • element type is SMESH.FACE
  • functor type is SMESH.FT_OverConstrainedFace
  • threshold value is not required
1 # Over-constrained faces
2 # create mesh
3 from SMESH_mechanic import *
4 # get all over-constrained faces
5 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_OverConstrainedFace)
6 ids = mesh.GetIdsFromFilter(filter)
7 print "Over-constrained faces:", ids

Download this script

See Also
Over-constrained faces

Double edges, Double faces, Double volumes

filters mesh elements basing on the same set of nodes:

  • element type is either SMESH.EGDE, SMESH.FACE or SMESH.VOLUME
  • functor type is either SMESH.FT_EqualEdges, SMESH.FT_EqualFaces or SMESH.FT_EqualVolumes,
  • threshold value is not required
1 # Double edges, Double faces, Double volumes
2 
3 
4 import salome
5 salome.salome_init()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New(salome.myStudy)
9 
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh = smeshBuilder.New(salome.myStudy)
13 import salome_notebook
14 
15 # make a mesh on a box
16 box = geompy.MakeBoxDXDYDZ(100,100,100)
17 mesh = smesh.Mesh( box, "Box" )
18 mesh.Segment().NumberOfSegments(10)
19 mesh.Quadrangle()
20 mesh.Hexahedron()
21 mesh.Compute()
22 # copy all elements with translation and Merge nodes
23 mesh.TranslateObject( mesh, smesh.MakeDirStruct( 10,0,0), Copy=True )
24 mesh.MergeNodes( mesh.FindCoincidentNodes(1e-7) )
25 # create filters to find equal elements
26 equalEdgesFilter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_EqualEdges)
27 equalFacesFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_EqualFaces)
28 equalVolumesFilter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_EqualVolumes)
29 # get equal elements
30 print "Number of equal edges:", len( mesh.GetIdsFromFilter( equalEdgesFilter ))
31 print "Number of equal faces:", len( mesh.GetIdsFromFilter( equalFacesFilter ))
32 print "Number of equal volumes:", len( mesh.GetIdsFromFilter( equalVolumesFilter ))

Download this script

Double nodes

filters mesh nodes which are coincident with other nodes (within a given tolerance):

  • element type is SMESH.NODE
  • functor type is SMESH.FT_EqualNodes
  • threshold value is not required
  • default tolerance is 1.0e-7
1 # Double nodes
2 
3 import salome
4 salome.salome_init()
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New(salome.myStudy)
7 import SMESH
8 from salome.smesh import smeshBuilder
9 smesh = smeshBuilder.New(salome.myStudy)
10 
11 # make a mesh on a box
12 box = geompy.MakeBoxDXDYDZ(100,100,100)
13 mesh = smesh.Mesh( box, "Box" )
14 mesh.Segment().NumberOfSegments(10)
15 mesh.Quadrangle()
16 mesh.Hexahedron()
17 mesh.Compute()
18 # copy all elements with translation
19 mesh.TranslateObject( mesh, [10,0,0], Copy=True )
20 # create a filter to find nodes equal within tolerance of 1e-5
21 filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_EqualNodes, Tolerance=1e-5)
22 # get equal nodes
23 print "Number of equal nodes:", len( mesh.GetIdsFromFilter( filter ))

Download this script

Node connectivity number

filters nodes according to a number of elements of highest dimension connected to a node:

  • element type should be SMESH.NODE
  • functor type should be SMESH.FT_NodeConnectivityNumber
  • threshold is an integer value (number of elements)
1 # Number of connectivities of a node
2 
3 # create a mesh
4 from SMESH_mechanic import *
5 
6 # get nodes connected to more than 6 tetrahedra
7 conn_nb_filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_NodeConnectivityNumber,'>', 6 )
8 ids = mesh.GetIdsFromFilter( conn_nb_filter )
9 print "Number of nodes connected to more than 6 tetrahedra:", len(ids)

Download this script

Borders at multi-connection

filters 1D mesh elements (segments) according to the specified number of connections (faces and volumes on whose border the segment lies):

  • element type is SMESH.EDGE
  • functor type is SMESH.FT_MultiConnection
  • threshold is integer value (number of connections)
1 # Borders at multi-connection
2 
3 import salome
4 salome.salome_init()
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New(salome.myStudy)
7 import SMESH
8 from salome.smesh import smeshBuilder
9 smesh = smeshBuilder.New(salome.myStudy)
10 
11 # make a mesh on a box
12 box = geompy.MakeBoxDXDYDZ(100,100,100)
13 mesh = smesh.Mesh( box, "Box" )
14 mesh.Segment().NumberOfSegments(10)
15 mesh.Quadrangle()
16 mesh.Hexahedron()
17 mesh.Compute()
18 # copy all elements with translation and merge nodes
19 mesh.TranslateObject( mesh, [10,0,0], Copy=True )
20 mesh.MergeNodes( mesh.FindCoincidentNodes( 1e-5 ))
21 
22 # get mesh edges with number of connected elements (faces and volumes) == 3
23 filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_MultiConnection, 3)
24 ids = mesh.GetIdsFromFilter(filter)
25 print "Number of border edges with 3 faces connected:", len(ids)

Download this script

See Also
Borders at Multiconnection

Borders at multi-connection 2D

filters 2D mesh elements (faces) with the specified maximal number of faces connected to a border (link between nodes, not mesh segment):

  • element type is SMESH.FACE
  • functor type is SMESH.FT_MultiConnection2D
  • threshold is integer value (number of connections)
1 # Borders at multi-connection 2D
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get faces which consist of edges belonging to 2 mesh elements
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MultiConnection2D, 2)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces consisting of edges belonging to 2 faces:", len(ids)

Download this script

See Also
Borders at Multiconnection 2D

Length

filters 1D mesh elements (edges) according to the edge length value:

  • element type should be SMESH.EDGE
  • functor type should be SMESH.FT_Length
  • threshold is floating point value (length)
1 # Length
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get edges with length > 14
6 filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_Length, SMESH.FT_MoreThan, 14)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of edges with length > 14:", len(ids)

Download this script

See Also
Length 1D

Length 2D

filters 2D mesh elements (faces) according to the maximum length of its edges (links between nodes):

  • element type should be SMESH.FACE
  • functor type should be SMESH.FT_Length2D
  • threshold is floating point value (edge length)
1 # Length 2D
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all faces that have edges with length > 14
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_MoreThan, 14)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with maximum edge length > 14:", len(ids)

Download this script

See Also
Length 2D

Element Diameter 2D

filters 2D mesh elements (faces) according to the maximum length of its edges and diagonals:

  • element type should be SMESH.FACE
  • functor type should be SMESH.FT_MaxElementLength2D
  • threshold is floating point value (length)
1 # Element Diameter 2D
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all faces that have elements with length > 10
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MaxElementLength2D, SMESH.FT_MoreThan, 10)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces with maximum element length > 10:", len(ids)

Download this script

See Also
Element Diameter 2D

Element Diameter 3D

filters 3D mesh elements (volumes) according to the maximum length of its edges and diagonals:

  • element type should be SMESH.VOLUME
  • functor type should be SMESH.FT_MaxElementLength3D
  • threshold is floating point value (edge/diagonal length)
1 # Element Diameter 3D
2 
3 # create mesh with volumes
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get all volumes that have elements with length > 10
8 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_MaxElementLength3D, SMESH.FT_MoreThan, 10)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of volumes with maximum element length > 10:", len(ids)

Download this script

See Also
Element Diameter 3D

Bare border volumes

filters 3D mesh elements with bare borders, i.e. having a facet not shared with other volumes and without a face on it:

  • element type is SMESH.VOLUME
  • functor type is SMESH.FT_BareBorderVolume
  • threshold value is not required
1 # Bare border volumes
2 
3 # create mesh
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # remove some volumes to have volumes with bare borders
8 mesh.RemoveElements( mesh.GetElementsByType(VOLUME)[0:5] )
9 # get all volumes with bare borders
10 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_BareBorderVolume)
11 ids = mesh.GetIdsFromFilter(filter)
12 print "Volumes with bare borders:", ids

Download this script

See Also
Bare border volumes

Over-constrained volumes

filters over-constrained volumes, whose all nodes are on the mesh boundary:

  • element type is SMESH.VOLUME
  • functor type is SMESH.FT_OverConstrainedVolume
  • threshold value is not required
1 # Over-constrained volumes
2 
3 # create mesh
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get all over-constrained volumes
8 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_OverConstrainedVolume)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Over-constrained volumes:", ids

Download this script

See Also
Over-constrained faces

Belong to Mesh Group

filters mesh entities (nodes or elements) included in a mesh group defined by threshold value:

  • element type can be any, from SMESH.NODE to SMESH.BALL
  • functor type should be SMESH.FT_BelongToMeshGroup
  • threshold is mesh group object
1 # Belong to Mesh Group criterion
2 
3 # create mesh
4 from SMESH_mechanic import *
5 print
6 
7 # create a group of all faces (quadrangles) generated on sub_face3
8 quads_on_face3 = mesh.MakeGroup("quads_on_face3", SMESH.FACE, SMESH.FT_BelongToGeom,'=',sub_face3)
9 print "There are %s quadrangles generated on '%s' and included in the group '%s'" % ( quads_on_face3.Size(), sub_face3.GetName(), quads_on_face3.GetName() )
10 
11 # create a group of all the rest quadrangles, generated on other faces by combining 2 criteria:
12 # - negated FT_BelongToMeshGroup to select elements not included in quads_on_face3
13 # - FT_ElemGeomType to select quadrangles
14 not_on_face3 = smesh.GetCriterion( SMESH.FACE, SMESH.FT_BelongToMeshGroup,'=',quads_on_face3, SMESH.FT_LogicalNOT )
15 quadrangles = smesh.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=',SMESH.Geom_QUADRANGLE )
16 
17 rest_quads = mesh.MakeGroupByCriteria("rest_quads", [ not_on_face3, quadrangles ])
18 print "'%s' group includes all the rest %s quadrangles" % ( rest_quads.GetName(), rest_quads.Size() )
19 

Download this script

Belong to Geom

filters mesh entities (nodes or elements) which all nodes lie on the shape defined by threshold value:

  • element type can be any, from SMESH.NODE to SMESH.BALL
  • functor type should be SMESH.FT_BelongToGeom
  • threshold is geometrical object
  • tolerance is a distance between a node and the geometrical object; it is used if an node is not associated to any geometry.
1 # Belong to Geom
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all faces which nodes lie on the face sub_face3
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces which nodes lie on sub_face3:", len(ids)

Download this script

Lying on Geom

filters mesh entities (nodes or elements) at least one node of which lies on the shape defined by threshold value:

  • element type can be any, from SMESH.NODE to SMESH.BALL
  • functor type should be SMESH.FT_LyingOnGeom
  • threshold is geometrical object
  • tolerance is a distance between a node and the geometrical object; it is used if an node is not associated to any geometry.
1 # Lying on Geom
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all faces at least one node of each lies on the face sub_face3
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_LyingOnGeom, sub_face3)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces at least one node of each lies on sub_face3:", len(ids)

Download this script

Belong to Plane

filters mesh entities (nodes or elements) which all nodes belong to the plane defined by threshold value with the given tolerance:

  • element type can be any except SMESH.VOLUME
  • functor type should be SMESH.FT_BelongToPlane
  • threshold is geometrical object (plane)
  • default tolerance is 1.0e-7
1 # Belong to Plane
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # create plane
6 plane_1 = geompy.MakePlane(p3,seg1,2000)
7 geompy.addToStudy(plane_1, "plane_1")
8 # get all nodes which lie on the plane \a plane_1
9 filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_BelongToPlane, plane_1)
10 ids = mesh.GetIdsFromFilter(filter)
11 print "Number of nodes which lie on the plane plane_1:", len(ids)

Download this script

Belong to Cylinder

filters mesh entities (nodes or elements) which all nodes belong to the cylindrical face defined by threshold value with the given tolerance:

  • element type can be any except SMESH.VOLUME
  • functor type should be SMESH.FT_BelongToCylinder
  • threshold is geometrical object (cylindrical face)
  • default tolerance is 1.0e-7
1 # Belong to Cylinder
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get all faces which lie on the cylindrical face \a sub_face1
6 filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BelongToCylinder, sub_face1)
7 ids = mesh.GetIdsFromFilter(filter)
8 print "Number of faces which lie on the cylindrical surface sub_face1:", len(ids)

Download this script

Belong to Surface

filters mesh entities (nodes or elements) which all nodes belong to the arbitrary surface defined by threshold value with the given tolerance:

  • element type can be any except SMESH.VOLUME
  • functor type should be SMESH.FT_BelongToGenSurface
  • threshold is geometrical object (arbitrary surface)
  • default tolerance is 1.0e-7
1 # Belong to Surface
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # create b-spline
6 spline_1 = geompy.MakeInterpol([p4,p6,p3,p1])
7 surface_1 = geompy.MakePrismVecH( spline_1, vz, 70.0 )
8 geompy.addToStudy(surface_1, "surface_1")
9 # get all nodes which lie on the surface \a surface_1
10 filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_BelongToGenSurface, surface_1)
11 ids = mesh.GetIdsFromFilter(filter)
12 print "Number of nodes which lie on the surface surface_1:", len(ids)

Download this script

Range of IDs

filters mesh entities elements (nodes or elements) according to the specified identifiers range:

  • element type can be any, from SMESH.NODE to SMESH.BALL
  • functor type is SMESH.FT_RangeOfIds
  • threshold is string listing required IDs and/or ranges of IDs, e.g."1,2,3,50-60,63,67,70-78"
1 # Range of IDs
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # get nodes with identifiers [5-10] and [15-30]
6 criterion1 = smesh.GetCriterion(SMESH.NODE, SMESH.FT_RangeOfIds, Threshold="5-10",\
7  BinaryOp=SMESH.FT_LogicalOR)
8 criterion2 = smesh.GetCriterion(SMESH.NODE, SMESH.FT_RangeOfIds, Threshold="15-30")
9 filter = smesh.CreateFilterManager().CreateFilter()
10 filter.SetCriteria([criterion1,criterion2])
11 ids = mesh.GetIdsFromFilter(filter)
12 print "Number of nodes in ranges [5-10] and [15-30]:", len(ids)

Download this script

Badly oriented volume

filters 3D mesh elements (volumes), which are incorrectly oriented from the point of view of MED convention.

  • element type should be SMESH.VOLUME
  • functor type is SMESH.FT_BadOrientedVolume
  • threshold is not required
1 # Badly oriented volume
2 
3 # create mesh with volumes
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get all badly oriented volumes
8 filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_BadOrientedVolume)
9 ids = mesh.GetIdsFromFilter(filter)
10 print "Number of badly oriented volumes:", len(ids)

Download this script

Linear / quadratic

filters linear / quadratic mesh elements:

  • element type should be either SMESH.EDGE, SMESH.FACE or SMESH.VOLUME
  • functor type is SMESH.FT_LinearOrQuadratic
  • threshold is not required
  • if unary operator is set to SMESH.FT_LogicalNOT, the quadratic elements are selected, otherwise (by default) linear elements are selected
1 # Linear / quadratic
2 
3 # create mesh
4 from SMESH_mechanic import *
5 
6 # get linear and quadratic edges
7 filter_linear = smesh.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic)
8 filter_quadratic = smesh.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic, SMESH.FT_LogicalNOT)
9 ids_linear = mesh.GetIdsFromFilter(filter_linear)
10 ids_quadratic = mesh.GetIdsFromFilter(filter_quadratic)
11 print "Number of linear edges:", len(ids_linear), "; number of quadratic edges:", len(ids_quadratic)
12 
13 # convert mesh to quadratic
14 print "Convert to quadratic..."
15 mesh.ConvertToQuadratic()
16 
17 # get linear and quadratic edges
18 ids_linear = mesh.GetIdsFromFilter(filter_linear)
19 ids_quadratic = mesh.GetIdsFromFilter(filter_quadratic)
20 print "Number of linear edges:", len(ids_linear), "; number of quadratic edges:", len(ids_quadratic)

Download this script

Group color

filters mesh entities, belonging to the group with the color defined by the threshold value.

  • element type can be any, from SMESH.NODE to SMESH.BALL
  • functor type is SMESH.FT_GroupColor
  • threshold should be of SALOMEDS.Color type
1 # Group color
2 
3 # create mesh
4 from SMESH_mechanic import *
5 # create group of edges
6 all_edges = mesh.GetElementsByType(SMESH.EDGE)
7 grp = mesh.MakeGroupByIds("edges group", SMESH.EDGE, all_edges[:len(all_edges)/4])
8 import SALOMEDS
9 c = SALOMEDS.Color(0.1, 0.5, 1.0)
10 grp.SetColor(c)
11 # get number of the edges not belonging to the group with the given color
12 filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_GroupColor, c, SMESH.FT_LogicalNOT)
13 ids = mesh.GetIdsFromFilter(filter)
14 print "Number of edges not beloging to the group with color (0.1, 0.5, 1.0):", len(ids)

Download this script

Geometry type

filters mesh elements by the geometric type defined with the threshold value. The list of available geometric types depends on the element entity type.

  • element type can be any, e.g.: SMESH.EDGE, SMESH.FACE, SMESH.VOLUME, etc.
  • functor type should be SMESH.FT_ElemGeomType
  • threshold is either of smesh.GeometryType values. Type SMESH.GeometryType._items in the Python Console to see all geometric types.
1 # Geometry type
2 
3 # create mesh with volumes
4 from SMESH_mechanic import *
5 mesh.Tetrahedron()
6 mesh.Compute()
7 # get all triangles, quadrangles, tetrahedrons, pyramids
8 filter_tri = smesh.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_TRIANGLE)
9 filter_qua = smesh.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE)
10 filter_tet = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_TETRA)
11 filter_pyr = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_PYRAMID)
12 ids_tri = mesh.GetIdsFromFilter(filter_tri)
13 ids_qua = mesh.GetIdsFromFilter(filter_qua)
14 ids_tet = mesh.GetIdsFromFilter(filter_tet)
15 ids_pyr = mesh.GetIdsFromFilter(filter_pyr)
16 print "Number of triangles:", len(ids_tri)
17 print "Number of quadrangles:", len(ids_qua)
18 print "Number of tetrahedrons:", len(ids_tet)
19 print "Number of pyramids:", len(ids_pyr)

Download this script

Entity type

filters mesh elements by the geometric type and number of nodes.

  • element type can be any, e.g.: SMESH.EDGE, SMESH.FACE, SMESH.VOLUME, etc.
  • functor type should be SMESH.FT_EntityType
  • threshold is either of SMESH.EntityType values. Type SMESH.EntityType._items in the Python Console to see all entity types.
1 # Entity type
2 
3 # create a mesh
4 from SMESH_mechanic import *
5 
6 # make the mesh quadratic
7 mesh.ConvertToQuadratic()
8 # make some elements bi-quadratic
9 for face in SubFaceL[: len(SubFaceL)/2]:
10  mesh.ConvertToQuadratic( theSubMesh=mesh.Group( face ), theToBiQuad=True )
11 
12 # get triangles with 7 nodes
13 filter_tri = smesh.GetFilter(SMESH.FACE, SMESH.FT_EntityType,'=', SMESH.Entity_BiQuad_Triangle )
14 ids_tri = mesh.GetIdsFromFilter(filter_tri)
15 print "Number of bi-quadratic triangles:", len(ids_tri)

Download this script

Ball diameter

filters ball elements by diameter.

  • element type should be SMESH.BALL
  • functor type should be SMESH.FT_BallDiameter
  • threshold is floating point value (ball diameter)
1 # Ball diameter
2 
3 # create a mesh
4 from SMESH_mechanic import *
5 
6 # create several balls with increasing diameter
7 for i in range(1,10):
8  diameter = float( i )
9  mesh.AddBall( i, diameter )
10  pass
11 
12 # get balls with diameter > 5.
13 diam_filter = smesh.GetFilter(SMESH.BALL, SMESH.FT_BallDiameter,'>', 5. )
14 ids = mesh.GetIdsFromFilter( diam_filter )
15 print "Number of balls with diameter > 5:", len(ids)

Download this script

Elements of a domain

filters elements of a specified domain.

  • element type can be any, e.g.: SMESH.EDGE, SMESH.FACE, SMESH.VOLUME, etc.
  • functor type should be SMESH.FT_ConnectedElements
  • threshold is either (1) node ID or (2) geometrical vertex or (3) 3 coordinates of a point.
1 # Elements of a domain
2 
3 import salome, SMESH
4 salome.salome_init()
5 from salome.geom import geomBuilder
6 geompy = geomBuilder.New(salome.myStudy)
7 from salome.smesh import smeshBuilder
8 smesh = smeshBuilder.New(salome.myStudy)
9 
10 # create two boxes to have two domains in the mesh
11 
12 box1 = geompy.MakeBoxDXDYDZ( 100,100,100 )
13 box2 = geompy.MakeTranslation( box1, 200, 0, 0 )
14 boxes = geompy.MakeCompound( [box1, box2] )
15 box1, box2 = geompy.SubShapeAll( boxes, geompy.ShapeType["SHAPE"], "box")
16 
17 vertex = geompy.SubShape( box1, geompy.ShapeType["VERTEX"], [1] )
18 
19 # create a mesh
20 
21 mesh = smesh.Mesh( boxes )
22 mesh.Segment(box1).NumberOfSegments( 5 ) # to have different nb of elements on the boxes
23 mesh.Segment(box2).NumberOfSegments( 10 )
24 mesh.Quadrangle()
25 mesh.Hexahedron()
26 mesh.Compute()
27 
28 # Create filters with FT_ConnectedElements criterion by pointing a domain in different ways:
29 
30 # using point coordinates in box_1
31 nodeFilter = smesh.GetFilter( SMESH.NODE, SMESH.FT_ConnectedElements, "=", "1.,2,10", mesh=mesh )
32 print "Nb. nodes in box_1:", len( nodeFilter.GetIDs())
33 
34 # using point coordinates in box_2
35 edgeFilter = smesh.GetFilter( SMESH.EDGE, SMESH.FT_ConnectedElements, "=", [202,1,1 ], mesh=mesh )
36 print "Nb. segments in box_2:", len( edgeFilter.GetIDs())
37 
38 # using a geom vertex of box_1
39 faceFilter = smesh.GetFilter( SMESH.FACE, SMESH.FT_ConnectedElements, "=", vertex, mesh=mesh )
40 print "Nb. faces in box_1:", len( edgeFilter.GetIDs())
41 
42 # using node ID in box_2
43 voluFilter = smesh.GetFilter( SMESH.VOLUME, SMESH.FT_ConnectedElements, "=", 10, mesh=mesh )
44 print "Nb. volumes in box_2:", len( voluFilter.GetIDs())
45 

Download this script

How to combine several criteria into a filter?

Several criteria can be combined into a filter.

Example :

1 # Combine several criteria into a filter
2 
3 # create mesh
4 from SMESH_mechanic import *
5 
6 # get all the quadrangle faces ...
7 criterion1 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE, SMESH.FT_LogicalAND)
8 # ... but those from sub_face3
9 criterion2 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3, SMESH.FT_LogicalNOT)
10 
11 quadFilter = smesh.GetFilterFromCriteria([criterion1,criterion2])
12 
13 # get faces satisfying the criteria
14 ids = mesh.GetIdsFromFilter(quadFilter)
15 
16 # create a group of faces satisfying the criteria
17 myGroup = mesh.GroupOnFilter(SMESH.FACE,"Quads_on_cylindrical_faces",quadFilter)

Download this script