[SMESH] Applying a filter to a Group in TUI

Hi,

I want to apply a filter to a group of my mesh. I can do that in the GUI with “edit as standalone” on the group, “set filter” then selecting “current dialog” as a source. But when I dump the study, I just have the list of deleted IDs with no way to reproduce that.

The documentation Grouping Elements — Mesh 9.11.0 documentation show how to do that by applying the filter to the whole mesh which would takes days instead of the nearly half an hour if I applying the filter only on the groups.

I try to that with the RemovePredicate method of the group and GetPredicate method of the filter but that had not worked either.

Do you know how to reproduce in the TUI the GUI behaviour ?

Thank you,

Regards,

Jonas

1 Like

I was looking for something else and your search popped up. If you can mention what your filter criteria are I might have some Python code that could help you. I think you can do what you want generally if, in Python, you get the ID of the element you want to act on through the group.GetIds() or very similarly-named method (e.g. capitalizations might be different). Then you can work through that element list using the various element information methods of the mesh which will return the element property (whatever you want to filter on) by ID. Also, see if you can find what you need in the old forum. - Kirk

Thank you for your answer. My filter is Lying on Geom (SMESH.FT_LyingOnGeom) which may be the most demanding filter (especially as my geometry is a 3D helyx). I did not manage to apply the filter only to the elements that were in the group in the TUI.

Best,
Jonas

Wow this is really old. I am sorry I did not give this sooner. Maybe I did not have it then. Apologies if I missed a key point of yours in my haste. - Kirk

edge_types=[SMESH.Entity_Edge, SMESH.Entity_Quad_Edge]
face_types=[SMESH.Entity_Triangle, SMESH.Entity_Quad_Triangle, SMESH.Entity_BiQuad_Triangle]
face_types+=[SMESH.Entity_Quadrangle, SMESH.Entity_Quad_Quadrangle, SMESH.Entity_BiQuad_Quadrangle]
vol_types=[SMESH.Entity_Tetra, SMESH.Entity_Quad_Tetra, SMESH.Entity_Pyramid, SMESH.Entity_Quad_Pyramid, SMESH.Entity_Hexa]
vol_types+=[SMESH.Entity_Quad_Hexa, SMESH.Entity_TriQuad_Hexa, SMESH.Entity_Penta, SMESH.Entity_Quad_Penta, SMESH.Entity_BiQuad_Penta]
vol_types+=[SMESH.Entity_Hexagonal_Prism, SMESH.Entity_Polyhedra, SMESH.Entity_Quad_Polyhedra, SMESH.Entity_Ball]

ETdict={‘EDGE’:edge_types,‘FACE’:face_types,‘VOLUME’:vol_types}
SMETdict={‘NODE’:SMESH.NODE, ‘ELEM0D’:SMESH.ELEM0D, ‘EDGE’:SMESH.EDGE,‘FACE’:SMESH.FACE,‘VOLUME’:SMESH.VOLUME,}

def MakeElemTypeFilter(strEType):
aCriteria =
for et in ETdict[strEType]:
aCriterion = smesh.GetCriterion(SMETdict[strEType],SMESH.FT_EntityType,‘=’,et,SMESH.FT_LogicalOR)
aCriteria.append(aCriterion)
return smesh.GetFilterFromCriteria(aCriteria)

def DefineFEGroupOnGeometry(Mesh,geoRefs,strName,strEType):
aCriteria =
if type(geoRefs)!=tuple and type(geoRefs)!=list: geoRefs=(geoRefs,)
else: pass
for g in geoRefs:
aCriterion = smesh.GetCriterion(SMETdict[strEType],SMESH.FT_BelongToGeom,SMESH.FT_Undefined,g,SMESH.FT_Undefined,SMESH.FT_LogicalOR)
aCriteria.append(aCriterion)
aFilter = smesh.GetFilterFromCriteria(aCriteria)
aFilter.SetMesh(Mesh.GetMesh())
out = Mesh.GroupOnFilter(SMETdict[strEType], strName, aFilter)
return out

usage:

#Delete all edge elements (all types)
aFilter = MakeElemTypeFilter(‘EDGE’)
aFilter.SetMesh(Mesh_0.GetMesh())
ids = Mesh_0.GetIdsFromFilter(aFilter)
edges_to_delete = Mesh_0.GroupOnFilter(SMESH.EDGE, ‘edges_to_delete’, aFilter)
Mesh_0.RemoveGroupWithContents(edges_to_delete)
out_str=" Deleted %d edge elements." % len(ids)

#Get KEEP face elements

We just want the ones we need for:

slabs (both real and penetration zone)

soil loading and bearing and

flange / embedment ring contact regions

All these have ‘_fac’ in definition.

keys=GroupDict.keys()
keys=[str(k) for k in keys]
keys=[k for k in keys if ‘_fac’ in k and ‘face’ not in k]
geom_groups=[GroupDict[key][‘GEOM_obj’] for key in keys]
keep_faces = DefineFEGroupOnGeometry(Mesh_0,geom_groups,‘keep_faces’,‘FACE’)
ids = keep_faces.GetIDs(); c2=len(ids)
out_str+=“\n A total of %d face elements will be kept.” % c2

#Define del_faces by carve keep_faces from all_faces
del_faces = Mesh_0.CutGroups(all_faces,keep_faces,‘del_faces’)
ids = del_faces.GetIDs(); c3=len(ids)
out_str+=“\n A total of %d face elements will be deleted.” % c3
out_str+=“\n The expected number of deletions is: %d” % (c1-c2)
out_str+=“\n The process deviated by %d (expected - actual)” % (c1-c2-c3)
output(out_str,outpr=True)
if c1-c2-c3 != 0:
out_str=“There is a problem with the number of deleted faces expected vs actually deleted. You probably need help.”
output(out_str,outpr=True)
raise ValueError(out_str)
else: pass

Mesh_0.RemoveGroupWithContents(del_faces); del del_faces
Mesh_0.RemoveGroup(keep_faces); del keep_faces
Mesh_0.RemoveGroup(all_faces); del all_faces