Lesson3.1 BasicScripting
Lesson3.1 BasicScripting
1 – Basic Scripting
This lesson will demonstrate how to make your own script using the EDEMpy library. We will start by
stepping through a very basic example which calls functions and attributes from the EDEMpy package to
access data from a simulation.
Note, when creating scripts you can use any Python IDE of your choosing, or none at all if you prefer.
Spyder is used as the script editor throughout this course. Altair Compose is another good option.
We will create a simple script which extracts data from this simulation of a Rock Box. The script aims to
output the pressure on the Rock Box walls at the last timestep.
First, save a new Python file to the directory of your EDEM simulation files. Next, start any script by first
importing the EDEMpy packages required to call the functions you wish to use. Here import the ‘Deck’
package and define a callable variable, Deck, to access data from a specified simulation file. By appending
appropriate attributes from the deck class, you can access the different simulation properties of the
particles, geometry and interactions.
The following commands call the number of timesteps and their values from the simulation via the deck
class. As mentioned earlier in this course, the attributes and functions of the classes can be found in the
EDEMpy documentation.
The following attribute obtains a list of the geometries within the model.
Next, we look at calling functions. In this case we are interested in the contacts between the particles and
the geometry walls at the last timestep. By consecutively calling the timestep and contact classes you can
output the number of contacts, and the contact array. If we run this, we see the following output. The
first and third columns of the contact array represent the following.
Since we are only interested in the contacts between the particles and the Rock Box walls, we need to
create an index from the contact array. Having printed the geometry names earlier, we can see that we
need to store the indices of all the contacts with the geometry ID, zero, in the third column.
Next, we obtain the normal and tangential forces at the last timestep with the following functions. By
appending the index which we just created from the contact array, only the forces on the Rock Box walls
are outputted.
To find the magnitude of each individual force vector, a function from the Python NumPy package is used.
Add the NumPy package to the beginning of your script. To find the total force on the Rock Box walls, the
magnitudes of each force vector is summed.
Finally, since stress is equal to the force divided by area, the total normal and tangential stress on the
walls is found by dividing the respective total forces by the area of the walls. Running the full script gives
the following.