In this lesson, we cover how to run the same analysis completely in Python using PyMAPDL. Using PyMAPDL, one of the PyAnsys packages, we can run crystal plasticity simulations completely in Python without having to open any graphical user interfaces, which can be beneficial for running parametric studies.
Before you proceed, you need to install PyMAPDL following the instructions here Getting started — PyMAPDL. The example Jupyter Notebook can be downloaded here:
Download the Jupyter Notebook here.
We start by loading all required libraries and provide file names to the .cdb and .dat files generated in previous lessons:
We then launch PyMAPDL and set the appropriate unit system:
Now, we read the mesh contained in the .cdb file, and show a shape check summary:
Turn on automatic element technology control, which is the default when running the simulation from Mechanical as in Lesson 5:
Get the maximum and minimum coordinates values of the nodes, and use those values to select appropriate boundary surfaces to apply boundary conditions:
Insert solution control, turn on auto time stepping, large deformation formulation, and use the sparse direct solver:
Use the input command to read the material assignment .dat file generated in Lesson 4:
Now, we can solve the analysis:
We can post-process the results to generate the stress-strain curve:
We can visualize the stress contour with Pyvista:
Finally, we safely close and exit PyMAPDL: