There are two ways we could impose boundary conditions. The first way is to treat ``particle'' 1 and ``particle'' N as ``walls'' and impose a fixed motion on them. For example, they could remain fixed for all times. Or one or the other could vibrate. In this case, the particles always retain their ordering - particle j is immediately to the left of particle j+1.
A second kind of boundary is `no boundary' or ``periodic'' boundary
conditions. This means that if a particle near x=1 is, say,
heading to the right, past x=1, it reappears on the far left at x=0.
To implement this kind of condition, fortran uses a `mod' function.
For reals, the function looks like a=1.2, 0.2 = amod(a,1.0).
For doubles, the function is dmod.
Unfortunately, if you try b=-0.1, -0.1=amod(b,1.0). But what
we really want is for (small) negatives to reappear a bit less than
1. So before applying the mod, add 1:
a=1.1
b=-0.2
ap=amod(1.0+a,1.0)
bp=amod(1.0+b,1.0)
gives the right behavior -
.
One minor complication arises when using periodic boundaries.
The particle originally designated `N' - the last one on the right -
could reappear immediately to the left of the particle originally
designated `1'. When you compute collision times and partners,
you just need to be careful of this. The function mod
gives integer `mod', but you need to be careful. For example,
.