Modelintro
Hard-disk model
Physical model of particles as hard circles moving in a box, colliding elastically with each other and the walls.
The hard-disk model is a model from physics: circles (disks) move in a two-dimensional box, collide elastically with each other and with the walls, and never overlap. On this site it is the standard example of event-driven simulation, where a priority queue of predicted collisions replaces a fixed time step. The words "hard disk" mean a rigid circle, not a storage device. For the cost model of a storage disk, see the external memory model.
The machine
The system. Each disk has a position , a velocity , a radius and a mass . The box is the unit square. The only force is the hard core: the distance between the centres of disks and is never less than , and no disk crosses a wall. Between collisions each disk moves in a straight line at constant speed.
Collisions. When disk touches a vertical wall, the sign of the part of its velocity changes. A horizontal wall changes the part. When disks and touch, they exchange momentum along the line through their centres. With , and as defined below, measured at the time of contact, the impulse is , and the new velocities are and . For equal masses, this swaps the parts of the two velocities along the line through the centres, and the other parts do not change.
The time of the next collision. Let , and . The disks do not overlap, so . They touch at the first time with . This is a quadratic equation in . Let
If , the disks do not move toward each other, and they do not collide. If , they pass each other with no contact. Otherwise
A wall is simpler: a disk at with radius and hits the right wall after . If , it hits the left wall after . If , it never hits a vertical wall. The horizontal walls are the same with in place of .
Example. In an open plane, with no walls, two disks of radius , so , start at and with velocities and . Then , , , , , and . So . This agrees with a direct count: the gap between the centres must close from to at a speed of . After the collision the two velocities swap, to and .
What it counts
A simulation is measured by the work it does for each unit of simulated time. There are two ways to run the system.
Time-driven simulation. Move every disk by , then test each pair for overlap, and repeat. Each step costs pair tests, so one unit of time costs . A large misses collisions: two fast disks can pass through each other between two steps. A small makes the simulation slow. No choice of is correct for every input.
Event-driven simulation. Compute the times of future collisions and jump from one collision to the next. The state between events is known exactly, so no collision is missed. The algorithm keeps a priority queue of events keyed by time:
- For each disk, predict its collision with each wall and with each other disk, and insert each event with a finite time. This is predictions.
- Remove the event with the smallest time .
- If the event is no longer valid, discard it and go to step 2.
- Move all disks to time , and change the velocities of the disks in the event.
- For each disk in the event, predict its new collisions with the walls and with the other disks, and insert them. Go to step 2.
Invalid events. A predicted event is no longer valid when a disk in it has had a collision since the prediction, because the path of that disk changed. This holds for a wall event too. The algorithm does not search the queue to remove such events. It stores, with each event, the number of collisions of each disk at the time of the prediction, and in step 3 it compares these numbers with the current ones. This is lazy deletion.
Cost. With a binary heap, step 1 costs . Each collision adds events. Invalid events stay in the heap until they reach the top, so after collisions the heap can hold events, and an insertion costs . At any time at most two events for each pair of disks are valid (one from the prediction of each disk), and at most two for each disk and the walls (one vertical wall and one horizontal wall), so at most events are valid. To keep the heap small, rebuild it from its valid events each time it holds events. A rebuild by bottom-up heap construction takes time and leaves at most events, so at least insertions come between two rebuilds, and the rebuilds add amortized time to each insertion. The heap always holds events, so an insertion costs . Each event is inserted once and removed at most once, so the removals of invalid events cost each and can be charged to their insertions. Each collision then costs amortized. Step 4 costs in this simple form. Lubachevsky (1991) reduced the cost: each disk keeps its own time, so step 4 moves only the disks in the event, and the box is divided into cells, so a disk predicts collisions only with disks in the cells next to it. A crossing of a cell boundary is one more kind of event. At a fixed density, each event then costs time (see spatial hashing for the grid of cells).
Cost for each mean free time. The mean free time is the mean time between two collisions of one disk. In each mean free time, each disk has one collision on average, so the system has collisions. The simple event-driven method then costs for each mean free time, and the method of Lubachevsky costs at a fixed density. In the unit square with a fixed packing fraction, the radius of a disk is , so the mean free time is for a fixed mean speed. One unit of time then holds collisions, and the simple method costs for it.
Rounding. With floating-point numbers, a predicted time can be slightly earlier than the current time, and two disks can overlap by a tiny amount after a collision. Then a pair can collide again at once, and the simulation can stall. Implementations treat a predicted time slightly before the current time as the current time, and they predict a collision only when for a small .
Relation to other models
- Other event-driven systems. The same loop of remove, check and predict runs any simulation in which the state changes only at discrete events: queues of customers, digital circuits, and network packets. The hard-disk system is the usual teaching example, because the events are easy to compute and easy to see.
- Monte Carlo. A second way to study the system does not follow the motion. A step moves one disk by a small random vector and rejects the move if two disks overlap. This is a Markov chain that samples the legal configurations uniformly, and it is the Metropolis algorithm for this system. Event-chain Monte Carlo (Bernard, Krauth and Wilson, 2009) moves one disk until it touches another, then continues with the disk it touched, so no move is rejected. It is much faster than the Metropolis algorithm on dense systems.
- Cost models of this area. The model is a physical system, not a model of computation. The cost of a simulation of it is measured in the usual way on the word RAM, with each floating-point operation counted as one step.
Known results in the model
- Metropolis, Rosenbluth, Rosenbluth, Teller and Teller (1953) introduced the Metropolis Monte Carlo method on a system of rigid disks in two dimensions.
- Alder and Wainwright (1957) found a transition between a fluid and a solid in a system of hard spheres, and Alder and Wainwright (1959) described the event-driven method of molecular dynamics, which predicts the next collision and jumps to it.
- Alder and Wainwright (1962) used molecular dynamics on hard disks in two dimensions and found a transition between the fluid and the solid.
- Lubachevsky (1991) gave the event-driven algorithm with cells and a time for each disk, with cost for each event at fixed density.
- Bernard and Krauth (2011) used event-chain Monte Carlo and found that the hard-disk system melts in two steps: a first-order transition from the liquid to an intermediate phase, called the hexatic phase, and a continuous transition from the hexatic phase to the solid.
References
- https://algs4.cs.princeton.edu/61event/, Section 6.1, Event-driven simulation, on the booksite of Sedgewick and Wayne
- Robert Sedgewick and Kevin Wayne, Algorithms, fourth edition, Section 6.1 (event-driven simulation)
- B. J. Alder and T. E. Wainwright, Phase transition for a hard sphere system, Journal of Chemical Physics 27 (1957), page 1208
- B. J. Alder and T. E. Wainwright, Studies in molecular dynamics. I. General method, Journal of Chemical Physics 31 (1959), page 459
- B. J. Alder and T. E. Wainwright, Phase transition in elastic disks, Physical Review 127 (1962), page 359
- Boris D. Lubachevsky, How to simulate billiards and similar systems, Journal of Computational Physics 94 (1991), pages 255 to 283
- Nicholas Metropolis, Arianna W. Rosenbluth, Marshall N. Rosenbluth, Augusta H. Teller and Edward Teller, Equation of state calculations by fast computing machines, Journal of Chemical Physics 21 (1953), page 1087
- Etienne P. Bernard, Werner Krauth and David B. Wilson, Event-chain Monte Carlo algorithms for hard-sphere systems, Physical Review E 80 (2009), article 056704
- E. P. Bernard and W. Krauth, Two-step melting in two dimensions: first-order liquid-hexatic transition, Physical Review Letters 107 (2011), article 155704
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag N39YK7 Edit this page History Report an error Markdown JSON