Filter overlapping spheres in Mechanical

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 419
5 Likes First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

Filter overlapping spheres in Mechanical

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 419
    5 Likes First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    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.

    all_spherical_faces = ExtAPI.DataModel.GetObjectsByType(Ansys.ACT.Automation.Mechanical.NamedSelections)[0].Children[2].Ids
    centroids = {}
    for face_id in all_spherical_faces:
        value = (round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[0] * 1000, 2),
                 round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[1] * 1000, 2),
                 round(ExtAPI.DataModel.GeoData.GeoEntityById(face_id).Centroid[2] * 1000, 2))
        centroids.update({str(face_id): value})
    
    reduced_list = centroids.copy()
    face_pairs = []
    for face_id, centroid in centroids.iteritems():
        reduced_list.pop(face_id)
        if centroid in reduced_list.values():
            face_pairs.append((face_id, reduced_list.keys()[reduced_list.values().index(centroid)]))
    
    # Create Named selections
    for index, face_pair in enumerate(face_pairs, start=1):
        # sphere face
        sphere = Model.AddNamedSelection()
        sphere.Name = "sphere_%s" % index
        selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
        selection.Ids = [int(face_pair[0])]
        sphere.Location = selection
        # cavity face
        sphere = Model.AddNamedSelection()
        sphere.Name = "cavity_%s" % index
        selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
        selection.Ids = [int(face_pair[1])]
        sphere.Location = selection