next up previous
Next: Initial Conditions Up: Project Lagrangian Previous: The Difference Equations

Boundary Conditions

Use periodic boundary conditions to allow simulation of an infinite wave train. Note, though, the presence of $P_{n+1}$ and $x_{n-1}$ in (2.9.1). If $n$ runs from $1$ to $N$ then $P_{N+1}$ and $x_0$ will be needed. This is best done by creating ``ghost'' cells at the end of the arrays. In C(++) this can be done by a declaration such as
        double x[N+1], u[N+1], P[N+2];
and, after each loop in which $P$ or $x$ are updated, by setting $P_{N+1} = P_1$ and $x_0 = x_N - L$, where $L$ is the equilibrium length of the grid. Note that this requires you to leave a couple of empty array elements, but for large $N$ this is not significant.