DPF - How to retrieve quantities only on corner nodes of a given named selection?

Pierre Thieffry
Pierre Thieffry Member, Moderator, Employee Posts: 107
25 Answers Second Anniversary 10 Comments 25 Likes
✭✭✭✭
edited June 2023 in Structures

User has created a name selection on a face, yet wants to extract stress values only at corner nodes. How can he do this?

Tagged:

Answers

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 107
    25 Answers Second Anniversary 10 Comments 25 Likes
    ✭✭✭✭
    Answer ✓

    Not sure this is the cleanest way, but the below code will work. The idea is to collect a list of all corner nodes from the mesh, then intersect a named selection's ids with this list and scope results to this restricted list of nodes

    import mech_dpf
    import Ans.DataProcessing as dpf
    import Ans.DataProcessing.operators as ops
    
    mech_dpf.setExtAPI(ExtAPI)
    my_data_source = mech_dpf.GetDataSources()
    
    ns = ops.scoping.on_named_selection()
    ns.inputs.data_sources.Connect(my_data_source)
    ns.inputs.requested_location.Connect("Nodal")
    ns.inputs.named_selection_name.Connect("FACE")
    
    model=dpf.Model(my_data_source)
    model.ReleaseStreams()
    
    rst_mesh=model.Mesh
    corner_nodes=[]
    
    # Parse all nodes to find corner node ids
    all_elems=rst_mesh.Elements
    for el in all_elems:
        corner_nodes.extend(el.CornerNodeIds)
    # Remove duplicates
    corner_nodes=list(dict.fromkeys(corner_nodes))
    
    # Create node scoping only on corner nodes
    # intersection of full list of corner_nodes and scoping from above named selection
    corner_scoping=dpf.Scoping()
    corner_scoping.Ids=list(set(corner_nodes) & set(ns.outputs.mesh_scoping.GetData().Ids))
    
    # Retrieve whichever result, scoped on corner nodes of interest
    stress_op = ops.result.stress_X()
    stress_op.inputs.data_sources.Connect(my_data_source)
    stress_op.inputs.mesh_scoping.Connect(corner_scoping)
    
    my_stress = stress_op.outputs.fields_container.GetData()[0]
    
    for id in my_stress.ScopingIds:
        print(id,my_stress.GetEntityDataById(id)[0])