Grouping Elements

Create a Standalone Group

# Attention! This script has been written using the old approach basing on direct usage of SMESH idl interface.

# For the moment smesh package doesn't provide methods to create a standalone group.

# In the next SALOME version the scripts will be updated to use only the commands from smesh package.

 

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

# Get ids of all faces with area > 100

aFilterMgr = smesh.CreateFilterManager()

aFunctor = aFilterMgr.CreateArea()

 

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor( aFunctor )

aPredicate.SetMargin( 100 )

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate( aPredicate )

 

anIds = aFilter.GetElementsId( mesh )

 

 

# 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

import salome

import geompy

import smesh

 

# create a box

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

geompy.addToStudy(box, "box")

 

# add the first face of the box to the study

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

face = subShapeList[0]

geompy.addToStudyInFather(box, face, "face 1")

 

# create group of edges on the face

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

geompy.AddObject(aGeomGroupE, 3)

geompy.AddObject(aGeomGroupE, 6)

geompy.AddObject(aGeomGroupE, 8)

geompy.AddObject(aGeomGroupE, 10)

geompy.addToStudyInFather(face, aGeomGroupE, "Group of Edges")

 

# create quadrangle 2D mesh on the box

quadra = smesh.Mesh(box, "Box : quadrangle 2D mesh")

algo1D = quadra.Segment()

quadra.Quadrangle()

algo1D.NumberOfSegments(7)

 

# compute the mesh

quadra.Compute()

 

# create SMESH group on the face with name "SMESHGroup1"

aSmeshGroup1 = quadra.Group(face, "SMESHGroup1")

 

# create SMESH group on <aGeomGroupE> with default name

aSmeshGroup2 = quadra.Group(aGeomGroupE)

 

salome.sg.updateObjBrowser(1)

Edit a Group

# Attention! This script has been written using the old approach basing on direct usage of SMESH idl interface.

# For the moment smesh package doesn't provide methods to edit a group.

# In the next SALOME version the scripts will be updated to use only the commands from smesh package.

 

import SMESH

import SMESH_mechanic

 

smesh  = SMESH_mechanic.smesh

mesh   = SMESH_mechanic.mesh

salome = SMESH_mechanic.salome

 

# Get ids of all faces with area > 35

aFilterMgr = smesh.CreateFilterManager()

aFunctor = aFilterMgr.CreateArea()

 

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor(aFunctor)

aPredicate.SetMargin(35.)

 

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate(aPredicate)

 

anIds = aFilter.GetElementsId(mesh)

 

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

 

# create a group by adding elements with area > 35

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

aGroup.Add(anIds)

 

# Get ids of all faces with area > 40

aFunctor = aFilterMgr.CreateArea()

aPredicate = aFilterMgr.CreateMoreThan()

aPredicate.SetNumFunctor(aFunctor)

aPredicate.SetMargin(40.)

aFilter = aFilterMgr.CreateFilter()

aFilter.SetPredicate(aPredicate)

anIds = aFilter.GetElementsId(mesh)

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

 

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

aGroup.Remove(anIds)

 

# print the result

aGroupElemIDs = aGroup.GetListOfID()

print "Criterion: 35 < Area < 40, Nb = ", len(aGroupElemIDs)

j = 1

for i in range(len(aGroupElemIDs)):

  if j > 20: j = 1; print ""

  print aGroupElemIDs[i],

  j = j + 1

  pass

print ""

 

salome.sg.updateObjBrowser(1)

 

 

Union of two groups

# Attention! This script has been written using the old approach basing on direct usage of SMESH idl interface.

# For the moment smesh package doesn't provide methods to create a union of two groups.

# In the next SALOME version the scripts will be updated to use only the commands from smesh package.

 

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)

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

 

# create a group by adding elements with area > 20

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

aGroup1.Add(anIds)

 

# 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)

 

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

 

# create a group by adding elements with area = 20

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

aGroup2.Add(anIds)

 

# 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)

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

 

# create a group by adding elements with area < 20

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

aGroup4.Add(anIds)

 

# 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

# Attention! This script has been written using the old approach basing on direct usage of SMESH idl interface.

# For the moment smesh package doesn't provide methods to create an intersection of two groups.

# In the next SALOME version the scripts will be updated to use only the commands from smesh package.

 

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)

 

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

 

# create a group by adding elements with area > 20

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

aGroup1.Add(anIds)

 

# 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)

 

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

 

# create a group by adding elements with area < 60

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

aGroup2.Add(anIds)

 

# 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

# Attention! This script has been written using the old approach basing on direct usage of SMESH idl interface.

# For the moment smesh package doesn't provide methods to create a cut of two groups.

# In the next SALOME version the scripts will be updated to use only the commands from smesh package.

 

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)

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

 

# create a group by adding elements with area > 20

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

aGroupMain.Add(anIds)

 

# 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)

 

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

 

# create a group by adding elements with area < 60

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

aGroupTool.Add(anIds)

 

# create a cut of groups : area >= 60

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

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

salome.sg.updateObjBrowser(1)