Vous êtes sur la page 1sur 30

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:

dT = f (T , t ) dt
Before we used a forward difference scheme, what happens if we use a backward difference scheme?

T j T j 1 dt

+ O(dt ) = f (T j , t j )

T j T j-1 + dtf (T j , t j )

Numerical Methods in Geophysics

Implicit Methods

What is an implicit method?


or

T j T j 1 (1 + T j T0 (1 +

dt

) 1

dt

) j

Is this scheme convergent? 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

1 0< <1 dt 1+

Numerical Methods in Geophysics

Implicit Methods

What is an implicit method?

1 0< <1 dt 1+

This scheme is always stable! This is called unconditional stability ... which doesnt mean its accurate! Lets see how it compares to the explicit method...

Numerical Methods in Geophysics

Implicit Methods

What is an implicit method?


Explicit unstable - implicit stable - both inaccurate
dt=1.41; ta u=0.7 1.5

red-analytic blue-explicit green-implicit

0.5 Te mpe ra ture

-0.5

-1

-1.5

4 Time (s )

Numerical Methods in Geophysics

Implicit Methods

What is an implicit method?


Explicit stable - implicit stable - both inaccurate
dt=1; ta u=0.7 1

red-analytic blue-explicit green-implicit

0.5 Te mpe ra ture 0 -0.5 0

4 Time (s )

Numerical Methods in Geophysics

Implicit Methods

What is an implicit method?


Explicit stable - implicit stable - both inaccurate
dt=0.5; ta u=0.7 1 0.9 0.8 0.7 Te mpe ra ture 0.6 0.5 0.4 0.3 0.2 0.1 0 0 2 4 Time (s )
Numerical Methods in Geophysics Implicit Methods

red-analytic blue-explicit green-implicit

What is an implicit method?


Explicit stable - implicit stable - both accurate
dt=0.1; ta u=0.7 1 0.9 0.8 0.7 Te mpe ra ture 0.6 0.5 0.4 0.3 0.2 0.1 0 0 2 4 Time (s )
Numerical Methods in Geophysics Implicit Methods

red-analytic blue-explicit green-implicit

It doesnt look like we gained much from unconditional stability!

Mixed implicit-explicit schemes


We start again with ...

dT = f (T , t ) dt
Let us interpolate the right-hand side to j+1/2 so that both sides are defined at the same location in time ...

T j +1 T j dt

f (T j +1 , t j +1 ) + f (T j , t j ) 2

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 ...

T j +1 T j t

2 2 3 dT t d T t d T 3 + O ( t ) + = + 2 3 6 dt j dt j 2 dt j

... also the interpolation can be written as ...


2 2 1 1 df t d f ( f j + f j +1 ) = 2 f j + t + 2 2 2 2 dt dt j

3 O ( t ) + j

since

dT = f (T , t ) dt

=>

d 2T df (T , t ) = 2 dt dt
Implicit Methods

Numerical Methods in Geophysics

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:

1 (T j +1 + T j ) dt 2 dt dt T j +1 (1 + ) T j (1 ) 2 2
leading to the extrapolation scheme

T j +1 T j

Numerical Methods in Geophysics

Implicit Methods

Mixed implicit-explicit schemes

dt 1 2 T j +1 T j dt 1 + 2

How stable is this scheme? The solution decays if ...

dt 1 2 1 < dt 1 + 2

<1

Numerical Methods in Geophysics

Implicit Methods

Mixed implicit-explicit schemes

dt 1 2 1 < dt 1 + 2

<1

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 then compare 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); Ta(i+1)=exp(-dt*i/tau); Ti(i+1)=T(i)*(1+dt/tau)^(-1); Tm(i+1)=(1-dt/(2*tau))/(1+dt/(2*tau))*Tm(i); end

% % % %

explicit forward analytic solution implicit mixed

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

dt=1.4; ta u=0.7 1 0.8 0.6 0.4 Te mpe ra ture 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 2 4 Time (s ) 6 8

red-analytic blue-explicit green-implicit black-mixed

10

Numerical Methods in Geophysics

Implicit Methods

Mixed implicit-explicit schemes

dt=1; ta u=0.7 1

red-analytic blue-explicit green-implicit black-mixed

0.5 Te mpe ra ture 0 -0.5 0

4 Time (s )

Numerical Methods in Geophysics

Implicit Methods

Mixed implicit-explicit schemes

dt=0.5; ta u=0.7 1 0.9 0.8 0.7 Te mpe ra ture 0.6 0.5 0.4 0.3 0.2 0.1 0 0 2 4 Time (s ) 6 8

red-analytic blue-explicit green-implicit black-mixed

Numerical Methods in Geophysics

Implicit Methods

Mixed implicit-explicit schemes

dt=0.1; tau=0.7

0.9
dt=0.1; ta u=0.7 0.2

0.8
Te mpe ra ture

0.7
Te mpe ra ture

0.15

red-analytic blue-explicit green-implicit black-mixed

0.6

0.1

0.5

0.4

0.05

1.2

1.4 Time (s )

1.6

1.8

0.3

0.2

0.1

4
Time(s)

10

The mixed scheme is a clear winner!


Numerical Methods in Geophysics Implicit Methods

The Diffusion equation

C C =k 2 t x
2

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! Lets try a forward time-centered space scheme ...

Numerical Methods in Geophysics

Implicit Methods

The Diffusion equation


+1 n n n n Cn = C + s ( C 2 C + C j j j +1 j j 1 )

where

dt s=k 2 dx
how stable is this scheme? We use the following Ansatz

T = eidt

X = e ikdx

after going into the equation with


n Cm = e i (ndt kmdx ) = X mT n

Numerical Methods in Geophysics

Implicit Methods

The Diffusion equation


... which leads to ...

T (1 + sX 1 2 s + sX 1 ) = 0
and

T 1 4s
so the stability criterion is

1 s dt dx 2 /( 2k ) 2
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.
n n n n +1 Cn = C + s ( C 2 C + C j j j +1 j j 1 )

is equivalent to
n C1n +1 C 1 +1 n C n s = 1 2 1 C j j n C n +1 C J J

Numerical Methods in Geophysics

Implicit Methods

The Diffusion equation (matrix form)


... this can be written using operators ...

n +1

= c + Lc
n

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


... lets try an implicit scheme using the interpolation ...

dt C (t + dt ) + C (t ) C ( x, t + ) 2 2
and
n +1 + Cn C j j

dt

k n +1 n +1 n +1 n n n = C 2 C + C + C 2 C + C j +1 j j 1 j +1 j j 1 2 2dx

... 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 ...
n +1 n +1 n n n +1 ( s / 2)C n + ( 1 + s ) C ( s / 2 ) C = ( s / 2 ) C + ( 1 s ) C + ( s / 2 ) C j +1 j j 1 j +1 j j 1

... again this is an implicit scheme, we rewrite this in matrix form ...

C1n +1 C1n +1 n C n = ( s / 2) (1 + s ) ( s / 2) s s s ( / 2 ) ( 1 ) ( / 2 ) C j j n +1 n C J C J
... or using operators ...
n +1

Uc
Numerical Methods in Geophysics

=Vc

Implicit Methods

The Diffusion equation


... and the solution to this system of equations is ...

n +1

=U Vc

... we have to perform a tridiagonal matrix inversion to solve this system. Stability analysis using the Z-transform yields

T ((1 + s ) s / 2( X 1 + X 1 )) = T ((1 s ) + s / 2( X 1 + X 1 ))
T = (1 ) /(1+ )

= s(1 cos )
... where we used ...

cos = cos kx = ( X 1 + X 1 ) / 2
Numerical Methods in Geophysics Implicit Methods

The Diffusion equation

T = (1 ) /(1+ )

= s(1 cos )

... T describes the time-dependent behaviour of the numerical solution, as before we find ...

| T |=| (1 ) /(1+ ) | 1
... 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 Poissons equation :
2 ( 2 + x z ) = F

applying a centered FD approximation yields ...

1 ( i , j 1 2 i , j + i , j +1 + i 1, j 2 i , j + i +1, j ) = F 2 dx
rearranging ...

i, j

i , j 1 + i , j +1 + i 1, j + i +1, j = 4

Fdx 2 + 4

... 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 ...
m +1

i, j

m i , j 1 + m i , j +1 + m i 1, j + m i +1, j = 4

Fdx 2 + 4

... where m is the iteration index. One can start from an initial guess (e.g. zero) and change the solution until it doesnt change anymore within some tolerance e.g.
m +1 m | ij ij |<

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

Vous aimerez peut-être aussi