General Mechanical

General Mechanical

Topics relate to Mechanical Enterprise, Motion, Additive Print and more

Python Result at any time step of Transient Structural in Ansys Mechanical

    • user deleted
      Ansys Employee


      Due to several reasons, I have to use "ERESX,NO" APDL command during my solution. With this command, all results are shown as integration point results copied to nodes, which gives lower overall stresses. I wrote a simple Python Result script that extrapolates results to nodes and shows stresses as the right node result (values are identical to ones without the ERESX command). Hovewer, results are shown only for one step, and they don't change when I choose a different time ("retrieve this result" button). Are there any commands to change the displayed values for any chosen time? Or is the only solution to create new results for each time-step needed and display them separately?

      The best possible variant is for Python Result to be exactly the same in terms of functionality as ANSYS basic results (i.e., results work at any time, animation across time is possible, e.t.c.).

      Code used is shown below.

      def post_started(sender, analysis):# Do not edit this line

      def define_dpf_workflow(analysis):
          import mech_dpf
          import Ans.DataProcessing as dpf
          # get integration points (Gaussian points)
          data_source = dpf.DataSources(analysis.ResultFileName)
          # get mesh
          model = dpf.Model(data_source)
          mesh = model.Mesh
          # Von Mises op
          von_mises_op = dpf.operators.invariant.von_mises_eqv_fc()

          # create stress operator and get stress results(6) in the integration points
          stress_op = dpf.operators.result.stress()
          # set time scoping
          time_scoping = dpf.Scoping()
          number_sets = stress_op.outputs.fields_container.GetData().GetTimeFreqSupport().NumberSets
          time_scoping.Ids = range(1, number_sets + 1)

          # extrapolate results from gauss points to nodes
          gauss_to_node_op = dpf.operators.averaging.gauss_to_node_fc()

          # get von mises stress
          avg_mises_op = dpf.operators.averaging.elemental_nodal_to_nodal_fc()
          dpf_workflow = dpf.Workflow()
          dpf_workflow.Record('wf_id', True)
          this.WorkflowId = dpf_workflow.GetRecordedId()

    • mrife
      Ansys Employee

      Hi Aleksandr

      Instead of:   

      number_sets = stress_op.outputs.fields_container.GetData().GetTimeFreqSupport().NumberSets

      time_scoping.Ids = range(1, number_sets + 1)

      Try this instead (don't use your number_sets at all):

      timeScop.Ids = [i for i in range(1,model.TimeFreqSupport.NumberSets+1)]

      Then add that timeScop to the result operators

      • user deleted
        Ansys Employee

        Hi, Mike!

        Changed the mentioned lines to the following:

            time_scoping.Ids = [i for i in range(1, model.TimeFreqSupport.NumberSets + 1)]

        Regarding the addition of it to the result operator, you mean adding it to the elemental_nodal_to_nodal_fc/gauss_to_node_fc similar to the last string above, right? If this is the case, I believe this cannot be done to these operators (according to the PyDPF online help; see screenshots below; these operators do not have time scoping inputs).

        After changing the code, my result is shown below. Only the first step is visible; pressing on different time steps has no effect. Am I missing something? I'm new to this and may be doing something wrong.



    • mjmiddle
      Ansys Employee

      Do you have a property provider which creates fields in the Details, and then sets the value of those fields for the display time or result set chosen? Your code produces this:

      The purpose of the "Retrieve this result" when a time history step is chosen in a native result is to populate the Details. Here is a native von Mises result:

      The purpose of "Retrieve this Result" is to populate the fields sich as Maximum, Minimum, etc... in the Details for the time set (0.5 s) above. If you have not written fields in the Property Provider for this and supplied the code to fill in these fields, then the "Retrieve this Result" is meaningless. Note that you can retrieve the individual data from the field to get data for each time.

      Also, I'm not sure why you added the elemental_nodal_to_nodal_fc() operator section when you have already have the operator gauss_to_node_fc().

      • user deleted
        Ansys Employee


        It looks like I do not have it (property provider), as all I added is this python result, and that’s all. I didn’t know about this and will look more into this thing.

        My interest in the “Retrieve this Result” button is only to display another time step. For a normal result, displaying could be done by clicking on the graph; however, you can enforce it changing using the retrieve option. I wrote about this option, thinking it should be similar in the python result. As of now, only the first time step is shown unless I change the time step used in the code.

        My result looks like this, no play/stop button. May it be because analysis is Transient? I wish to see python result produced by the gauss to node operator at any time step, but it doesn’t work for me at the moment.

        I added “the elemental_nodal_to_nodal_fc()” operator as done in PyDPF help example “04 extrapolation stress 3d”. There it is used in order for the mesh.plot function to work, I believe, but may be here it is unneccessary, I didn’t check if that’s the case.


        Tried using my python result in Static Analysis; only first result is shown again, and there are no play/stob/e.t.c. buttons. I’m not adding/using/turning in something needed for this, perhaps?


    • mjmiddle
      Ansys Employee

      Even if you use the property provider to make your own fields, such as a time field, and include the code to fill in more fields with the data at the time entered in the field, it will not be triggered to popolate this field or run the callback when you click in the graph or table and choose "Retrieve This Result." If you really want it to behave this way, you need to create an ACT extension that defines this result. This has an accompanying XML file that determines the Outline objects that can be added from your extension.

      Have you made an ACT extension before? There an an ACT training for Mechanical in the Ansys Learning Hub:

      There is also information in the online help for creating ACT extensions. See this page for creating ACT extensions with result objects:


      • user deleted
        Ansys Employee


        Uh-oh, got it. This will be my first time using ACT and I will look more into it then.

        Alternatively, I think something similar can be done using only rst file and Python with the help of PyDPF and pyplot, however I am not sure which is easier. 

        Anyway, many thanks for the help!


Viewing 3 reply threads
  • The topic ‘Python Result at any time step of Transient Structural in Ansys Mechanical’ is closed to new replies.