Skip to main content

Introduction

In Ansys Mechanical models, very often there is a need to post-process equivalent stress or total deformation or the like for many solid/surface bodies or groups of them.  Using Named Selections, grouped in a Tree Grouping folder, one can write a Python script in Mechanical to auto-generate the results objects.  Moreover, once can then take the newly created results objects and export the results for all result sets to a .csv file, again, using a Python script in Mechanical.  In this article, we will explore the use of two Python scripts in Mechanical to accomplish both tasks.

Model Preparation

To generate the Equivalent Stress results objects, and Tree Grouping folder of Named Selections needs to be available.  One can auto-generate such Named Selections for solid bodies using Python scripting as well as one can add manually created Named Selections to a Tree Grouping folder called "Results Scoping."

Results Objects Creation

The creation script add_eqv_stress_post_proc_for_all_named_selections.py will create an Equivalent Stress results object for each Named Selection in the Results Scoping folder and place them in a Tree Grouping folder, named Eqv Stresses for Named Selections: Results Scoping for post-processing objects as shown below.

The script loops through all of the analyses in the model by analysis number.  The following snippet shows input parameters to the script:

Here, analysisNumbers is a (comma-separated) list of analyses for which to create Equivalent Stress results objects by reading the Tree Grouping folder of Named Selections defined by NAMED_SEL_FOLDER.

Exporting Results to CSV File

Once the Equivalent Stress results are created, then the script read_eqv_stress_table_at_all_times.py will read the full table of each Equivalent Stress result in the Eqv Stresses for Named Selections: Results Scoping folder and write a CSV file into the user_files directory in the Workbench project.  The following snippet shows the parameters that can be adjusted for this script.

Here, again, analysisNumbers is a (comma-separated) list of analyses for which to read Equivalent Stress results objects by reading the Tree Grouping folder of Equivalent Stress results defined by RESULTS_FOLDER.

Conclusion

In conclusion, using scripting in Ansys Mechanical, it is relatively straightforward to automate results generation and extraction.

Going Further

  • Contact Ozen Engineering for your Mechanical scripting needs.  There are expert consultants ready to support such requests.
Downloadable Resources

PyMechanical scripts and example exported results file

 

Mark Lytell
Post by Mark Lytell
October 29, 2024