Simple low-speed impact MD simulation
This is a simple 3d molecular dynamics (MD) simulation of a low-speed impact. This is a simple demo-code with rigid (spherical) body interaction including rotation and a simple phenomenological friction model with an easy-to-understand first-order ODE integrator (Euler method).
What is being done
This is a molecular dynamics (MD) simulation of a number of spherical particles which are each characterized by radius, mass, inertia, position, velocity and angular velocity. The simulation computes the interaction forces of each particle with all other particles and numerically integrates the Newtonian equations of motion. I.e. the sum force on each particle gives its acceleration which is used to calculate new speed and position taking a tiny time step. With updated state (speed,...), the force is calculated again, etc.
The following forces are considered:
The simulation includes translational and angular velocities and also computes the corresponding forces, i.e. if two particles collide non-centrally, they spin afterwards.
The numerical integrator is an Euler-type first order integrator as explained above: With tiny time steps, forces give new (translational and angular) speed and new speed gives new position. Nothing fancy but very easy to understand.
And what can you do with it? For example the simulation of a low-speed impact in granular media as presented below. However, the number of balls in the sim is limited by your computer's performance...
The simulation program can be downloaded below. But please note that the source code presented here is not complete. The reason is that it depends on some external numerics templates which in turn depend on tons of other code. So, for now, I decided to only publish the simulation core while general math routines (such as cross product,...) are not included. Hence, if you want to play with it, you first need to understand what is being done to fill the gaps.
When started, the simulation will compute the motion of all particles except the impact bullet ball. Leave the sim running this way for a while until the sand balls have settled down. Then, start the bullet ball by pressing 's'. This will also start the frame ouput.
The graphical display is an x-z projection of the 3d area: Looking into the screen you look along the y axis onto the x-z-plane. Only the center part (usually including the bullet ball) is displayed to keep things well visible. Fancy 3d visualisation can be done afterwards.