How to get access to the data generated by Mechanical in h5 file?

Options
Javier Vique
Javier Vique Member, Employee Posts: 95
Second Anniversary 5 Answers 25 Likes 10 Comments
✭✭✭✭

When mapping results (e.g. temperature from a steady-state thermal to static structural), there is now an option to do it by h5 file. If we want to get access to the data included in that h5 file, how can we do it?

Tagged:

Answers

  • Javier Vique
    Javier Vique Member, Employee Posts: 95
    Second Anniversary 5 Answers 25 Likes 10 Comments
    ✭✭✭✭

    This exercise is developed in Ansys 25R2. Keeping the same example given in the explanation, we would like to verify temperatures written to h5 file.
    So first step is to activate 'To Binary File' in 'Mapped Data' inside 'Imported Body Temperature' object of Mechanical. Then we need to open the generated file in HDFView. There we will be able to see the name given to the results to be mapped. For this example, the name is "target_data_45".

    Now we make use of dpf to extract the data we are interested in. Below the code:

    temp_file = r'here the h5 file path'
    
    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    ds = dpf.DataSources()
    ds.SetResultFilePath(temp_file,'h5dpf')
    
    op = dpf.operators.result.result_provider()
    op.inputs.data_sources.Connect(ds)
    op.inputs.result_name.Connect('target_data_45')
    my_fc = op.outputs.fields_container.GetData()
    
    print('Temp at node 561 is %.3f' % my_fc[0].GetEntityDataById(561)[0])
    print('Temp at node 546 is %.3f' % my_fc[0].GetEntityDataById(546)[0])
    print('Temp at node 633 is %.3f' % my_fc[0].GetEntityDataById(633)[0])
    

    As we can see below, we confirm that temperatures matches with probe values from Mechanical: