Numerical Solution of The Advection Equation: 0.8 T 0 Min T 5 Min T 10 Min T 20 Min

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Numerical solution of the advection equation

Dr Maarten van Reeuwijk

0.8
t=0 min
0.6 t=5 min
t=10 min
C(x;t)

0.4 t=20 min

0.2

0
-50 0 50 100 150 200
x [m]

The advection equation


0.8
t=0 min
0.6 t=5 min
Consider the advection t=10 min
C(x;t)

0.4 t=20 min


equation
0.2

+ =0 0
-50 0 50 100 150 200
x [m]

The solution to this equation is extremely simple: the initial profile remains
unchanged and translates at velocity U. Indeed, the the analytical solution is

= ( − ) where ( )= ( ; )

Interestingly, the advection equation is a difficult equation to simulate. The


absence of diffusion (i.e. no smoothing out of the solution) allows for
discretization errors to accumulate and destroy the solution. This is particularly
profound when the concentration profile has large gradients.

Computing Engineering Analysis (CI3-321/MvR) Page 56

1
Central discretisation of the advection operator
t
The most obvious choice is to approximate
the advection operator with a central
difference scheme:


+ =0
2Δ x1 x2 x3 x4 x5 x

This scheme is second order accurate, but tends to generate overshoots


and undershoots if there are large gradients in the solution.

Computing Engineering Analysis (CI3-321/MvR) Page 57

Upwind discretisation of the advection operator

A scheme which does not cause artificial overshoots is the upwind


scheme. As the name suggests, this scheme uses the upwind values to
approximate the advective operator:


+ =0 if >0
Δ

+ =0 if <0
Δ

Upwind schemes aim to do justice to the fact that for advection problems,
information travels downstream. Hence, the advection operator is skewed
towards the upstream direction to better approximate the flow of information.

However, this scheme is only first-order accurate and suffers from


numerical diffusion.

Computing Engineering Analysis (CI3-321/MvR) Page 58

2
Example advection of a shockwave
t=5s
• Consider the advection of 1.5
analytical
a scalar with initial

C(x; t) [kg/m3]
1 upwind
conditions:
central
0.5

1 if |x| < 10
( , 0) = !
0 otherwise
0

-0.5
• The analytical and the -40 -20 0 20 40
x [m]
two numerical solutions
t=10s
are shown in the figure 1.5
on the right. analytical
C(x; t) [kg/m3]

1 upwind
• Clearly, both schemes
have problems: the central
0.5
central scheme
0
oscillates unphysically,
and the upwind scheme -0.5
is too diffusive. -40 -20 0 20 40
x [m]
pde005.m

Computing Engineering Analysis (CI3-321/MvR) Page 59

Leading errors for central and upwind scheme


Recall that the Taylor expansion for c around xi is given by
) ( − )) + ( − )+
( )= + ( ( − )+ ), + +, + -(Δ 0)
2! 3!

Substitution of the Taylor series expansions in the central and upwind


schemes results in

Δ ) +
+ ( + +, + -(Δ +) =0
6
CENTRAL

Δ )
+ ( − ), + -(Δ )) =0
UPWIND 2

In a way this only confirms what we already knew, namely that the central
and upwind scheme have a second and first order truncation error,
respectively.
However, if we look at the equations above slightly differently, we can
understand the behaviour of the numerical schemes.
Computing Engineering Analysis (CI3-321/MvR) Page 60

3
The modified equation
• Numerical schemes provide solutions to the governing equation in the limit
of ∆x → 0. But which equation is solved when this limit has not been
reached?
• This equation is called the modified equation, which includes the leading
error term due to the discretisation.
• The modified equation for the central scheme is

Δ ) +
+ + =0
6 +

• The extra term in this equation is a third derivative, which is dispersive.


• The modified equation for the upwind scheme is

Δ
+ −
)

) =0
2
• The extra term in the equation above is a second derivative, which is a
diffusion term.

Computing Engineering Analysis (CI3-321/MvR) Page 61

You are not solving what you think you are solving I
You want to solve + = 0 and use a second order central scheme.
t = 60.0s
0.2
Advection equation with ∆ x = 1
Fully converged solution of modified equation
0.15
Analytical solution of advection equation
c [kg/m3]

0.1

0.05 Numerical dispersion


(propagation velocity depends
on wave-length)
0
-20 0 20 40 60 80
x [m]

You are actually solving Dispersion


+ Δ ) relation
+ +1 = 0 where 1= 2 = 3 − 3+ 1
+ 6
pde008.m

Computing Engineering Analysis (CI3-321/MvR) Page 62

4
You are not solving what you think you are solving II
You want to solve + = 0 and use a first order upwind scheme.
t = 60.0s
0.2
Advection equation with ∆ x = 1
Fully converged solution of modified equation
0.15
Analytical solution of advection equation
c [kg/m3]

0.1

0.05
Numerical diffusion

0
-20 0 20 40 60 80
x [m]

You are actually solving


) Δ
+ −4 ) = 0 where 4 =
2
pde009.m

Computing Engineering Analysis (CI3-321/MvR) Page 63

Numerical approximations and monotonicity


• Godunov (1959) showed that only first order schemes can remain
monotonic, which is known as Godunov’s theorem:

Linear numerical schemes for solving partial differential equations


(PDE's), having the property of not generating new extrema
(monotone scheme), can be at most first-order accurate.

• Higher order schemes will therefore always generate non-monotonic


solutions if there is insufficient resolution.

Godunov, Sergei K. (1959), A Difference Scheme for Numerical Solution of Discontinuous Solution of
Hydrodynamic Equations, Math. Sbornik, 47, 271-306, translated US Joint Publ. Res. Service, JPRS
7226, 1969. See Hirsch (2002), recommended reading

Computing Engineering Analysis (CI3-321/MvR) Page 64

5
Accuracy versus monotonicity

• Godunov’s theorem shows that there is a problem with simulating advection


equations with finite differences: you cannot both have an accurate scheme
and guarantee monotonic behaviour.
• Non-monotonicity of numerical schemes can cause severe difficulties.
• For example, when solving transport equations for internal energy and
density, it is crucial that the solutions remain positive. If this does not
happen, it is highly likely that the solution becomes unstable;
• A popular solution to the problem of accuracy versus monotonicity is to use
so-called high-resolution schemes. The idea is to use accurate schemes
(> first order), which reduce to first order schemes when gradients become
too steep as to avoid unphysical over- and undershoots. They do this by
limiting the fluxes. See e.g. Hirsch, recommended reading.

Computing Engineering Analysis (CI3-321/MvR) Page 65

Solving variable-coefficient PDEs

• Many PDEs have variable coefficients. Consider for example the


following PDE which has a variable diffusion coefficient:
5 5
= 4

• In order to solve this PDE using finite differences use the product rule
5 d4 5 )5
= +4 )
d
• and then discretise all derivatives in the usual manner:
d5 4 −4 5 −5 5 − 25 + 5
= +4
d 2Δ 2Δ Δ )
• Here, 4 = 4( ).
• If 4( ) is an analytical expression, the differentiation can be performed
manually rather than via numerical differentiation.

Computing Engineering Analysis (CI3-321/MvR) Page 66

6
Take-home messages

• Resolution is key to accuracy


• You are not solving the equations you
think you are solving
• Any numerical approximation provides the solution
to a modified equation;
• Only converges to the problem you are trying to
solve with sufficient resolution.
• Check for convergence
• always run simulations at higher (or lower)
resolution to check your answer has converged;
• Both in time and space.
• Learn from numerics Further reading:
• Numerical methods are very useful to understand • Ferziger & Peric, Computational
the physics of a problem; methods for Fluid Dynamics
• Very useful to check analytical solutions • Hirsch, Numerical computation of
• The methods you learnt are straightforward to internal and external flows
extend to higher dimensions or multiple dependent • Hoffman, Numerical methods for
variables. engineers and scientists

Computing Engineering Analysis (CI3-321/MvR) Page 67

Unsteady two-dimensional diffusion


2 2 2

0 0 0

-2 -2 -2

-2 0 2 -2 0 2 -2 0 2

function dCdt = pde(t, C, dx, dy, Nx, Ny, D)


C = reshape(C, Nx+1, Ny+1); % convert vector to 2D array
dCdt = zeros(size(C));
for i = 2:Nx
for j = 2:Ny
dCdt(i, j) = D * (C(i+1, j) - 2 * C(i,j) + C(i-1, j)) / dx^2 ...
+ D * (C(i, j+1) - 2 * C(i,j) + C(i, j-1)) / dy^2;
end
end
% Dirichlet BCs use dc/dt = 0, so no need to specify these explicitly
dCdt = dCdt(:); % convert 2D array to vector
pde010.m

Computing Engineering Analysis (CI3-321/MvR) Page 68

You might also like