libgran: a C++ template library for DEM simulations
libgran is a C++ template library for Discrete Element Method (DEM) simulations. DEM is a technique for simulation of granular media consisting of rigid spherical particles.

Background
DEM is a technique for simulation of granular media consisting of rigid spherical particles. The resultant force and torque acting on each particle are computed and used with Newton’s second law to compute the motion of particles:
The forces that particles experience arise from friction at inter-particle contacts, bonding between particles, inter-particle attraction, field forces, etc. libgran contains a bonded and a non-bonded contact model, a Van der Waals attraction model and is designed to be easily extensible with custom models.
Included force models
Contact force
The contact model is based on constraining the four degrees of freedom of motion of two particles relative to each other: normal translation, tangential translation, torsion, and rolling. Let us consider two particles i and j. We can begin by defining a unit normal vector:
The relative velocity at the point of contact is:
where is particle radius corrected for inter-particle overlap/separation, is particle translational velocity, and is particle angular velocity. Relative velocity can be decomposed into normal and residual (tangential) components:
Similarly, relative angular velocity:
can be decomposed into normal (torsional) and residual (rolling) components:
To constrain the four degrees of freedom, we insert four springs, as illustrated in the featured image. The length of the normal spring, , can be computed directly at any point in the simulation from positions of the particles, , and their radius, :
The remaining three springs have zero length at the time the contact is formed and have their lengths accumulated throughout the duration of the contact. Let a spring vector be . Then the rate of stretching / contraction of a spring, , is given by:
Then, as long as the contact lasts, spring is incremented at each time step to obtain a new spring, , to be used at the next time step:
Bonded contact force
For a pair of particles that is connected with a rigid bond, we would like to approximate a rigid-body motion. In other words, the common reference frame of particles i and j can rotate and translate, but any translation or rotation of particle i relative to particle j should be restricted. The distance between all points in the pair of particles should be approximately preserved over time. It can be shown that when using the springs defined in the contact force section to restrict the motion of particles i and j, then the union of particles i and j will undergo rigid body motion as the stiffness of inserted springs approaches infinity. In the simulation we need to use a finite stiffness value, but as long as the amplitude of oscillations is much smaller than the length scale of particles in the simulation, the motion will, approximately, be rigid.
To stabilize the system over time and dissipate any vibrational kinetic energy in the bonds, each spring is supplemented by a dashpot element. The force, , exerted on particle i by each spring in the i-j bond is given by:
where is stiffness and is the damping coefficient of the respective spring. And forces exerted on particle j are equal in magnitude and opposite in direction. Forces arising from the normal and tangential springs are applied to the particles. The force associated with the tangential spring will also give rise to torques because the tangential force is not collinear with . Forces computed from the torsion and rolling resistance springs are quasi-forces that are not applied to particles i and j, but are only used to compute torques that will be applied to the particles.
Frictional contact force
The model described in Luding 2008 is used to simulate frictional contacts between non-bonded particles. A brief description is provided here and the reader is referred to Luding 2008 for a more detailed description. Luding’s model uses the same four springs described in an earlier section to compute normal and tangential forces, rolling and torsion resistance torques. Instead of directly setting force proportional to spring elongation, a certain degree of slip is allowed between particles in contact. That is done by computing a test force, :
and deciding whether static or dynamic friction should be used based on Coulomb’s law of friction:
where is the static friction coefficient, is the dynamic friction coefficient, and is the magnitude of the normal force between the two particles. Then a choice is made whether static or dynamic friction should be used based on the following condition:
In case the contact is determined to be in the state of static friction, the tangential spring is incremented as described in contact force section and the test force is used to compute torques and, in the case of the tangential force, is also applied to the contacting particles. In case the contact is determined to be in the state of dynamic friction, the spring is not allowed to stretch anymore. Instead, a certain extent of slipping is allowed. The spring to be used at the next iteration, , is set to
and the magnitude of the Coulomb’s force, , is used to compute torques and, if applicable, accelerate the particles in contact.
The model is only enabled when the normal force is repulsive. Once particles are not overlapping, the frictional force is set to zero and accumulated springs are reset.
Van der Waals attraction force
Hamaker 1937 derived the potential energy, , due to Van der Waals attraction between two particles of radius whose surfaces are separated by distance from each other to be:
where is the Hamaker constant - a material property. The magnitude of force acting on the particles can be derived by differentiating potential energy, , with respect to separation distance, , and the direction of the force will coincide with the normal unit vector defined earlier:
Since in the limit as approaches the magnitude of force (and potential energy) becomes infinite, a saturation distance is introduced. Attractive force does not increase past the saturation distance. The magnitude of varies between 0.4 and 1 nm (Ranade 1987).
Available software
Source code is available on GitHub.
Documentation
Comprehensive documentation, including tutorials and class reference, is available externally.
Acknowledgement
- Project funded by U.S. National Science Foundation, award #AGS-2222104