Find the maximum value in a field AND corresponding scoping ID

Jim Kosloski
Jim Kosloski Member, Employee Posts: 11
First Anniversary Ansys Employee First Comment
edited October 24 in Structures

I need to find the node with the max stress. How can I do this using DPF

Tagged:

Comments

  • M
    M Member, Employee Posts: 169
    50 Answers 100 Comments 100 Likes First Anniversary

    Hello Jim, I think in the example:
    https://dpf.docs.pyansys.com/version/0.8/examples/00-basic/02-basic_field_containers.html#sphx-glr-examples-00-basic-02-basic-field-containers-py

    the end there is are a few lines to show how to get max and Ids of the field.

  • M
    M Member, Employee Posts: 169
    50 Answers 100 Comments 100 Likes First Anniversary

    Example how to do this in the mechanical scripting window with dpf. The example is von mises stress, but you can change that line to any result.

    import mech_dpf
    import Ans.DataProcessing as dpf
    
    #Result Data
    analysis1 = ExtAPI.DataModel.Project.Model.Analyses[0]
    dataSource = dpf.DataSources(analysis1.Solution.ResultFilePath)
    #model
    my_model = dpf.Model(analysis1.Solution.ResultFilePath)
    #my mesh
    my_mesh = my_model.Mesh
    
    #time scoping
    my_time_scoping = 1
    
    #Time list
    timelist = dpf.operators.metadata.time_freq_provider(data_sources=dataSource).outputs.gettime_freq_support().TimeFreqs.Data
    
    result_fc = dpf.operators.result.stress_von_mises(time_scoping=my_time_scoping,data_sources=dataSource).outputs.fields_container.GetData()
    result_field = result_fc[0]
    max_min_op = dpf.operators.min_max.min_max(field=result_field)
    max_id = max_min_op.outputs.field_max.GetData().ScopingIds
    max_value = max_min_op.outputs.field_max.GetData().Data
    
    min_id = max_min_op.outputs.field_min.GetData().ScopingIds
    min_value = max_min_op.outputs.field_min.GetData().Data
    
    max_result = [max_id[0],max_value[0]]
    min_result = [min_id[0],min_value[0]]
    print(max_result)
    print(min_result)