How do I get real and imaginary stress tensor for a harmonic analysis using DPF-Core?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 444
250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
✭✭✭✭
edited June 2023 in Structures

I am using DPF-Core (PyAnsys) via an IDE (Integrated Development Environment eg. Visual Studio Code) and using PyDPF to retrieve Data from an RST file of a Harmonic analysis. The RST file contains a named-selection "NODE" (a set of nodes). How do I retrieve the stress-tensor (real and imaginary part) for each node at each frequency?

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 444
    250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
    ✭✭✭✭
    Answer ✓
    from ansys.dpf import core as dpf
    from ansys.dpf.core import operators as ops
    
    model = dpf.Model(r"\Path\to\my\file.rst")
    print(model)
    
    tf = model.metadata.time_freq_support
    print('Number of solution sets', tf.n_sets)
    
    stress = ops.result.stress(data_sources=model)
    freq_ids = list(range(1, model.metadata.time_freq_support.n_sets+1))
    
    print(model.metadata.available_named_selections)
    
    ns_operator = dpf.operators.scoping.on_named_selection()
    ns_operator.inputs.named_selection_name.connect('NODE')
    ns_operator.inputs.data_sources.connect(model)
    stress.inputs.mesh_scoping.connect(ns_operator.outputs.mesh_scoping)
    stress.inputs.time_scoping.connect(freq_ids)
    stress.inputs.requested_location.connect("Nodal") 
    
    fields = stress.outputs.fields_container.get_data()
    
    for freq_id in freq_ids:
        print("REAL - %s" % fields.get_field_by_time_id(freq_id).data)
        print("IMAG - %s" % fields.get_imaginary_field(freq_id).data)
    
  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 444
    250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
    ✭✭✭✭
    Answer ✓

    In case you want to retrieve this data in Mechanical, mech_dpf must be used, the following code will give the same output in Mechanical Scripting Console.

    NOTE: Please set Mechanical analysis system index in line number 6. This code assumes the first analysis to be Harmonic and retrieves data from that analysis.

    import mech_dpf
    mech_dpf.setExtAPI(ExtAPI)
    import Ans.DataProcessing as dpf
    dpf.DataProcessingCore.LoadLibrary("math",r"C:\Program Files\ANSYS Inc\v212\aisol\bin\winx64\Ans.Dpf.Math.dll")
    
    ds = mech_dpf.GetDataSources(0)
    timeProvider = dpf.operators.metadata.time_freq_provider()
    timeProvider.inputs.data_sources.Connect(ds)
    freqs = timeProvider.outputs.time_freq_support.GetData()
    numSets = freqs.NumberSets
    ids = [index + 1 for index in range(numSets)]
    
    freq_scoping = dpf.Scoping()
    freq_scoping.Ids = ids
    
    ns_op = dpf.Operator("scoping_provider_by_ns")
    ns_op.Connect(1, "NODE")
    ns_op.Connect(4, ds)
    
    #Stress Y
    op_sy = dpf.Operator("S")
    op_sy.Connect(0, freq_scoping)
    op_sy.Connect(1, ns_op)
    op_sy.Connect(4, ds)
    op_sy.Connect(9, "Nodal")
    
    for id in ids:
        print "REAL - %s " % op_sy.GetOutputAsFieldsContainer(0).GetFieldByTimeId(id).Data
        print "IMAG - %s " % op_sy.GetOutputAsFieldsContainer(0).GetImaginaryField(id).Data