Lecture 3 Numerical Methods
Lecture 3 Numerical Methods
Specific methods:
Finite differences
Pseudospectral methods
Finite volumes
Specific methods:
Finite differences
Pseudospectral methods
Finite volumes
applied to the acoustic wave equation
Example: seismic wave propagation
Why numerical methods
Generally heterogeneous
medium
Seismometers
explosion
we need numerical
solutions! we need grids!
And big computers
Partial Differential Equations in Geophysics
) (
2 2 2
2 2
z
y x
t
s p c p
+ +
+ The acoustic
wave equation
- seismology
- acoustics
- oceanography
- meteorology
Diffusion, advection,
Reaction
- geodynamics
- oceanography
- meteorology
- geochemistry
- sedimentology
- geophysical fluid dynamics
P pressure
c acoustic wave speed
s sources
P pressure
c acoustic wave speed
s sources
p RC C C k C
t
+ v
C tracer concentration
k diffusivity
v flow velocity
R reactivity
p sources
C tracer concentration
k diffusivity
v flow velocity
R reactivity
p sources
Numerical methods: properties
Finite differences
Finite volumes
- time-dependent PDEs
- seismic wave propagation
- geophysical fluid dynamics
- Maxwells equations
- Ground penetrating radar
-> robust, simple concept, easy to
parallelize, regular grids, explicit method
Finite elements
- static and time-dependent PDEs
- seismic wave propagation
- geophysical fluid dynamics
- all problems
-> implicit approach, matrix inversion, well founded,
irregular grids, more complex algorithms,
engineering problems
- time-dependent PDEs
- seismic wave propagation
- mainly fluid dynamics
-> robust, simple concept, irregular grids, explicit
method
Other Numerical methods:
Particle-based
methods
Pseudospectral
methods
- lattice gas methods
- molecular dynamics
- granular problems
- fluid flow
- earthquake simulations
-> very heterogeneous problems, nonlinear problems
Boundary element
methods
- problems with boundaries (rupture)
- based on analytical solutions
- only discretization of planes
--> good for problems with special boundary conditions
(rupture, cracks, etc)
- orthogonal basis functions, special case of FD
- spectral accuracy of space derivatives
- wave propagation, GPR
-> regular grids, explicit method, problems with
strongly heterogeneous media
What is a finite difference?
Common definitions of the derivative of f(x):
dx
x f dx x f
f
dx
x
) ( ) (
lim
0
+
dx
dx x f x f
f
dx
x
) ( ) (
lim
0
dx
dx x f dx x f
f
dx
x
2
) ( ) (
lim
0
+
,
`
.
|
dk e k ikF
dk e k F x f
ikx
ikx
x x
) (
) ( ) (
.. let us recall the definition of the derivative using Fourier integrals ...
... we could either ...
1) perform this calculation in the space domain by convolution
2) actually transform the function f(x) in the k-domain and back
Numerical Methods in Geophysics The Fourier Method
The Fast Fourier Transform
... the latter approach became interesting with the introduction of the
Fast Fourier Transform (FFT). Whats so fast about it ?
The FFT originates from a paper by Cooley and Tukey (1965, Math.
Comp. vol 19 297-301) which revolutionised all fields where Fourier
transforms where essential to progress.
The discrete Fourier Transform can be written as
1 ,..., 1 , 0 ,
1 ,..., 1 , 0 ,
1
/ 2
1
0
/ 2
1
0
N k e u u
N k e u
N
u
N ikj
N
j
j k
N ikj
N
j
j k
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1
2
1
0
1
2
1
0
) 1 ( 1
2 2 6 4 2
1 3 2
1
1
1
1 1 1 1 1
2
N N
N N
N
N
u
u
u
u
u
u
u
u
.. where ...
N i
e
/ 2
Numerical Methods in Geophysics The Fourier Method
The Fast Fourier Transform
... the FAST bit is recognising that the full matrix - vector multiplication
can be written as a few sparse matrix - vector multiplications
(for details see for example Bracewell, the Fourier Transform and its
applications, MacGraw-Hill) with the effect that:
Number of multiplications Number of multiplications
full matrix FFT
N
2
2Nlog
2
N
this has enormous implications for large scale problems.
Note: the factorisation becomes particularly simple and effective
when N is a highly composite number (power of 2).
Numerical Methods in Geophysics The Fourier Method
The Fast Fourier Transform
.. the right column can be regarded as the speedup of an algorithm
when the FFT is used instead of the full system.
Number of multiplications Number of multiplications
Problem full matrix FFT Ratio full/FFT
1D (nx=512) 2.6x10
5
9.2x10
3
28.4
1D (nx=2096) 94.98
1D (nx=8384) 312.6
Numerical Methods in Geophysics The Fourier Method
Acoustic Wave Equation - Fourier Method
let us take the acoustic wave equation with variable density
,
`
.
|
p p
c
x x t
1 1
2
2
the left hand side will be expressed with our
standard centered finite-difference approach
[ ]
,
`
.
|
+ + p dt t p t p dt t p
dt c
x x
1
) ( ) ( 2 ) (
1
2 2
... leading to the extrapolation scheme ...
Numerical Methods in Geophysics The Fourier Method
Acoustic Wave Equation - Fourier Method
where the space derivatives will be calculated using the Fourier Method.
The highlighted term will be calculated as follows:
) ( ) ( 2
1
) (
2 2
dt t p t p p dt c dt t p
x x
+
,
`
.
|
+
n
j x
n n n
j
P P ik P P
1
FFT
FFT
multiply by 1/
,
`
.
|
,
`
.
|
,
`
.
|
n
j x x
n
x
n
x
n
j x
P P ik P P
1
FFT
1
FFT
1
1
... then extrapolate ...
Numerical Methods in Geophysics The Fourier Method
Acoustic Wave Equation - 3D
) ( ) ( 2
1 1 1
) (
2 2
dt t p t p
p p p dt c
dt t p
z z y y x x
+
,
`
.
|
,
`
.
|
+
,
`
.
|
+
,
`
.
|
+
n
j x
n n n
j
P P ik P P
1
FFT
FFT
,
`
.
|
,
`
.
|
,
`
.
|
n
j x x
n
x
n
x
n
j x
P P ik P P
1
FFT
1
FFT
1
1
.. where the following algorithm applies to each space dimension ...
Numerical Methods in Geophysics The Fourier Method
Comparison with finite differences - Algorithm
let us compare the core of the algorithm - the calculation of the
derivative
(Matlab code)
f u n c t i o n d f = f d e r 1 d ( f , d x , n o p )
% f D E R 1 D ( f , d x , n o p ) f i n i t e d i f f e r e n c e
% s e c o n d d e r i v a t i v e
n x = m a x ( s i z e ( f ) ) ;
n 2 = ( n o p - 1 ) / 2 ;
i f n o p = = 3 ; d = [ 1 - 2 1 ] / d x ^ 2 ; e n d
i f n o p = = 5 ; d = [ - 1 / 1 2 4 / 3 - 5 / 2 4 / 3 - 1 / 1 2 ] / d x ^ 2 ; e n d
d f = [ 1 : n x ] * 0 ;
f o r i = 1 : n o p ;
d f = d f + d ( i ) . * c s h i f t 1 d ( f , - n 2 + ( i - 1 ) ) ;
e n d
Numerical Methods in Geophysics The Fourier Method
Comparison with finite differences - Algorithm
... and the first derivative using FFTs ...
f u n c t i o n d f = s d e r 1 d ( f , d x )
% S D E R 1 D ( f , d x ) s p e c t r a l d e r i v a t i v e o f v e c t o r
n x = m a x ( s i z e ( f ) ) ;
% i n i t i a l i z e k
k m a x = p i / d x ;
d k = k m a x / ( n x / 2 ) ;
f o r i = 1 : n x / 2 , k ( i ) = ( i ) * d k ; k ( n x / 2 + i ) = - k m a x + ( i ) * d k ; e n d
k = s q r t ( - 1 ) * k ;
% F F T a n d I F F T
f f = f f t ( f ) ; f f = k . * f f ; d f = r e a l ( i f f t ( f f ) ) ;
.. simple and elegant ...
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Dispersion and Stability
... with the usual Ansatz
) ( dt n kjdx i n
j
e p
we obtain
) ( 2 2 ndt kjdx i n
j x
e k p
) ( 2
2
2
2
sin
4
ndt kjdx i n
j t
e
dt
dt
p
... leading to
2
sin
2 dt
cdt
k
dx cdt
cdt k
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 10Hz
Example of acoustic 1D wave simulation.
FD 3 -point operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Sourcetimefunction
0 10 20 30
0
0.5
1
Gaussinspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-0.5
0
0.5
1
Time(sec)
3point - 2order; T=6.6s, Error =50.8352%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 10Hz
Example of acoustic 1D wave simulation.
FD 5 -point operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Source time function
0 10 20 30
0
0.5
1
Gauss inspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-0.5
0
0.5
1
Time (sec)
5 point - 2 order; T=7.8 s, Error =3.9286%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 10Hz
Example of acoustic 1D wave simulation.
Fourier operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Sourcetimefunction
0 10 20 30
0
0.5
1
Gauss inspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-1
-0.5
0
0.5
1
Time(sec)
Fourier - 2order; T=35s, Error =2.72504%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 20Hz
Example of acoustic 1D wave simulation.
FD 3 -point operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Sourcetimefunction
0 10 20 30
0
0.5
1
Gaussinspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-1
-0.5
0
0.5
1
Time(sec)
3point - 2order; T=7.8s, Error =156.038%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 20Hz
Example of acoustic 1D wave simulation.
FD 5 -point operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Sourcetimefunction
0 10 20 30
0
0.5
1
Gaussinspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-0.5
0
0.5
1
Time(sec)
5point - 2order; T=7.8s, Error =45.2487%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - 20Hz
Example of acoustic 1D wave simulation.
Fourier operator
red-analytic; blue-numerical; green-difference
0 200 400 600
-0.5
0
0.5
1
Sourcetimefunction
0 10 20 30
0
0.5
1
Gaussinspace
0.8 0.9 1 1.1 1.2 1.3 1.4 1.5
-1
-0.5
0
0.5
1
Time(sec)
Fourier - 2order; T=34s, Error =18.0134%
Numerical Methods in Geophysics The Fourier Method
Fourier Method - Comparison with FD - Table
0
20
40
60
80
100
120
140
160
5 Hz 10 Hz 20 Hz
3 point
5 point
Fourier
Difference (%) between numerical and analytical solution
as a function of propagating frequency
Simulation time
5.4s
7.8s
33.0s
Numerical Methods in Geophysics The Fourier Method
Numerical solutions and Greens Functions
The concept of Greens Functions (impulse responses) plays an
important role in the solution of partial differential equations. It is also
useful for numerical solutions. Let us recall the acoustic wave equation
p c p
t
2 2
with being the Laplace operator. We now introduce a delta source in
space and time
p c t x p
t
+
2 2
) ( ) (
the formal solution to this equation is
x
c x t
c
t x p
) / (
4
1
) , (
2
(Full proof given in Aki and Richards, Quantitative Seismology, Freeman+Co, 1981, p. 65)
Numerical Methods in Geophysics The Fourier Method
Numerical solutions and Greens Functions
In words this means (in 1D and 3D but not in 2D, why?) , that in
homogeneous media the same source time function which is input at the
source location will be recorded at a distance r, but with amplitude
proportional to 1/r.
An arbitrary source can evidently be constructed by summing up different
delta - solutions. Can we use this property in our numerical simulations?
What happens if we solve our numerical system with delta functions as
sources?
x
c x t
c
t x p
) / (
4
1
) , (
2
1
~
Finite elements basic formulation
Let us start with a simple linear system of equations
| * y
and observe that we can generally multiply both sides of
this equation with y without changing its solution. Note
that x,y and b are vectors and A is a matrix.
b Ax
n
y yb yAx
We first look at Poissons equation (e.g., wave equation
without time dependence)
) ( ) ( x f x u
where u is a scalar field, f is a source term and in 1-D
2
2
2
x
Formulation Poissons equation
fv uv
We now multiply this equation with an arbitrary function
v(x), (dropping the explicit space dependence)
... and integrate this equation over the whole domain. For
reasons of simplicity we define our physical domain D in
the interval [0, 1].
D D
fv uv
dx fv dx uv
1
0
1
0
... why are we doing this? ... be patient ...
Partial Integration
... partially integrate the left-hand-side of our equation ...
dx fv dx uv
1
0
1
0
[ ] dx u v uv dx uv
+
1
0
1
0
1
0
we assume for now that the derivatives of u at the boundaries vanish
so that for our particular problem
dx u v dx uv
1
0
1
0
... so that we arrive at ...
... with u being the unknown function. This is also true for our
approximate numerical system
dx fv dx v u
1
0
1
0
... where ...
i
N
i
i
c u
1
~
was our choice of approximating u using basis functions.
dx fv dx v u
1
0
1
0
~
The basis functions
... otherwise we are
free to choose any
function ...
The simplest choice
are of course linear
functions:
+ grid nodes
blue lines basis
functions
i
1
2
3
4
5
6
7
8
9
1 0
we are looking for functions
i
with the following property
'
i j x x for
x x for
x
j
i
i
, 0
1
) (
The discrete system
The ingredients:
k
v
i
N
i
i
c u
1
~
dx fv dx v u
1
0
1
0
~
dx f dx c
k k
n
i
i i
,
`
.
|
1
0
1
0
1
... leading to ...
The discrete system
dx f dx c
k k i
n
i
i
1
0
1
0
1
... the coefficients c
k
are constants so that for one
particular function
k
this system looks like ...
k ik i
g A b
... probably not to your surprise this can be written in matrix form
k i
T
ik
g b A
The solution
... with the even less surprising solution
( )
k
T
ik i
g A b
1
together we obtain
) ( ) (
~
1
2 2 2
x t c u u
i
N
i
i t t t
note that now our coefficients are time-dependent!
... and ...
]
]
]
+
]
]
]
1
0
1
0
2
1
0
2
j j
i
i i j
i
i i t
f dx c v dx c
which we can write as ...
Time extrapolation
]
]
]
+
]
]
]
1
0
1
0
2
1
0
2
j j
i
i i j
i
i i t
f dx c v dx c
... in Matrix form ...
g c A v c M
T T
+
2
M
A b
... remember the coefficients c correspond to the
actual values of u at the grid points for the right choice
of basis functions ...
How can we solve this time-dependent problem?
stiffness matrix
mass matrix
FD extrapolation
... let us use a finite-difference approximation for
the time derivative ...
g c A v c M
T T
+
2
... leading to the solution at time t
k+1
:
g c A v
dt
c c c
M
k
T
k k
T
+
,
`
.
|
+
+
2
2
1 1
2
[ ]
1
2 2 1
1
2 ) ( ) (
+
+
k k k
T T
k
c c dt c A v g M c
we already know how to calculate the matrix A but
how can we calculate matrix M?
Matrix assembly
% assemble matrix Mij
M=zeros(nx);
for i=2:nx-1,
for j=2:nx-1,
if i==j,
M(i,j)=h(i-1)/3+h(i)/3;
elseif j==i+1
M(i,j)=h(i)/6;
elseif j==i-1
M(i,j)=h(i)/6;
else
M(i,j)=0;
end
end
end
% assemble matrix Aij
A=zeros(nx);
for i=2:nx-1,
for j=2:nx-1,
if i==j,
A(i,j)=1/h(i-1)+1/h(i);
elseif i==j+1
A(i,j)=-1/h(i-1);
elseif i+1==j
A(i,j)=-1/h(i);
else
A(i,j)=0;
end
end
end
M
ij
A
ij
Numerical example regular grid
This is a movie obtained with the sample Matlab program: femfd.m
Finite Elements - Summary