How to automate Ansys Mechanical using Python?

AhmedzeidAhmedzeid Member Posts: 12

Hello all,

I am writing a code in Python that carries out the helical compression spring design process. It can for example solve for the required spring wire diameter given the load applied. I wish to send the design parameters (wire diameter, applied load, number of coils, etc...) to Ansys to perform a simulation for it and plot the stress profile for this particular design.

How can I automate such process, such that my Python code would automatically send these information to Ansys for it to automatically run the simulation using these information?

Any help would be appreciated.

Regards,

Ahmed Zeid

Best Answer

Answers

  • AniketAniket Ansys Employee Posts: 1,211

    If you are using parametric geometry you can create multiple design points to simulate this. (https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v211/en/wb2_help/wb2h_parmdespt.html) Do you want to automate the result post processing as well? If yes, you can take a look at the Mechanical automation APIs here:

    ANSYS Store Developer Resources

    and

    https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v211/en/act_script/act_script.html

    -Aniket

    How to access Ansys help links

    Guidelines for Posting on Ansys Learning Forum

  • AhmedzeidAhmedzeid Member Posts: 12

    Thank you for your reply, @Aniket


    I am indeed working with a parametric geometry, as I have generated a script for a CAD software that will receive the geometry details from my python code, generate the geometry and later export it to Ansys to run the simulation.

    First, and as for the parametric simulation recommendation, I looked it up, and it actually looks like it might work for my case. However, I wish to write a general simulation script that will work as my template for all different designs, and hence change the applied force parameter for example (inputted by user in the python code) and run the simulation using this force and the previously imported geometry, then finally do the postprocessing in the form of a stress profile plot. I tried to record this general script (the template) from Mechanical (using the script recording beta feature in my 2020R2), but unfortunately the parametric design steps were not caught in the script as they took place in WB not inside Mechanical as I understood. Is there a way where I can write the portion of the script that is related to the parametric design and postprocessing manually? Please note that I do not need multiple design points, as I am running only one simulation by spring design (i.e. design point).

    Secondly, would it be a good idea to, generate a template Macro on MAPDL, then to run the simulation I would export my geometry file to MAPDL, change the parameters and real constants in the template Macro and run the simulation instead of the first point?

    Thirdly, as I understood, ACT can help you do things such as customizing a data input GUI. I tend to run my simulation in the background, and only show its results in my python code. Would I still be needing ACT, since I am not visually interacting with ANSYS at all during the simulation?

    Lastly, I am actually using Ansys products installed on university machines, and hence do not have access to Ansys customer portal. Would you mind if you mentioned the titles of the documents instead of the direct links please? Perhaps I can find some information about them online.

    I am sorry if my question was too long, as this is my very first attempt with Ansys automation and I am a bit confused with all the material I found online during my research. Please feel free to answer whichever parts of my question you would like to.


    Thank you once again for your help,

    Ahmed Zeid

  • AniketAniket Ansys Employee Posts: 1,211
    1. If a standard feature of parameters would work I don't think you need to script that, you can only script that part that is not covered in the standard feature, like exporting the images for each design point
    2. Sure, if you are comfortable with APDL, instead of python and ok with the legacy graphics for image export and have your geometry properly tagged for faces/edges that are used for BCs using named selections/components, you can use APDL code to automate this instead of ACT
    3. ACT can automate things in batch too, but for result image capture I think it will need a GUI as far as I am aware.
    4. Please check the first link in my signature to access those links. If you are still not able to access those links please let me know!

    -Aniket

    How to access Ansys help links

    Guidelines for Posting on Ansys Learning Forum

  • AhmedzeidAhmedzeid Member Posts: 12
    1. I understand that you're suggesting that I don't script the standard features available in Mechanical because I can just do it manually. If my understanding was correct, then that's probably not the best suited for my case, as the simulation should be done automatically with absolutely no interaction from my side with Mechanical. That's why I wanted to script the whole thing.
    2. I found that MAPDL would be more suited for my case as it is faster to load up and solve than Mechanical. I tend to do this by creating a CAD file, converting it to IGES, exporting it to MAPDL, apply SOLID187 element to it to make nodes, and carry on with the meshing, BC, .etc... (The whole process is Macro recorder). Do you think that I am missing any steps or most likely to run into problems using this approach?
    3. Just for reference, I found out about this module called PyMPDL. It's such a convenient and powerful tool whenever Python/MAPDL integration is needed. https://mapdldocs.pyansys.com/#
    4. The Ansys help links worked out perfectly for me. Thanks a lot!


    Regards,

    Ahmed Zeid

  • AniketAniket Ansys Employee Posts: 1,211
    Accepted Answer

    2 . I don't think you will run into problems if you are able to import the iges files without any issues.

    3 . Good find! Best luck!

    -Aniket

    How to access Ansys help links

    Guidelines for Posting on Ansys Learning Forum

Sign In or Register to comment.