# Stable algorithm for event detection in event-driven particle dynamics

## Abstract

Event-driven particle dynamics is a fast and precise method to simulate particulate systems of all scales. In this work it is demonstrated that, despite the high accuracy of the method, the finite machine precision leads to simulations entering invalid states where the dynamics are undefined. A general event-detection algorithm is proposed which handles these situations in a stable and efficient manner. This requires a definition of the dynamics of invalid states and leads to improved algorithms for event-detection in hard-sphere systems.

## Keywords

DEM Event-driven Molecular dynamics Hard sphere Collision detection## 1 Introduction

Event-diven particle-dynamics (EDPD) is the oldest particle simulation technique [1] and has found application in a wide range of fields, from predicting vapor-liquid equilibria [7] to the design of granular vibration dampers [3]. Although typically used to simulate simple particle models such as the hard sphere, the EDPD technique remains a general approach to particle simulations as potentials can be discretized to accurately approximate more conventional model systems, such as Lennard-Jonesium [6], or directly fit to physical data [37]. Introducing the *coefficient of restitution*, EDPD algorithms can also be used to simulate systems of dissipatively interacting particles, such as granular flows.

Hard-sphere EDPD algorithms in particular are often much more efficient (sometimes by orders of magnitude) than “soft” models which must solve Newton’s equation of motion using time-stepping numerical integration techniques [16]. Disregarding machine precision, EDPD algorithms solve the dynamics of discontinuous-potential models (such as hard spheres) analytically and do not suffer from errors due to the finite time step always used in numerical quadrature [16].

Despite these advantages, there remain numerical difficulties in the implementation of the EDPD algorithm due to the finite precision of floating point calculations originating from the machine precision. Small numerical errors in the detection and processing of events can cause the simulation to enter states where the dynamics is undefined. Interestingly, this ambiguity in the dynamics of invalid states has also led to some difficulties in theoretical treatments in the past [11]. These difficulties are not discussed in the earliest EDPD implementations [1] as they are relatively rare and frequently resolve themselves; however, for large systems and/or large simulation times, one must provide rules to handle such situations. In addition, there are systems, such as dissipative (granular) gases, which are prone to clustering [22] such that even for small numbers of particles these finite-precision errors deteriorate until the simulation must be halted. Modified algorithms have been proposed to combat these difficulties but current solutions are complex and fail in certain cases [29, 32] or modify the system dynamics in an undesired way [8, 19].

In this work the difficulties of event-detection in EDPD simulations are outlined and a general algorithm for stable event-detection is proposed. In Sect. 2, the basic event-driven algorithm is outlined for the hard-sphere model. The origin of invalid states is then introduced in Sect. 3, before an improved version of the event-detection algorithm is presented in Sect. 4. Finally, in Sect. 5, a more complex example of a bouncing ball is used to illustrate that the dynamics of invalid states must be defined, and demonstrates the extension of the stable algorithm for hard spheres to fixed boundaries.

## 2 Basic event-driven algorithm for identical hard spheres

- 1.
The simulation is started with certain initial conditions for the positions and velocities of the particles. Obviously, due to Eq. (2), any legal initial state requires that the particles must not overlap one another.

- 2.
Each possible pairing of particles is tested to determine if and when a collision is encountered, and the results are used to construct a list of all possible future events. This list is then sorted to determine the earliest event, which is the only event in the list which is guaranteed to occur. If a particle has multiple events occuring at the same instant, an ambigutity in the event order is introduced; however, it is often implicitly assumed that the execution order in these cases is unimportant and these effects are not discussed here.

- 3.
The particle positions are propagated along ballistic trajectories until the time of the earliest event.

- 4.
The velocities of the two colliding particles are updated according to the collision rule, Eq. (3).

- 5.
Any events in the future event list which involve either of the colliding particles are updated and the list is re-sorted to determine the next event to be processed.

- 6.
Check for conditions to terminate the simulation, e.g. the total real time or number of events processed.

- 7.
Continue with step 3.

*event-driven*. The basic algorithm outlined above contains the basic ingredients of an EDPD algorithm, albeit it would be unstable due to precision errors and of time complexity \(\mathcal{O}\left( N^2\right) \) per event processed. Indeed, there is a range of methods used to accelerate these calculations [18, 31], including the use of neighbor lists [1], the delayed states algorithm [17], calendar priority queues [28], and other optimizations [20, 34, 35] which reduce the calculation costs to constant time (\(\mathcal{O}\left( 1\right) \)) per event. Although the cost of simulating each event is now independent of system size it should be noted that, for equilibrium systems, the number of events to be processed per unit of simulation time still scales as \(O(N)\). Nevertheless, common to all algorithms is that the primary cost of simulation arises from the detection of events.

While the algorithmic challenge of EDPD is the bookkeeping of the list of future events, the numerical challenge is the computation of the times of the events and it is the latter which is the subject of this paper. We will show that naïve algorithms will result in invalid states and eventually failure of the algorithm due to unavoidable numerical errors resulting from the finite machine precision.

## 3 Event calculation errors

While errors resulting in \(\left| \mathbf {r}_{ij}\right| \gtrsim \sigma \) are uncritical for the stability of the algorithm, the opposite case, \(\left| \mathbf {r}_{ij}\right| \lesssim \sigma \) is fatal since the computation of the next event corresponds to a collision where \(\mathbf {v}_{ij}\cdot \hat{\mathbf {r}}_{ij} > 0\). Execution of this collision approximates entangled circular rings and this entanglement will persist forever, unless it is resolved due to another numerical error in a future collision. As shown in Fig. 3, this situation is not a rare event but concerns approximately half of all collisions, therefore, *any* useful EDPD algorithm must provide measures to cope with this situation. There are two different approaches: a) avoid situations where \(\left| \mathbf {r}_{ij}\right| < \sigma \), and b) admit such situations but provide methods to recover from them. One method exploiting solution a) to prevent overlaps from forming due to numerical errors is to retrospectively search along the pre-collision trajectory of colliding particle pairs for a collision state which is not overlapping [2]. Unfortunately, this iterative approach is expensive and will limit the computational speed of EDPD. A more efficient scheme to prevent overlaps by biasing the movement of particles by (temporarily) modifying the particle diameter so that detected interactions occur at a small distance from the invalid state is proposed by Pöschel and Schwager [29]. Unortunately, this approach does not exactly simulate the desired system but a slightly different system following a slightly different dynamics. It may also be shown that there are cases where these approaches fail to prevent overlaps forming [29].

## 4 Stable EDPD for hard-sphere systems

### 4.1 General approach

*overlap function*and the concept of

*stabilizing interactions*. Overlap functions are common in studies on event-driven asymmetric-potential systems [2], where they have also been called the overlap potential [10] or the indicator function [38]. For a simple hard-sphere system with zero relative acceleration, a suitable overlap function, \(f_\text {HS}\), is defined via Eq. (7):

*immediately*after a preceding collision to ensure that overlapping particles do not approach one another. It is generated in response to a negative and decreasing overlap function and prevents the overlap function decaying any further.

Using the overlap function and the concept of stabilizing interactions, a stable algorithm for hard-sphere systems can be defined as an algorithm which ensures the overlap function does not decrease for any particle pair in contact or in an overlapping state:

### 4.2 Algorithmic implementation for hard-sphere systems

Although the stable algorithm defines the dynamics for three-body interactions, it should not be used as a physical model for these effects. It only provides a stable definition of the dynamics for rare cases where multiple events occur at the same time (due to numerical errors). In systems where three-body collisions or persistent contacts are common, an appropriate model must be used. This model may also be event-driven (e.g., stepped potentials [36]) but this again requires the general approach outlined here to ensure that the simulation is stable with respect to numerical errors.

There are some cases where the execution of collisions will not cause the overlap function to increase. Fortunately, this behavior is often required to recover the correct dynamics, as illustrated in the following section.

## 5 Advanced example: bouncing ball

The simple coordinate transformation of varying \(r_{\mathrm {plate}}\) should yield identical results; however, the finite precision of the floating point math causes some difficulties: for \(\approx \)50 % of the sampled values of \(r_{\mathrm {plate}}\), the simulation must be halted after only \({\approx }30\) events on average as the argument of the square root in Eq. (12) becomes negative. This result arises due to the sphere overlapping the wall after a collision by a small amount \({\approx }10^{-16}\,\sigma \), exactly as in the hard-sphere system. The argument of the square root then turns negative once the velocity decays to the point where the peak of the trajectory no longer escapes the small overlap with the wall. A naive implementation may assume that if there are no real roots to Eq. (11) the ball misses the plate; however, this is clearly impossible in this system. This system demonstrates that for inelastic systems with external forces, it is easy to enter regions of undefined dynamics.

One possible treatment of this case is to halt the simulation immediately; however, this will leave the system with a non-zero velocity, a finite number of events in the trajectory, and an overlap. Applying the stable algorithm defined in Sect. 4.1 to the overlap function in Eq. (11) provides a more satisfactory resolution where the motion of the particle is continued until it reaches its peak, where the velocity reduces to zero. The algorithm also causes an infinite number of future events to take place at zero time to prevent the overlap from increasing again, which approximates the exact solution of inelastic collapse to the precision of the calculations. To complete the description of the stable algorithm in this case, an optimized stable event-detection rule for a ball falling onto a plane in three-dimensions is given in Algorithm 2.

## 6 Conclusions

A general and stable approach to event-detection in hard-sphere systems has been proposed and sample implementations given in Algorithms 1 and 2. It defines the dynamics of overlapping particles to minimize their effect on the trajectory of the system. The algorithm relies on treating interactions as stabilizing events for overlapping particle pairs which are not improving with time.

Although this work has focussed on the hard-sphere system, the general concept can be extended to the full range of particle systems studied using event-driven techniques. The extension to other assymmetric hard-core potentials is straightforward provided an overlap function, \(f\), with the characteristics outlined in Sect. 4.1 and algorithms to determine its derivative and roots are available. These are available in certain cases [38] but are non-trivial and must be implemented numerically for some systems such as ellipsoidal particles [10].

Algorithm 2 demonstrates that the stable algorithm can be applied to boundary interactions. An extension of the algorithm to sphere-triangle interactions would allow the simulation of complex geometries in biological processes [5] and the rapid design and import of boundaries from CAD programs for the study of granular/solids processing systems [29]. The primary difficulty in this extension is the definition of a suitable overlap function for collision detection of composite objects.

To apply the technique to molecular systems, an extension to softer stepped [36] or terraced potentials is required. Such potentials, including the fundamental square-well potential, require additional care in the definition of the overlap function as the invalid states of the model depend on the interaction history of the particle pairs. The generalization to stepped potentials, composite objects, and complex shapes will be explored in future publications.

Reference implementations of all algorithms presented in this paper are available in the open-source DynamO [4] simulation package.

## Notes

### Acknowledgments

We gratefully acknowledge the support of the Cluster of Excellence ‘Engineering of Advanced Materials’ at the University of Erlangen-Nuremberg, which is funded by the German Research Foundation (DFG) within the framework of its ‘Excellence Initiative’. The authors would like to thank Roland Reichardt and J. Sebastián Gonzáles for discussing their EDPD implementations.

## References

- 1.Alder BJ, Wainwright TE (1959) Studies in molecular dynamics. 1. general method. J Chem Phys 31(2):459–466. doi: 10.1063/1.1730376 MathSciNetCrossRefGoogle Scholar
- 2.Allen MP, Frenkel D, Talbot J (1989) Molecular dynamics simulation using hard particles. Comput Phys Rep 9:301–353. doi: 10.1063/1.1730376 CrossRefGoogle Scholar
- 3.Bannerman MN, Kollmer JE, Sack A, Heckel M, Müller P, Pöschel T (2011) Movers and shakers: granular damping in microgravity. Phys Rev E 84:011–301. doi: 10.1103/PhysRevE.84.011301
- 4.Bannerman MN, Sargant R, Lue L (2011) Dynamo: a free o(n) general event-driven simulator. J Comput Chem 32:3329–3338. doi: 10.1002/jcc.21915 CrossRefGoogle Scholar
- 5.Byrne MJ, Waxham MN, Kubota Y (2010) Cellular dynamic simulator: an event driven molecular simulation environment for cellular physiology. Neroinformatics 8(2):63–82. doi: 10.1007/s12021-010-9066-x CrossRefGoogle Scholar
- 6.Chapela GA, del Rio F, Benavides AL, Alejandre J (2010) Discrete perturbation theory applied to lennard-jones and yukawa potentials. J Chem Phys 133:234. doi: 10.1063/1.3518711 107CrossRefGoogle Scholar
- 7.Cui J, Elliott JR (2002) Phase diagrams for a multistep potential model of \(n\)-alkanes by discontinuous molecular dynamics and thermodynamic perturbation theory. J Chem Phys 116:8625–8631. doi: 10.1063/1.1469608 CrossRefGoogle Scholar
- 8.Deltour P, Barrat JL (1997) Quantitative study of a freely cooling granular medium. J Phys 1(7):137–151Google Scholar
- 9.Donev A, Torquato S, Stillinger FH (2005) Neighbor list collision-driven molecular dynamics simulation for nonspherical hard particlesi. i. algorithmic details. J Comput Phys 202:737–764. doi: 10.1016/j.jcp.2004.08.014 zbMATHMathSciNetCrossRefGoogle Scholar
- 10.Donev A, Torquato S, Stillinger FH (2005) Neighbor list collision-driven molecular dynamics simulation for nonspherical hard particles: ii. applications to ellipses and ellipsoids. J Comput Phys 202:765–793. doi: 10.1016/j.jcp.2004.08.025 zbMATHMathSciNetGoogle Scholar
- 11.Dorfman JR, Ernst MH (1989) Hard-sphere binary-collision operators. J Stat Phys 57:581–593. doi: 10.1007/BF01022823 MathSciNetCrossRefGoogle Scholar
- 12.Falcon E, Laroche C, Fauve S, Coste C (1998) Behavior of one inelastic ball bouncing repeatedly off the ground. Eur Phys J B 3:45–57. doi: 10.1007/s100510050283 CrossRefGoogle Scholar
- 13.Frenkel D, Maguire JF (1983) Molecular dynamics study of the dynamical properties of an assembly of infinitely thin hard rods. Mol Phys 49(3):503–541. doi: 10.1080/00268978300101331 CrossRefGoogle Scholar
- 14.Granlund T (2013) The GMP development team: GNU MP: the GNU Multiple Precision Arithmetic Library, 5.1.3 edn. http://gmplib.org/
- 15.Guttenberg N (2011) Approximate hard-sphere method for densely packed granular flows. Phys Res 83:051–306. doi: 10.1103/PhysRevE.83.051306 Google Scholar
- 16.Haile JM (1997) Molecular dynamics simulation: elementary methods. Wiley, New YorkGoogle Scholar
- 17.Jefferson DR (1985) Virtual time. TOPLAS 7(3):404–425. doi: 10.1145/3916.3988 MathSciNetCrossRefGoogle Scholar
- 18.Lubachevsky BD (1991) How to simulate billiards and similar systems. J Comput Phys 94:255–283 Google Scholar
- 19.Luding S, McNamara S (1998) How to handle the inelastic collapse of a dissipative hard-sphere gas with the tc model. Granul Matter 1:113–128CrossRefGoogle Scholar
- 20.Marin M, Risso D, Cordero P (1993) Efficient algorithms for many-body hard particle molecular-dynamics. J Comput Phys 109:306–317zbMATHCrossRefGoogle Scholar
- 21.McNamara S, Flekkøy EG, Måløy KJ (2000) Grains and gas flow: molecular dynamics with hydrodynamic interactions. Phys Rev E 61:4054Google Scholar
- 22.McNamara S, Young WR (1994) Inelastic collapse in two dimensions. Phys Rev E 50:R28–R31. doi: 10.1103/PhysRevE.50.R28 CrossRefGoogle Scholar
- 23.Mehlhorn K, Näher S, Seel M, Uhrig C (1999) LEDA: a platform for combinatorial and geometric computing. Cambridge University Press, CambridgezbMATHGoogle Scholar
- 24.Montaine M, Heckel M, Kruelle C, Schwager T, Pöschel T (2011) Coefficient of restitution as a fluctuating quantity. Phys Rev E 84:041–306CrossRefGoogle Scholar
- 25.Müller P, Pöschel T (2011) Collision of viscoelastic spheres: compact expressions for the coefficient of normal restitution. Phys Rev E 84:021–302Google Scholar
- 26.Müller P, Pöschel T (2012) Oblique impact of frictionless spheres: on the limitations of hard sphere models for granular dynamics. Granul Matter 14:115–120CrossRefGoogle Scholar
- 27.Müller P, Pöschel T (2013) Event-driven molecular dynamics of soft particles. Phys Rev E 87:033–301CrossRefGoogle Scholar
- 28.Paul G (2007) A complexity \({o}(1)\) priority queue for event driven molecular dynamics simulations. J Comput Phys 221(2):615–625. doi: 10.1016/j.jcp.2006.06.042 zbMATHCrossRefGoogle Scholar
- 29.Pöschel T, Schwager T (2005) Computational granular dynamics. Springer, Berlin. doi: 10.1007/3-540-27720-X Google Scholar
- 30.Press WH, Flannery BP, Teukolsky SA, Vetterling WT (1986) Numerical recipes: the art of scientific computing. Cambridge University Press, CambridgeGoogle Scholar
- 31.Rapaport DC (1980) Event scheduling problem in molecular dynamics simulation. J Comput Phys 34(2):184–201. doi: 10.1016/0021-9991(80)90104-7 MathSciNetCrossRefGoogle Scholar
- 32.Reichardt R, Wiechert W (2007) Event driven algorithms applied to a high energy ball mill simulation. Granul Matter 9:251–266. doi: 10.1007/s10035-006-0034-y CrossRefGoogle Scholar
- 33.Schwager T, Pöschel T (2008) Coefficient of restitution for viscoelastic spheres: the effect of delayed recovery. Phys Rev E 78:051–304CrossRefGoogle Scholar
- 34.Shida K, Anzai Y (1992) Reduction of the event-list for molecular dynamic simulation. Comput Phys Commun 69:317–329CrossRefGoogle Scholar
- 35.Shida K, Yamada S (1995) Reduced event-list on an array for many-body simulation. Comput Phys Commun 86:289–296CrossRefGoogle Scholar
- 36.Thomson C, Lue L, Bannerman MN (2014) Mapping continuous potentials to discrete forms. J Chem Phys 140:034–105. doi: 10.1063/1.4861669 CrossRefGoogle Scholar
- 37.Vahid A, Sans AD, Elliot JR (2008) Correlation of mixture vapor-liquid equilibria with the speadmd model. Ind Eng Chem Res 47:7955–7964. doi: 10.1021/ie800374h CrossRefGoogle Scholar
- 38.van Zon R, Schofield J (2008) Event-driven dynamics of rigid bodies interacting via discretized potentials. J Chem Phys 128:154. doi: 10.1063/1.2901173 119Google Scholar