You are on page 1of 23

Finite difference method for 2-D heat equation

Praveen. C
praveen@math.tifrbng.res.in

Tata Institute of Fundamental Research


Center for Applicable Mathematics
Bangalore 560065
http://math.tifrbng.res.in/~praveen

January 27, 2013

1 / 23
Heat equation

• Partial differential equation in Ω = (0, 1) × (0, 1), µ > 0

ut = µ(uxx + uyy ), (x, y) ∈ Ω, t>0


u(x, y, 0) = f (x, y), (x, y) ∈ Ω
u(x, y, t) = g(x, y, t), (x, y) ∈ Ω, t>0

• Space mesh of (Mx + 1) × (My + 1) points in Ω

1
∆x = , xj = j∆x, j = 0, 1, . . . , Mx
Mx
1
∆y = , yk = k∆y, k = 0, 1, . . . , My
My

2 / 23
FTCS scheme
Dt+ unj,k = µ(Dx+ Dx− unj,k + Dy+ Dy− unj,k )

un+1 n
j,k − uj,k unj−1,k − 2unj,k + unj+1,k
Dt+ unj,k = , Dx+ Dx− unj,k =
∆t ∆x2
n n n
uj,k−1 − 2uj,k + uj,k+1
Dy+ Dy− unj,k =
∆y 2
Define
µ∆t µ∆t
rx = , ry =
∆x2 ∆y 2
Define undivided finite differences

δx2 unj,k = unj−1,k − 2unj,k + unj+1,k , δy2 unj,k = unj,k−1 − 2unj,k + unj,k+1

FTCS scheme
un+1 n 2 n 2 n
j,k = uj,k + rx δx uj,k + ry δy uj,k
or
un+1 2 2 n
j,k = (1 + rx δx + ry δy )uj,k

3 / 23
FTCS scheme: maximum stability

un+1 n n n n n
j,k = (1 − 2rx − 2ry )uj,k + rx (uj−1,k + uj+1,k ) + ry (uj,k−1 + uj,k+1 )

If
1
rx + ry ≤
2
then
min(unj±1,k , unj,k±1 , unj,k ) ≤ un+1 n n n
j,k ≤ max(uj±1,k , uj,k±1 , uj,k )

so that the scheme is stable in maximum norm. If ∆x = ∆y = h, then

2µ∆t 1 h2
≤ =⇒ ∆t ≤
h2 2 4µ
This time step restriction is half the value in one dimension.

4 / 23
FTCS scheme: Fourier stability
Take Fourier mode with wave-number (ξ, η) ∈ (−π, +π) × (−π, +π)
unj,k = ûn ei(jξ+kη)
Then
ûn+1 = ρûn
where
ρ(ξ, η) = 1 + 2rx (cos ξ − 1) + 2ry (cos η − 1)
= 1 − 4rx sin2 (ξ/2) − 4ry sin2 (η/2)
For stability we need |ρ(ξ, η)| ≤ 1. Maximum value of ρ
ρ=1 at (ξ, η) = (0, 0)
and minimum value of ρ
ρ = 1 − 4rx − 4ry at (ξ, η) = (π, π)
Hence we have stability provided
1
rx + ry ≤
2
5 / 23
BTCS scheme

un+1 n 2 n+1 2 n+1


j,k = uj,k + rx δx uj,k + ry δy uj,k

or
(1 − rx δy2 − ry δy2 )un+1 n
j,k = uj,k

Amplification factor Amplification factor


1
ρ= ≤1
1 + 4rx sin2 (ξ/2) + 4ry sin2 (η/2)

BTCS scheme is unconditionally stable.

6 / 23
Crank-Nicholson scheme

unj,k + un+1
j,k unj,k + un+1
j,k
un+1 n 2
j,k = uj,k + rx δx + ry δy2
2 2
or
1 1 1 1
(1 − rx δx2 − ry δy2 )un+1 2 2 n
j,k = (1 + rx δx + ry δy )uj,k
2 2 2 2
Amplification factor

1 − 2rx sin2 (ξ/2) − 2ry sin2 (η/2)


ρ= ≤1
1 + 2rx sin2 (ξ/2) + 2ry sin2 (η/2)

Crank-Nicholson scheme is unconditionally stable.

7 / 23
Peaceman-Rachford scheme
Update solution in two steps
1 1
tn → tn + ∆t → tn+1 , un → un+ 2 → un+1
2
Step 1: Implicit in x
n+ 1
uj,k 2 − unj,k µ 2 n+ 12 µ 2 n
= δ u + δ u
1
2 ∆t
∆x2 x j,k ∆y 2 y j,k
or
1 n+ 1 1
(1 − rx δx2 )uj,k 2 = (1 + ry δy2 )unj,k
2 2
Step 2: Implicit in y
n+ 1
un+1
j,k − uj,k
2
µ 2 n+ 12 µ 2 n+1
= δx uj,k + δ u
1
2 ∆t
∆x 2 ∆y 2 y j,k
or
1 1 2 n+ 2
1
(1 − ry δy2 )un+1
j,k = (1 + rx δx )uj,k
2 2
8 / 23
Peaceman-Rachford scheme: Fourier stability

Step 1:
1
[1 + 2rx sin2 (ξ/2)]ûn+ 2 = [1 − 2ry sin2 (η/2)]ûn
Step 2:
1
[1 + 2ry sin2 (η/2))ûn+1 = [1 − 2rx sin2 (ξ/2)]ûn+ 2
Combining the two

ûn+1 [1 − 2rx sin2 (ξ/2)][1 − 2ry sin2 (η/2)]


ρ= = ≤1
ûn [1 + 2rx sin2 (ξ/2)][1 + 2ry sin2 (η/2)]

The scheme is unconditionally stable.

9 / 23
Peaceman-Rachford scheme: Consistency
From Step 1
1 n+ 1 1
(1 − rx δx2 )uj,k 2 = (1 + ry δy2 )unj,k
2 2
Multiply on both sides
1 1 n+ 1 1 1
(1 + rx δx2 )(1 − rx δx2 )uj,k 2 = (1 + rx δx2 )(1 + ry δy2 )unj,k
2 2 2 2
Operators on left commute
1 1 n+ 1 1 1
(1 − rx δx2 ) (1 + rx δx2 )uj,k 2 = (1 + rx δx2 )(1 + ry δy2 )unj,k
2 | 2 {z } 2 2
use Step 2

Using Step 2

1 1 1 1
(1 − rx δx2 )(1 − ry δy2 )un+1 2 2 n
j,k = (1 + rx δx )(1 + ry δy )uj,k
2 2 2 2

10 / 23
Peaceman-Rachford scheme: Consistency

Expand difference operators on both sides

un+1
j,k − uj,k
n n+1
µ 2 uj,k + uj,k
n n+1
µ 2 uj,k + uj,k
= δ + δ
∆t ∆x2 x 2 ∆y 2 y 2
2 2 2
µ ∆t δx δy
− (un+1 − unj,k )
4 ∆x2 ∆y 2 j,k

This is Crank-Nicholson scheme with an extra term. This term is O ∆t2
since
n
δx2 δy2 ∂5u

n+1 n
+ O ∆t∆x2 + ∆t∆y 2 + ∆t2

2 2
(u j,k − uj,k ) = ∆t 2 2
∆x ∆y ∂t∂ x∂ y j,k

Hence the Peaceman-Rachford scheme is second order accurate in space and


time.

11 / 23
D’Yakonov Scheme

Peaceman-Rachford scheme
1 1 1 1
(1 − rx δx2 ) (1 − ry δy2 )un+1 2 2 n
j,k = (1 + rx δx )(1 + ry δy )uj,k
2 | 2 {z } 2 2
u∗
j,k

Step 1: Solve for u∗


1 1 1
(1 − rx δx2 )u∗j,k = (1 + rx δx2 )(1 + ry δy2 )unj,k
2 2 2
Step 2: Solve for un+1
1 ∗
(1 − ry δy2 )un+1
j,k = uj,k
2

12 / 23
Approximate factorization
Peaceman-Rachford scheme is close to Crank-Nicholson scheme
1 1 1 1
(1 − rx δx2 − ry δy2 )un+1 2 2 n
j,k = (1 + rx δx + ry δy )uj,k
2 2 2 2
Factorise operator on left hand side
1 1 1 1 rx ry 2 2
(1 − rx δx2 − ry δy2 ) = (1 − rx δx2 )(1 − ry δy2 ) − δ δ
2 2 2 2 4 x y

We cannot neglect the last term since it is O ∆t2 and the scheme would only
be first order accurate
n+1
∆t2
 4
rx ry 2 2 n+1 ∂ u
δ δ u = + higher order terms
4 x y j,k 4 ∂ 2 x∂ 2 y j,k

We factorise the right hand side also


1 1 1 1 rx ry 2 2 n+1
(1− rx δx2 )(1− ry δy2 )un+1 2 2 n
j,k = (1+ rx δx )(1+ ry δy )uj,k + δx δy (uj,k − unj,k )
2 2 2 2 | 4 {z }
O(∆t3 )

13 / 23
Peaceman-Rachford Scheme: Dirichlet BC
Step 1 is
1 n+ 1 1
(1 − rx δx2 )uj,k 2 = (1 + ry δy2 )unj,k
2 2
n+ 1
What boundary condition to use for uj,k 2 at j = 0, Mx ?

n+ 1
Option I: Since uj,k 2 ≈ u(xj , yk , tn + 12 ∆t)

n+ 1 1
uj,k 2 = g(xj , yk , tn + ∆t), j = 0, Mx
2
Option II: Using Step 1 and 2
n+ 1 1 1 1 1
uj,k 2 = (1 − ry δy2 )un+1 2 n
j,k + (1 + ry δy )uj,k
2 2 2 2
At j = 0, Mx
n+ 1 1 1 1 1 1
uj,k 2 = (1 − ry δy2 )g(xj , yk , tn + ∆t) + (1 + ry δy2 )g(xj , yk , tn )
2 2 2 2 2
n+ 1
If BC do not depend on t, then uj,k 2 = g(xj , yk )
14 / 23
D’Yakonov Scheme: Dirichlet BC

1
What boundary condition to use for u∗j,k at j = 0, Mx ? Unlike un+ 2 , we do
not know what u∗ represents. Instead use the numerical scheme itself; from
Step 2
1
u∗j,k = (1 − ry δy2 )un+1
j,k
2
Boundary condition for u∗j,k

1
u∗j,k = (1 − ry δy2 )g(xj , yk , tn+1 ), j = 0, Mx
2
E.g., at j = 0
ry n+1 ry n+1
u∗0,k = − n+1
gj,k−1 + (1 + ry )gj,k − gj,k+1
2 2

15 / 23
Peaceman-Rachford Scheme: Implementation
Step 1: For j = 1, . . . , Mx − 1 and k = 1, . . . , My − 1

1 n+ 1 1
(1 − rx δx2 )uj,k 2 = (1 + ry δy2 )unj,k
2 2
For k = 1, . . . , My − 1, solve tridiagonal matrix

rx n+ 12 n+ 1 rx n+ 21 1
− uj−1,k + (1 + rx )uj,k 2 − uj+1,k = (1 + ry δy2 )unj,k , j = 1, . . . , Mx − 1
2 2 2
Step 2: For j = 1, . . . , Mx − 1 and k = 1, . . . , My − 1

1 1 2 n+ 2
1
(1 − ry δy2 )un+1
j,k = (1 + rx δx )uj,k
2 2
For j = 1, . . . , Mx − 1, solve tridiagonal matrix
ry n+1 ry n+1 1 n+ 1
− u + (1 + ry )un+1
j,k − u = (1 + rx δx2 )uj,k 2 , k = 1, . . . , My − 1
2 j,k−1 2 j,k+1 2

Remark: Total work scales as O (Mx My ) and hence is optimal.


16 / 23
Douglas-Rachford Scheme
This is an approximate factorised version of the BTCS scheme.

(1 − rx δy2 − ry δy2 )un+1 = un

Factorise LHS operator

(1 − rx δy2 − ry δy2 ) = (1 − rx δx2 )(1 − ry δy2 ) − rx ry δx2 δy2

We can throw away the last term since we will get first order time accuracy.
But we can make a better approximation as follows.

(1 − rx δx2 )(1 − ry δy2 )un+1 = un + rx ry δx2 δy2 un+1

(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 + rx ry δx2 δy2 )un + rx ry δx2 δy2 (un+1 − un )
| {z }
O(∆t3 )

Douglas-Rachford scheme is given by

(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 + rx ry δx2 δy2 )un

17 / 23
Douglas-Rachford Scheme: Two step scheme

Introduce an intermediate state u∗

(1 − rx δx2 ) (1 − ry δy2 )un+1 = (1 + rx ry δx2 δy2 )un


| {z }
u∗

Two-step process

(1 − rx δx2 )u∗ = (1 + ry δy2 )un


(1 − ry δy2 )un+1 = u∗ − ry δy2 un

We avoid fourth differences δx2 δy2 . The equivalence is seen as follows.

(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 − rx δx2 )u∗ − (1 − rx δx2 )ry δy2 un


= (1 + ry δy2 )un − (1 − rx δx2 )ry δy2 un
= (1 + rx ry δx2 δy2 )un

18 / 23
Douglas-Rachford Scheme: Fourier stability

Amplification factor

1 + 16rx ry sin2 (ξ/2) sin2 (η/2)


ρ(ξ, η) = ≤1
[1 + 4rx sin2 (ξ/2)][1 + 4ry sin2 (η/2)]

The scheme is unconditionally stable.

19 / 23
Douglas-Rachford Scheme: Dirichlet BC

We need BC for u∗ at j = 0, Mx . Using Step 2 of the scheme

u∗ = (1 − ry δy2 )un+1 − ry δy2 un

This gives the boundary conditions

u∗j,k = (1 − ry δy2 )gj,k


n+1
− ry δy2 gj,k
n
, j = 0, Mx

20 / 23
Source terms
Heat equation with a forcing term

ut = µ(uxx + uyy ) + F (x, y, t)

Crank-Nicholson scheme, second order in time and space


1 1 1 1 ∆t n
(1 − rx δx2 − ry δy2 )un+1 = (1 + rx δx2 + ry δy2 )un + (F + F n+1 )
2 2 2 2 2
We can do a factorization as before
1 1 1 1 ∆t n
(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 + rx δx2 )(1 + ry δy2 )un + (F + F n+1 )
2 2 2 2 2
rx ry 2 2 n+1
− δx δy (u − un )
|4 {z }
O(∆t3 )

Ignoring last term, the resulting scheme is second order accurate


1 1 1 1 ∆t n
(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 + rx δx2 )(1 + ry δy2 )un + (F + F n+1 )
2 2 2 2 2
21 / 23
Source terms: Peaceman-Rachford Scheme
Use the viewpoint of two step process: tn → tn + 21 ∆t → tn+1

1 1 1 ∆t n
(1 − rx δx2 )un+ 2 = (1 + ry δy2 )un + F
2 2 2
1 1 1 ∆t n+1
(1 − ry δy2 )un+1 = (1 + rx δx2 )un+ 2 + F
2 2 2
1
To check the consistency of the scheme, eliminate un+ 2
1 1 1 1 1
(1 − rx δx2 )(1 − ry δy2 )un+1 = (1 − rx δx2 )(1 + rx δx2 )un+ 2
2 2 2 2
∆t 1
+ (1 − rx δx )F n+1
2
2 2
1 1 ∆t n
= (1 + rx δx )(1 + ry δy2 )un +
2
(F + F n+1 )
2 2 2
rx ∆t 2 n+1
− δx (F − F n)
| 2 {z }
O(∆t3 )

Hence the two-step scheme is second order accurate in time and space.
22 / 23
Source terms: D’Yakonov Scheme
Start with approximately factored Crank-Nicholson scheme
1 1 1 1 ∆t n
(1 − rx δx2 ) (1 − ry δy2 )un+1 = (1 + rx δx2 )(1 + ry δy2 )un + (F + F n+1 )
2 | 2 {z } 2 2 2
u∗

Two-step D’Yakonov scheme


1 1 1 ∆t n
(1 − rx δx2 )u∗ = (1 + rx δx2 )(1 + ry δy2 )un + (F + F n+1 )
2 2 2 2
1
(1 − ry δy2 )un+1 = u∗
2

Remark: We cannot spread out the source term into the two steps like this
1 1 1 ∆t n
(1 − rx δx2 )u∗ = (1 + rx δx2 )(1 + ry δy2 )un + F
2 2 2 2
1 ∆t n+1
(1 − ry δy2 )un+1 = u∗ + F
2 2
This scheme is only first order accurate in time.
23 / 23

You might also like