Before analyzing the algorithms to solve numerically the advection PDE, we illustrate a concrete physical problem from which this PDE arises. Let \(R\subset\Bbb R^3\) be a region bounded by a closed surface \(\partial R\) containing a mass of fluid \(M_R\) with density \(u\text{.}\) In particular, this means that the quantity of fluid contained in a subregion \(P\subset R\) is given by
Now, suppose that the fluid in some neighborhood of \(R\) moves with speed \({\mathbf v}(t,{\mathbf x})\text{.}\) Then we have the following continuity equation:
where \(\Sigma\) is the contribution given by sources and sinks inside \(R\) and the last term represents the net amount of fluid leaving (or entering) the region \(R\text{:}\) for every point \({\mathbf x}\in\partial R\text{,}\) the amount, per time unit, that is entering/leaving \(R\) through \({\mathbf x}\) is equal to
(recall that \({\mathbf dS}\) at \({\mathbf x}\) is perpendicular to \(\partial R\) at that point).
In absence of sources/sinks, we can use Stokes' theorem
1D Advection equation. We consider in particular the simple case of a 1-dimensional fluid with constant velocity field \(c\text{,}\) in which case the advection equation reduces to
\begin{equation*}
u_t+cu_x=0.
\end{equation*}
The most natural initial condition for such equation is specifying the shape of the solution at \(t=0\text{,}\) namely \(u(0,{\mathbf x})=f({\mathbf x})\text{.}\)
Characteristics. The analytical solution of the advection equation can be determined by the method of characteristics, which in this cases reduces to the following observation. Re-write the PDE as
namely \(x(t)=x_0+ct\text{.}\) This means that \(u(x,t)\) is equal to the value of \(f\) at the point \((0,x_0)\) such that \(x_0+c t = x\text{,}\) namely \(x_0=x-ct\text{.}\) In other words, the solution is
namely the profile of the solution at time \(t\) is the same as the profile at the initial time shifted by \(ct\) to the right. Below we solve numerically the 1D advection equation with several different instances of the Finite Differences Method (Section 1.17) to test the weak and strong points of this method for hyperbolic PDEs. Recall that the basic idea of this method is replacing the "phase space" \([0,T]\times[0,L]\) with the uniform lattice
has the dimension of a velocity. We call \(c_0\) the critical velocity of the lattice.
Subsection2.2.1FTBS (Downwind Method)
. In this first method, we use the forward Euler approximation for time derivatives and the backward one for space derivatives (Forward in Time, Backward in Space):
Notice that the solution of the FTBS system cannot give the values of the variables \(u_{n,0}\text{,}\) \(n\geq1\text{,}\) namely the values of the solution at the left endpoint at all times, since they would involve the coefficients \(u_{n-1,-1}\text{!}\) This is due to the fact that the PDE is defined for all \(x\in\Bbb R\) but numerical methods can only solve the problem within a finite box. The impossibility to get the \(u_{n,0}\text{,}\) \(n\geq1\text{,}\) corresponds to the fact that the characteristics of the PDE hit the boundary at all points \((t,0)\text{.}\) We need therefore to provide an extra boundary condition on the segment \((t,x)\text{,}\) \(0\leq x\leq L\text{,}\) corresponding to the values reached, on that segment, by the solution of the PDE.
Remark 1: this extra boundary condition is not really "extra". The point is that some of the characteristics meet first the time axis than the space axis (see Figure 2.2.1) and so the initial condition must be assiged also on that side. This is not a restriction in any way: the values on the x axis are anyway independent on each other (as long as the function is continuous).
Remark 2: different schemes will entail different kinds of extra boundary conditions!
FTBS local order. Let us set \(h=\Delta t\) and \(k=\Delta x\text{.}\) From the Taylor expansion formula we know that
is equal to zero for \(\nu=1\text{,}\) so we get the best possible precision with this method precisely when \(\nu=1\text{.}\)
FTBS consistency: the CFL condition. Courant, Friedrichs and Lewy formulated the following simple necessary condition for the convergence of a finite difference scheme.
Definition2.2.3.
For any variable \(u_{n,m}\) we define numerical and exact domains of dependence as follows: The numerical domain of dependence of \(u_{n,m}\) is the convex envelope of all coefficients \(u_{i,j}\) that \(u_{n,m}\) depends upon, explicitly or implicitly, in the linear system determined by the method. Its exact domain of dependence is the set of all points that lie on characteristic curves passing through \(u_{n,m}\text{.}\) For instance, in the picture below we show, in cyan, the numerical domain of dependence of the FTBS method. In green, we show the characteristic of an advection PDE with \(0<c<c_0\text{.}\) In this case, the exact domain of dependence of the PDE is a subset of its numerical one.
Theorem2.2.4(Courant, Friedrichs and Lewy).
A necessary condition for the convergence of a PDE Finite-Differences method is that the the exact domain of dependence of each variable be a subset of its numerical domain of dependence.
We give here an elementary proof for the case of advection PDEs with constant coefficients. Since we will do calculations in a floating point system, we can always assume that \(c/c_0\) is rational. This means that, for some large enough time (namely for large enough \(m\)), the characteristic curve passing through the node with index \((n,m)\) will also pass through some other node \((i,j)\text{,}\) \(i<m\) and so \(u_{n,m}=u_{i,j}\text{.}\) If the exact domain of dependence of \((n,m)\) is outside of the numerical domain of dependence, then \(u_{i,j}\) does not appear in the expression for \(u_{n,m}\) given by the FTBS system. Hence, when writing explicitly the value of \(u_{n,m}\) as function of the values of \(u\) at the initial time, we get two expressions depending on two disjoint sets of \(u(0,j)\text{.}\) Such expressions cannot coincide in general because the values \(u(0,j)\) are all independent of each other.
Recall now that characteristics for the Advection PDE \(u_t+cu_x=0\) are
\begin{equation*}
x(t) = x_0-ct.
\end{equation*}
Hence, in case of the FTBS scheme, there cannot be convergence for \(c<0\) while, for \(c\geq0\text{,}\) we must also have \(c/c_0\leq1\text{,}\) namely \(0\leq\nu\leq1\text{.}\)
Remark: the CFL condition is necessary but not sufficient!
FTBS convergence: the von Neumann condition. Consider a solution of the form
This is precisely the same range in which the method satisfies the CFL condition.
Implementation in Python. The code below uses FTBS to solve numerically the advection PDE
The following python code produces an animation showing the time evolution of the solution. The output does not show in the web page so to see the animation you need to cut&paste the code and run it on your machine.
Subsection2.2.2FTFS (Upwind)
If we use forward differences also for space, we get the algorithm
Below we show the numerical domain of dependence. Comparing with the previous method, it is clear that in this case there is consistency only for \(-1\leq\nu\leq0\text{.}\)
Ultimately, we showed that every Advection PDE can be solved numerically with either the FTBS algorithm or with the FTFS algorithm as long as we choose \(\Delta t\) and \(\Delta x\) so that \(|c|\leq c_0\text{.}\)
Subsection2.2.3FTCS (Centered)
Based on what seen above, a good candidate for an algorithm working for both \(c\geq0\) and \(c\geq0\) is the one where the centered differences approximation is used for the space derivative:
with \(0\leq n\leq N\text{,}\) \(1\leq j\leq M-1\text{,}\) \(\nu=c/c_0\text{.}\) Notice that for FTCS we need to set boundary conditions at both \(x=0\) and \(x=L\text{.}\)
FTCS Diagram. This scheme can be summarized by the following diagram:
CFL and von Neumann conditions. As expected, the domain of dependence of \(u_{n,m}\) in FTCS is a triangle symmetric with respect to the vertical direction and therefore we get a weaker bound from the CFL condition: with both positive or negative values of \(c\) we have that the characteristics are inside the domain of dependence as long as \(|\nu|\leq1\text{.}\) The von Neumann condition, though, gives us that
We say that the FTCS algorithm is unconditionally unstable, namely unstable for any value of \(\Delta t\) and \(\Delta x\text{.}\)
Subsection2.2.4The Lax Method
It turns out that there is a simple way to fix FTCS's problem, namely replacing the \(u_{n,m}\) term in the FTCS system with the average over its two neighbours:
The Lax Diagram This scheme can be summarized by the following diagram:
Lax's CFL and Von Neumann conditions. The CFL condition for this case, as expected, holds for both positive and negative values of \(c\) as long as \(\nu\leq1\text{.}\) Moreover, in this case
so the method is stable independently on \(\Delta x\) as long as \(\nu^2\leq1\) (conditional stability).
Implementation in Python. The code below uses the Lax algorithm to solve numerically the advection PDE
The dispersion problem. The Lax method works nice from the point of view of the "phase", in the sense that the velocity of the profiles is close to the constant velocity of the exact solution. What is much less satisfying is the evident damping problem: the profiles tend to become lower and larger, namely the numerical algorithm has a diffusion effect, a qualitative behavior that is absent in the exact solution.
A way to explain this phenomenon is to re-write the Lax algorithm as
While the last term becomes negligible for \(\Delta t\to0\text{,}\) the combination \((\Delta x)^2/\Delta t\) does not necessarily do that. Hence, the Lax method is also a solver for a diffusion PDE (see the section about the heat PDE) and so diffusion is inherently inside the algorithm.
Subsection2.2.5The Lax-Wendroff Method
The methods we illustrated so far use all the same idea: given the exact solution \(\hat u(t,x)\) of the advection PDE \(u_t+cu_x=0\text{,}\) one expands \(\hat u\) in Taylor series in \(t\) about \(t_0\) and gets
where \(\Delta t=t-t_0\text{.}\) Then, after replacing \(\hat u_t\) with \(-c\hat u_x\) and using either forward or central differencing for the derivative with respect to \(x\text{,}\) one gets, respectively, the FTBS and FTCS algorithms (and the Lax one, which is a deformation of FTCS).
A natural way to improve the precision of the solution is using one more term of the Taylor expansion:
The Lax-Wendroff algorithms consists in dropping all terms beyond the second order and replacing the derivatives with the central differencing and backward differencing for the second derivative:
Lax-Wendroff CFL and Von Neumann conditions. The CFL condition for this case is the same as for the Lax method, so a necessary condition for its consistence is that \(|c|\leq c_0\text{.}\) Moreover, in this case
so, just like the Lax method, it is stable independently on \(\Delta x\) as long as \(\nu^2\leq1\text{.}\) Unlike the Lax method, though, the diffusion in the Lax-Wendroff algorithm is much weaker.
Implementation in Python. The code below uses the Lax algorithm to solve numerically the advection PDE