finite difference method for 2-d heat...
TRANSCRIPT
Finite difference method for 2-D heat equation
Praveen. [email protected]
Tata Institute of Fundamental ResearchCenter for Applicable Mathematics
Bangalore 560065http://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 Ω
∆x =1
Mx, xj = j∆x, j = 0, 1, . . . ,Mx
∆y =1
My, yk = k∆y, k = 0, 1, . . . ,My
2 / 23
FTCS scheme
D+t u
nj,k = µ(D+
xD−x u
nj,k +D+
y D−y u
nj,k)
D+t u
nj,k =
un+1j,k − unj,k
∆t, D+
xD−x u
nj,k =
unj−1,k − 2unj,k + unj+1,k
∆x2
D+y D−y u
nj,k =
unj,k−1 − 2unj,k + unj,k+1
∆y2
Define
rx =µ∆t
∆x2, ry =
µ∆t
∆y2
Define undivided finite differences
δ2xu
nj,k = unj−1,k − 2unj,k + unj+1,k, δ2
yunj,k = unj,k−1 − 2unj,k + unj,k+1
FTCS schemeun+1j,k = unj,k + rxδ
2xu
nj,k + ryδ
2yu
nj,k
or
un+1j,k = (1 + rxδ
2x + ryδ
2y)unj,k
3 / 23
FTCS scheme: maximum stability
un+1j,k = (1− 2rx − 2ry)unj,k + rx(unj−1,k + unj+1,k) + ry(unj,k−1 + unj,k+1)
If
rx + ry ≤1
2
thenmin(unj±1,k, u
nj,k±1, u
nj,k) ≤ un+1
j,k ≤ max(unj±1,k, unj,k±1, u
nj,k)
so that the scheme is stable in maximum norm. If ∆x = ∆y = h, then
2µ∆t
h2≤ 1
2=⇒ ∆t ≤ h2
4µ
This time step restriction is half the value in one dimension.
4 / 23
FTCS scheme: Fourier stabilityTake Fourier mode with wave-number (ξ, η) ∈ (−π,+π)× (−π,+π)
unj,k = unei(jξ+kη)
Thenun+1 = ρun
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
rx + ry ≤1
2
5 / 23
BTCS scheme
un+1j,k = unj,k + rxδ
2xu
n+1j,k + ryδ
2yu
n+1j,k
or
(1− rxδ2y − ryδ2
y)un+1j,k = unj,k
Amplification factor Amplification factor
ρ =1
1 + 4rx sin2(ξ/2) + 4ry sin2(η/2)≤ 1
BTCS scheme is unconditionally stable.
6 / 23
Crank-Nicholson scheme
un+1j,k = unj,k + rxδ
2x
unj,k + un+1j,k
2+ ryδ
2y
unj,k + un+1j,k
2or
(1− 1
2rxδ
2x −
1
2ryδ
2y)un+1
j,k = (1 +1
2rxδ
2x +
1
2ryδ
2y)unj,k
Amplification factor
ρ =1− 2rx sin2(ξ/2)− 2ry sin2(η/2)
1 + 2rx sin2(ξ/2) + 2ry sin2(η/2)≤ 1
Crank-Nicholson scheme is unconditionally stable.
7 / 23
Peaceman-Rachford schemeUpdate solution in two steps
tn → tn +1
2∆t→ tn+1, un → un+ 1
2 → un+1
Step 1: Implicit in x
un+ 1
2
j,k − unj,k12∆t
=µ
∆x2δ2xu
n+ 12
j,k +µ
∆y2δ2yu
nj,k
or
(1− 1
2rxδ
2x)u
n+ 12
j,k = (1 +1
2ryδ
2y)unj,k
Step 2: Implicit in y
un+1j,k − u
n+ 12
j,k12∆t
=µ
∆x2δ2xu
n+ 12
j,k +µ
∆y2δ2yu
n+1j,k
or
(1− 1
2ryδ
2y)un+1
j,k = (1 +1
2rxδ
2x)u
n+ 12
j,k
8 / 23
Peaceman-Rachford scheme: Fourier stability
Step 1:[1 + 2rx sin2(ξ/2)]un+ 1
2 = [1− 2ry sin2(η/2)]un
Step 2:[1 + 2ry sin2(η/2))un+1 = [1− 2rx sin2(ξ/2)]un+ 1
2
Combining the two
ρ =un+1
un=
[1− 2rx sin2(ξ/2)][1− 2ry sin2(η/2)]
[1 + 2rx sin2(ξ/2)][1 + 2ry sin2(η/2)]≤ 1
The scheme is unconditionally stable.
9 / 23
Peaceman-Rachford scheme: Consistency
From Step 1
(1− 1
2rxδ
2x)u
n+ 12
j,k = (1 +1
2ryδ
2y)unj,k
Multiply on both sides
(1 +1
2rxδ
2x)(1− 1
2rxδ
2x)u
n+ 12
j,k = (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)unj,k
Operators on left commute
(1− 1
2rxδ
2x) (1 +
1
2rxδ
2x)u
n+ 12
j,k︸ ︷︷ ︸use Step 2
= (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)unj,k
Using Step 2
(1− 1
2rxδ
2x)(1− 1
2ryδ
2y)un+1
j,k = (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)unj,k
10 / 23
Peaceman-Rachford scheme: Consistency
Expand difference operators on both sides
un+1j,k − uj,k
∆t=
µ
∆x2δ2x
unj,k + un+1j,k
2+
µ
∆y2δ2y
unj,k + un+1j,k
2
−µ2∆t
4
δ2x
∆x2
δ2y
∆y2(un+1j,k − u
nj,k)
This is Crank-Nicholson scheme with an extra term. This term is O(∆t2
)since
δ2x
∆x2
δ2y
∆y2(un+1j,k − u
nj,k) = ∆t
(∂5u
∂t∂2x∂2y
)nj,k
+O(∆t∆x2 + ∆t∆y2 + ∆t2
)Hence the Peaceman-Rachford scheme is second order accurate in space andtime.
11 / 23
D’Yakonov Scheme
Peaceman-Rachford scheme
(1− 1
2rxδ
2x) (1− 1
2ryδ
2y)un+1
j,k︸ ︷︷ ︸u∗j,k
= (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)unj,k
Step 1: Solve for u∗
(1− 1
2rxδ
2x)u∗j,k = (1 +
1
2rxδ
2x)(1 +
1
2ryδ
2y)unj,k
Step 2: Solve for un+1
(1− 1
2ryδ
2y)un+1
j,k = u∗j,k
12 / 23
Approximate factorizationPeaceman-Rachford scheme is close to Crank-Nicholson scheme
(1− 1
2rxδ
2x −
1
2ryδ
2y)un+1
j,k = (1 +1
2rxδ
2x +
1
2ryδ
2y)unj,k
Factorise operator on left hand side
(1− 1
2rxδ
2x −
1
2ryδ
2y) = (1− 1
2rxδ
2x)(1− 1
2ryδ
2y)− rxry
4δ2xδ
2y
We cannot neglect the last term since it is O(∆t2
)and the scheme would only
be first order accurate
rxry4
δ2xδ
2yu
n+1j,k =
∆t2
4
(∂4u
∂2x∂2y
)n+1
j,k
+ higher order terms
We factorise the right hand side also
(1−1
2rxδ
2x)(1−1
2ryδ
2y)un+1
j,k = (1+1
2rxδ
2x)(1+
1
2ryδ
2y)unj,k+
rxry4
δ2xδ
2y(un+1
j,k − unj,k)︸ ︷︷ ︸
O(∆t3)
13 / 23
Peaceman-Rachford Scheme: Dirichlet BCStep 1 is
(1− 1
2rxδ
2x)u
n+ 12
j,k = (1 +1
2ryδ
2y)unj,k
What boundary condition to use for un+ 1
2
j,k at j = 0, Mx ?
Option I: Since un+ 1
2
j,k ≈ u(xj , yk, tn + 1
2∆t)
un+ 1
2
j,k = g(xj , yk, tn +
1
2∆t), j = 0,Mx
Option II: Using Step 1 and 2
un+ 1
2
j,k =1
2(1− 1
2ryδ
2y)un+1
j,k +1
2(1 +
1
2ryδ
2y)unj,k
At j = 0,Mx
un+ 1
2
j,k =1
2(1− 1
2ryδ
2y)g(xj , yk, t
n +1
2∆t) +
1
2(1 +
1
2ryδ
2y)g(xj , yk, t
n)
If BC do not depend on t, then un+ 1
2
j,k = g(xj , yk)14 / 23
D’Yakonov Scheme: Dirichlet BC
What boundary condition to use for u∗j,k at j = 0,Mx ? Unlike un+ 12 , we do
not know what u∗ represents. Instead use the numerical scheme itself; fromStep 2
u∗j,k = (1− 1
2ryδ
2y)un+1
j,k
Boundary condition for u∗j,k
u∗j,k = (1− 1
2ryδ
2y)g(xj , yk, t
n+1), j = 0,Mx
E.g., at j = 0
u∗0,k = −ry2gn+1j,k−1 + (1 + ry)gn+1
j,k −ry2gn+1j,k+1
15 / 23
Peaceman-Rachford Scheme: ImplementationStep 1: For j = 1, . . . ,Mx − 1 and k = 1, . . . ,My − 1
(1− 1
2rxδ
2x)u
n+ 12
j,k = (1 +1
2ryδ
2y)unj,k
For k = 1, . . . ,My − 1, solve tridiagonal matrix
−rx2un+ 1
2
j−1,k + (1 + rx)un+ 1
2
j,k − rx2un+ 1
2
j+1,k = (1 +1
2ryδ
2y)unj,k, j = 1, . . . ,Mx − 1
Step 2: For j = 1, . . . ,Mx − 1 and k = 1, . . . ,My − 1
(1− 1
2ryδ
2y)un+1
j,k = (1 +1
2rxδ
2x)u
n+ 12
j,k
For j = 1, . . . ,Mx − 1, solve tridiagonal matrix
−ry2un+1j,k−1 + (1 + ry)un+1
j,k −ry2un+1j,k+1 = (1 +
1
2rxδ
2x)u
n+ 12
j,k , k = 1, . . . ,My − 1
Remark: Total work scales as O (MxMy) and hence is optimal.16 / 23
Douglas-Rachford SchemeThis is an approximate factorised version of the BTCS scheme.
(1− rxδ2y − ryδ2
y)un+1 = un
Factorise LHS operator
(1− rxδ2y − ryδ2
y) = (1− rxδ2x)(1− ryδ2
y)− rxryδ2xδ
2y
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δ2x)(1− ryδ2
y)un+1 = un + rxryδ2xδ
2yu
n+1
(1− rxδ2x)(1− ryδ2
y)un+1 = (1 + rxryδ2xδ
2y)un + rxryδ
2xδ
2y(un+1 − un)︸ ︷︷ ︸O(∆t3)
Douglas-Rachford scheme is given by
(1− rxδ2x)(1− ryδ2
y)un+1 = (1 + rxryδ2xδ
2y)un
17 / 23
Douglas-Rachford Scheme: Two step scheme
Introduce an intermediate state u∗
(1− rxδ2x) (1− ryδ2
y)un+1︸ ︷︷ ︸u∗
= (1 + rxryδ2xδ
2y)un
Two-step process
(1− rxδ2x)u∗ = (1 + ryδ
2y)un
(1− ryδ2y)un+1 = u∗ − ryδ2
yun
We avoid fourth differences δ2xδ
2y. The equivalence is seen as follows.
(1− rxδ2x)(1− ryδ2
y)un+1 = (1− rxδ2x)u∗ − (1− rxδ2
x)ryδ2yu
n
= (1 + ryδ2y)un − (1− rxδ2
x)ryδ2yu
n
= (1 + rxryδ2xδ
2y)un
18 / 23
Douglas-Rachford Scheme: Fourier stability
Amplification factor
ρ(ξ, η) =1 + 16rxry sin2(ξ/2) sin2(η/2)
[1 + 4rx sin2(ξ/2)][1 + 4ry sin2(η/2)]≤ 1
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δ2y)un+1 − ryδ2
yun
This gives the boundary conditions
u∗j,k = (1− ryδ2y)gn+1
j,k − ryδ2ygnj,k, j = 0,Mx
20 / 23
Source termsHeat equation with a forcing term
ut = µ(uxx + uyy) + F (x, y, t)
Crank-Nicholson scheme, second order in time and space
(1− 1
2rxδ
2x −
1
2ryδ
2y)un+1 = (1 +
1
2rxδ
2x +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
We can do a factorization as before
(1− 1
2rxδ
2x)(1− 1
2ryδ
2y)un+1 = (1 +
1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
− rxry4
δ2xδ
2y(un+1 − un)︸ ︷︷ ︸O(∆t3)
Ignoring last term, the resulting scheme is second order accurate
(1− 1
2rxδ
2x)(1− 1
2ryδ
2y)un+1 = (1 +
1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
21 / 23
Source terms: Peaceman-Rachford SchemeUse the viewpoint of two step process: tn → tn + 1
2∆t→ tn+1
(1− 1
2rxδ
2x)un+ 1
2 = (1 +1
2ryδ
2y)un +
∆t
2Fn
(1− 1
2ryδ
2y)un+1 = (1 +
1
2rxδ
2x)un+ 1
2 +∆t
2Fn+1
To check the consistency of the scheme, eliminate un+ 12
(1− 1
2rxδ
2x)(1− 1
2ryδ
2y)un+1 = (1− 1
2rxδ
2x)(1 +
1
2rxδ
2x)un+ 1
2
+∆t
2(1− 1
2rxδ
2x)Fn+1
= (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
− rx∆t
2δ2x(Fn+1 − Fn)︸ ︷︷ ︸O(∆t3)
Hence the two-step scheme is second order accurate in time and space.22 / 23
Source terms: D’Yakonov SchemeStart with approximately factored Crank-Nicholson scheme
(1− 1
2rxδ
2x) (1− 1
2ryδ
2y)un+1︸ ︷︷ ︸
u∗
= (1 +1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
Two-step D’Yakonov scheme
(1− 1
2rxδ
2x)u∗ = (1 +
1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2(Fn + Fn+1)
(1− 1
2ryδ
2y)un+1 = u∗
Remark: We cannot spread out the source term into the two steps like this
(1− 1
2rxδ
2x)u∗ = (1 +
1
2rxδ
2x)(1 +
1
2ryδ
2y)un +
∆t
2Fn
(1− 1
2ryδ
2y)un+1 = u∗ +
∆t
2Fn+1
This scheme is only first order accurate in time.23 / 23