I want to simulate a Gaussian wave packet colliding with a potential step. I tried this (it indicates what do I want to solve, however I know it is naive):
a = 200;
b = 10.;
sol = NDSolve[{I D[u[t, x], t] == (-1/2) D[u[t, x], {x, 2}] +
HeavisideTheta[x] u[t, x],
u[0., x] == Exp[-((x + 0.7*a)^2./(2*b^2))] Exp[I x/4.],
u[t, a] == 0, u[t, -a] == 0},
u, {t, 0, 4000}, {x, -a, a},
AccuracyGoal -> 4, PrecisionGoal -> 8];
Animate[
Plot[Evaluate[Abs[u[t, x] /. First[sol]]^2], {x, -a, a}, PlotRange -> {0, 1}],
{t, 0, 413, 0.01}]
This code without the Heaviside term gives a freely moving wave-packet to the right.
I don't know how to incorporate the boundary conditions in this problem, that must be continuity of the solution and of its first derivative at the potential step, and finiteness of the solution as $x \rightarrow \infty$.
The solution of this problem is known exactly from many quantum mechanics textbooks (see for example Cohen-Tannoudji, Diu, Laloe, Quantum Mechanics, vol I, complement JI, pg. 79).
Post edition: apparently -after studying the answers given in this post- the problem is with the Heaviside Theta function, which is similar but not totally equivalent to the UnitStep. In fact, the Heaviside is defined as $=0$ if $x<0$; or $=1$ if $x>0$, while the UnitStep is defined as $=0$ if $x<0$; or $=1$ if $x \ge 0$. Could this simple difference be the source of the error I get with the original code?. I think that was the source of the error messages I got with this code since the HeavisdeTheta remains unevaluated at $x=0$.