Traffic example with time-dependent external velocity

Import the necessary packages.

Define the model

$$ \begin{aligned} V(x) &= [1 + 0.2\sin(t)] \cdot [1 + 0.2\cos(3x+t)] \\ W(x) &= \frac1{(|x|+1)^2} - \frac1{|x|+1} + 0.02x^2 \\ \mathop{\mathrm{mob}}(\rho) &= (1-\rho)_+^2 \end{aligned} $$

Define the ODE problem and the initial conditions

The initial condition approximates $\rho_0 = 1_{[-1,-1/2]} + 1_{[1/2,1]}$.

Solve the ODE

Plot the density

Let us first compute a more refined solution.

Now we can plot an animation of the density.

We can translate the particles so that the barycenter stays at the origin.