# Boundary Conditions

So for we have chosen simulations that never reach the edge or the boundary. We have either limited the time or, as with the particle in a box, setup a potential that forces the wave function to zero at the boundary. For many examples, this is sufficient. However, in general, we have to deal with the wave function at the boundary of our simulation. This example shows a wave packet that interacts with the boundary almost immediately.

Clearly the behavior at the boundary does not reflect physical reality. We can find the cause if we look at the update equations, and consider their evaluation at the ends of the grid.

To update the real part of the wave function

$$Re(\Psi \left(x,t+\Delta t\right))\approx Re(\Psi \left(x,t-\Delta t\right))-\frac{Im(\Psi \left(x+\Delta x,t\right))-2Im(\Psi \left(x,t\right))+Im(\Psi \left(x-\Delta x,t\right))}{{\left(\Delta x\right)}^{2}}\Delta t+2V\left(x\right)Im(\Psi \left(x,t\right))\Delta t$$
and to update the imaginary part we have

$$Im(\Psi \left(x,t+\Delta t\right))\approx Im(\Psi \left(x,t-\Delta t\right))+\frac{Re(\Psi \left(x+\Delta x,t\right))-2Re(\Psi \left(x,t\right))+Re(\Psi \left(x-\Delta x,t\right))}{{\left(\Delta x\right)}^{2}}\Delta t-2V\left(x\right)Re(\Psi \left(x,t\right))\Delta t$$

Remember that the terms like $\Psi \left(x,t\right)$ on the right side correspond to texture reads.

For simplicity focus on the right side of the grid. On the right edge, the problematic term is $\Psi \left(x+\Delta x,t\right)$ , which reads beyond the edge of the grid.

Remember that when we setup the textures, we set

```
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
```

So that when we read beyond the edge of the grid, we get the value at the edge. Clearly we need to do better for a realistic physical simulation.

This issue of what to do at the boundary of a simulation is one that recurs again and again in scientific computing. Indeed, the solution we will put forward borrows directly from the methods developed for electromagnetic fields.

We *impose* a wave equation at the boundary
^{1},
and numerically only treat the part that propagates from the interior region outward across the boundary. This is referred to as a one way
wave equation.

Of course the wave equation is not an exact match for the Schrödinger equation. However, the errors introduced by using the wave equation along the boundary are small compare to the errors introduced without this treatment of the boundary. We will see an obvious improvement.

The one way wave equation is a close kin to the standard wave equation. We start with a standard wave equation, then factor it into operators. $$\frac{{\partial}^{2}}{\partial {x}^{2}}\Psi \left(x,t\right)-\frac{1}{{{v}_{p}}^{2}}\frac{{\partial}^{2}}{\partial {t}^{2}}\Psi \left(x,t\right)=(\frac{{\partial}^{2}}{\partial {x}^{2}}-\frac{1}{{{v}_{p}}^{2}}\frac{{\partial}^{2}}{\partial {t}^{2}})\Psi \left(x,t\right)=(\frac{\partial}{\partial {x}^{\mathrm{}}}-\frac{1}{{v}_{p}}\frac{\partial}{\partial t})(\frac{\partial}{\partial x}+\frac{1}{{v}_{p}}\frac{\partial}{\partial t})\Psi \left(x,t\right)=0$$

Now, we can look at each of these differential operators separately. $$(\frac{\partial}{\partial x}-\frac{1}{{v}_{p}}\frac{\partial}{\partial t})\Psi \left(x,t\right)=0$$ which has solutions of the form $f\left(x+{v}_{p}t\right)$ , representing a leftward propagating wave. Impose this condition on the left edge of the grid, allowing only outward bound waves.

$$(\frac{\partial}{\partial x}+\frac{1}{{v}_{p}}\frac{\partial}{\partial t})\Psi \left(x,t\right)=0$$ has solutions of the form $f\left(x-{v}_{p}t\right)$ , representing a rightward propagating wave. Impose this condition at the right edge of the grid restricting the solution to rightward, outward, propagating waves.

Work through the application along the right edge in detail then carry what we learn over to the left edge. $$\frac{\partial}{\partial x}\Psi \left(x,t\right)=-\frac{1}{{v}_{p}}\frac{\partial}{\partial t}\Psi \left(x,t\right)$$

Write out expressions for the space and time derivatives at the edge of the grid as finite differences. $$\frac{\partial}{\partial t}\Psi \left(x,t\right)=\frac{\Psi \left(x,t+\Delta t\right)-\Psi \left(x,t\right)}{\Delta t}$$ $$\frac{\partial}{\partial x}\Psi \left(x,t\right)=\frac{\Psi \left(x,t\right)-\Psi \left(x-\Delta x,t\right)}{\Delta x}$$

We might be tempted substitute these expressions directly into the one way wave equation, but we can't quite do that yet. Something a little bit subtle has happened here. These expressions are defined at different locations, and we need to do a little more work before we have an optimal solution.

Luckily there is a simple process to shift the derivatives onto a common location.
Average the *x* derivative at *t* with a similar derivative at
*t*+Δ*t*. This shifts the derivative from
$\left(x-\frac{\Delta x}{2},t\right)$
to
$\left(x-\frac{\Delta x}{2},t+\frac{\Delta t}{2}\right)$
.

Similarly, evaluate the $t$ derivative at $x-\Delta x$ . Averaging this with the derivative at $x$ shifts the derivative from $\left(x,t+\frac{\Delta t}{2}\right)$ to $\left(x-\frac{\Delta x}{2},t+\frac{\Delta t}{2}\right)$ .

This gives us new expressions for the derivatives. $$\frac{\partial}{\partial t}\Psi \left(x,t\right)=\frac{1}{2}(\frac{\Psi \left(x,t+\Delta t\right)-\Psi \left(x,t\right)}{\Delta t}+\frac{\Psi \left(x-\Delta x,t+\Delta t\right)-\Psi \left(x-\Delta x,t\right)}{\Delta t})$$ $$\frac{\partial}{\partial x}\Psi \left(x,t\right)=\frac{1}{2}(\frac{\Psi \left(x,t\right)-\Psi \left(x-\Delta x,t\right)}{\Delta x}+\frac{\Psi \left(x,t+\Delta t\right)-\Psi \left(x-\Delta x,t+\Delta t\right)}{\Delta x})$$ .

Put these expressions into the one way wave equation for the right edge, giving a slightly long, but luckily not very complicated, expression. $$\frac{\Psi \left(L,t\right)-\Psi \left(L-\Delta x,t\right)}{\Delta x}+\frac{\Psi \left(L,t+\Delta t\right)-\Psi \left(L-\Delta x,t+\Delta t\right)}{\Delta x}=\frac{1}{{v}_{p}}(\frac{\Psi \left(L,t+\Delta t\right)-\Psi \left(L,t\right)}{\Delta t}+\frac{\Psi \left(L-\Delta x,t+\Delta t\right)-\Psi \left(L-\Delta x,t\right)}{\Delta t})$$

Rearrange terms to get an expression for $\Psi $ at the right edge of the grid at the most advanced time in the simulation. $$\Psi \left(L,t+\Delta t\right)=\Psi \left(L-\Delta x,t\right)+\frac{{v}_{p}\Delta t-\Delta x}{{v}_{p}\Delta t+\Delta x}(\Psi \left(L-\Delta x,t+\Delta t\right)-\Psi \left(L,t\right))$$

A similar process gives us an expression for $\Psi $ at the left ( $x=0$ ) edge. $$\Psi \left(0,t+\Delta t\right)=\Psi \left(\Delta x,t\right)+\frac{{v}_{p}\Delta t-\Delta x}{{v}_{p}\Delta t+\Delta x}(\Psi \left(\Delta x,t+\Delta t\right)-\Psi \left(0,t\right))$$

These update equations are significantly different from those we have seen before. In the next section we will see that they can be expressed elegantly with OpenGL geometry and shaders.