numerical solution of the wave equation
DESCRIPTION
In this exercise we will b e simulating propagation of sound in simple media using the ?nite di?erence metho d? The ?nite di?erence metho d is to b e implemented in Matlab? and also the plots should be made in Matlab?TRANSCRIPT
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
Numerical solution of the wave equation
Introduction
Marine seismic oil�gas exploration is carried out by generating soundwaves thatpropagate through the earth� The waves are reected from interfaces between dierentgeological layers� Receivers are recording the reected waves� converting the acousticenergy into electronic energy� and then storing the data on tape� By dierent seismicprocessing techniques an image of the subsurface can be made from the acquired data�
In this exercise we will be simulating propagation of sound in simple media using the�nite dierence method� The �nite dierence method is to be implemented in Matlab�and also the plots should be made in Matlab�
To avoid running out of computer memory we will restrict ourselves to two spatialdimensions represented by the x�axis and the z�axis� The equation de�ning the wavepropagation of the pressure �eld P x� z� t� is a partial dierential equation given by
��P x� z� t�
�x��
��P x� z� t�
�z��
�
c� x� z�
��P x� z� t�
�t�� S x� z� t� ��
where c x� z� is the wave�velocity and S x� z� t� is a source termWe shall replace the dierential equation �� with a �nite dierence equation being anapproximation to equation ��� The �nite dierence equation can be rearranged� enablingus to �nd the pressure at the next time step as a function of the pressure at present andprevious timesteps�
Derivation of the �nite di�erence formula
As a starting point for deriving the �nite dierence equation we consider the de�nition ofthe derivative of P x� z� t� with respect to x�
�P x� z� t�
�x� lim
�x��
P x��x� z� t�� P x� z� t�
�x
Allowing �x to be �nite rather than in�nitesimal yields the approximation�
�P x� z� t�
�x�
P x��x� z� t�� P x� z� t�
�x
The second derivative is obtained by repeating the above procedure�
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
��P x� z� t�
�x��
�
�x
�P x� z� t�
�x�
�P �x��x�z�t��x
��P �x�z�t�
�x
�x�
P x� ��x� z� t�� P x��x� z� t�� � P x��x� z� t�� P x� z� t��
�x�
we may perform a backward shift �x resulting in�
��P x� z� t�
�x��
P x��x� z� t�� �P x� z� t� � P x��x� z� t�
�x�
We introduce a more compact notation�
P x� z� t� � P nl�m � P l�x�m�z� n�t� ��
c x� z� � cl�m � c l�x�m�z� ��
S x� z� t� � Snl�m � S l�x�m�z� n�t� ��
��
On �nite dierence form equation �� appears this way�
P nl���m � �P n
l�m � P nl���m
�x��
P nl�m�� � �P n
l�m � P nl�m��
�z��
�
c�l�m
P n��l�m � �P n
l�m � P n��l�m
�t�� Sn
l�m
��
For simplicity we use the same step�length in the x� and z�direction �z � �x� Henceequation �� may be rewritten�
P n��l�m �
c�l�m�t�
�x�
�P nl���m � P n
l�m�� � �P nl�m � P n
l���m � P nl�m��
�� �P n
l�m � P n��l�m � c�l�m�t�Sn
l�m
��
Part ��
a� Make a Matlab program that gives the pressure �eld as a function of x and z at time��� s� n���� and plot the result� Use equation ��Let �x � �y � �m and let �t � �����s� m and l should cover a ���x��� grid�area�Assume a constant wave velocity of c� � ���� m�s The velocity of sound in water��
It is important that c�m�t�
�x�� �
�Otherwise the error will increase for each timestep
causing instability��Boundary conditions are P n
��m � P n����m � P n
l�� � P nl���� � �� while the initial conditions are
given by
P �l�m � � ��
P �l�m � � ��
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
n−1
n
n+1
Figure �� Finite dierence grid� The pressure at the star is calculated from the values ofthe pressure at the dots
To generate the waves we use a source Snl�m de�ned by
Sn������� � f n� ���
Snl�m � � else ���
f n� may be down�loaded from http���www�ipt�ntnu�no��bufag�kilde� Save kildeon your computer and load into Matlab with the command load kilde� Matlabfunctions suitable for two�dimensional plots include mesh� contour and contourf� Ifyou have named the pressure P� you could use the command contour P��You may try to �nd the pressure at other timesteps� but storing all timesteps in memorywill at some point cause memory shortage�
b� Register the pressure at all timesteps and all x�coordinates� but �x the z�coordinate atm����� Make a plot of this as well� This simulates seismic acquisition along the linem�����
Part ��
Repeat part �a� and b�� but insert a reector along m���� by letting the velocity be���� m�s above m�����
Matlab commands
The pc�version of Matlab is started by clicking the matlab�icon or writing matlab in therun window� The Unix version is started from the dtterm window or xterm window with
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
the command matlab� Writing quit at the Matlab prompt will terminate the session�Documentation for all matlab commands is obtained writing help command The currentworking directory can be found with the command pwd� You may change directory to e�g�c��yourdirectory assuming pc�matlab� using the command
cd c��yourdirectory
load kilde into Matlab by the commandload c��yourdirectory�kilde
You can plot kilde using the commandplot�kilde�
plot�kilde���� plots the �rst � timesamplesplot�kilde�������� plots every fourth sample up to ��plot�kilde� ����� reverses kilde
Reversing kilde can also be achieved by writing plot�fliplr�kilde��� The values alongthe x�axis correspond to the component�numbers of kilde if only kilde is included in theplot command� To adjust the x�axis� we �rst create a variable
x���length�kilde��� �
x has the same number of components as kilde which is important�� This number isfound with the length command� The component�values are������������������������������� The semicolon prevents these values from beingdisplayed on the screen We specify the x�coordinate by issuing two input vectors for theplot command� x and kilde� Two more vectors will be interpreted as a newx�coordinate�y�coordinate pair yielding two curves
plot�x�kilde�
plot�x�kilde�x�kilde�� Two curvesVectors can be created �manually� by writing the component values between brackets
� � � ���
This way you can manipulate kilde plot�� kilde��� kilde��� ��� The axis isspeci�ed using the command axis
axis��xmin xmax ymin ymax��
A matrix can be constructed like thismatrise�� ����������������
The rows of the matrix are separated by semicolons� This can be plotted using forinstance
mesh�matrise� orcontour�matrise�
Loops are constructed similarly to other programming languages� It can be done like thisfor k��� � energi�k��kilde�k��kilde�k��end
Matlab oers an alternative to the above structure�k��� � energi�k��kilde�k���kilde�k��
Placing a period before the multiplication sign ensures that multiplication is carried outcomponent by component� The last alternative is much faster than the for�end alternativeConditional statements are implemented this way
if �x�� �� y� �end
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
x is tested for equality with zero note two equal signs�� If this is true� y is assigned thevalue zero� In the next example x has to be dierent from zero and z has to be less than� for the operation y�� to be carried out
if ��x�� � � z�� � y� �end
��� corresponds to �and�� while ��� corresponds to �or��
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
0 50 100 150 200 250 300 350 400 450 5000
50
100
150
200
250
300
350
400
450
500
Figure �� Wave propagation as in part �� plotted using the command sequence�clf�for f��������� plot P f����������f��hold on�end
0 50 100 150 200 250 300 350 400 450 500
0
50
100
150
200
250
300
350
400
450
500
Tid
Figure �� Arrival times for dierent x values� z����
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud
TPG���� Anvendt datateknikk i geofag og petroleumsteknologi�ving �� � Matlab
�
0 50 100 150 200 250 300 350 400 450 5000
50
100
150
200
250
300
350
400
450
500
Figure �� Wave propagation with a reector at z����
0 50 100 150 200 250 300 350 400 450 500
0
50
100
150
200
250
300
350
400
450
500
Tid
Figure �� Arrival times for dierent x values� z����� direct wave and reection�
Norges teknisk�naturvitenskapelige universitetInstitutt for petroleumsteknologi og anvendt geofysikk
Stipendiat Tommy Toverud