Post on 31-Aug-2018
transcript
Finite Differences
Finite Difference Approximations
Simple geophysical partial differential equationsFinite differences - definitionsFinite-difference approximations to pde‘s
ExercisesAcoustic wave equation in 2DSeismometer equationsDiffusion-reaction equation
Finite differences and Taylor ExpansionStability -> The Courant CriterionNumerical dispersion
1Computational Seismology
dxxfdxxffx)()( −+
≈∂ +
Finite Differences
)( 222
22
zyx
ts pcp
∂+∂+∂=Δ
+Δ=∂ 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
pRCCCkCt +−∇•−Δ= 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
Partial Differential Equations in Geophysics
Finite Differences
Finite differences
Finite volumes
- time-dependent PDEs- seismic wave propagation- geophysical fluid dynamics- Maxwell’s 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
Numerical methods: properties
Finite Differences
Particle-based methods
Pseudospectralmethods
- lattice gas methods- molecular dynamics- granular problems- fluid flow- earthquake simulations-> very heterogeneous problems, nonlinear problems
Boundary elementmethods
- 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, ground penetrating radar-> regular grids, explicit method, problems with
strongly heterogeneous media
Other numerical methods
Finite Differences
What is a finite difference?
Common definitions of the derivative of f(x):
dxxfdxxff
dxx)()(lim
0
−+=∂
→
dxdxxfxff
dxx)()(lim
0
−−=∂
→
dxdxxfdxxff
dxx 2)()(lim
0
−−+=∂
→
These are all correct definitions in the limit dx->0.
But we want dx to remain FINITE
Finite Differences
What is a finite difference?
The equivalent approximations of the derivatives are:
dxxfdxxffx)()( −+
≈∂ +
dxdxxfxffx
)()( −−≈∂ −
dxdxxfdxxffx 2
)()( −−+≈∂
forward difference
backward difference
centered difference
Finite Differences
The big question:
How good are the FD approximations?
This leads us to Taylor series....
Finite Differences
Taylor Series
Taylor series are expansions of a function f(x) for some finite distance dx to f(x+dx)
What happens, if we use this expression for
dxxfdxxffx)()( −+
≈∂ + ?
...)(!4
)(!3
)(!2
)(dx)()( ''''4
'''3
''2
' ±+±+±=± xfdxxfdxxfdxxfxfdxxf
Finite Differences
Taylor Series
... that leads to :
The error of the first derivative using the forwardformulation is of order dx.
Is this the case for other formulations of the derivative?Let’s check!
)()(
...)(!3
)(!2
)(dx1)()(
'
'''3
''2
'
dxOxf
xfdxxfdxxfdxdx
xfdxxf
+=
⎥⎦
⎤⎢⎣
⎡+++=
−+
Finite Differences
... with the centered formulation we get:
The error of the first derivative using the centered approximation is of order dx2.
This is an important results: it DOES matter which formulationwe use. The centered scheme is more accurate!
Taylor Series
)()(
...)(!3
)(dx1)2/()2/(
2'
'''3
'
dxOxf
xfdxxfdxdx
dxxfdxxf
+=
⎥⎦
⎤⎢⎣
⎡++=
−−+
Finite Differences
xj − 1 xj xj + 1 xj + 2 xj + 3
f xj( )
dx h
desired x location
What is the (approximate) value of the function or its (first, second ..) derivative at the desired location ?
How can we calculate the weights for the neighboring points?
x
f(x)
Alternative Derivation
Finite Differences
Lets’ try Taylor’s Expansion
f x( )
dx
x
f(x)
dxxfxfdxxf )(')()( +≈+ (1)(2)
we are looking for something like
f x w f xiji
index jj L
( ) ( )( )
,( ) ( )≈ ∑
=1
Alternative Derivation
dxxfxfdxxf )(')()( −≈−
Finite Differences
deriving the second-order scheme …
a f a f a f d x+ ≈ + '
b f b f b f d x− ≈ − '
⇒ + ≈ + + −+ −a f b f a b f a b f d x( ) ( ) '
the solution to this equation for a and b leads to a system of equations which can be cast in matrix form
dxbaba
/10
=−=+
01
=−=+
baba
Interpolation Derivative
2nd order weights
Finite Differences
Taylor Operators
... in matrix form ...
⎟⎟⎠
⎞⎜⎜⎝
⎛=⎟⎟
⎠
⎞⎜⎜⎝
⎛⎟⎟⎠
⎞⎜⎜⎝
⎛− 0
111
11ba
Interpolation Derivative
... so that the solution for the weights is ...
⎟⎟⎠
⎞⎜⎜⎝
⎛=⎟⎟
⎠
⎞⎜⎜⎝
⎛⎟⎟⎠
⎞⎜⎜⎝
⎛− dxb
a/10
1111
⎟⎟⎠
⎞⎜⎜⎝
⎛⎟⎟⎠
⎞⎜⎜⎝
⎛−
=⎟⎟⎠
⎞⎜⎜⎝
⎛−
01
1111 1
ba
⎟⎟⎠
⎞⎜⎜⎝
⎛⎟⎟⎠
⎞⎜⎜⎝
⎛−
=⎟⎟⎠
⎞⎜⎜⎝
⎛−
dxba
/10
1111 1
Finite Differences
... and the result ...
Interpolation Derivative
Can we generalise this idea to longer operators?
⎟⎟⎠
⎞⎜⎜⎝
⎛=⎟⎟
⎠
⎞⎜⎜⎝
⎛2/12/1
ba
⎟⎟⎠
⎞⎜⎜⎝
⎛−
=⎟⎟⎠
⎞⎜⎜⎝
⎛1
12
1dxb
a
Let us start by extending the Taylor expansion beyond f(x±dx):
Interpolation and difference weights
Finite Differences
'''!3
)2(''!2)2(')2()2(
32
fdxfdxfdxfdxxf −+−≈−*a |
*b |
*c |
*d |
... again we are looking for the coefficients a,b,c,d with whichthe function values at x±(2)dx have to be multiplied in order
to obtain the interpolated value or the first (or second) derivative!
... Let us add up all these equations like in the previous case ...
'''!3)(''
!2)(')()(
32
fdxfdxfdxfdxxf −+−≈−
'''!3)(''
!2)(')()(
32
fdxfdxfdxfdxxf +++≈+
'''!3
)2(''!2)2(')2()2(
32
fdxfdxfdxfdxxf +++≈+
Higher order operators
Finite Differences
≈+++ +++−−− dfcfbfaf
++++ )( dcbaf
+++−− )22(' dcbadxf
++++ )222
2(''2 dcbafdx
)68
61
61
68('''3 dcbafdx ++−−
... we can now ask for the coefficients a,b,c,d, so that theleft-hand-side yields either f,f’,f’’,f’’’ ...
Higher order operators
Finite Differences
1=+++ dcba
022 =++−− dcba
0222
2 =+++ dcba
068
61
61
68
=++−− dcba
... if you want the interpolated value ...
... you need to solve the matrix system ...
Linear system
Finite Differences
High-order interpolation
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
−−
−−
0001
6/86/16/16/822/12/1221121111
dcba
... with the result after inverting the matrix on the lhs ...
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
−
−
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
6/13/23/26/1
dcba
... Interpolation ...
Finite Differences
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
−−
−−
00/10
6/86/16/16/822/12/1221121111
dx
dcba
... with the result ...
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
−
−=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
6/13/43/4
6/1
21dx
dcba
... first derivative ...
First derivative
Finite Differences
Our first FD algorithm (ac1d.m) !
)( 222
22
zyx
ts pcp
∂+∂+∂=Δ
+Δ=∂ P pressure
c acoustic wave speed
s sources
P pressurec
acoustic wave speed
s sources
Problem:
Solve the 1D acoustic wave equation using the finite Difference method.Problem:
Solve the 1D acoustic wave equation using the finite
Difference method.
Solution:Solution:
[ ]2
2
22
)()(2
)()(2)()(
sdtdttptp
dxxpxpdxxpdxdtcdttp
+−−+
−+−+=+
Finite Differences
Problems: Stability
[ ]2
2
22
)()(2
)()(2)()(
sdtdttptp
dxxpxpdxxpdx
dtcdttp
+−−+
−+−+=+
1≈≤ εdxdtc
Stability:
Careful analysis using harmonic functions shows that a stable numerical calculation is subject to special conditions (conditional stability). This holds for many numerical problems.(Derivation on the board).
Stability:
Careful analysis using harmonic functions shows that a stable numerical calculation is subject to special conditions (conditional stability). This holds for many numerical problems.(Derivation on the board).
Finite Differences
Problems: Dispersion
[ ]2
2
22
)()(2
)()(2)()(
sdtdttptp
dxxpxpdxxpdx
dtcdttp
+−−+
−+−+=+
Dispersion:
The numerical approximation has artificial dispersion,
in other words, the wave speed becomes frequency dependent (Derivation in the board). You have to find a frequency bandwidth where this effect is small.
The solution is to use a sufficient number of grid points per wavelength.
Dispersion:
The numerical approximation has artificial dispersion,in other words, the wave speed becomes frequency dependent (Derivation in the board). You have to find a frequency bandwidth where this effect is small.The solution is to use a sufficient number of grid points per wavelength.
True velocity
Finite Differences
Our first FD code!
[ ]2
2
22
)()(2
)()(2)()(
sdtdttptp
dxxpxpdxxpdx
dtcdttp
+−−+
−+−+=+
% Time stepping
for i=1:nt,
% FD
disp(sprintf(' Time step : %i',i));
for j=2:nx-1d2p(j)=(p(j+1)-2*p(j)+p(j-1))/dx^2; % space derivative
endpnew=2*p-pold+d2p*dt^2; % time extrapolationpnew(nx/2)=pnew(nx/2)+src(i)*dt^2; % add source termpold=p; % time levelsp=pnew;p(1)=0; % set boundaries pressure freep(nx)=0;
% Display plot(x,p,'b-')title(' FD ')drawnow
end
Finite Differences
Snapshot Example
0 1000 2000 3000 4000 50000
500
1000
1500
2000
2500
3000
Distance (km)
Tim
e (s
) Velocity 5 km/s
Finite Differences
Finite Differences - Summary
Conceptually the most simple of the numerical methods and can be learned quite quicklyDepending on the physical problem FD methods are conditionally stable (relation between time and space increment)FD methods have difficulties concerning the accurate implementation of boundary conditions (e.g. free surfaces, absorbing boundaries)FD methods are usually explicit and therefore very easy to implement and efficient on parallel computersFD methods work best on regular, rectangular grids