How do I retrieve Von-Mises stress of nodes in a Named Selection using DPF-Core?

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

I am using DPF-Core outside WB and there using CPython to retrieve Data from an RST of Harmonic analysis. The RST file contains a named-selection "MYNAMEDSELECTION" (a set of nodes). How do I retrieve the von-mises for each node at each frequency?

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
    import os
    from ansys.dpf import core
    from ansys.dpf.core import operators as ops
    
    rst_file = os.path.join(r"\Path\to\my\rst\file")
    model = core.Model(rst_file)
    
    # Print solution object
    print(model)
    
    # Print available named selections
    print('Named selections in model:', model.metadata.available_named_selections)
    
    # Get number of result sets
    tf = model.metadata.time_freq_support
    print('Number of solution sets:', tf.n_sets)
    
    # Restrict data to a specific named selection
    ns_operator = ops.scoping.on_named_selection()
    ns_operator.inputs.data_sources.connect(model)
    ns_operator.inputs.named_selection_name.connect('MYNAMEDSELECTION')
    
    # Get node numbers for nodes in named selection
    mesh_data = ns_operator.outputs.mesh_scoping.get_data()
    print(mesh_data.ids)
    
    # Extract data on the named selection
    equivalent_stress = ops.result.stress_von_mises(data_sources=model)
    
    # Create list for result sets
    freq_ids = list(range(1, model.metadata.time_freq_support.n_sets+1))
    
    # Restrict scoping to named selection
    equivalent_stress.inputs.mesh_scoping.connect(ns_operator.outputs.mesh_scoping)
    equivalent_stress.inputs.time_scoping.connect(freq_ids)
    
    fields = equivalent_stress.outputs.fields_container.get_data()
    
    for field in fields:
        print(field.data)