You are on page 1of 13

Victor Matveev, MRB / NIDDK / NIH

Numerical Integration of 3D Reaction-Diusion Equations


(Dierence methods for parabolic PDEs, boundary value problem)
Reaction-Diusion Problem:
Calcium :
[Ca
2+
]
t
= D
Ca

2
[Ca
2+
] +

j
R
j
+

m
a
m
(x x
m
) (1)
Buer :
[B
j
]
t
= D
B
j

2
[B
j
] + R
j
(2)
Reaction term ( Ca + B
j

CaB
j
) :
R
j
= k
+
j
[B
j
][Ca
2+
] + k

j
([B
j
]
total
[B
j
]) (3)
Diusion/heat equation in one dimension
Explicit and implicit dierence schemes
Stability analysis
Non-uniform grid
Three dimensions: Alternating Direction Implicit (ADI) methods
Non-homogeneous diusion equation: dealing with the reaction term
1
Diusion/heat equation in one spatial dimension
f
t
= D

2
f
x
2
(4)
Discretization of coordinates: (x, t) (x
j
, t
n
)
x
j
= x
0
+ j x ; t
n
= t
0
+ nt ; f(x
j
, t
n
) f
n
j
Finite dierence approximation for 1st derivative:
f
n+1
j
f
n
j
t
=
f
n+1/2
j
t
+ O(t
2
) =
f
n
j
t
+ O(t) =
f
n+1
j
t
+ O(t) (5)
Finite dierence approximation for 2nd derivative:
(f
n
j+1
f
n
j
)/x (f
n
j
f
n
j1
)/x
x
=
f
n
j1
2f
n
j
+ f
n
j+1
x
2
=

2
f
n
j
x
2
+ O(x
2
) (6)
1. Euler (explicit) scheme: f
n+1
j
f
n
j
= (f
n
j1
2f
n
j
+ f
n
j+1
)
2
x
f
n
j
where Dt/x
2
Given f
n
j
, values at next time step f
n+1
j
are computed directly
Stable for < 1/2
Truncation error: T = O(t) + O(x
2
)
2. Fully implicit scheme: f
n+1
j
f
n
j
= (f
n+1
j1
2f
n+1
j
+ f
n+1
j+1
)
2
x
f
n+1
j
(backward Euler method)
Tridiagonal system of linear equations must be solved at each time step
Unconditionally stable
Truncation error: T = O(t) + O(x
2
)
3. Crank-Nicholson (implicit) scheme: f
n+1
j
f
n
j
= /2{
2
x
f
n
j
+
2
x
f
n+1
j
}
symmetric representation: (1

2

2
x
)f
n+1
j
= (1 +

2

2
x
)f
n
j
(7)
Truncation error: T = O(t
2
) + O(x
2
)
Unconditionally stable
2
Solving the fully implicit scheme: tridiagonal system
f
t
= D

2
f
x
2
f
n+1
j
f
n
j
= (f
n+1
j1
2f
n+1
j
+ f
n+1
j+1
) (8)
Assume Dirichlet boundary conditions: f
0
= f
N
= 0
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
1 + 2 0 0
1 + 2 0 0
0 1 + 2
0 0 1 + 2

1 + 2 0
0 1 + 2
0 1 + 2
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
f
n+1
0
f
n+1
1
f
n+1
3
f
n+1
4

f
n+1
N2
f
n+1
N1
f
n+1
N
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
=
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
f
n
0
f
n
1
f
n
3
f
n
4

f
n
N2
f
n
N1
f
n
N
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
L
j
f
j1
+ C
j
f
j
+ R
j
f
j+1
= H
j
j = 0..N
L
0
= R
N
= 0, L
j
= R
j
= , C
j
= 1 + 2
Solve by Gaussian elimination:
1. Forward elimination: R
0
= R
0
/C
0
, H
0
= H
0
/C
0
(9)
C
j
= C
j
L
j
R
j1
, j = 1..N (10)
H
j
= (H
j
L
j
H
j1
)/C
j
, j = 1..N (11)
R
j
= R
j
/C
j
, j = 1..N (12)
2. Backward substitution: f
N
= H
N
(13)
f
j
= H
j
R
j
f
j+1
, j = N 1 . . . 0. (14)
Operations per time step: 5N multiply/divide + 3N add/subtract
3
Stability Analysis: Fourier Method
Dierence scheme is linear (as well as the PDEs), so the error satises
the same equation
Substitute into equations the solution (for the error instability) of the
form f
n
j
=
n
exp(i x
j
k) ( where k = m/(Nx), m = 0..N )
Method is stable if < 1
1. Forward Euler (explicit scheme): f
n+1
j
f
n
j
=
x
(f
n
j1
2f
n
j
+ f
n
j+1
)
(
n+1

n
) exp(i x
j
k) =
x

n
exp(i x
j
k) [exp(i xk) 2 + exp(i xk)]
1 =
x
[exp(i xk) 2 + exp(i xk)]
= 1 4
x
sin
2
(xk/2)
|| < 1
x
< 1/2 (15)
2. Backward Euler (implicit scheme): f
n+1
j
f
n
j
=
x
(f
n+1
j1
2f
n+1
j
+ f
n+1
j+1
)
(
n+1

n
) exp(i x
j
k) =
x

n+1
exp(i x
j
k) [exp(i xk) 2 + exp(i xk)]
1 =
x
[exp(i xk) 2 + exp(i xk)]
=
1
1 + 4
x
sin
2
(xk/2)
< 1 (always stable) (16)
4
Non-Uniform Grid: x
i+1
x
i
= x
i
Finite dierence approximation for the 2nd derivative:
(f
n
j+1
f
n
j
)/x
j
(f
n
j
f
n
j1
)/x
j1
(x
j1
+ x
j
)/2
=

2
f
n
j
x
2
+ O(x
2
j,j1
) + O(x
j
x
j1
)
(17)
To maintain accuracy, set x
j
= x
j1
(1 ), 1
Modied dierence scheme:
f
n+1
j
f
n
j
= (f
n+1
j1
2f
n+1
j
+f
n+1
j+1
) f
n+1
j
f
n
j
=

j
f
n+1
j1
+
0
j
f
n+1
j
+
+
j
f
n+1
j+1
(18)
where

j
=
2Dt
x
j1
(x
j1
+ x
j
)

0
j
=
2Dt
x
j1
x
j

+
j
=
2Dt
x
j
(x
j1
+ x
j
)
Minimal spacing decreases exponentially with increasing N:
x
j
= (1 + )x
j1
= (1 + )
j
x
0

j
x
0
x
0
=
x
N

n
5
Flux boundary conditions:
f
0,N
n
+ bf
0,N
= c (19)
Consider eld values at (virtual) points outside the boundary:
f
1
= f(x
0
x), f
N+1
= f(x
N
+ x)
f
0
x

f
1
f
1
2x
+ O(x
2
)
f
0
x
+ bf
0
= c f
1
f
1
+ 2x(bf
0
c) = 0
f
1
= f
1
+ 2x(bf
0
c) (20)
Dierence equation at point x
0
:
f
n+1
0
f
n
0
= (f
n+1
1
2f
n+1
0
+ f
n+1
1
)
= (f
n+1
1
+ 2x(bf
n+1
0
c) 2f
n+1
0
+ f
n+1
1
)
= 2 (f
n+1
1
+ (bx 1)f
n+1
0
cx)
[2(1 bx) + 1]f
n+1
0
2f
n+1
1
= f
n
0
2cx (21)
Dierence equation at point x
N
:
[2(1 bx) + 1]f
n+1
N
2f
n+1
N1
= f
n
N
2cx (22)
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
1 + 2(1 bx) 2 0
1 + 2 0
0 1 + 2

1 + 2 0
0 1 + 2
0 2 1 + 2(1 bx)
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
f
n+1
0
f
n+1
1
f
n+1
3

f
n+1
N2
f
n+1
N1
f
n+1
N
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
=
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
f
n
0
2cx
f
n
1
f
n
3

f
n
N2
f
n
N1
f
n
N
2cx
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
_
6
Diusion/heat equation in three spatial dimensions
f
t
= D
_
_

2
f
x
2
+

2
f
y
2
+

2
f
z
2
_
_
(23)
1. Euler (explicit) scheme: f
n+1
f
n
=
_

2
x
+
y

2
y
+
z

2
z
_
f
n
where f
n
f
n
ijk
f(x
i
, y
j
, z
k
; t
n
)

x
Dt/x
2
,
y
Dt/y
2
,
z
Dt/z
2

2
x
f
n
f
n
i1jk
2f
n
ijk
+ f
n
i+1jk
,
2
y
f
n
f
n
ij1k
2f
n
ijk
+ f
n
ij+1k

2
z
f
n
f
n
ijk1
2f
n
ijk
+ f
n
ijk+1
Stability condition:
x
+
y
+
z
1/2
2. Implicit schemes: Alternating Direction Implicit (ADI) Methods
Backward Euler (f
n+1
f
n
=
_

2
x
+
y

2
y
+
z

2
z
_
f
n+1
) no longer practical: re-
quires solution of a (non-tridiagonal) system of N
3
equations.
Locally One-Dimensional (LOD) method
3D analog of Crank-Nicholson scheme:
(1

x
2

2
x

y
2

2
y

z
2

2
z
)f
n+1
= (1 +

x
2

2
x
+

y
2

2
y
+

z
2

2
z
)f
n
(24)
Factorization (introduces additional terms of order O(t
2
))
(1

x
2

2
x
)(1

y
2

2
y
)(1

z
2

2
z
)f
n+1
= (1 +

x
2

2
x
)(1 +

y
2

2
y
)(1 +

z
2

2
z
)f
n
(25)
To solve Eq. (25), break down each iteration into several steps:
(1

x
2

2
x
)f
n
= (1 +

x
2

2
x
)f
n
(1

y
2

2
y
)f
n
= (1 +

y
2

2
y
)f
n
(1

z
2

2
z
)f
n+1
= (1 +

z
2

2
z
)f
n
(26)
Each time step three tridiagonal systems are solved for all points.
Truncation error: T = O(t
2
) + O(x
2
) + O(y
2
) + O(z
2
)
Always stable
Problem: equations for intermediate values f
n
, f
n
are not consistent with the full
dierential equation: additional care required dealing with boundary conditions
7
Douglas-Gunn ADI Method
Another deformation of the Crank-Nicholson method:
(1
A
x
2
)(1
A
y
2
)(1
A
z
2
)f
n+1
=
_
(1 +
A
x
2
)(1 +
A
y
2
)(1 +
A
z
2
)
A
x
A
y
A
z
4
_
f
n
(27)
where A
x

x

2
x
= D
t
x
2

2
x
, A
y

y

2
y
, A
z

z

2
z
Multi-step implementation - Douglas-Gunn method
(1
A
x
2
)f
n
= (1 +
A
x
2
+ A
y
+ A
z
)f
n
(28)
(1
A
y
2
)f
n
= (1 +
A
x
2
+
A
y
2
+ A
z
)f
n
+
A
x
2
f
n
(29)
(1
A
z
2
)f
n+1
= (1 +
A
x
2
+
A
y
2
+
A
z
2
)f
n
+
A
x
2
f
n
+
A
y
2
f
n
(30)
Each equation is a valid approximation of the full diusion equation -
no modication needed for boundary conditions
Simplify by subtracting Eq.(28) from Eq.(29), and Eq.(29) from Eq.(30):
(1
A
x
2
)f
n
= (1 +
A
x
2
+ A
y
+ A
z
)f
n
(31)
(1
A
y
2
)f
n
= f
n

A
y
2
f
n
(32)
(1
A
z
2
)f
n+1
= f
n

A
z
2
f
n
(33)
Truncation error: T = O(t
2
) + O(x
2
) + O(y
2
) + O(z
2
)
Always stable
8
Heterogeneous Diusion/heat equation in 1D
f
t
= D

2
f
x
2
+ H(f, t) (34)
Crank-Nicholson scheme:
f
n+1
j
f
n
j
= /2{
2
x
f
n
j
+
2
x
f
n+1
j
} +
t
2
(H(f
n+1
, t
n+1
) + H(f
n
, t
n
)) (35)
Symmetric form:
(1

2

2
x
)f
n+1
j
= (1 +

2

2
x
)f
n
j
+
t
2
(H(f
n+1
, t
n+1
) + H(f
n
, t
n
)) (36)
For non-linear H(f), this scheme can be solved using predictor/corrector
or iteration methods, or one has to give up O(t
2
) accuracy:
H(f
n+1
) = H(f
n
) + H

(f
n
)(f
n+1
f
n
)/t + O(t)
Without loss of accuracy, one can substitute H
n
H(f
n
, t
n
) H(f
n
, t
n+1/2
),
H
n+1
H(f
n+1
, t
n+1
) H(f
n+1
, t
n+1/2
). The following is an equivalent
scheme:
(1

2

2
x
)f
n+1
j
= (1 +

2

2
x
)f
n
j
+
t
2
(H(f
n+1
, t
n+
1
2
) + H(f
n
, t
n+
1
2
)) (37)
9
Heterogeneous diusion/heat equation in 3D
f
t
= D
_
_

2
f
x
2
+

2
f
y
2
+

2
f
z
2
_
_
+ H(f, t) (38)
Douglas-Gunn method for heterogeneous equation:
(1
A
x
2
)f
n
= (1 +
A
x
2
+ A
y
+ A
z
)f
n
+ t ( H(f
n
) + H(f
n
) ) (39)
(1
A
y
2
)f
n
= (1 +
A
x
2
+
A
y
2
+ A
z
)f
n
+
A
x
2
f
n
+ t ( H(f
n
) + H(f
n
) ) (40)
(1
A
z
2
)f
n+1
= (1+
A
x
2
+
A
y
2
+
A
z
2
)f
n
+
A
x
2
f
n
+
A
y
2
f
n
+t ( H(f
n
)+H(f
n+1
) )
(41)
where + = 1, + = 1, + = 1.
Choice of coecients consistent with second order accuracy:
= = 1, = = 0, = = 1/2.
Subtract Eq.(39) from Eq.(40), and Eq.(40) from Eq.(41):
(1
A
x
2
)f
n
= (1 +
A
x
2
+ A
y
+ A
z
)f
n
+ t H
n
(42)
(1
A
y
2
)f
n
= f
n

A
y
2
f
n
(43)
(1
A
z
2
)f
n+1
= f
n

A
z
2
f
n
+
t
2
(H
n+1
H
n
) (44)
where H
n
H(f
n
, t
n
), H
n+1
H(f
n+1
, t
n+1
).
Apply operator (1
A
x
2
)(1
A
y
2
) from the left to recover the dierence scheme:
(1
A
x
2
)(1
A
y
2
)(1
A
z
2
)f
n+1
=
_
(1 +
A
x
2
)(1 +
A
y
2
)(1 +
A
z
2
)
A
x
A
y
A
z
4
_
f
n
+
t
2
(H
n
+ H
n+1
)
t
2
(A
x
+ A
y

A
x
A
y
2
)(H
n+1
H
n
) (45)
Without loss of accuracy, one can substitute H
n
H(f
n
, t
n
) H(f
n
, t
n+1/2
),
H
n+1
H(f
n+1
, t
n+1
) H(f
n+1
, t
n+1/2
).
10
Reaction-diusion with one buer (Hines method)
Calcium :
[Ca]
t
= D
Ca

2
[Ca] + R +

m
a
k
(x x
m
) (46)
Buer :
[B]
t
= D
B

2
[B] + R (47)
Reaction term : R = k
+
[B][Ca] + k

([B]
total
[B]) (48)
Dierence scheme for source term: H
source
(x
i
, y
j
, z
k
) =

c
m

i
i
m

j
j
m

k
k
m
Heterogeneity for [Ca]: H
Ca
([Ca], t) = H
source
+ R([Ca], [B])
Heterogeneity for [B]: H
B
([B], t) = R([Ca], [B]) (49)
Problem: to solve for [Ca]
n+1
, knowledge of [B]
n+1
is required; to solve for
[B]
n+1
, knowledge of [Ca]
n+1
is required.
Solution: compute [Ca] and [B] on time grids staggered by t/2
(1
A
x
2
)[Ca]
n
= (1 +
A
x
2
+ A
y
+ A
z
)[Ca]
n
+ t H
Ca
([Ca]
n
, [B]
n+
1
2
))
(1
A
y
2
)[Ca]
n
= [Ca]
n

A
y
2
[Ca]
n
(1
A
z
2
)[Ca]
n+1
= [Ca]
n

A
z
2
[Ca]
n
+
t
2
(H
Ca
([Ca]
n+1
, [B]
n+
1
2
) H
Ca
([Ca]
n
, [B]
n+
1
2
))
(1
A
x
2
)[B]
n
1
2

= (1 +
A
x
2
+ A
y
+ A
z
)[B]
n
1
2
+ t H
B
([B]
n
1
2
, [Ca]
n
)
(1
A
y
2
)[B]
n
1
2

= [B]
n
1
2

A
y
2
[B]
n
1
2
(1
A
z
2
)[B]
n+
1
2
= [B]
n
1
2

A
z
2
[B]
n
1
2
+
t
2
(H
B
([B]
n+
1
2
, [Ca]
n
) H
B
([B]
n
1
2
, [Ca]
n
))
11
Fully implicit dierence scheme in 3D with heterogeneity
Fully implicit ADI method (Douglas-Rachford):
(1 A
x
)f
n
= (1 + A
y
+ A
z
)f
n
+ H
n
t (50)
(1 A
y
)f
n
= (1 + A
z
)f
n
+ A
x
f
n
+ H
n
t (51)
(1 A
z
)f
n+1
= f
n
+ A
x
f
n
+ A
y
f
n
+ H
n+1
t (52)
Each equation is a valid approximation of the full diusion equation -
no modication needed for boundary conditions
Agrees with the following deformation of the fully implicit dierence
scheme:
(1 A
x
)(1 A
y
)(1 A
z
)f
n+1
= (1 + A
x
A
y
+ A
y
A
z
+ A
x
A
z
A
x
A
y
A
z
)f
n
+ H
n+1
t + A
x
A
y
(H
n+1
H
n
)t (53)
where A
x

x

2
x
= D
t
x
2

2
x
, A
y

y

2
y
, A
z

z

2
z
Simplify by subtracting Eq.(50) from Eq.(51), and Eq.(51) from Eq.(52):
(1 A
x
)f
n
= (1 + A
y
+ A
z
)f
n
+ H
n
t (54)
(1 A
y
)f
n
= A
y
f
n
+ f
n
(55)
(1 A
z
)f
n+1
= A
z
f
n
+ f
n
+ (H
n+1
H
n
)t (56)
Truncation error: T = O(t) + O(x
2
) + O(y
2
) + O(z
2
)
Always stable
12
Heterogeneous diusion/heat equation in 2D
f
t
= D
_
_

2
f
x
2
+

2
f
y
2
_
_
+ H(f, t) (57)
1. Douglas-Gunn/Crank-Nicholson method:
(1
A
x
2
)f
n
= (1 +
A
y
2
)f
n
+
t
2
H(f
n
, t
n
) (58)
(1
A
y
2
)f
n+1
= (1 +
A
x
2
)f
n
+
t
2
H(f
n+1
, t
n+1
) (59)
Corresponding dierence scheme:
(1
A
x
2
)(1
A
y
2
)f
n+1
= (1 +
A
x
2
)(1 +
A
y
2
)f
n
+
t
2
(H
n
+ H
n+1
) +
t
4
A
x
(H
n
H
n+1
) (60)
where A
x

x

2
x
= D
t
x
2

2
x
, A
y

y

2
y
2. Fully implicit method:
(1 A
x
)f
n
= (1 + A
y
)f
n
+ t H(f
n
, t
n
) (61)
(1 A
y
)f
n+1
= f
n
+ A
x
f
n
+ t H(f
n+1
, t
n+1
) (62)
Corresponding deformation of the fully implicit dierence scheme:
(1 A
x
)(1 A
y
)f
n+1
= (1 + A
x
A
y
)f
n
+ H
n+1
t + A
x
(H
n
H
n+1
)t (63)
13

You might also like