Need help defining a "Python Result" custom plot for a path.

Kev
Kev Member Posts: 41
10 Comments First Anniversary 5 Likes Name Dropper
**

Hi again :) Would anyone have a sample "Python Result" code for drawing stresses on a path? (Similar to user defined plots on a path)

Don't quite know where to look or where to begin.

Thanks

Best Answer

Answers

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

    Hi @Kev , maybe this example could help: https://dpf.docs.pyansys.com/version/stable/examples/06-plotting/04-plot_on_path.html#sphx-glr-examples-06-plotting-04-plot-on-path-py

    This example is for PyDPF so uses a CPython implementation of DPF. But it could be adapted to an Iron Python implementation to work in a Python Result.

    Please note that this example maps result stress onto a path. This is not equivalent to plotting linearized stress.

  • Kev
    Kev Member Posts: 41
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Hi @Pernelle Marone-Hitz . Thanks again for the help. This is quite close to what I intend to achieve. I can run the code in python launcher and it does the plotting which gives me a starting point. However, I need assistance in making the code address my results file/ model as opposed to the sample one :

    model = dpf.Model(examples.find_simple_bar())

    In VBA we could get the current/active instance of the application of interest and navigate from there ( get to the attribute or property of interest).

    I Don't know how to achieve this with python and ansys.

    • Where can I find the API reference documentation on this area?
    • What would be the easiest way to debug "Plot Result" codes and Cpython codes like the one you sent me a link to? I cannot use Ansys's shell to debug these can I?

    Thanks again

    Cheers

  • Kev
    Kev Member Posts: 41
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Thanks again @Pernelle Marone-Hitz . I like how the help document has sample code showing how to implement methods or to use the function similar to VBA help documents.

    Pernelle, for the purposes of our ACT it would be amazing if I could somehow change the values of the user defined chart that I have set up on a path geometry to some custom values(calculated weld throat) and regenerate the results ! To your knowledge, is this is something that can be achieved ? the reason I want to take advantage of the user defined plot is that it already contains the path and the body associated with the path (bodies dictate the element orientation).

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

    @Kev , yes that seems doable, but not by "changing" the values per say. I would recommend creating a Python Result, from which you'll be able to display on the model / path any value that you want.

  • Kev
    Kev Member Posts: 41
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Hi @Pernelle Marone-Hitz thanks so much. I also came to the same conclusion. I now have a working process using the python results. Just need to work out a way to line up the calculated values to their corresponding nodes. As you know, the user defined results scoped to paths have the stress values according to the distance traversed on the path, so no nodeID's are recorded in the PlotData! only coordinates! I have to find a way to get the node Ids corresponding to those coordinates. At the moment I am using a displacement plot scoped to the path's parent edges to provide me with a list of nodeIDs. However I am having trouble finding the coordinates of a node knowing its ID. Would you know a good way to do so without using the mapdl core or pyvista?

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

    Hi v@Kev as you seem to be in Mechanical (using a Python Result object), I think the easiest way to go to get the coordinates of nodes would be through MeshData. See here: https://discuss.ansys.com/discussion/comment/595#Comment_595

    You'll also have access to meshData.Nodes and their coordinates through there.

  • Kev
    Kev Member Posts: 41
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Thanks @Pernelle Marone-Hitz . It worked great :) . Sorry I was away on another project.

    May I ask why is the 'Value' that is returned by the 'Node' key in the PlotData property of a displacement plot ( defined on an edge) different form the actual node IDs? I was hoping that I could get the node IDs of interest via that method.

    In any case, I have paths (or their corresponding edges) that I'd like to extract ID's of the Nodes that lie on them using mechanical scripting. Would appreciate a nudge in the right direction with this one as well.

    Thanks again Pernelle

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

    Hi @Kev , I'm happy to help but please open different threads for your different questions, it'll be easier for us to handle.

    The node ids should be the same whether you retrieve them through plot data or through mesh data. Please create a new post for this and share an example I can reproduce.

  • Kev
    Kev Member Posts: 41
    10 Comments First Anniversary 5 Likes Name Dropper
    **

    Sorry for that @Pernelle Marone-Hitz . Will do :)