Opening result files with DPF / Defining datasources

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
100 Answers 500 Comments 250 Likes Second Anniversary
✭✭✭✭

There are different ways of referencing the datasources in DPF, which are they?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭
    edited February 2024

    The first method is to use streams. A stream opens the data files and these files will stay opened with some data cached to make the next evaluation faster. Remember to close the streams after you're finished with them!

    A typical example using streams would look like this:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    #Data sources
    dataSources = mech_dpf.GetStreams()
    #Scoping
    scoping = dpf.Scoping()
    scoping.Ids = [1]
    scoping.Location = 'Nodal'
    #Stress X direction
    stressXOp = dpf.operators.result.stress_X()
    stressXOp.inputs.streams_container.Connect(dataSources)
    stressXOp.inputs.mesh_scoping.Connect(scoping)
    sX = stressXOp.outputs.fields_container.GetData()
    print('sX is: ')
    print(sX)
    print('sX[0] is:')
    print(sX[0])
    print('sX on node #1 is: ')
    print(sX[0].Data)
    # Release stream
    dataSources = dataSources.ReleaseHandles()
    

    Another method is to directly set the path to the result file. The same example would then look like this:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    #Get path to result file
    import os
    folder = r"D:\DummyModel_files\dp0\SYS\MECH"
    filename = "file.rst"
    filepath = os.path.join(folder,filename)
    #Data sources
    dataSources = dpf.DataSources()
    dataSources.SetResultFilePath(filepath)
    #Scoping
    scoping = dpf.Scoping()
    scoping.Ids = [1]
    scoping.Location = 'Nodal'
    #Stress X direction
    stressXOp = dpf.operators.result.stress_X()
    stressXOp.inputs.data_sources.Connect(dataSources)
    stressXOp.inputs.mesh_scoping.Connect(scoping)
    sX = stressXOp.outputs.fields_container.GetData()
    print('sX on node #1 is: ')
    print(sX[0].Data)
    

    Note: A very convenient way to get the path to the result file from the Mechanical interface is to use the Mechanical automation API:

    analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    filepath = analysis.ResultFileName
    

    Finally, another very convenient way of opening a file through DPF is to use the Model class. This class facilitates the access to the various information about the result file. The same example as before, using the Model class:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI(ExtAPI)
    #Get path to result file
    analysis = ExtAPI.DataModel.Project.Model.Analyses[0]
    filepath = analysis.ResultFileName
    #Data sources
    dataSources = dpf.DataSources()
    dataSources.SetResultFilePath(filepath)
    # Model
    model=dpf.Model(dataSources)
    print(model)
    print(model.AvailableNamedSelections)
    print(model.Mesh)
    #Scoping
    scoping = dpf.Scoping()
    scoping.Ids = [1]
    scoping.Location = 'Nodal'
    #Stress X direction
    stressXOp = dpf.operators.result.stress_X()
    stressXOp.inputs.data_sources.Connect(dataSources)
    stressXOp.inputs.mesh_scoping.Connect(scoping)
    sX = stressXOp.outputs.fields_container.GetData()
    print('sX on node #1 is: ')
    print(sX[0].Data)
    

    Many information can be fetched from the Model class:

    model=dpf.Model(dataSources)
    print(model)
    print(model.ResultInfo)
    print(model.AvailableNamedSelections)
    print(model.TimeFreqSupport)
    print(model.ResultInfo.UnitSystem)
    print(model.ResultInfo.AnalysisType)
    print(model.Mesh)
    # Access mesh
    my_nodes = model.Mesh.Nodes
    my_nodes [0].Id
    my_nodes [0].X
    model.Mesh.ElementScoping.Ids[10]
    
  • total_obliteration
    total_obliteration Member Posts: 12
    First Anniversary Name Dropper First Comment
    **

    Is there any calculation-time-wise benefit of using streams? Currently, my script to extract contacts reaction force (using nmisc) for every of 77 load steps from only 3 named selection runs more than 3 hours.

    Could you provide insights how to optimize working with big .rst files (150GB+)?

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭

    Evaluation will be faster with steams as the data is cached. For big .rst files, you could consider using incremental operator.

  • Hrishikesh.Panchanwagh
    Hrishikesh.Panchanwagh Member Posts: 8
    First Comment
    **

    Hello, I am just getting started, so pardon my silly questions. I am trying to open results from my model and I get error using Model class. The file does exist and I was able to do some APDL script post processing with it. Is there anything else I need to check? Error "Traceback (most recent call last): Exception: scoping_provider_by_ns:159<-MeshSelectionManagerProvider:162<-mapdl::rst::MeshSelectionManagerProvider:163<-Unable to open the following file: ...\dp0\SYS\MECH\file.rst"

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 913
    100 Answers 500 Comments 250 Likes Second Anniversary
    ✭✭✭✭

    @Hrishikesh.Panchanwagh Again, please create a separate post for this.