The main problem here seems to be that Mathematica is giving strange results when you ask it to take the derivative of the function Arg
. As an example of this, suppose you take $\arg(e^{ix})$, where $x$ is a real number. You would expect that $\arg(e^{ix}) = x \; (\mathrm{mod} \; 2\pi)$, and therefore the derivative of this function should be a constant for most values of $x$. But this isn't what Mathematica does:
Plot[Evaluate[ReIm[D[Arg[Exp[I x]], x]]], {x, 0, 2}]
You do get the expected results if you insert a ComplexExpand
, and if your expression is something that simplifies when you use ComplexExpand
:
Plot[Evaluate[ReIm[D[ComplexExpand[Arg[Exp[I x]]], x]]], {x, 0, 2}]
However, ComplexExpand
can't do much with an arbitrary InterpolatingFunction
, so this method isn't suitable here. There may be some well-justified complex analysis reason why the first snippet above returns the given plot (it appears that the result is $i e^{2ix}$), but I'm not sure what it is just now. Alternately, it may be a bug.
To work around this, you can rewrite your equations so that they solve for the real and imaginary parts of $u$ separately, and then use the usual sorts of formulas to find the phase of $u$ and its derivatives:
eqns = {I D[u[t, x], t] + D[u[t, x], x, x] +
1/2 Abs[u[t, x]]^2 u[t, x] == 0, u[0, x] == 2 Sech[2 x]};
expandedeqns = Flatten[ComplexExpand[
ReIm[eqns /. {u[x_, t_] -> uR[x, t] + I uI[x, t],
Derivative[y__][u][x_, t_] ->
Derivative[y][uR][x, t] + I Derivative[y][uI][x, t]}]]]
sol = NDSolve[Evaluate[expandedeqns], {uR, uI}, {t, 0, 10}, {x, -10, 10}]
g[t_, x_] = ArcTan[uR[t, x], uI[t, x]] /. First[sol]
h[t_, x_] = D[g[t, x], x]
DensityPlot[h[t, x], {t, 0, 10}, {x, -10, 10}]
Finally, as noted by xzczd in the comments, you should not expect this answer to be correct unless you have fully specified the boundary conditions.