Periodic boundary conditions¶
Rather than have hard walls which reflect particles back into the box a common choice is to implement periodic
boundary conditions where a particle leaving the box at $x=L$, is teleported back to $x=0$. Implement this logic by changing the rules for wall_time
, and pair_time
. Update the graphics code to display 9 copies of the unit cell to check the logic of your collision rules.
The pressure can still be calculated in this case using the virial theorem: VirialTheorem.html $$ PV = N k_BT - \frac{m}{2t_{sim}} \sum_{pairs} ({\bf v}_i-{\bf v}_j) \cdot ({\bf r}_i-{\bf r}_j) $$ We can take the mass as unity in our simulations, the temperature is calculated from the average kinetic energy per particle.
The management of collisions between particles which overlap with the cell boundary is quite delicate. One solution is to to bound the motion of particles in a single call to md_step()
. The positions of the particles are in the range $0< x_i <L$. We always consider the separations between two particles to be in $-L/2 < (x_i-x_j) < L/2$. This does not miss any events if the maximum time between updates is bounded by $(L/2-2\sigma)/(2v_{max})$ where $v_{max}$ is the largest velocity component in the system. We thus introduce an extra "event" in which nothing happens in the main loop of md_step()
.