Numerical diffusion
Numerical methods for PDEs represent a well-established research field in Applied Mathematics, and their use as powerful tools for many real-world applications continues to attract interest from the international community. The performance of numerical techniques for solving PDEs can be significantly affected by several undesirable effects. One of these subtle effects, referred to as numerical diffusion, may lead—if not carefully analyzed and controlled—to results that are inconsistent with the underlying physics of the system.
Attached: transport.py, transport.m
Let’s consider the initial value problem for \(u=u(t,x)\)
with \(c>0\), and introduce the discretization denoted by
\(\{t^n\}_n,\{x_j\}_j\) being the usual uniformly distributed grid points
We want to investigate the consistence of the following numerical methods:
-
Explicit Upwind (first order accurate)
\[ u^{n+1}_j=u^n_j-c\,\frac{\Delta t}{\Delta x}(u^n_j - u^n_{j-1}). \] -
Lax-Friedrichs (second order accurate)
- Lax-Wendroff (second order accurate)
In fact, for \(c>0\) all of these share the same CFL condition
which ensures their stability and prevent them from blowing up at finite time. However, the choice of \(\lambda<1\) introduces a so-called numerical diffusion (or dissipation), consisting of a tendency to flatten (dissipate) the solution more and more after each time step. Although the Lax-Friedrichs method is second order accurate, one can observe a very strong diffusion, providing solutions which are physically inconsistent and even worse than those produced with a only first order accurate method such as Explicit Upwind.
The solution to \((1)\) is given by
just consisting of a shift of the initial data in the right direction, with velocity \(c\). In the Python (or MATLAB) script “transport.py” (or "transport.m") you can see a comparison of the three methods; I took a simple Gaussian function as initial data and I used periodic boundary conditions. We expect this Gaussian to be just transported to the right, but we can clearly see that the Explicit Upwind and the Lax-Friedrichs methods tend to flatten it. This effect is even more evident when we consider a smaller CFL value (you can do so by changing the value of the “cfl” variable in the Python or MATLAB script). On the other hand, picking \(\lambda=1\) we are able to recover a perfect transport for both methods.
So… we just need to put \(\lambda=1\) to solve this issue?
Actually, in practice, this could be very dangerous. Numerical noise is always present in every algorithm; any number fed into the code is always affected by a round-off error, and even a microscopic round-off error on \(\Delta t\), \(\Delta x\) or \(c\) may lead to a value of \(\lambda\) greater than \(1\) (hence, the code will blow up eventually!). The best choice is to take \(\lambda\) slightly less than \(1\). Take-home message: avoid the \(\lambda=1\) shortcut.
The modified equations
In this section I want to show you that this numerical effect can be actually deduced from our methods’ formulas through the so-called modified equations, and it can be also quantified; this will allow us to make a comparison of the methods above and justify what we observed numerically from the Python script.
Let us first consider the Explicit Upwind method. From a continuous perspective, we can naively interprete it as the outcome of a point-wise evaluation of the relation
onto the points \(\{(t^n,x_j)\}_{n,j}\); in some sense the method seeks for a function \(u\) satisfying this relation. What if this function actually solves \((1)\)? Let’s perform a Taylor expansion of \(u(t+\Delta t,x)\) and \(u(t,x-\Delta x)\) up to third order to get
where I omitted the arguments \((t,x)\) of \(u\) and its derivatives for brevity. Assuming \(u\) solves \((1)\), we have that
Plugging this expression into the previous one and dividing everything by \(\Delta t\) we get
As you can see, we have first order consistence with the target equation,
and second order consistence with the diffusive equation,
with diffusion coefficient
this is precisely the numerical diffusion of the Explicit Upwind method. We can perform the same computations for the Lax-Friedrichs method, obtaining
We can immediately observe that this becomes huge when \(\lambda\) is small (go back to the Python script, take \(\lambda=0.001\) and see what happens); moreover,
which justifies our numerical observations. Lastly, it is interesting to see that the same calculations for the Lax-Wendroff method lead to
Exercise
Show that the Lax-Wendroff method has third order consistence with the dispersive equation