How to extract unaveraged stresses at a node using DPF?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 86
First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member
edited June 2023 in Structures

How to extract unaveraged stresses at a node (at all elements the node shares) using DPF?

Tagged:

Answers

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 86
    First Answer First Anniversary Name Dropper Solution Developer Community of Practice Member
    Answer ✓

    Below script shows how one could extract unaveraged component stresses (in this case stress Y) at a node. The values corresponding to all the elements connected to the input node id are printed at the end.

    Note: This approach cannot be used for getting unaveraged principal/equivalent stresses, as the midside node stresses will be incorrectly computed.

    ##Unaveraged Nodal Stresses based on Node Id. 
    import mech_dpf
    import Ans.DataProcessing as dpf 
    mech_dpf.setExtAPI(ExtAPI)
    
    #Get the data source (i.e. result file)
    dataSource = mech_dpf.GetDataSources(0)
    
    #Enter the node ID
    nodeId = 100
    
    #get Connected Elements
    mesh = dpf.operators.mesh.mesh_provider()
    mesh.inputs.data_sources.Connect(dataSource)
    node_connectivity = mesh.outputs.getmesh().NodalConnectivityPropertyField.GetEntityDataById(nodeId)
    
    #Create operator
    sy_op = dpf.operators.result.stress_Y() 
    sy_op.inputs.data_sources.Connect(dataSource)
    sy_op.inputs.requested_location.Connect('ElementalNodal')
    
    sy_fields = sy_op.outputs.fields_container.GetData()
    sy_field = sy_fields[0]
    
    #Extend stress result also to mid side nodes
    mid_op = dpf.operators.averaging.extend_to_mid_nodes()
    mid_op.inputs.field.Connect(sy_field)
    sy_field_corner_mid = mid_op.outputs.field.GetData()
    
    print 'Number of elements connected to node',nodeId,'=',len(node_connectivity)
    
    for id in node_connectivity:
        elem_num = mesh.outputs.getmesh().ElementIds[id]
        elem = mesh.outputs.getmesh().ElementById(elem_num)
        node_index = elem.NodeIds.IndexOf(nodeId)
        stress_y = sy_field_corner_mid.GetEntityDataById(elem_num)[node_index]
        print 'stress at element',mesh.outputs.getmesh().ElementIds[id],'and node',nodeId,'is',stress_y