Grouping Elements

Create a Standalone Group

 

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 100

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 100 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# print the result

print "Criterion: Area > 100 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# create a group consisting of faces with area > 100

aGroup = mesh.CreateGroup( SMESH.FACE, "Area > 100" )

aGroup.Add( anIds )

 

salome.sg.updateObjBrowser(1)

 

Create a Group on Geometry

Attention! This script was written using old approach, based on direct usage of SMESH idl interface. To be updated for version 3.2.1 to use smesh package.
 

import salome

import geompy

 

import SMESH

import StdMeshers

 

smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")

 

# create a box

box = geompy.MakeBox(0., 0., 0., 100., 100., 100.)

 

# add the box to the study

idbox = geompy.addToStudy(box, "box")

 

# add the first face of the box to the study

subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])

face = subShapeList[0]

name = geompy.SubShapeName(face, box)

idface = geompy.addToStudyInFather(box, face, name)

 

# create a hypothesis

numberOfSegments = 7

hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")

hypNbSeg.SetNumberOfSegments(numberOfSegments)

 

# create algorithms

regular1D = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")

quad2D = smesh.CreateHypothesis("Quadrangle_2D", "libStdMeshersEngine.so")

 

# initialize a mesh with the box

mesh = smesh.CreateMesh(box)

 

# add hypotheses and algorithms to the box

mesh.AddHypothesis(box,hypNbSeg)

mesh.AddHypothesis(box,regular1D)

mesh.AddHypothesis(box,quad2D)

 

# compute the mesh

ret = smesh.Compute(mesh,box)

if ret == 0:

    print "probleme when computing the mesh"

else:

    print "Computation succeded"

 

# create geometry groups on the face

aGeomGroup1 = geompy.CreateGroup(face, geompy.ShapeType["FACE"])

geompy.AddObject(aGeomGroup1, 1)

 

aGeomGroup2 = geompy.CreateGroup(face, geompy.ShapeType["EDGE"])

geompy.AddObject(aGeomGroup2, 3)

geompy.AddObject(aGeomGroup2, 6)

geompy.AddObject(aGeomGroup2, 8)

geompy.AddObject(aGeomGroup2, 10)

 

geompy.addToStudy(aGeomGroup1, "Group on Faces")

geompy.addToStudy(aGeomGroup2, "Group on Edges")

 

# create SMESH groups

aSmeshGroup1 = mesh.CreateGroupFromGEOM(SMESH.FACE, "SMESHGroup1",

aGeomGroup1)

aSmeshGroup2 = mesh.CreateGroupFromGEOM(SMESH.EDGE, "SMESHGroup2", aGeomGroup2)

 

salome.sg.updateObjBrowser(1)  

 

Edit a Group

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 30 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA > 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group of elements with area [20; 60] by removing elements with area > 60 from  group aGroup

aGroup.Remove(anIds)

 

# print the result

aGroupElemIDs = aGroup.GetListOfID()

print "Criterion: 20 < Area < 60 = ", len( aGroupElemIDs )

for i in range( len( aGroupElemIDs ) ):

  print aGroupElemIDs[ i ]

 

salome.sg.updateObjBrowser(1)

 

 

Union of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup1 = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup1.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA = 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateEqualTo()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup2 = mesh.CreateGroup( SMESH.FACE, "Area = 20" )

aGroup2.Add( anIds )

 

print "Criterion: Area = 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# create union group : area >= 20

aGroup3 = mesh.UnionGroups(aGroup1, aGroup2, "Area >= 20")

print "Criterion: Area >= 20 Nb = ", len( aGroup3.GetListOfID() )

 

# Criterion : AREA < 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 20

aGroup4 = mesh.CreateGroup( SMESH.FACE, "Area < 20" )

aGroup4.Add( anIds )

 

print "Criterion: Area < 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create union group : area >= 20 and area < 20

aGroup5 = mesh.UnionGroups(aGroup3, aGroup4, "Any Area")

print "Criterion: Any Area Nb = ", len( aGroup5.GetListOfID() )

 

salome.sg.updateObjBrowser(1)

 

 

 

Intersection of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroup1 = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroup1.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA < 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 60

aGroup2 = mesh.CreateGroup( SMESH.FACE, "Area < 60" )

aGroup2.Add( anIds )

 

print "Criterion: Area < 60 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create an intersection of groups : 20 < area < 60

aGroup3 = mesh.IntersectGroups(aGroup1, aGroup2, "20 < Area < 60")

print "Criterion: 20 < Area < 60 Nb = ", len( aGroup3.GetListOfID() )

 

salome.sg.updateObjBrowser(1)

 

   

Cut of two groups

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

aFilterMgr = smesh.CreateFilterManager()

 

# Criterion : AREA > 20

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 20 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area > 20

aGroupMain = mesh.CreateGroup( SMESH.FACE, "Area > 20" )

aGroupMain.Add( anIds )

 

print "Criterion: Area > 20 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

 

# Criterion : AREA < 60

 

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateLessThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 60 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

# create a group by adding elements with area < 60

aGroupTool = mesh.CreateGroup( SMESH.FACE, "Area < 60" )

aGroupTool.Add( anIds )

 

print "Criterion: Area < 60 Nb = ", len( anIds )

for i in range( len( anIds ) ):

  print anIds[ i ]

  

# create an intersection of groups : area >= 60

aGroupRes = mesh.CutGroups(aGroupMain, aGroupTool, "Area >= 60")

print "Criterion: Area >= 60 Nb = ", len( aGroupRes.GetListOfID() )

 

salome.sg.updateObjBrowser(1)