I'm trying to solve Liouville's equation:
$\frac{\partial\rho}{\partial t}-f(q)\frac{\partial\rho}{\partial p}+p\frac{\partial\rho}{\partial q}=0$
I believe this should be solvable given an initial distribution, $\rho(q,p,0)$
For a harmonic oscillator $f(q)=q$ and an initial Gaussian distribution I have tried:
eqn = Derivative[0, 0, 1][ρ][q, p, t] - q*Derivative[0, 1, 0][ρ][q, p, t] + p*Derivative[1, 0, 0][ρ][q, p, t] == 0;
ρ0 = 10/Pi E^(-10*((q - 0.5)^2 + p^2));
sol = NDSolve[{eqn, ρ[q, p, 0] == ρ0}, ρ, {q, -1, 1}, {p, -1, 1}, {t, 0, 2*Pi}]
The result should have the whole Gaussian simply rotating around the origin over time.
I get two errors:
NDSolve::bcart: Warning: an insufficient number of boundary conditions have been specified for the direction of independent variable p. Artificial boundary effects may be present in the solution.
NDSolve::eerr: Warning: scaled local spatial error estimate of 51097.533173032294` at t = 6.283185307179586` in the direction of independent variable q is much greater than the prescribed error tolerance. Grid spacing with 35 points may be too large to achieve the desired accuracy or precision. A singularity may have formed or a smaller grid spacing can be specified using the MaxStepSize or MinPoints method options.
and clearly broken results:
I've tried using the finite difference method, which gives the error:
NDSolve::femcscd: The PDE is convection dominated and the result may not be stable. Adding artificial diffusion may help.
with less ugly but still incorrect plots.
Although I think this particular harmonic oscillator case can be solved with the method of characteristics, I'd like to be able to solve for more complex cases with a different $f(p)$ which would require numerical solving.
I'm not too fussed about the initial distribution being a Gaussian, if for some reason that's causing issues. In fact, I'd ideally like some kind of step function - although I feel that's only going to cause more problems.
eqn = Derivative[0, 0, 1][ρ][q, p, t] - q*Derivative[0, 1, 0][ρ][q, p, t] + p*Derivative[1, 0, 0][ρ][q, p, t] == 0;
$\endgroup$