How do I check with PyDPF if a particular result is available for a time-step in my results file?

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 489
100 Answers 250 Likes 100 Comments Second Anniversary
✭✭✭✭

How do I check with PyDPF if a particular result is available for a time-step in my results file?

Comments

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 489
    100 Answers 250 Likes 100 Comments Second Anniversary
    ✭✭✭✭
    edited March 31

    You need to scope all the time-steps in your Time scoping. DPF returns a fields container with Fields for all time-steps but where results are absent the elementary count is 0. The following code can be used as an example:

    from ansys.dpf import core as dpf
    
    rst = r"\Path\to\file.rst"
    
    dpf.start_local_server(ansys_path=r"C:\Program Files\ANSYS Inc\v222")
    print(dpf.SERVER.info)
    model = dpf.Model(rst)
    
    ds = dpf.DataSources(rst)
    ts = dpf.Scoping()
    ts.ids = range(1, model.metadata.time_freq_support.n_sets + 1)
    
    stress = dpf.operators.result.stress(data_sources=ds, time_scoping=ts)
    stress_fc = stress.outputs.fields_container.get_data()
    
    def check_if_result_exists_at_time(fc, time_index):
        if fc[time_index].elementary_data_count > 0:
            return True
        return False
    
    time_index = 2
    res_bol = check_if_result_exists_at_time(stress_fc, time_index)
    print(f"Stress result at time-step {time_index}: {res_bol}")