[DPF] An unexpected error occurred - rst file used by another program

Options
Adrien Vet
Adrien Vet Member Posts: 10
Name Dropper Photogenic First Comment
edited June 2023 in Structures

Hello, I'm writing some codes in DPF in a python result inside my modal analysis, so I need to read the rst file with the dataSource accessed with the "dpf.DataSources(analysis.ResultFileName)" command.

My code works well, but when I want to resolve my modal analysis, it shows this error :

An unexpected error occurred : ansys failed saving the rst file to the working directory path because rst file is used by another program.

I guess that ansys opened the rst file in the dpf to read some results, but the rst file is still opened and not close when we perform the solve. How can I somehow "close" the rst file at the end of my python result ?

Thanks for help,

Adrien

Best Answer

  • Aria
    Aria Member, Employee Posts: 65
    First Anniversary Ansys Employee First Answer Name Dropper
    edited June 2023 Answer ✓
    Options

    @Adrien Vet could you try releasing the file in this manner?

    analysis1 = ExtAPI.DataModel.Project.Model.Analyses[0]
    dataSource = dpf.DataSources(analysis1.Solution.ResultFilePath)
    my_model = dpf.Model(analysis1.Solution.ResultFilePath)
    my_model.ReleaseStreams()
    

Answers

  • Aria
    Aria Member, Employee Posts: 65
    First Anniversary Ansys Employee First Answer Name Dropper
    edited June 2023
    Options

    You could try using "with" to access the RST:

    with dpf.Model(Analysis.ResultFileName) as myDS:
        # code block...
    

    If you use streams:

    import mech_dpf
    import Ans.DataProcessing as dpf
    mech_dpf.setExtAPI
    
    
    analysis = Model.Analyses[0]
    dataSource = dpf.DataSources(analysis.Solution.ResultFilePath)
    mech_dpf.setExtAPI(ExtAPI)
    streams = mech_dpf.GetStreams(0)
    def get_all_conta_elems(streams):
        op = dpf.operators.scoping.on_property(
                                    property_name = "mapdl_element_type",
                                    property_id = 174,
                                    requested_location = "Elemental",
                                    streams_container=streams)
        conta_elems = op.outputs.mesh_scoping.GetData().Ids
        return conta_elems
    
    con_elem = get_all_conta_elems(streams)
    streams.ReleaseHandles()
    
  • Adrien Vet
    Adrien Vet Member Posts: 10
    Name Dropper Photogenic First Comment
    edited June 2023
    Options

    Thanks for your reply,

    Unfortunately, when I try "with", it tells me this error :

    Indeed, the dpf.Model(analysis.ResultFileName) has not attribute named "__exit__" to exit the file :

    1. >>> print(dir(dpf.Model(analysis.ResultFileName)))
    2. ['AvailableNamedSelections', 'CreateOperator', 'DataSources', 'Equals', 'GetHashCode', 'GetNamedSelection', 'GetType', 'MemberwiseClone', 'Mesh', 'MeshProvider', 'ModelsResults', 'ReferenceEquals', 'ReleaseStreams', 'ResultFilePath', 'ResultInfo', 'ResultInfoProvider', 'SetResultFilePath', 'StreamsProvider', 'TimeFreqSupport', 'TimeFreqSupportProvider', 'ToString', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'results']


  • Adrien Vet
    Adrien Vet Member Posts: 10
    Name Dropper Photogenic First Comment
    Options

    The code lines you propose seem to solve my problem.

    Thank you !