Filter overlapping spheres in Mechanical

Member, Moderator, Employee Posts: 479
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭
edited June 2023 in Structures

Filter overlapping spheres in Mechanical

Tagged:

Answers

  • Member, Moderator, Employee Posts: 479
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    Answer ✓

    For a case where say spheres are embedded in a matrix material and one needs to separate cavity face (belonging to the matrix) and sphere face, which lie on top of each other, one can use the following code.

    This code compares the centroids of the spheres after rounding off to 2 digits (on milli scale) as they don't exactly match. Some adjustment will be required based on the model.

    Also create a named selection all_spherical_faces manually using worksheet with all spheres in the model.

    1. all_spherical_faces = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.NamedSelections)[0].Children[2].Ids
    2. centroids = {}
    3. for face_id in all_spherical_faces:
    4. value = (round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[0] * 1000, 2),
    5. round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[1] * 1000, 2),
    6. round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[2] * 1000, 2))
    7. centroids.update({str(face_id): value})
    8.  
    9. reduced_list = centroids.copy()
    10. face_pairs = []
    11. for face_id, centroid in centroids.iteritems():
    12. reduced_list.pop(face_id)
    13. if centroid in reduced_list.values():
    14. face_pairs.append((face_id, reduced_list.keys()[reduced_list.values().index(centroid)]))
    15.  
    16. # Create Named selections
    17. for index, face_pair in enumerate(face_pairs, start=1):
    18. # sphere face
    19. sphere = Model.AddNamedSelection()
    20. sphere.Name = "sphere_%s" % index
    21. selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    22. selection.Ids = [int(face_pair[0])]
    23. sphere.Location = selection
    24. # cavity face
    25. sphere = Model.AddNamedSelection()
    26. sphere.Name = "cavity_%s" % index
    27. selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
    28. selection.Ids = [int(face_pair[1])]
    29. sphere.Location = selection

Welcome!

It looks like you're new here. Sign in or register to get started.