Advection-diffusion#
The 1D advection-diffusion equation is
where \(v\) is a constant velocity and \(D\) the diffusivity.
Imagine you want to solve this on a domain from \(x=0\) to \(x=1\) with periodic boundary conditions. One approach is to take the Fourier transform \(f(x)\rightarrow g(k)\) which gives
Previously, we solved this analytically to obtain \(g(t)\), but now in preparation for more complicated examples, let’s evolve \(g\) in time numerically.
Exercise: advection-diffusion with Fourier decomposition
Solve equation (16) with a constant velocity \(v\) and diffusivity \(D\). Your goal should be to advect the starting profile \(f_0(x)\) for exactly the time needed to wrap around the grid and get back to its starting point. You can then see how well your method works by comparing with the original profile.
Use a grid from \(x=0\) to \(x=1\) with periodic boundary conditions. Start with \(v=1\) and \(D=0\). You can then try different values of \(D\) and \(v\) to see how it changes the result.
For the time-update, try explicit, implicit or semi-implicit time updates
It is useful to choose a timestep
for some constant \(\alpha\) (for the explicit method you will need to choose \(\alpha\) small enough to keep the method stable).
For \(f_0(x)\), try using a Gaussian, sine wave, or top hat and see how it changes the result.
Exercise: advection-diffusion with finite-difference
Repeat the previous exercise, but now using finite differences. For the advection part, here are some schemes you can use:
Lax-Friedrich
Lax-Wendroff
Leapfrog
You can use operator splitting to advance in time: apply the advection update and diffusion update alternately to your solution.