Export temperatures from a RTH file to a csv file with PyAnsys

Oscar
Oscar Member, Employee Posts: 11
Photogenic First Comment First Anniversary Ansys Employee
✭✭✭
edited June 2023 in Structures

How to export temperatures from a RTH file to a csv file with PyAnsys?

Tagged:

Answers

  • Oscar
    Oscar Member, Employee Posts: 11
    Photogenic First Comment First Anniversary Ansys Employee
    ✭✭✭
    Answer ✓
    from ansys.dpf import core as dpf
    import numpy as np
    
    # please set the result file path to the right path
    model = dpf.DataSources()
    model = dpf.Model(r"D:\...\file.rth")
    
    time_freq_support =  model.metadata.time_freq_support
    time_1 = list(time_freq_support.time_frequencies.data)
    
    t1 = dpf.operators.result.temperature()
    t1.inputs.data_sources.connect(model)
    t1.inputs.time_scoping.connect(time_1)
    
    temp = np.array(np.append("Time",t1.outputs.fields_container.get_data()[0].scoping.ids))
    
    for i in range(0, len(time_1)):
        temp = np.vstack([temp,np.append(time_1[i],t1.outputs.fields_container.get_data()[i].data)])
    
    np.savetxt("D:\...\Test.csv", temp, delimiter=",", fmt="%s")