Load output of PyMechanical Script to PyDyna

cardiac.scripter
cardiac.scripter Member Posts: 6
First Comment
**

I have a .mechdat file output from a previous sim in PyMechanical. How can I load it as an input mesh for subsequent simulation in PyDyna?

Thanks in advance

Comments

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 287
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited January 13

    Hello

    One approach is in Pymechanical to generate the k file (also define all of the LS-Dyna loads/bc if one wants), which you can then import into pyDyna.

    To generate the k file in pymechanical use:

    analysis = Model.AddLSDynaAnalysis()
    
    
    analysis.WriteInputFile('D:\\mypymechkfile.k')
    

    Then import the k file into PyDyna

    Thank you

    Erik

  • cardiac.scripter
    cardiac.scripter Member Posts: 6
    First Comment
    **

    Hi Erik,

    So construct a model from the mechdat file within PyMechanical with the deformed geometry. Then save that as .k file with the lines above.

    Have I understood you correctly?

    Cheers

  • cardiac.scripter
    cardiac.scripter Member Posts: 6
    First Comment
    **

    Just because I want to use the deformed geometry from the result of the PyMechanical script as the starting geometry for the PyDyna script.

  • cardiac.scripter
    cardiac.scripter Member Posts: 6
    First Comment
    **

    I realised an oversight on my part.

    I need the .rst file.

    However, I am struggling to load the .rst file with PyMechanical. Once in PyMechanical its easy to then follow your instructions.

    Would you suggest opening in pyDPF? I was thinking to go down this route, but I can't find documentation of then saving in PyDyna format.

    Ben

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee, GitHub-issue-creator Posts: 347
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    I am struggling to load the .rst file with PyMechanical.

    You might find this discussion useful:
    https://discuss.ansys.com/discussion/3460/which-scripting-part-or-pyansys-modules-can-i-use-to-obtain-results-in-the-avz-format

  • cardiac.scripter
    cardiac.scripter Member Posts: 6
    First Comment
    **

    Hi Landon,

    Thanks for this.

    I have downloaded the library and tried the method.

    It worked, thank you Erik and Landon.


    ```python
    from ansys.mechanical.core import App
    import sys
    import os
    from ansys.mechanical.core import global_variables

    library = r"C:\Users\XXX\Scripts\ResultsFileMechReader"
    result_file = r"C:\Users\XXX\StaticStructural\file.rst"

    outfolder = os.path.split(result_file)[0]
    app = App()
    globals().update(global_variables(app))

    sys.path.append(library)
    sys.path.append(r'C:\Program Files\ANSYS Inc\v242\aisol\DesignSpace\DSPages\Python'.format(app.version))

    import RunAPDL
    RunAPDL.Initialize(ExtAPI, Ansys)
    SI, CdbPath = RunAPDL.GetCdbFileFromResultFile(result_file)

    import RunMech
    RunMech.Initialize(ExtAPI, Ansys)
    RunMech.ImportResultsToCurrentSession(CdbPath, result_file, library)

    results =ExtAPI.DataModel.GetObjectsByType(Ansys.Mechanical.DataModel.Enums.DataModelObjectCategory.Result)

    Set units

    ExtAPI.Application.ActiveUnitSystem = MechanicalUnitSystem.StandardNMMdat

    analysis = Model.AddLSDynaAnalysis()

    dyna_file = r"C:\Users\XXX\stress_free_mesh.k"
    analysis.WriteInputFile(dyna_file)


  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 287
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    Hi @cardiac.scripter

    That is great.

    In this way do you export to the LS-Dyna k file a deformed geometry (as per rst file)?

    Erik

  • cardiac.scripter
    cardiac.scripter Member Posts: 6
    First Comment
    **

    Hi Erik,

    Yes I can. Works well.