In a previous post we have shown how to use series expansion to analyze the numerical viscosity(i.e. dissipation).

Today we will revise our Mathematica code and give intuitive running results to visualize the effects of dissipation and dispersion.

First we introduce a new Mathematica function expandToOrder. We will use it to expand a function to a desired order.

expandToOrder[u_, n_] := Function[
  {x, t},
  Normal[
     Series[u[x + k \[CapitalDelta]x, t + k \[CapitalDelta]t], {k, 0, 
       n}]] /. k -> 1]

For example, if we want to expand function u to the second order, we can write:

us2 = expandToOrder[u, 2]

The result us2 is a function of expansion location.

Dissipation

In the section 4.3.2 of book1 it states that the even-order spatial derivative contributes to the dissipation effect. We will give an second order example to visualize that.

First let’s examine the modified PDE.

us2 = expandToOrder[u, 2]

fds = (u[i, n + 1] - u[i, n])/\[CapitalDelta]t + 
   c (u[i, n] - u[i - 1, n])/\[CapitalDelta]x == 0

fds /. {
    u[i, n + 1] -> us2[x, t] /. \[CapitalDelta]x -> 0,
    u[i, n] -> 
      us2[x, t] /. {\[CapitalDelta]x -> 0, \[CapitalDelta]t -> 0},
    u[i - 1, n] -> 
      us2[x, t] /. {\[CapitalDelta]x -> -\[CapitalDelta]x, \
\[CapitalDelta]t -> 0}
    } // Simplify // pdConv

The first line gets the series expansion to the second order; and then we compute the finite difference scheme fds, which is forward in time and backward in space. Finally we substitute the series expansion into this finite difference scheme and get:

The left hand side is the original PDE we want to solve. However dissipation is introduced by a second order spatial derivative due to the truncation error.

We will use a concrete example in numpy to illustrate how it impacts the result:

forward in time and backward in space convection

Dispersion

On the other hand the dispersion is introduced by odd order spatial derivative. This time we use a finite difference scheme which is central in time and space.

By similar Mathematica code,

us2 = expandToOrder[u, 3]

fds = (u[i, n + 1] - u[i, n - 1])/(2 \[CapitalDelta]t) + 
   c (u[i + 1, n] - u[i - 1, n])/(2 \[CapitalDelta]x) == 0

fds /. {
    u[i, n + 1] -> us3[x, t] /. \[CapitalDelta]x -> 0,
    u[i + 1, n] -> us3[x, t] /. \[CapitalDelta]t -> 0,
    u[i - 1, n] -> 
      us3[x, t] /. {\[CapitalDelta]x -> -\[CapitalDelta]x, \
\[CapitalDelta]t -> 0},
    u[i, n - 1] -> 
      us3[x, t] /. {\[CapitalDelta]x -> 
       0, \[CapitalDelta]t -> -\[CapitalDelta]t}
    } // Simplify // pdConv

we get

We can see the spatial truncation error is dominated by a third order term. Again there is an example in numpy to illustrate the effect of dispersion:

central in time and space

References

  1. Zikanov, Oleg. Essential computational fluid dynamics. John Wiley & Sons, 2010.