Numerical Methods in Geophysics:Implicit Methods
What is an implicit scheme?
Explicit vs. implicit scheme for Newtonian Cooling
Crank-Nicholson Scheme (mixed explicit-implicit)
Explicit vs. implicit for the diffusion equation
Relaxation Methods
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
Let us recall the ODE:
),( tTfdtdT
=
Before we used a forward difference scheme, what happensif we use a backward difference scheme?
),()(1jj
jj tTfdtOdtTT
=+− −
),(dt1 jjj-j tTfTT +≈⇒
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
or
Is this scheme convergent?
11 )1( −− +≈
τdtTT jj
jj
dtTT −+≈ )1(0 τ
Does it tend to the exact solution as dt->0? YES, it does (exercise)
Is this scheme stable, i.e. does T decay monotonically? This requires
11
10 <+
<
τdt
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
11
10 <+
<
τdt
This scheme is always stable! This is calledunconditional stability
... which doesn’t mean it’s accurate!Let’s see how it compares to the explicit method...
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
0 2 4 6 8-1.5
-1
-0.5
0
0.5
1
1.5
Time(s)
Tem
pera
ture
dt=1.41; tau=0.7
Explicit unstable - implicit stable - both inaccurate
red-analyticblue-explicit
green-implicit
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
Explicit stable - implicit stable - both inaccurate
0 2 4 6 8-0.5
0
0.5
1
Time(s)
Tem
pera
ture
dt=1; tau=0.7red-analyticblue-explicit
green-implicit
Numerical Methods in Geophysics Implicit Methods
What is an implicit method?
Explicit stable - implicit stable - both inaccurate
0 2 4 6 80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time(s )
Tem
pera
ture
dt=0.5; tau=0.7red-analyticblue-explicit
green-implicit
Numerical Methods in Geophysics Implicit Methods
0 2 4 6 80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time(s )
Tem
pera
ture
dt=0.1; tau=0.7
What is an implicit method?
Explicit stable - implicit stable - both accurate
red-analyticblue-explicit
green-implicit
It doesn’t look like we gained much from unconditional stability!
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
We start again with ...
),( tTfdtdT
=
Let us interpolate the right-hand side to j+1/2 so that both sides are defined at the same location in time ...
2),(),( 111 jjjjjj tTftTf
dtTT +
≈− +++
Let us examine the accuracy of such a scheme using our usual tool, the Taylor series.
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
... we learned that ...
)(62
33
32
2
21 tO
dtTdt
dtTdt
dtdT
tTT
jjj
jj ∆+⎟⎟⎠
⎞⎜⎜⎝
⎛∆+⎟⎟
⎠
⎞⎜⎜⎝
⎛∆+⎟
⎠⎞
⎜⎝⎛=
∆
−+
... also the interpolation can be written as ...
( )⎥⎥⎦
⎤
⎢⎢⎣
⎡∆+⎟⎟
⎠
⎞⎜⎜⎝
⎛∆+⎟
⎠⎞
⎜⎝⎛∆+=+ + )(
22
21
21 3
2
22
1 tOdt
fdtdtdftfff
jjjjj
),( tTfdtdT
=dt
tTdfdt
Td ),(2
2
=since =>
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
... it turns out that ...this mixed scheme is accurate to second order!
The previous schemes (explicit and implicit) were all first order schemes.
Now our cooling experiment becomes:
)(21
11
jjjj TT
dtTT
+−≈−
++
τ
)2
1()2
1(1 ττdtTdtT jj −≈+⇒ +
leading to the extrapolation scheme
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
−≈⇒ +
τ
τ
21
21
1 dt
dt
TT jj
How stable is this scheme?The solution decays if ...
1
21
21
1 <⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
−<−
τ
τdt
dt
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
1
21
21
1 <⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡
+
−<−
τ
τdt
dt
This scheme is always stable for positive dt and τ!If dt>2 τ, the solution decreases monotonically!
Let us now look at the Matlab code and thencompare it to the other approaches.
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
t0=1.tau=.7;dt=.1;dt=input(' Give dt : ');
nt=round(10/dt);
T=t0;Ta(1)=1;Ti(1)=1;Tm(1)=1;
for i=1:nt,t(i)=i*dt;T(i+1)=T(i)-dt/tau*T(i); % explicit forwardTa(i+1)=exp(-dt*i/tau); % analytic solutionTi(i+1)=T(i)*(1+dt/tau)^(-1); % implicit Tm(i+1)=(1-dt/(2*tau))/(1+dt/(2*tau))*Tm(i); % mixedend
plot(t,T(1:nt),'b-',t,Ta(1:nt),'r-',t,Ti(1:nt),'g-',t,Tm(1:nt),'k-')xlabel('Time(s)')ylabel('Temperature')
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
0 2 4 6 8 10-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Time(s)
Tem
pera
ture
dt=1.4; tau=0.7red-analyticblue-explicit
green-implicitblack-mixed
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
0 2 4 6 8 1-0.5
0
0.5
1
Time(s )
Tem
pera
ture
dt=1; tau=0.7 red-analyticblue-explicit
green-implicitblack-mixed
Numerical Methods in Geophysics Implicit Methods
Mixed implicit-explicit schemes
0 2 4 6 80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time(s)
Tem
pera
ture
dt=0.5; tau=0.7 red-analyticblue-explicit
green-implicitblack-mixed
Numerical Methods in Geophysics Implicit Methods
0 2 4 6 8 100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Time(s)
Tem
pera
ture
dt=0.1; tau=0.7
Mixed implicit-explicit schemes
1 1.2 1.4 1.6 1.8 20.05
0.1
0.15
0.2
Time(s )
Tem
pera
ture
dt=0.1; tau=0.7
red-analyticblue-explicit
green-implicitblack-mixed
The mixed scheme is a clear winner!
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
2
2
xCk
tC
∂∂
=∂∂
k diffusivity
The diffusion equation has many applications in geophysics, e.g. temperature diffusion in the Earth, mixing problems, etc.
A centered time - centered space scheme leads to a unconditionally unstable scheme!
Let’s try a forward time-centered space scheme ...
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
)2( 111 n
jnj
nj
nj
nj CCCsCC −++ +−+=
where
2dxdtks =
how stable is this scheme? We use the following Ansatz
dtieT ω= ikdxeX −=after going into the equation with
nmkmdxndtinm TXeC == − )(ω
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
... which leads to ...
0)21( 11 =+−+− −sXssXT
and
sT 41−≤
so the stability criterion is
)2/(21 2 kdxdts ≤⇒≤
This stability scheme is impractical as the required time step must be very small to achieve stability.
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation (matrix form)
any FD algorithm can also be written in matrix form, e.g.
)2( 111 n
jnj
nj
nj
nj CCCsCC −++ +−+=
is equivalent to
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−=
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
+
+
+
nJ
nj
n
nJ
nj
n
C
C
C
s
C
C
C 1
1
1
11
121
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation (matrix form)
... this can be written using operators ...
nnn cLcc +=+1
where L is the tridiagonal scaled Laplacian operator, if the boundary values are zero (blank parts of matrix
contain zeros)
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
... let’s try an implicit scheme using the interpolation ...
2)()()
2,( tCdttCdttxC ++
≈+
and
( )nj
nj
nj
nj
nj
nj
nj
nj CCCCCC
dxk
dtCC
1111
1112
1
222 −+
+−
+++
+
+−++−=+
... so again we have defined both sides at the same location ... half a time step in the future ...
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
... after rearranging ...
nj
nj
nj
nj
nj
nj CsCsCsCsCsCs 11
11
111 )2/()1()2/()2/()1()2/( −+
+−
+++ +−+=−++−
... again this is an implicit scheme, we rewrite this in matrix form ...
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−=
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−+−
+
+
+
nJ
nj
n
nJ
nj
n
C
C
C
sss
C
C
C
sss
1
1
1
11
)2/()1()2/()2/()1()2/(
... or using operators ...
nn cVcU =+1
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
... and the solution to this system of equations is ...
nn cVUc 11 −+ =
... we have to perform a tridiagonal matrix inversion to solve this system.Stability analysis using the Z-transform yields
))(2/)1(())(2/)1(( 1111 −− ++−=+−+ XXssTXXssT
)1/()1( ββ +−=⇒T)cos1( θβ −= s
... where we used ...
2/)(coscos 11 −+=∆= XXxkθ
Numerical Methods in Geophysics Implicit Methods
The Diffusion equation
)cos1( θβ −= s)1/()1( ββ +−=⇒T
... T describes the time-dependent behaviour of the numerical solution, as before we find ...
1|)1/()1(||| ≤+−= ββT
... which means the solution is unconditionally stable ...
... this scheme implies that the FD solution at each grid point is affected by all other points. Physically this could be
interpreted as an infinite interaction speed in the discrete world of the implicit scheme!
Numerical Methods in Geophysics Implicit Methods
The Relaxation Method
Let us consider a space-dependent problem, the Poisson’s equation :
Fzx −=Φ∂+∂ )( 22
applying a centered FD approximation yields ...
( ) Fdx jijijijijiji −=Φ+Φ−Φ+Φ+Φ−Φ +−+− ,1,,11,,1,2 221
rearranging ...
44
2,1,11,1,
,Fdxjijijiji
ji +⎟⎟⎠
⎞⎜⎜⎝
⎛ Φ+Φ+Φ+Φ=Φ +−+−
... so the value at (i,j) is the average of the surrounding values plus a (scaled) source term ...
Numerical Methods in Geophysics Implicit Methods
The Relaxation Method
... the solution can be found by an iterative procedure ...
44
2,1,11,1,1
,Fdxji
mji
mji
mji
mm
ji +⎟⎟⎠
⎞⎜⎜⎝
⎛ Φ+Φ+Φ+Φ=Φ +−+−+
... where m is the iteration index. One can start from an initial guess (e.g. zero) and change the solution until it doesn’t
change anymore within some tolerance e.g.
ε<Φ−Φ + || 1 mij
mij
If there is a stationary state to a diffusion problem, it could be calculated with the time-dependent problem, or with the relaxation
method, assuming dC/dt=0. What is more efficient? (Exercise)
Numerical Methods in Geophysics Implicit Methods
Implicit Methods - Summary
Certain FD approximations to time-dependent partial differential equations lead to implicit solutions. That means to
propagate (extrapolate) the numerical solution in time, a linear system of equations has to be solved.
The solution to this system usually requires the use of matrix inversion techniques.
The advantage of some implicit schemes is that they are unconditionally stable, which however does not mean they
are very accurate.
It is possible to formulate mixed explicit-implicit schemes (e.g. Crank-Nickolson or trapezoidal schemes) , which are
more accurate than the equivalent explicit or implicit schemes.
Numerical Methods in Geophysics Implicit Methods