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

import salome

import geompy

 

import StdMeshers

 

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

 

smeshgui = salome.ImportComponentGUI("SMESH")

smeshgui.Init(salome.myStudyId);

 

# 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

print "-------------------------- create Hypothesis"

 

print "-------------------------- NumberOfSegments"

numberOfSegments = 7

 

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

hypNbSeg.SetNumberOfSegments(numberOfSegments)

 

print hypNbSeg.GetName()

print hypNbSeg.GetId()

print hypNbSeg.GetNumberOfSegments()

 

smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")

 

print "-------------------------- MaxElementArea"

maxElementArea = 800

 

hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")

hypArea.SetMaxElementArea(maxElementArea)

 

print hypArea.GetName()

print hypArea.GetId()

print hypArea.GetMaxElementArea()

 

smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_500")

 

print "-------------------------- MaxElementVolume"

maxElementVolume = 900

 

hypVolume = smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")

hypVolume.SetMaxElementVolume(maxElementVolume)

 

print hypVolume.GetName()

print hypVolume.GetId()

print hypVolume.GetMaxElementVolume()

 

smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_500")

 

# create algorithms

print "-------------------------- create Algorithms"

 

print "-------------------------- Regular_1D"

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

smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")

 

print "-------------------------- Quadrangle_2D"

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

smeshgui.SetName(salome.ObjectToID(quad2D), "Quadrangle_2D")

 

# initialize a mesh with the box

mesh = smesh.CreateMesh(box)

smeshgui.SetName(salome.ObjectToID(mesh), "MeshBox")

 

# add a hypothesis to the box

print "-------------------------- add hypothesis to the box"

mesh.AddHypothesis(box,hypNbSeg)

mesh.AddHypothesis(box,hypArea)

mesh.AddHypothesis(box,hypVolume)

mesh.AddHypothesis(box,regular1D)

mesh.AddHypothesis(box,quad2D)

 

# compute the mesh

print "-------------------------- compute the mesh of the box"

ret = smesh.Compute(mesh,box)

print ret

if ret == 0:

    print "probleme when computing the mesh"

 

# create geometry groups on the plane:

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

 

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)