Parameterizing a Python code data into mechanical for the opt analysis

Rosse7
Rosse7 Member Posts: 7
First Comment
**

Hi, in my Static Structural Analysis I added an APDL command snippet and an after-post Python (in CPython language) code object in solution branch.
With the APDL script I saved some numeric results data as csv file subsequently read and manipulated with the Python code object generating a new array.
Then, I would need to set it as new output parameter so that it will appear (and obviously its value as well) in the output parameter set for the optimization analsysis, but I don't know how to do it.
Thank you

Comments

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭

    Hi,
    a couple of comments:

    • CPython in Mechanical is beta, which means we do not guarantee it will work and do not provide support over it.
    • Your workflow seems somewhat convoluted. Why use an APDL command snippet? You can embedded APDL commands in the Python Code object, and, most probably, you can retrieve the results that you are looking for without having to use APDL (Mechanical Automation API, DPF, ...)
    • To define that outputs of a Python Code object can be a parameter, you simply have to edit the property provider accordingly (prop.CanParameterize = True). Further info available here: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v242/en/wb_sim/ds_python_code_Property_Provider.html
  • Rosse7
    Rosse7 Member Posts: 7
    First Comment
    **

    Hi,
    I used APDL to access the force reaction step results and save them in a csv file that I subsequently retrieved and processed with the python code and finally, after some simple math operations, I obtained a new output array.
    Sincerely, I expected that the parameterization of this array value (e.g. [k]) was possible by simply adding just one line code like, for instance, in APDL with *GET,my_par, ...

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭

    These results can be directly accessed through Mechanical automation API and/or DPF. You do not need to use APDL nor to write to an external file, which will take some time. In Mechanical, you can define that scalar values are parameters, but not table values.

  • Rosse7
    Rosse7 Member Posts: 7
    First Comment
    **


    As you can see I added the property k as parameterizable but it has not any value; in my case I'd want "<?WORD FLAGGED?>" value (e.g. = 2) in k array.
    Can you show me, please?
    Sorry but I really don't know how to do.
    Thank you

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭

    In principle, if K was a scalar value and if you were using Iron Python, if you check the tick mark next to it, K will become a parameter. If it's defined as an input parameter, you can then change its value from the parameter set in the WB project page. If it's an output parameter, you'll get the computed value by solving the model.
    Again, you're using CPython here, so there is no guarantee it'll work, and also there is no way I'm aware of to parametrize a complete array, just scalar values.
    Have you considered using PyMechanical instead of Mechanical Scripting ? Maybe it'll make your workflow easier. https://mechanical.docs.pyansys.com/version/stable/

  • Rosse7
    Rosse7 Member Posts: 7
    First Comment
    **

    I have to try first with CPython and if it definitely does not work I will surely change in Iron Python or PyMechanical as you suggest.
    But before that I need to understand just one thing, please.
    From the picture attached you can see how I add the new property/parameter in the property provider but I have not still assigned its value and this is the reason the value cell is empty (or not active).
    By assuming that the value I want to assign is 10, then a scalar, how can I modify the property provider in order to do it ?
    Only this and if it is not possible I will change method, I promise :)
    Thank you

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 871
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭

    The value of the property needs to be defined in the "Script" tab. From the help page I shared above: