In a previous article, we detailed the process of calibrating a material model for Ansys Mechanical using optiSlang entirely within Ansys Workbench. In this series of articles, we will detail the same process using PyAnsys with the Stochos 6.0.2 Python 3.12 library from Probabilistic Intelligence using both Ansys Workbench and an external Python script.
The following steps are required to complete the entire calibration; the boldface items will be discussed in the current article:
PyAnsys and Stochos are Python 3.12 libraries. It is recommended to create a virtual environment or, even better, an Anaconda Python environment into which you can install both PyAnsys and Stochos. We will not discuss these matters any further in this article.
Recalling the model setup detailed in the previous article, we specify the bounds and units for the Voce hardening material model parameters as follows, noting that all of these parameters are of continuous type:
Parameter |
Units |
Bounds |
Young's Modulus, E | MPa | [160000, 200000] |
Initial Yield Stress, S0 | MPa | [1100, 1600] |
Linear Hardening Coefficient, R0 | MPa | [1, 1000] |
Exponential Hardening Coefficient, Rinf | MPa | [400, 900] |
Exponential Saturation Parameter, b | None | [160, 400] |
Stochos requires the bounds and types to be in lists. Here is a code snippet for said parameter definition:
The Workbench model that we use is a simplified version of the one used in the previous article. Here, we only require the Parameter Set to be maintained, shown here, noting the input parameter IDs:
To keep parameter information organized, we set up a dictionary in Python:
In the project user_files directory, we have the reference signal file, force_displacement_ref.txt, which is in the following format, noting that we added a (0,0) point at the beginning:
When the model is solved, a file of the same format, force_displacement_sim.txt, is generated by APDL commands and stored in the dp0\SYS\MECH project folder. We will read this file after each model solution and process it as part of the optimization process.
Finally, we must ensure that the model can be solved across the entire range of the parameter bounds so that we can automate the parametric study. This model has been run at all corner cases and shown to converge in all cases.
For the overall code, we import the following libraries:
Stochos provides readily available objective and constraint functions through the vast example library. Here, we regress simulation signals to a reference signal, so we modify the example functions to implement the following:
Note the acq_func="SEI" line in the optimizer definition, which is appropriate for signal regression.
To begin the optimization process, we need to run a start DOE to generate data for DIMGP model training. Based on the optimization and constraint functions, Stochos readily creates an optimal, space-filling design:
We store the resulting "DOE_start_design_matrix.csv" file in the same directory as the Workbench model for ease of retrieval.
PyWorkbench is a PyAnsys module that we use to launch and control Workbench through external Python scripting. To get started, we define important directories and paths:
Next, we need Workbench command strings, in IronPython format, which control Workbench and set parameter values in Workbench.
Having these control strings, we launch Workbench 2025 R1, showing the GUI using the code:
At the end of the full Python script, we close Workbench gracefully using the command:
The function that runs and analyses the start DOE design points applies the following algorithm:
Here is the code for this function in two pieces:
The following snippet shows the code to control the process, noting that some parameters are not shown:
After running the start DOE, we obtain 13 (out of 30) valid simulation signals (that have positive everywhere gradient).
Also, we obtain a start sensitivity analysis from Stochos that shows which parameters are most important. Evidently, R0 is not an important parameter.
Finally, the summary data shows that run 5 has the lowest L2 distance to the reference signal, but yet there is a need to optimize in order to obtain a better calibration.
In conclusion, we showed the first part of the process for using Stochos and PyAnsys to optimize a material model within Ansys Mechanical. We showed how the process of updating parameters and solving the model can be automated using PyWorkbench. Additionally, we showed how Stochos can provide a start DOE to train a DIMGP model to be used for future optimization. Finally, we showed how a straightforward Python script can be used to automate the entire process.
In Part II of the series, we will explore the process of optimization to obtain material model parameters that provide a minimal L2 distance.
Download the following .zip file to obtain the Workbench project and Python code to reproduce the results in this article: Ansys 2025 R1 model archive and Python code