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 u t = µ(u xx + u yy ), (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 (M x + 1) (M y + 1) points in Ω x = 1 M x, x j = j x, j = 0, 1,..., M x y = 1 M y, y k = k y, k = 0, 1,..., M y 2 / 23
FTCS scheme D + t u n = µ(d + x D x u n + D + y D y u n ) Define D t + u n = un+1 t un, D + x D x u n = un j 1,k 2un + un j+1,k x 2 D + y D y u n = un 1 2un + un +1 y 2 r x = µ t x 2, Define undivided finite differences r y = µ t y 2 δ 2 xu n = u n j 1,k 2u n + u n j+1,k, δ 2 yu n = u n 1 2u n + u n +1 FTCS scheme or u n+1 u n+1 = un + r x δ 2 xu n + r y δ 2 yu n = (1 + r xδ 2 x + r y δ 2 y)u n 3 / 23
FTCS scheme: maximum stability If then u n+1 = (1 2r x 2r y )u n + r x (u n j 1,k + u n j+1,k) + r y (u n 1 + u n +1) r x + r y 1 2 min(u n j±1,k, u n ±1, u n ) u n+1 max(un j±1,k, u n ±1, u n ) so that the scheme is stable in maximum norm. If x = y = h, then 2µ t h 2 1 2 = t h2 4µ This time step restriction is half the value in one dimension. 4 / 23
FTCS scheme: Fourier stability Take Fourier mode with wave-number (ξ, η) ( π, +π) ( π, +π) u n = û n e i(jξ+kη) Then where û n+1 = ρû n ρ(ξ, η) = 1 + 2r x (cos ξ 1) + 2r y (cos η 1) = 1 4r x sin 2 (ξ/2) 4r y sin 2 (η/2) For stability we need ρ(ξ, η) 1. Maximum value of ρ ρ = 1 at (ξ, η) = (0, 0) and minimum value of ρ ρ = 1 4r x 4r y at (ξ, η) = (π, π) Hence we have stability provided r x + r y 1 2 5 / 23
BTCS scheme or u n+1 = un + r x δxu 2 n+1 + r yδyu 2 n+1 (1 r x δ 2 y r y δ 2 y)u n+1 Amplification factor Amplification factor ρ = BTCS scheme is unconditionally stable. = un 1 1 + 4r x sin 2 (ξ/2) + 4r y sin 2 (η/2) 1 6 / 23
Crank-Nicholson scheme or u n+1 = u n un + r x δx 2 + un+1 + r y δy 2 2 (1 1 2 r xδ 2 x 1 2 r yδ 2 y)u n+1 u n + un+1 2 = (1 + 1 2 r xδ 2 x + 1 2 r yδ 2 y)u n Amplification factor ρ = 1 2r x sin 2 (ξ/2) 2r y sin 2 (η/2) 1 + 2r x sin 2 (ξ/2) + 2r y sin 2 (η/2) 1 Crank-Nicholson scheme is unconditionally stable. 7 / 23
Peaceman-Rachford scheme Update solution in two steps Step 1: Implicit in x t n t n + 1 2 t tn+1, u n u n+ 1 2 u n+1 or u n+ 1 2 u n 1 2 t = µ x 2 δ2 xu n+ 1 2 + µ y 2 δ2 yu n (1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r yδ 2 y)u n Step 2: Implicit in y or u n+1 1 un+ 2 1 2 t = µ x 2 δ2 xu n+ 1 2 + µ y 2 δ2 yu n+1 (1 1 2 r yδy)u 2 n+1 = (1 + 1 2 r xδx)u 2 n+ 1 2 8 / 23
Peaceman-Rachford scheme: Fourier stability Step 1: [1 + 2r x sin 2 (ξ/2)]û n+ 1 2 = [1 2ry sin 2 (η/2)]û n Step 2: [1 + 2r y sin 2 (η/2))û n+1 = [1 2r x sin 2 (ξ/2)]û n+ 1 2 Combining the two ρ = ûn+1 û n = [1 2r x sin 2 (ξ/2)][1 2r y sin 2 (η/2)] [1 + 2r x sin 2 (ξ/2)][1 + 2r y sin 2 (η/2)] 1 The scheme is unconditionally stable. 9 / 23
Peaceman-Rachford scheme: Consistency From Step 1 (1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r yδ 2 y)u n Multiply on both sides (1 + 1 2 r xδ 2 x)(1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n Operators on left commute Using Step 2 (1 1 2 r xδx) 2 (1 + 1 2 r xδx)u 2 n+ 1 2 = (1 + 1 }{{} 2 r xδx)(1 2 + 1 2 r yδy)u 2 n use Step 2 (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y)u n+1 = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n 10 / 23
Peaceman-Rachford scheme: Consistency Expand difference operators on both sides u n+1 u t = µ u n x 2 δ2 + un+1 x 2 µ2 t 4 δ 2 x x 2 + µ y 2 δ2 y δy 2 y 2 (un+1 un ) u n + un+1 2 This is Crank-Nicholson scheme with an extra term. This term is O ( t 2) since δx 2 δ 2 ( y 5 ) n x 2 y 2 (un+1 u un ) = t t 2 x 2 + O ( t x 2 + t y 2 + t 2) y Hence the Peaceman-Rachford scheme is second order accurate in space and time. 11 / 23
D Yakonov Scheme Peaceman-Rachford scheme (1 1 2 r xδx) 2 (1 1 2 r yδy)u 2 n+1 = (1 + 1 }{{} 2 r xδx)(1 2 + 1 2 r yδy)u 2 n u Step 1: Solve for u Step 2: Solve for u n+1 (1 1 2 r xδ 2 x)u = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n (1 1 2 r yδ 2 y)u n+1 = u 12 / 23
Approximate factorization Peaceman-Rachford scheme is close to Crank-Nicholson scheme (1 1 2 r xδ 2 x 1 2 r yδ 2 y)u n+1 Factorise operator on left hand side = (1 + 1 2 r xδ 2 x + 1 2 r yδ 2 y)u n (1 1 2 r xδ 2 x 1 2 r yδ 2 y) = (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y) r xr y 4 δ2 xδ 2 y We cannot neglect the last term since it is O ( t 2) and the scheme would only be first order accurate ( r x r y 4 δ2 xδyu 2 n+1 = t2 4 ) n+1 u 4 2 x 2 + higher order terms y We factorise the right hand side also (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y)u n+1 = (1+ 1 2 r xδx)(1+ 2 1 2 r yδy)u 2 n + r xr y 4 δ2 xδy(u 2 n+1 un ) }{{} O( t 3 ) 13 / 23
Peaceman-Rachford Scheme: Dirichlet BC Step 1 is (1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r yδ 2 y)u n What boundary condition to use for u n+ 1 2 at j = 0, M x? Option I: Since u n+ 1 2 u(x j, y k, t n + 1 2 t) Option II: Using Step 1 and 2 At j = 0, M x u n+ 1 2 = g(x j, y k, t n + 1 2 t), j = 0, M x u n+ 1 2 = 1 2 (1 1 2 r yδy)u 2 n+1 + 1 2 (1 + 1 2 r yδy)u 2 n u n+ 1 2 = 1 2 (1 1 2 r yδ 2 y)g(x j, y k, t n + 1 2 t) + 1 2 (1 + 1 2 r yδ 2 y)g(x j, y k, t n ) If BC do not depend on t, then u n+ 1 2 = g(x j, y k ) 14 / 23
D Yakonov Scheme: Dirichlet BC What boundary condition to use for u at j = 0, M x? Unlike u n+ 1 2, we do not know what u represents. Instead use the numerical scheme itself; from Step 2 Boundary condition for u u = (1 1 2 r yδ 2 y)u n+1 u = (1 1 2 r yδ 2 y)g(x j, y k, t n+1 ), j = 0, M x E.g., at j = 0 u 0,k = r y 2 gn+1 1 + (1 + r y)g n+1 r y 2 gn+1 +1 15 / 23
Peaceman-Rachford Scheme: Implementation Step 1: For j = 1,..., M x 1 and k = 1,..., M y 1 (1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r yδ 2 y)u n For k = 1,..., M y 1, solve tridiagonal matrix r x j 1,k + (1 + r x)u n+ 1 2 r x 1 2 un+ 2 1 2 un+ 2 Step 2: For j = 1,..., M x 1 and k = 1,..., M y 1 j+1,k = (1 + 1 2 r yδ 2 y)u n, j = 1,..., M x 1 (1 1 2 r yδy)u 2 n+1 = (1 + 1 2 r xδx)u 2 n+ 1 2 For j = 1,..., M x 1, solve tridiagonal matrix r y 2 un+1 1 + (1 + r y)u n+1 r y 2 un+1 +1 = (1 + 1 2 r xδx)u 2 n+ 1 2, k = 1,..., M y 1 Remark: Total work scales as O (M x M y ) and hence is optimal. 16 / 23
Douglas-Rachford Scheme This is an approximate factorised version of the BTCS scheme. (1 r x δy 2 r y δy)u 2 n+1 = u n Factorise LHS operator (1 r x δ 2 y r y δ 2 y) = (1 r x δ 2 x)(1 r y δ 2 y) r x r y δ 2 xδ 2 y 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 r x δ 2 x)(1 r y δ 2 y)u n+1 = u n + r x r y δ 2 xδ 2 yu n+1 (1 r x δ 2 x)(1 r y δ 2 y)u n+1 = (1 + r x r y δ 2 xδ 2 y)u n + r x r y δ 2 xδ 2 y(u n+1 u n ) }{{} O( t 3 ) Douglas-Rachford scheme is given by (1 r x δ 2 x)(1 r y δ 2 y)u n+1 = (1 + r x r y δ 2 xδ 2 y)u n 17 / 23
Douglas-Rachford Scheme: Two step scheme Introduce an intermediate state u Two-step process (1 r x δ 2 x) (1 r y δ 2 y)u n+1 }{{} u 2 = (1 + r x r y δxδy)u 2 n (1 r x δ 2 x)u = (1 + r y δ 2 y)u n (1 r y δ 2 y)u n+1 = u r y δ 2 yu n We avoid fourth differences δ 2 xδ 2 y. The equivalence is seen as follows. (1 r x δ 2 x)(1 r y δ 2 y)u n+1 = (1 r x δ 2 x)u (1 r x δ 2 x)r y δ 2 yu n = (1 + r y δ 2 y)u n (1 r x δ 2 x)r y δ 2 yu n = (1 + r x r y δ 2 xδ 2 y)u n 18 / 23
Douglas-Rachford Scheme: Fourier stability Amplification factor ρ(ξ, η) = The scheme is unconditionally stable. 1 + 16r x r y sin 2 (ξ/2) sin 2 (η/2) [1 + 4r x sin 2 (ξ/2)][1 + 4r y sin 2 (η/2)] 1 19 / 23
Douglas-Rachford Scheme: Dirichlet BC We need BC for u at j = 0, M x. Using Step 2 of the scheme This gives the boundary conditions u = (1 r y δ 2 y)u n+1 r y δ 2 yu n u = (1 r y δ 2 y)g n+1 r yδ 2 yg n, j = 0, M x 20 / 23
Source terms Heat equation with a forcing term u t = µ(u xx + u yy ) + F (x, y, t) Crank-Nicholson scheme, second order in time and space (1 1 2 r xδ 2 x 1 2 r yδ 2 y)u n+1 = (1 + 1 2 r xδ 2 x + 1 2 r yδ 2 y)u n + t 2 (F n + F n+1 ) We can do a factorization as before (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y)u n+1 = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n + t 2 (F n + F n+1 ) r xr y 4 δ2 xδ 2 y(u n+1 u n ) }{{} O( t 3 ) Ignoring last term, the resulting scheme is second order accurate (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y)u n+1 = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n + t 2 (F n + F n+1 ) 21 / 23
Source terms: Peaceman-Rachford Scheme Use the viewpoint of two step process: t n t n + 1 2 t tn+1 (1 1 2 r xδ 2 x)u n+ 1 2 = (1 + 1 2 r yδ 2 y)u n + t 2 F n (1 1 2 r yδ 2 y)u n+1 = (1 + 1 2 r xδ 2 x)u n+ 1 2 + t 2 F n+1 To check the consistency of the scheme, eliminate u n+ 1 2 (1 1 2 r xδ 2 x)(1 1 2 r yδ 2 y)u n+1 = (1 1 2 r xδ 2 x)(1 + 1 2 r xδ 2 x)u n+ 1 2 + t 2 (1 1 2 r xδ 2 x)f n+1 = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n + t 2 (F n + F n+1 ) r x t 2 δ2 x(f n+1 F n ) }{{} O( t 3 ) 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 2 r xδx) 2 (1 1 2 r yδy)u 2 n+1 = (1 + 1 }{{} 2 r xδx)(1 2 + 1 2 r yδy)u 2 n + t 2 (F n + F n+1 ) u Two-step D Yakonov scheme (1 1 2 r xδ 2 x)u = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n + t 2 (F n + F n+1 ) (1 1 2 r yδ 2 y)u n+1 = u Remark: We cannot spread out the source term into the two steps like this (1 1 2 r xδ 2 x)u = (1 + 1 2 r xδ 2 x)(1 + 1 2 r yδ 2 y)u n + t 2 F n (1 1 2 r yδ 2 y)u n+1 = u + t 2 F n+1 This scheme is only first order accurate in time. 23 / 23