6 The Crank-Nicolson method

In the notation established for the explicit method, the so-called Crank-Nicolson scheme can be written

u j n + 1 = u j n + 1 2 r u j 1 n 2 u j n + u j + 1 n ⏟ + u j 1 n + 1 2 u j n + 1 + u j + 1 n + 1 ⏟

which might, at first glance, look off-puttingly complicated. To aid clarity, certain groups of terms have been gathered together in the above:

these are the terms that appeared on the right hand side of the explicit method and are involved with approximating u x x at time t = n δ t
these are very similar to the terms, but all the superscripts are n + 1 instead of n , that is the terms approximate u x x at time t = ( n + 1 ) δ t

(the factor of 1 2 outside the large bracket shows that we take the average of and )

Figure 7 shows another way of thinking of this numerical method. As in the earlier diagram of this type, arrows point away from positions relating to terms on the right-hand side of the numerical scheme.

Figure 7

No alt text was set. Please request alt text from the person who provided you with this resource.

The new terms in the Crank-Nicolson method, as compared with the explicit method, give rise to two new unfilled circles on the diagram and the horizontal arrows.

The implementation of this method is similar to that used for the explicit method, but there is a key difference. The Crank-Nicolson scheme is implicit , for consider its use in the first time-step when finding u j 1 ,

u j 1 = u j 0 ⏟    ✓ + 1 2 r u j 1 0 ⏟    ✓ 2 u j 0 ⏟    ✓ + u j + 1 0 ⏟    ✓ + u j 1 1 2 u j 1 + u j + 1 1 ⏟ ?

The terms labelled   ✓ are known from the initial condition. But there are other unknown terms on the right-hand side. We cannot simply “read off" the values at the new time-step as we did using the explicit scheme. Instead we have to store all of the equations given by the stencil at a particular time-step and then solve them as a system of simultaneous equations. The following Example illustrates this point.

Example 17

The temperature u ( x , t ) of a metal bar of length ℓ = 1.2 at a distance x from one end and at time t is modelled by the partial differential equation

u t = α u x x ( 0 < x < &ell; , t > 0 ) .

It is given that the metal has diffusivity α = 1 , that the two ends of the bar are kept at temperature u = 0 and that the initial temperature distribution is

u ( x , 0 ) = f ( x ) = x ( &ell; x ) 3

Use the Crank-Nicolson difference scheme with δ x = 0.4 and δ t = 0.1 to approximate u ( x , t ) at t = δ t and t = 2 δ t .

Solution

In this case r = α δ t ( δ x ) 2 = 0.62500 so that the numerical scheme can be written

u j n + 1 = u j n + 0.62500 2 ( u j 1 n 2 u j n + u j + 1 n + u j 1 n + 1 2 u j n + 1 + u j + 1 n + 1 )

Moving the unknowns to the left of the equation we obtain

0.31250 u j 1 n + 1 + 1.62500 u j n + 1 0.31250 u j + 1 n + 1 = 0.37500 u j n + 0.31250 ( u j 1 n + u j + 1 n )

The first stage is to use the given data to find u j 0

u 0 0 = 0 from the boundary condition u 1 0 = f ( δ x ) = f ( 0.4 ) = 0.28622 from the initial condition u 2 0 = f ( 2 δ x ) = f ( 0.8 ) = 0.20239 from the initial condition u 3 0 = 0 from the boundary condition

The first time-step will find u j 1 . First we note that the boundary condition implies that u 0 1 = u 3 1 = 0 . Two uses of the stencil give

0.31250 u 0 1 + 1.62500 u 1 1 0.31250 u 2 1 = 0.37500 u 1 0 + 0.31250 ( u 0 0 + u 2 0 ) = 0.17058 0.31250 u 1 1 + 1.62500 u 2 1 0.31250 u 3 1 = 0.37500 u 2 0 + 0.31250 ( u 1 0 + u 3 0 ) = 0.16534

The implicit nature of this method means that we have to do some extra work to complete the time-step. We must now solve the simultaneous equations

1.62500 0.31250 0.31250 1.62500 u 1 1 u 2 1 = 0.17058 0.16534

In this case there are only two unknowns and it is a simple matter to solve the pair of equations to give u 1 1 = 0.12932 and u 2 1 = 0.12662 .

The second time-step will find u j 2 . First we note that the boundary condition implies that u 0 2 = u 3 2 = 0 . Two uses of the stencil give

0.31250 u 0 2 + 1.62500 u 1 2 0.31250 u 2 2 = 0.37500 u 1 1 + 0.31250 ( u 0 1 + u 2 1 ) = 0.08806 0.31250 u 1 2 + 1.62500 u 2 2 0.31250 u 3 2 = 0.37500 u 2 1 + 0.31250 ( u 1 1 + u 3 1 ) = 0.08789

The implicit nature of this method means that we have to do some extra work to complete the time-step. We must now solve the simultaneous equations

1.62500 0.31250 0.31250 1.62500 u 1 2 u 2 2 = 0.08806 0.08789

In this case there are only two unknowns and it is a simple matter to solve the pair of equations to give u 1 2 = 0.06707 and u 2 2 = 0.06699 .

Figure 8 depicts the numerical solutions found in Example 17 above. (Again, the dotted lines are intended to aid clarity, they are not part of the numerical solution.)

Figure 8

No alt text was set. Please request alt text from the person who provided you with this resource.

Task!

The temperature u ( x , t ) of a metal bar of length &ell; = 0.9 at a distance x from one end and at time t is modelled by the partial differential equation

u t = α u x x ( 0 < x < &ell; , t > 0 ) .

It is given that the metal has diffusivity α = 0.25 , that the two ends of the bar are kept at temperature u = 0 and that the initial temperature distribution is

u ( x , 0 ) = f ( x ) = sin ( π x &ell; )

Use the Crank-Nicolson difference scheme with δ x = 0.3 and δ t = 0.2 to approximate u ( x , t ) at t = δ t and t = 2 δ t .

In this case r = α δ t ( δ x ) 2 = 0.55556 so that the numerical scheme can be written

u j n + 1 = u j n + 0.55556 2 ( u j 1 n 2 u j n + u j + 1 n + u j 1 n + 1 2 u j n + 1 + u j + 1 n + 1 )

Moving the unknowns to the left of the equation we obtain

0.27778 u j 1 n + 1 + 1.55556 u j n + 1 0.27778 u j + 1 n + 1 = 0.44444 u j n + 0.27778 ( u j 1 n + u j + 1 n )

The first stage is to use the given data to find u j 0

u 0 0 = 0 from the boundary condition u 1 0 = f ( δ x ) = f ( 0.3 ) = 0.86603 from the initial condition u 2 0 = f ( 2 δ x ) = f ( 0.6 ) = 0.86603 from the initial condition u 3 0 = 0 from the boundary condition

The first time-step will find u j 1 . First we note that the boundary condition implies that u 0 1 = u 3 1 = 0 .

Two uses of the stencil give

0.27778 u 0 1 + 1.55556 u 1 1 0.27778 u 2 1 = 0.44444 u 1 0 + 0.27778 ( u 0 0 + u 2 0 ) = 0.62546 0.27778 u 1 1 + 1.55556 u 2 1 0.27778 u 3 1 = 0.44444 u 2 0 + 0.27778 ( u 1 0 + u 3 0 ) = 0.62546

The implicit nature of this method means that we have to do some extra work to complete the time-step. We must now solve the simultaneous equations

1.55556 0.27778 0.27778 1.55556 u 1 1 u 2 1 = 0.62546 0.62546

In this case there are only two unknowns and it is a simple matter to solve the pair of equations to give u 1 1 = 0.48949 and u 2 1 = 0.48949 .

The second time-step will find u j 2 . First we note that the boundary condition implies that u 0 2 = u 3 2 = 0 . Two uses of the stencil give

0.27778 u 0 2 + 1.55556 u 1 2 0.27778 u 2 2 = 0.44444 u 1 1 + 0.27778 ( u 0 1 + u 2 1 ) = 0.35352 0.27778 u 1 2 + 1.55556 u 2 2 0.27778 u 3 2 = 0.44444 u 2 1 + 0.27778 ( u 1 1 + u 3 1 ) = 0.35352

The implicit nature of this method means that we have to do some extra work to complete the time-step. We must now solve the simultaneous equations

1.55556 0.27778 0.27778 1.55556 u 1 2 u 2 2 = 0.35352 0.35352

In this case there are only two unknowns and it is a simple matter to solve the pair of equations to give u 1 2 = 0.27667 and u 2 2 = 0.27667 .

6.1 In general

Having now seen some instances with a relatively large δ x , we now look at the general case where the space step may be much smaller. In this case there will be a larger system of equations to solve at each time-step than was the case above.

In general, the procedure of moving the unknowns to the left hand side of the equation leads to

r 2 u j 1 n + 1 + ( 1 + r ) u j n + 1 r 2 u j + 1 n + 1 = r 2 u j 1 n + ( 1 r ) u j n + r 2 u j + 1 n

which we apply all the way along the x -axis. That is, we put j = 1 , 2 , 3 , , J 1 in the above expression and hence derive a system of equations for all the u with superscript n + 1 .

1 + r r 2 0 0 r 2 1 + r r 2 0 r 2 1 + r r 2 &vellip; &dtdot; &dtdot; &dtdot; r 2 0 0 r 2 1 + r u 1 n + 1 u 2 n + 1 u 3 n + 1 &vellip; u J 1 n + 1 = r 2 u 0 n ̲ + ( 1 r ) u 1 n + r 2 u 2 n + r 2 u 0 n + 1 ̲ ̲ r 2 u 1 n + ( 1 r ) u 2 n + r 2 u 3 n r 2 u 2 n + ( 1 r ) u 3 n + r 2 u 4 n &vellip; r 2 u J 2 n + ( 1 r ) u J 1 n + r 2 u J n ̲ + r 2 u J n + 1 ̲ ̲

The underlined terms on the right-hand side will be known from the boundary conditions. The doubly underlined quantities are “new" at the current time-step and involve the only appearances of n + 1 on the right-hand side. All the other u approximations at time level n + 1 are unknown at this stage and appear on the left.

The matrix on the left-hand side of the system has the following properties

It is also true that the matrix is strictly diagonally dominant . (That is, the diagonal element on each row is greater in size than the sum of the absolute values of the off-diagonal elements on that row.) This means that methods such as Jacobi and Gauss Seidel (see HELM booklet  30 for details) would work very well.

6.2 Stability of the Crank-Nicolson scheme

This is the big pay-off when using the Crank-Nicolson method.

Key Point 21

The Crank-Nicolson method is stable for all values of r .

This is excellent news. It means that there is no hideously restrictive constraint on the size of δ t .