Upload
farid-hendra-pradana
View
225
Download
0
Embed Size (px)
DESCRIPTION
numerik
Citation preview
Numerical Methods in Geodynamics
Daniel Kohn
Lets consider the problem (not very physical) of a flow into a barrier of constanttemperature. What is the temperature field for the following situation:
T=0
x=0 x=1
T=1
constant speed U
Abbildung 1: Problem 1
Assume steady state:
UT
x=
2T
x2(1)
With the boundary conditions
at x = 0 T = 0
at x = L T = 1
we can find the analytical solution
T =exp(Pe x
L) 1
exp(Pe) 1 (2)
with the Peclet number defined as Pe := UL. Using a central difference dis-
cretization for the advective term we get:
UTk+1 Tk1
2h=
Tk+1 2Tk + Tk1h2
. (3)
Let = Uh2
the mesh Peclet number.
Exercise 1 Set up this problem in MATLAB.
2Writing eq. (3) as matrix equation we can implement the problem in MATLABby the following script:
% Numerical Methods in Geodynamics
% Exercise 1
%
% Daniel Koehn
% Kiel, the 23 rd of march 2004
clear all
close all
% define constants
alpha = 0.5; % mesh peclet number
N=6; % number of grid points
T0=0; % temperature at grid point number 0
TN=1; % temperature at grid point number N
L=10; % length of the rod
h=L./(N-1); % grid point spacing
kappa =1; % thermal diffusivity
U=(alpha.*2.*kappa)./h; % velocity
Pe=(U.*L)./kappa; % Peclet number
% central difference scheme
% -------------------------
% build matrix-equation
% cofficient matrix
e0 = -2.*ones(N-2,1); % elements on main diagonal
e1 = -(alpha-1).*ones(N-3,1); % 1st upper diagonal
e2 = (alpha+1).*ones(N-3,1); % 1st lower diagonal
S = diag(e0) + diag(e1,1) + diag(e2,-1)
% RHS vector
b = zeros(N-2,1);
% apply boundary conditions
b(1) = -(alpha+1).*T0;
b(N-2) = (alpha-1).*TN;
% plot RHS vector b
b
% matrix inversion
% ----------------
Ta=inv(S)*b;
3% add boundary points
Tc=[T0 Ta TN];
% plot temperature field
% ----------------------
% position vector
x=0:h:L;
% calculate exact solution
Tex=(exp(Pe.*(x./L))-1)./(exp(Pe)-1)
plot(x,Tc,--,x,Tex);
% axis and title
af=xlabel(x/m);
bf=ylabel(T/C);
df=title(Advection/Diffusion in 1D (central differences));
ef=legend(central differences,exact,2)
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,14,FontName,Times);
% output as eps-file
print -deps exer_1_0p5.eps
For = 0.5, 1.0 and 2.5 you get the results as shown in figure 2. Note the strongoscillations of the solution, when > 1.
40 2 4 6 8 100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x/m
T/C
Advection/Diffusion in 1D (central differences)central differencesexact
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
x/m
T/C
Advection/Diffusion in 1D (central differences)central differencesexact
0 2 4 6 8 100.5
0
0.5
1
x/m
T/C
Advection/Diffusion in 1D (central differences)central differencesexact
Abbildung 2: Results using the central difference discretization for = 0.5 (top), = 1.0 (middle), = 2.5 (bottom). The numerical solutions are shown as dashedlines, the exact solution (2) as solid lines.
5Now what if we use upwind differences on the advection term ?
UT
x= U
Tk Tk1h
2T
x2=
Tk+1 2Tk + Tk1h2
(4)
In this case, the solution is formally less accurate but it never oscillates andconverges towards the correct solution.
Exercise 2 Program this in MATLAB
% Numerical Methods in Geodynamics
% Exercise 2
%
% Daniel Koehn
% Kiel, the 23 rd of march 2004
clear all
close all
% define constants
alpha = 1.0; % mesh peclet number
N=6; % number of grid points
T0=0; % temperature at grid point number 0
TN=1; % temperature at grid point number N
L=10; % length of the rod
h=L./(N-1); % grid point spacing
kappa =1; % thermal diffusivity
U=(alpha.*2.*kappa)./h; % velocity
Pe=(U.*L)./kappa; % Peclet number
% upwind difference scheme
% -------------------------
% build matrix-equation
% cofficient matrix
e0 = 2.*(alpha+1).*ones(N-2,1); % elements on main diagonal
e2 = -((2.*alpha)+1).*ones(N-3,1); % 1st lower diagonal
e1 = -ones(N-3,1); % 1st upper diagonal
S = diag(e0) + diag(e1,1) + diag(e2,-1)
% RHS vector
b = zeros(N-2,1);
% apply boundary conditions
b(1) = ((2.*alpha)+1).*T0;
b(N-2) = TN;
6% plot RHS vector b
b
% matrix inversion
% ----------------
Ta=inv(S)*b;
% add boundary points
Tc=[T0 Ta TN];
% plot temperature field
% ----------------------
% position vector
x=0:h:L;
% calculate exact solution
Tex=(exp(Pe.*(x./L))-1)./(exp(Pe)-1)
plot(x,Tc,--,x,Tex);
% axis and title
af=xlabel(x/m);
bf=ylabel(T/C);
df=title(Advection/Diffusion in 1D (upwind differences));
ef=legend(upwind differences,exact,2)
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,14,FontName,Times);
% output as eps-file
print -deps exer_2_1p0.eps
70 2 4 6 8 100
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x/m
T/C
Advection/Diffusion in 1D (upwind differences)upwind differencesexact
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
x/m
T/C
Advection/Diffusion in 1D (upwind differences)upwind differencesexact
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
x/m
T/C
Advection/Diffusion in 1D (upwind differences)upwind differencesexact
Abbildung 3: Results using the upwind difference discretization for = 0.5 (top), = 1.0 (middle), = 2.5 (bottom). The numerical solutions are shown as dashedlines, the exact solution (2) as solid lines.
8Exercise 3 Upwind differencing can also be viewed as adding artifical diffusionavis =
Uh2, so that the
effective diffusion is eff = +
uh2, i.e.:
UTk Tk1
h= U
Tk+1 Tk12h
Uh2
Tk+1 2Tk + Tk1h2
. (5)
With this artifical diffusion, show that the MATLAB solution for central diffe-rences gives the answer for upwind differences.
First we replace the thermal diffusivity in the mesh Peclet number by effin the MATLAB script for the central difference scheme. Then we can changethe artifical diffusion avis between 1 and 5. The results are plotted in figure 4.For avis = 1 we get a solution comparable with the original central differencescheme. With increasing avis the oscillations are more and more damped. Foravis = 4 we get nearly the analytical solution.
0 2 4 6 8 100.5
0
0.5
1
x/m
T/C
Advection/Diffusion in 1D (central differences+artifical viscosity)central differences+artifical viscosityexact
kav=1
kav=2
kav=3
kav=4
kav=5
Abbildung 4: The solutions of the central difference scheme for values of avis between1 and 5.
9Exercise 4 Compare the advection of a Gaussian temperature distribution using
central differences
upwind differences
The time evolution of the Gaussian temperature distribution can be computedwith the following MATLAB script:
% Numerical Methods in Geodynamics
% Exercise 4
%
% Daniel Koehn
% Kiel, the 24 th of march 2004
clear all
close all
% define constants
U=0.5; % velocity
N=1000; % number of grid points
L=150; % some length
dx=L./(N-1); % grid spacing
dt=dx./(200.*U) % Courant criteria
a=0.15; % half width of Gaussian
x0=15; % offset of Gaussian
tsamp= 20000.*dt; % take snapshot every tsamp
t1=0; % take first snapshot at time t1
t0=0;
t=t0; % start timer at t0
% set up initial condition (Gaussian)
x=0:dx:L;
Tm=exp(-(a.*(x-x0)).^2);
Ti=Tm;
for i=1:300000
% calculate temperature T at time step n
% from temperature Tm at time step n-1
% allocate memory for T
T=Tm;
% iteration
for k=2:N-1
T(k) = Tm(k)+dt.*((-U./(2.*dx)).*(Tm(k+1)-Tm(k-1)));
end
10
% schuffle vector elements
Tm=T;
if(t>t1)
plot(x,T);
hold on;
% axis and title
af=xlabel(x/m);
bf=ylabel(T/C);
df=title(Advection in 1D (forward differences));
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
t1=t1+tsamp;
end
t=t+dt;
% boundary
Tm(1)=Tm(2);
Tm(N)=Tm(N-1);
end
% output as eps-file
print -deps exer_3_gauss_cent_diff.eps
The results are shown in figure 5. While the upwind discretization scheme pro-duces strong diffusion of temperature, the central difference scheme shows noone.
11
0 50 100 1500
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
x/m
T/C
Advection in 1D (upwind differences)
0 50 100 1500.2
0
0.2
0.4
0.6
0.8
1
1.2
x/m
T/C
Advection in 1D (forward differences)
Abbildung 5: Time evolution of a Gaussian temperature distribution using an upwinddifference discretization scheme (top) and a central difference discretization scheme(bottom).
12
Exercise 5 Explore the 1D-problem from the last exercise in 2D using the ve-locity field
V = (u, v) = (y, x) (6)
2 1.5 1 0.5 0 0.5 1 1.5
2
1.5
1
0.5
0
0.5
1
1.5
x/m
y/m
Velocity field
The 2D-version of the MATLAB script from the last exercise using an upwinddiscretization scheme is listed below:
% Numerical Methods in Geodynamics
% 2D-Advection-Eq.
%
% Daniel Koehn
% Kiel, the 24 th of march 2004
clear all
close all
% define constants
N=100; % number of grid points in x-direction
M=100; % number of grid points in y-direction
L=4.0; % some length
13
dx=L./(N-1); % grid spacing
offx =2.5 % offset in x- and y-direction
% set up mesh
for j=1:M
for i=1:N
V(i,j)= i.*dx-offx; % velocity in y direction
U(i,j)=-(j.*dx-offx); % velocity in x direction
X(i,j)=i.*dx-offx; % x-coordinate
Y(i,j)=j.*dx-offx; %y-coordinate
end
end
% plot velocity field
%quiver(X,Y,U,V);
axis tight
grid off
hold off
% axis and title
af=xlabel(x/m);
bf=ylabel(y/m);
df=title(Velocity field);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
%print -deps exer_6_gauss_vel.eps
vmaxx = 2.5;
dt=dx./(4.*vmaxx) % Courant criteria
a=15; % half width of Gaussian
x0=-1.0; % offset of Gaussian in x-direction
y0=0.0; % offset of Gaussian in y-direction
% set up initial condition (Gaussian)
for j=1:M
for i=1:N
xi=i.*dx-offx; % x-coordinate
yi=j.*dx-offx; % y-coordinate
Tm(i,j)=exp(-(a.*((xi-x0).^2+(yi-y0).^2)));
end
end
% introduce boundary conditions
Tm(1,:)=0;
Tm(:,1)=0;
Tm(N,:)=0;
Tm(:,N)=0;
14
for k=1:1
% calculate temperature T at time step n
% from temperature Tm at time step n-1
% allocate memory for T
T=Tm;
% iteration (upwind differences)
for j=2:M-1
for i=2:N-1
if(U(i,j)>0)
dT1=(Tm(i,j)-Tm(i-1,j));
else
dT1=(Tm(i+1,j)-Tm(i,j));
end
if(V(i,j)>0)
dT2=(Tm(i,j)-Tm(i,j-1));
else
dT2=(Tm(i,j+1)-Tm(i,j));
end
T(i,j) = Tm(i,j)+dt.*(((-U(i,j)./dx).*dT1)+((-V(i,j)./dx).*dT2));
end
end
% schuffle vector elements
length(Tm)
length(T)
Tm=T;
end
imagesc(Tm);
axis equal;
axis tight;
hold on;
% axis and title
af=xlabel(x/GP);
bf=ylabel(y/GP);
df=title(Advection in 2D (upwind differences));
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps exer_6_gauss_1.eps
The pictures in figure 6 are illustrating the evolution of the Gaussian in time. Note thestrong numerical diffusivity by using the upwind difference scheme.
15
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
PAdvection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
x/GP
y/G
P
Advection in 2D (upwind differences)
20 40 60 80 100
10
20
30
40
50
60
70
80
90
100
Abbildung 6: A Gaussian temperature distribution in the velocity field (6) after 1,100, 500, 1000, 2000, 5000, 10000 and 60000 timesteps (from top to bottom).
16
Exercise 6 Solve the 1-D heat conduction equation
T
t=
2T
x2, (7)
using a singular solution method.
1. Nearest neighbor criteria for t (Courant number).
2. Nearest 2-neighbors can give and receive heat.
3. For any t, superimposing analytical solutions. Compare with finite difference ap-proximation.
Using the parameters from the dike cooling problem in section 4-19 in Turcotte andSchubert: Geodynamics the following MATLAB script calculates the temperature as afunction of distance for t=1000 days using finite differences.
% Numerical Methods in Geodynamics
% Exercise 4a
%
% Daniel Koehn
% Kiel, the 23 rd of march 2004
clear all
close all
% define constants
N=400; % number of grid points
L=20; % some length
dx=2.*L./(N-1); % grid spacing
x0=L; % offset of Gaussian
% numerical values from Turcotte and Schubert, Geodynamics
% Section 4-19, Section 4-21
Q=8.8e9; % heat
rho=2900; % density
c=1.2e3; % specific heat
kappa=5e-7; % thermal diffusivity
dt=dx./(100.*kappa) % size of time step
tmax=1000.*86400; % end of calculation after tmax days
% set up initial condition (Gaussian)
t0=100.*86400; % start calculation after 8.64e6 s or 100 days
Tau=round((tmax-t0)./dt) % number of time steps
x=0:dx:2.*L;
Tm=(Q./(2.*rho.*c.*sqrt(pi.*kappa.*t0))).*exp((-(x-x0).^2)./(4.*kappa.*t0));
Ti=Tm;
T1000ex=(Q./(2.*rho.*c.*sqrt(pi.*kappa.*tmax))).*exp((-(x-x0).^2)./(4.*kappa.*tmax));
% set up boundary conditions
T0=Tm(1)
TN=Tm(N)
for i=1:Tau
17
% calculate temperature T at time step n+1
% from temperature Tm at time step n
% allocate memory for T
T=Tm;
% iteration
for k=2:N-1
T(k) = Tm(k) + dt.*((kappa./(dx.^2)).*(Tm(k-1)+Tm(k+1)-2.*Tm(k)));
end
% schuffle vector elements
Tm=T;
% implement boundary
Tm(1)=T(2);
Tm(N)=T(N-1);
end
plot(x,Ti,x,T1000ex,x,T,--);
% axis and title
af=xlabel(x/m);
bf=ylabel(T-T_0/K);
df=title(Diffusion in 1D (forward differences));
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps exer_4_heat_trans.eps
The analytical solution for this problem can be written as
T =Q
2cpit
exp
( (x x0)
2
4t
), (8)
where Q is the heat content, density, c specific heat and the thermal diffusivity. Acomparison between the analytical and the numerical solution is schown in figure 7. Asingular solution method is realized with the MATLAB script:
% Numerical Methods in Geodynamics
% Exercise 4b
%
% Daniel Koehn
% Kiel, the 23 rd of march 2004
%
% update: 26 th of march 2004 - fixed artifical diffusion bug
18
clear all
close all
% define constants
N=100; % number of grid points
L=20; % some length
dx=2.*L./(N-1); % grid spacing
x0=L; % offset of Gaussian
% numerical values from Turcotte and Schubert, Geodynamics
% Section 4-19, Section 4-21
Q=8.8e9; % heat
rho=2900; % density
c=1.2e3; % specific heat
kappa=5e-7; % thermal diffusivity
dt=dx./(13.5*kappa) % size of time step
tmax=1000.*86400; % end of calculation after tmax days
% set up initial condition (Gaussian)
t0=100.*86400; % start calculation after 8.64e6 s or 100 days
Tau=round((tmax-t0)./dt) % number of time steps
x=0:dx:2.*L; % coordinates of the grid points
xi=(dx./2):dx:2.*L; % coordinates of the integration points
Tm=(Q./(2.*rho.*c.*sqrt(pi.*kappa.*t0))).*exp((-(x-x0).^2)./(4.*kappa.*t0));
Ti=Tm; % calculate initial condition
T=Ti;
% exact solution after 1000 days
T1000ex=(Q./(2.*rho.*c.*sqrt(pi.*kappa.*tmax))).*exp((-(x-x0).^2)./(4.*kappa.*tmax));
% set up boundary conditions
T0=Tm(1)
TN=Tm(N)
t1=t0;
% calculate heat content in each cell
for k=1:N
Q0(k)=rho.*c.*Tm(k).*dx;
end
NS=N-3;
NE=4;
dir=-1;
for i=1:Tau
t=t1-t0;
% calculate change in heat content for each cell k
QSUM=0.0;
for k=NS:dir:NE
% calculate heat content in neighbor no. 1
Q1=Q0(k).*(erf(abs(xi(k-2)-x(k))./(2.*sqrt(kappa.*t)))-...
erf(abs(xi(k-1)-x(k))./(2.*sqrt(kappa.*t))))./2;
% calculate heat content in neighbor no. 2
19
Q2=Q0(k).*(erf(abs(xi(k-3)-x(k))./(2.*sqrt(kappa.*t)))-...
erf(abs(xi(k-2)-x(k))./(2.*sqrt(kappa.*t))))./2 ;
% heat content in neighbor no. 3 is symmetric to heat content in neighbor no. 1
Q3=Q1;
% heat content in neighbor no. 4 is symmetric to heat content in neighbor No. 2
Q4=Q2;
QSUM = QSUM + Q0(k);
% add heat content to neighbor cells
Q0(k-2)=Q0(k-2)+abs(Q2);
Q0(k-1)=Q0(k-1)+abs(Q1);
Q0(k+1)=Q0(k+1)+abs(Q3);
Q0(k+2)=Q0(k+2)+abs(Q4);
% subtract heat content from cell no. k
Q0(k)=Q0(k)-abs(Q1)-abs(Q2)-abs(Q3)-abs(Q4);
end
% implement boundary
Q0(1)=Q0(2);
Q0(2)=Q0(3);
Q0(3)=Q0(4);
Q0(N-2)=Q0(N-3);
Q0(N-1)=Q0(N-2);
Q0(N)=Q0(N-1);
for k=1:N
% calculate temperature in cell k
T(k)=Q0(k)./(rho.*c.*dx);
end
t1=t1+dt;
NSS=NE;
dir = -dir;
NE=NS;
NS=NSS;
end
QSUM
Tau
plot(x,Ti,x,T1000ex,x(4:N),T(4:N),--);
% axis and title
af=xlabel(x/m);
bf=ylabel(T-T_0/K);
df=title(Diffusion in 1D (singular solution));
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
20
% output as eps-file
print -deps exer_4_heat_trans_sing_sol.eps
A comparison between the analytical and the numerical solution using the singularsolution method is shown in figure 8. Using a fixed number of grid points the error ofthe solution highly depends on the size of the time step, as can be seen by choosingdifferent time-step-sizes in the MATLAB script.
21
0 5 10 15 20 25 30 35 400
50
100
150
200
250
300
350
x/m
TT 0
/K
Diffusion in 1D (forward differences)
initial condition t=100 days
exact solution t=1000 days finite difference solution t=1000 days
Abbildung 7: Comparsion between the analytical (8) and the numerical solution usinga forward finite difference scheme.
0 5 10 15 20 25 30 35 400
50
100
150
200
250
300
350
x/m
TT 0
/K
Diffusion in 1D (singular solution)
initial condition t=100 days
exact solution t=1000 days
singular solution method t=1000 days
Abbildung 8: Comparsion between the analytical (8) and the numerical solution usingthe singular solution method.
22
Exercise 7 Form a 5 point central difference scheme for y in the form
y3 =1
h2(1y2 + 2y2 + 3y3 + 4y4 + 5y5) (9)
with equidistant sampling points. Estimate its O(h?) accuracy.
x
y
y1 y2y3
y4
y5
h h h h
Abbildung 9: The construction of the five-point FD-scheme.
Using Taylors theorem together with figure 9 to expand around x = 0 = x3 we get
y1 = y3 2hy3 +1
2!4h2y3
1
3!8h3y3 +
1
4!16h4y3 +O(h5y3 )
y2 = y3 hy3 +1
2!h2y3
1
3!h3y3 +
1
4!h4y3 +O(h5y3 )
y4 = y3 + hy3 +
1
2!h2y3 +
1
3!h3y3 +
1
4!h4y3 +O(h5y3 )
y5 = y3 + 2hy3 +
1
2!4h2y3 +
1
3!8h3y3 +
1
4!16h4y3 +O(h5y3 )
(10)
Using Eq. (10) Eq. (9) can be written as
y3 (x) =1
h2[(1 + 2 + 3 + 4 + 5)y3
+ (21 2 + 03 + 4 + 25)hy3+ (41 + 2 + 03 + 4 + 45)
h2
2!y3
+ (81 2 + 03 + 4 + 85)h3
3!y3
+ (161 + 2 + 03 + 4 + 165)h4
4!y3 ]
(11)
23
In order to make the rhs as exact in y3 as possible when h 0 we need to make asmany low order terms as possible identically zero:
1 + 2 + 3 + 4 + 5 = 0
21 2 + 03 + 4 + 25 = 041 + 2 + 03 + 4 + 45 = 2!
81 2 + 03 + 4 + 85 = 0161 + 2 + 03 + 4 + 165 = 0
(12)
This set of equations can be solved for the five unknowns i using the MATLAB-script
% 5-point difference scheme
%
% Daniel Koehn
% Raisdorf, the 18th of May 2004
clear all
close all
syms h;
% set up coefficient matrix
A=[1 1 1 1 1
-2 -1 0 1 2
4 1 0 1 4
-8 -1 0 1 8
16 1 0 1 16];
% set up rhs
b=[0 0 2 0 0];
b=b;
% invert matrix A
x=inv(A)*b;
x=sym(x)
The solution is 1 = 1/12, 2 = 4/3, 3 = 5/2, 4 = 4/3 and 5 = 1/12. So thefive point-difference-scheme can be written in the form:
yi =1
h2( 1
12yi2 +
4
3yi1 5
2yi +
4
3yi+1 1
12yi+2) (13)
It is accurate to O(h4y3 )-terms.
24
Exercise 8 Choose f(x) = sin(pix2). Solve the systems
2 11 2 1
......
...
1 2 11 1
u1
u2...
uN
=
h2f1
h2f2......
hfN
(14)
2 11 2 1
......
...
1 2 11 1
u1
u2...
uN
=
h2f1
h2f2......
h2 fN2
(15)
exactly for grids of h,h2,h4,h8and determine how the accuracy uFD ucont. is improved
as a function of h as h 0. Try 2 Norms, the 2-norm, and the -norm, and onlyconsider errors at the finite difference grid points. Also, take fi = f(xi).Try your super-duper 5-point difference scheme at the points 3 N 2. How muchaccurate is it ? (both within system (14) and (15)).
To find the exact solution ucont. to the problem we integrate
2u
x2= f(x) = sin
(pix
2
)(16)
twice and get
u
x=
2
picos
(pix
2
)+ c1
u =4
pi2sin
(pix
2
)+ c1x+ c2
(17)
where c1 and c2 denote constants of integration. We estimate them by applying theboundary conditions
u(0) = 0
u(1) = 0(18)
It follows that c1 = c2 = 0. We can conclude that the exact solution of (16) is
u =4
pi2sin
(pix
2
). (19)
The FD-Code for system (14) was realized in the following MATLAB-script:
% Numerical Methods in Geodynamics
% Exercise 9
% 1st order flux b.c.
25
%
% Daniel Koehn
% Kiel, the 18 th of may 2004
clear all
close all
% define constants
L=1.0; % some length
dh=1; % gridsize refineing factor
for j=1:4
h=0.1./dh % grid point spacing
N=(L./h)+1; % number of grid points
% 1st order scheme system
% -------------------------
% build matrix-equation
% cofficient matrix
e0 = 2.*ones(N,1); % elements on main diagonal
e1 = -1.*ones(N-1,1); % 1st upper diagonal
e2 = -1.*ones(N-1,1); % 1st lower diagonal
S = diag(e0) + diag(e1,1) + diag(e2,-1);
S(N,N)=1;
S;
% RHS vector
b = ones(N-1,1);
x=0;
% build elements 1 - (N-1)
for i=1:N-1
b(i)=(h.^2).*sin(pi.*i.*h./2);
x=x+h;
end
% apply boundary conditions
% build element N
%b(N)=h.*sin(pi.*N.*h./2);
b(N)=0;
% plot RHS vector b
b;
% matrix inversion
% ----------------
u=inv(S)*b;
% plot solutions
% ----------------------
% position vector
26
xe=0:h:L;
% calculate exact solution
uex=((4./(pi.^2)).*sin(pi.*xe./2));
% calculate 2-norm
du(dh)=0;
for i=1:N
dus=(u(i)-uex(i)).^2;
du(dh)=du(dh)+dus;
end
du(dh)=sqrt(du(dh));
% calculate infinity-norm
dui(dh)=0;
for i=1:N
dus=(u(i)-uex(i)).^100;
dui(dh)=dui(dh)+dus;
end
dui(dh)=(dui(dh)).^(1./100);
% plot solutions
plot(xe,u,--,xe,uex);
hold on;
% refine grid
dh=dh.*2;
end
% axis and title
af=xlabel(x);
bf=ylabel(u);
df=title(Poisson Equation with fixed and flux b.c. (1st order));
ef=legend(1st order b.c.,exact,2);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,14,FontName,Times);
% output as eps-file
print -deps 1st_order_scheme.eps
% output of 2-norm
du
% output of infinity-norm
dui
27
The code for the 2nd order scheme (15) is only a slightly modification of the 1st orderscheme code. The last element of the rhs vector has to be changed:
% apply flux boundary condition
% build element N
b(N)=(h.^2).*sin(pi.*N.*h./2)./2;
The results of calculations with grids h,h2,h4and h
8are shown in figure 10 and figure ??.
The MATLAB-script for the five-point scheme with 2nd order flux boundary schemelooks like this:
% Numerical Methods in Geodynamics
% Exercise 9a
% 5-point scheme
% 2nd order flux boundary scheme
%
% Daniel Koehn
% Kiel, the 18 th of may 2004
clear all
close all
% define constants
L=1.0; % some length
dh=1; % gridsize refineing factor
for j=1:4
h=0.1./dh % grid point spacing
N=(L./h)+1; % number of grid points
% 1st order scheme system
% -------------------------
% build matrix-equation
% cofficient matrix
e0 = (5./2).*ones(N,1); % elements on main diagonal
e1 = (-4./3).*ones(N-1,1); % 1st upper diagonal
e2 = (-4./3).*ones(N-1,1); % 1st lower diagonal
e3 = (1./12).*ones(N-2,1); % 2nd upper diagonal
e4= (1./12).*ones(N-2,1); % 2nd lower diagonal
S = diag(e0) + diag(e1,1) + diag(e2,-1)+diag(e3,2)+diag(e4,-2);
% build 1st and 2nd equation
S(1,1)=2; S(1,2)=-1; S(1,3)=0;
S(2,1)=-1; S(2,2)=2; S(2,3)=-1; S(2,4)=0;
% build last 2 equation
S(N,N)=1; S(N,N-1)=-1; S(N,N-2)=0;
S(N-1,N)=-1; S(N-1,N-1)=2; S(N-1,N-2)=-1; S(N-1,N-3)=0;
S;
% RHS vector
b = ones(N-1,1);
28
x=0;
% build elements 1 - (N-1)
for i=1:N-1
b(i)=(h.^2).*sin(pi.*i.*h./2);
x=x+h;
end
% apply boundary conditions
% build element N
b(N)=(h.^2).*sin(pi.*N.*h./2)./2;
% plot RHS vector b
b;
% matrix inversion
% ----------------
u=inv(S)*b;
% plot solutions
% ----------------------
% position vector
xe=0:h:L;
% calculate exact solution
uex=((4./(pi.^2)).*sin(pi.*xe./2));
% calculate 2-norm
du(dh)=0;
for i=1:N
dus=(u(i)-uex(i)).^2;
du(dh)=du(dh)+dus;
end
du(dh)=sqrt(du(dh));
% calculate infinity-norm
dui(dh)=0;
for i=1:N
dus=(u(i)-uex(i)).^100;
dui(dh)=dui(dh)+dus;
end
dui(dh)=(dui(dh)).^(1./100);
% plot solutions
plot(xe,u,--,xe,uex);
hold on;
% refine grid
dh=dh.*2;
end
29
% axis and title
af=xlabel(x);
bf=ylabel(u);
df=title(Poisson Equation with fixed and flux b.c. (2nd order));
ef=legend(2nd order b.c.,exact,2);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,14,FontName,Times);
% output as eps-file
print -deps 2nd_order_scheme.eps
% output of 2-norm
du
% output of infinity-norm
dui
The accuracy of the schemes was measured by the 2-norm S2 and the -norm S.The norms are defined as:
S2 =
( Ni=1
(uFD,i ucont.,i)2)1/2
S ( Ni=1
(uFD,i ucont.,i)100)1/100 (20)
The results of the accuracy measurements are collected in table 1 and are plotted infigure 11.
30
h h/2 h/4 h/8
three-point-scheme 1st order flux b.c.
S2 0.2236 0.1527 0.1060 0.0743
S 0.0752 0.0371 0.0185 0.0093
three-point-scheme 2nd order flux b.c.
S2 0.3223 0.2160 0.1484 0.1034
S 0.1066 0.0523 0.0260 0.0130
five-point-scheme 1st order flux b.c.
S2 0.2220 0.1521 0.1058 0.0742
S 0.0748 0.0370 0.0185 0.0093
five-point-scheme 2nd order flux b.c.
S2 0.3205 0.2153 0.1482 0.1033
S 0.1059 0.0521 0.0259 0.0130
Tabelle 1: S2 and S-norm for 1st and 2nd order flux b.c. for the three- andthe five-point scheme.
31
0 0.2 0.4 0.6 0.8 10
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
x
u
Poisson Equation with fixed and flux b.c. (1st order)1st order b.c.exact
Abbildung 10: Results of the FD-scheme with 1st order flux b.c. for grids h = 0.1, h2,h4
and h8, compared with the exact solution (19).
0 0.02 0.04 0.06 0.08 0.10
0.05
0.1
0.15
0.2
0.25
0.3
0.35
h
u
Comparison of 2 and norm for the different schemesS2 1stS
1st
S2 2ndS
2nd
S2 5p 1stS
5p 1st
S2 5p 2ndS
5p 2nd
Abbildung 11: Comparison between the 2- and the-norm for the different schemes.
32
Problem 1 Multigrid
Make a MATLAB finite difference programm that reproduces figure 18a-e. The startingcondition is shown in figure 18a
vj =1
2
[sin
(12jpi
N
)+ sin
(30jpi
N
)](21)
with N=48, with a weighted Jacobi smoother = 2/3.
The main part of the multigrid code is in the MATLAB-script multigrid.m:
% Numerical Methods in Geodynamics
% Multigrid
%
% Daniel Koehn
% Kiel, the 13th of april 2004
clear all
close all
% define constants
N=48; % number of grid points
w=2./3; % damp factor
enorm = 1; % dummy normalization factor
% central difference scheme
% -------------------------
% build matrix-equation
% coefficient matrix
e0 = 2.*ones(N-1,1); % elements on main diagonal
e1 = -1.*ones(N-2,1); % 1st upper diagonal
e2 = -1.*ones(N-2,1); % 1st lower diagonal
S = diag(e0) + diag(e1,1) + diag(e2,-1);
% RHS vector
b = zeros(N-1,1);
% boundary conditions are both zero
% v(0)=v(N)=0;
% define gridpoints
J=1:N-1;
% initial guess
for j=1:N-1
v(j) = (1./2).*(sin(12.*j.*pi./N)+sin(30.*j.*pi./N));
end
% save 1st guess v0
v0=v;
% plot inital guess with boundary points
33
plot([0 J N],[0 v0 0]);
axis tight;
% axis and title
af=xlabel(grid point);
bf=ylabel(v_j);
df=title(Initial guess );
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps multigrid_a.eps;
% apply 1 weighted Jacobi iteration step
[vn]=jac(v,w,S,b);
% save solution v1n after 1 weighted Jacobi step
v1n = vn;
% plot solution v1n after 1 weighted Jacobi step
% with boundary points
figure
plot([0 J N],[0 v0 0],[0 J N],[0 v1n 0]);
axis tight;
% axis and title
af=xlabel(grid point);
bf=ylabel(v_j);
df=title(Solution after 1 fine grid relaxation);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps multigrid_b.eps;
% apply 2 more Jacobi iteration steps
for j=1:2
v = vn;
[vn]=jac(v,w,S,b);
end
% save solution v3n after 3 Jacobi iterations
v3n=vn;
% plot solution v3n after 3 weighted Jacobi steps
34
% with boundary points
figure
plot([0 J N],[0 v0 0],[0 J N],[0 v1n 0],[0 J N],[0 v3n 0]);
axis tight;
% axis and title
af=xlabel(grid point);
bf=ylabel(v_j);
df=title(Solution after 3 fine grid relaxations);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps multigrid_c.eps
% calculate residual
r = b - S * vn;
% full-weighted restriction
[J2h,I2h,v2h,S1,b1] = weight_res(N,vn,S,r);
% one Jacobi iteration step on coarse grid
v = v2h;
v=v;
[v2h]=jac(v,w,S1,b1);
% Correct fine grid solution (Prolongation)
[v1m] = prolong(N,I2h,v3n,v2h);
% plot sparseisity of matrix I2h
%figure
%spy(I2h);
figure
% plot solution v3n after 1 weighted Jacobi step
% on the coarse grid with boundary points
plot([0 J N],[0 v0 0],[0 J N],[0 v1n 0],[0 J N],[0 v3n 0],J,v1m);
axis tight;
% axis and title
af=xlabel(grid point);
bf=ylabel(v_j);
df=title(Solution on coarse grid after full-weighted restriction);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
35
% output as eps-file
print -deps multigrid_d.eps
% apply two more Jacobi steps on coarse grid
for i=1:2
v2hs = v2h;
[v2h]=jac(v2hs,w,S1,b1);
end
% Correct fine grid solution (Prolongation)
[v3m] = prolong(N,I2h,v3n,v2h);
% plot solution v2h after 3 weighted Jacobi steps
% on the coarse grid with boundary points
figure
plot([0 J N],[0 v0 0],[0 J N],[0 v1n 0],[0 J N],[0 v3n 0],J,v3m);
axis tight;
% axis and title
af=xlabel(grid point);
bf=ylabel(v_j);
df=title(Solution on coarse grid after 3 Jacobi iteration steps);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps multigrid_e.eps
The weighted jacobi iteration will be done with the function jac.m
function [vn] = jac(v,w,A,f)
% Weighted Jacobi iteration
%
% Daniel Koehn
% Raisdorf, the 13th of april 2004
% calculate residual r
r=f-A*v;
% calculate inverse of diagonal D of matrix A
D=diag(A);
D=1./D;
S = diag(D);
% Make one Jacobi iteration step
vn = v + (w * S * r);
The full-weighted restriction is realized in the function weight res.m
function [J2h,I2h,v2h,A2h,b1] = weight_res(N,vn,S,b)
36
% Full-Weighted Restriction
%
% Daniel Koehn
% Kiel, the 15th of april 2004
% full-weighted restriction
% build restriction matrix I2h
I2h=zeros((N./2)-1,N-1);
dj=0;
for i=1:((N/2)-1)
I2h(i,1+dj) = 1./4;
I2h(i,2+dj) = 2./4;
I2h(i,3+dj) = 1./4;
dj=dj+2;
end
% apply full-weighted restriction on vn
v2h = I2h*vn;
% define gridpoints on coarse grid
J2h=2:2:N-1;
% calculate Matrix A2h
A2h = I2h*S*(2.*I2h);
% apply full-weighted restriction on residual rh
b1=I2h*b;
The fine grid correction will be done with the function prolong.m:
function [vn1] = prolong(N,I2h,vn,v2h)
% Fine Grid Correction
%
% Daniel Koehn
% Kiel, the 15th of april 2004
% apply fine grid correction
vn1 = vn + (2.*I2h) * v2h;
37
0 5 10 15 20 25 30 35 40 450.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
grid point
vj
Initial guess
Abbildung 12: The initial guess vj = 12
[sin
(12jpiN
)+ sin
(30jpiN
)]with N=48 for a
coarse grid correction scheme applied with the weighted Jacobi iteration ( = 2/3)
0 5 10 15 20 25 30 35 40 450.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
grid point
vj
Solution after 1 fine grid relaxation
Abbildung 13: The approximation (and error) after one fine grid relaxation sweepsuperimposed upon the initial guess.
38
0 5 10 15 20 25 30 35 40 450.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
grid point
vj
Solution after 3 fine grid relaxations
Abbildung 14: The error after three fine grid relaxation sweeps superimposed uponprevious iterates.
0 5 10 15 20 25 30 35 40 450.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
grid point
vj
Solution on coarse grid after fullweighted restriction
Abbildung 15: The fine grid residual is transferred to the coarse grid by full weighting.This figure shows the error after one relaxation sweep on the coarse grid residualequation, superimposed upon previous approximationes.
39
0 5 10 15 20 25 30 35 40 450.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
grid point
vj
Solution on coarse grid after 3 Jacobi iteration steps
Abbildung 16: The error after three relaxation sweeps on the coarse grid residualequation superimposed upon previous approximations.
40
Problem 2 Temperature and melting of continental crust
Here we are solving 2 types of problems.
1. Heat conduction with a source term
T
t=
2T
z2+ q(z) (22)
2. Conduction-advection for a very simple case of advective flow
u = U0x
Lw = U0 z
L, (23)
where U0 is the stretching/compression velocity at the edge of the region of in-terest. For this particular velocity field, the temperature is constant with x, i.e.T=T(z), so we can again make a 1-D approximation to the problem
T
t U0 z
L
T
z=
2T
z2+ q(z). (24)
The boundary conditions are
T = 0 at z = 0
T = Tmantle = 1300C at z = L = 300 km
(25)
Moho
crust
mantle q=0
q=0z
T=0
at z=L, T=Tmantle
xLL
z=L=300 km
z=0
Abbildung 17: Model of the crust and the upper mantle.
Take L=300 km and assume that the initial Moho is 30 km deep (figure 17). Formulatea 1-D Finite difference algorithm for cases 1 and 2 in MATLAB.
41
1. Start with T = Tm everywhere except z = 0. Solve the problem of halfspacecoolingwith no crustal heat source and no avection. This has an error functionsolution given in Turcotte & Schubert 4-22 Ocean Plate Topography ([1]).
The solution to the halfspace cooling problemgiven in [1] has the form
T (z) = (T0 Tm)erf(
z
2t
)+Tm (26)
with T0 = 0 K, Tm = Tmantle = 1300C and = 1.0 106 m2/s. Using a central
difference scheme for the heat conduction term in eq. (22) and an upwind differencescheme for the time derivative we can write down the following MATLAB code to solvethe heat conduction problem.
% Numerical Methods in Geodynamics
% Crustal_melting_cond
%
% Daniel Koehn
% Kiel, the 22nd of may 2004
clear all
close all
% define constants
N=1000; % number of grid points
L=300.*1000; % depth of the model (km)
Lmoho = 30.*1000; % depth of the Moho (km)
kappa = 1e-6; % thermal diffusivity
rhoc=2700; % density of the crust
Tmantle = 1300 + 273; % temperature at lithosphere base
tend=1e7.*31536000; % stop calculation after tend Mio years
dz=L./(N-1); % grid spacing
dt=3e10; % time step
TN=round(tend./dt) % number of time steps
zi=0;
% setup inital temperature Tm, depth z and heat production q
for i=1:N
Tm(i) =Tmantle;
z(i)=zi;
% radioactive heat production in the crust
q(i) = 0.0;
% no radioactive heat production in the mantle
if(zi>=Lmoho)
q(i)=0.0;
end
zi=zi+dz;
end
% setup boundary conditions
Tm(1)=0;
Tm(N)=Tmantle;
42
t=0;
for i=1:TN
% calculate temperature T at time step n
% from temperature Tm at time step n-1
% allocate memory for T
T=Tm;
% iteration
for k=2:N-1
T(k) = Tm(k)+dt.*((kappa./(dz.^2)).*((Tm(k-1)+Tm(k+1)-2.*Tm(k)))+q(k));
end
% schuffle vector elements
Tm=T;
t=t+dt;
end
% Calculate exact solution to halfspace cooling model
% given in Turcotte & Schubert 4-16 Cooling of the Oceanic Ltihosphere
Tex =((Tm(1)-Tm(N)).*erfc(z./(2.*sqrt(kappa.*t))))+Tm(N);
% plot solution
plot(T,z./1000,Tex,z./1000,--);
axis ij;
hold on
% axis and title
af=xlabel(T/K);
bf=ylabel(z/km);
df=title(Halfspace cooling model);
ef=legend(numerical solution,exact solution,2);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,15,FontName,Times);
% output as eps-file
print -deps halfspace_cooling.eps
43
Figure 18 compares the numerical solution calculated using the MATLAB code withthe exact solution eq.(26).
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
Halfspace cooling model
numerical solutionexact solution
Abbildung 18: Comparison between the numerical solution and the exact solution eq.(26) for the
halfspace cooling problem after 10 Ma.
2. Solve the problem for a constant crustal heat production of H = 3 1010Wkg andc = 2700 kg/m
3, m = 3300 kg/m3 and = 1 mm2/s.
To calculate the crustal heat production rate q = Hcp we assume a specific heat cp 850 J/kg/K. Figure 19 shows the distribution of the heat production rate q in themodel. The MATLAB script crust melt cond sour.m includes heat production in thecrust.
% Numerical Methods in Geodynamics
% Crustal_melting_cond_sour
%
% Daniel Koehn
% Kiel, the 22nd of may 2004
clear all
close all
% define constants
N=1000; % number of grid points
L=300.*1000; % depth of the model (km)
44
Lmoho = 30.*1000; % depth of the Moho (km)
kappa = 1e-6; % thermal diffusivity
H=3e-10; % rate of radioactive heat production in
% the crust
cp=850; % specific heat
rhoc=2700; % density of the crust
Tmantle = 1300 + 273; % temperature at lithosphere base
tend=10e7.*31536000; % stop calculation after tend Mio years
dz=L./(N-1); % grid spacing
dt=3e10; % time step
TN=round(tend./dt) % number of time steps
zi=0;
% setup inital temperature Tm, depth z and heat production q
for i=1:N
Tm(i) =Tmantle;
z(i)=zi;
% radioactive heat production in the crust
q(i) = H./cp;
%q(i) = 0.0;
% no radioactive heat production in the mantle
if(zi>=Lmoho)
q(i)=0.0;
end
zi=zi+dz;
end
% setup boundary conditions
Tm(1)=0;
Tm(N)=Tmantle;
t=0;
for i=1:TN
% calculate temperature T at time step n
% from temperature Tm at time step n-1
% allocate memory for T
T=Tm;
% iteration
for k=2:N-1
T(k) = Tm(k)+dt.*((kappa./(dz.^2)).*((Tm(k-1)+Tm(k+1)-2.*Tm(k)))+q(k));
end
% schuffle vector elements
Tm=T;
t=t+dt;
end
% Calculate exact solution to halfspace cooling model
% given in Turcotte & Schubert 4-16 Cooling of the Oceanic Ltihosphere
Tex =((Tm(1)-Tm(N)).*erfc(z./(2.*sqrt(kappa.*t))))+Tm(N);
45
% plot solution
plot(T,z./1000,Tex,z./1000,--);
axis ij;
hold on
% axis and title
af=xlabel(T/K);
bf=ylabel(z/km);
df=title(Halfspace cooling model);
ef=legend(numerical solution,exact solution with q=0,2);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
set(ef,FontSize,15,FontName,Times);
% output as eps-file
print -deps halfspace_cooling_with_heat.eps
% plot distribution of radioactive elements
figure
plot(q,z./1000);
axis ij;
hold on
% axis and title
af=xlabel(q/K/s);
bf=ylabel(z/km);
df=title(q-Distribution);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps q-distribution.eps
46
The solution to the heat-conduction problem with sources is plotted in figure 20.
0 0.5 1 1.5 2 2.5 3 3.5 4x 1013
0
50
100
150
200
250
300q/K/s
z/km
qDistribution
Abbildung 19: Distribution of the heat production rate q in the model with constantcrustal heat production.
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
Halfspace cooling model
numerical solutionexact solution with q=0
Abbildung 20: Comparison between the solution of the halfspace cooling model withheat source in the crust (solid line) and the exact solution with no heat sources (eq.(26)/dashed line) after 100 Ma.
47
3. Assume the crust thickness from 30 km to 60 km in 10 My. What happens toits temperature? (solve equation /problem 2). Does it increase /decrease withdepth ?
Using an upwind scheme for the advective term in eq. (24) we can formulate thefollowing MATLAB code
% Numerical Methods in Geodynamics
% Crustal_melting_cond_adv_sour
%
% Daniel Koehn
% Kiel, the 23rd of may 2004
clear all
close all
% define constants
N=1000; % number of grid points
L=300.*1000; % depth of the model (km)
Lmoho = 30.*1000; % depth of the Moho (km)
kappa = 1e-6; % thermal diffusivity
H=3e-10; % rate of radioactive heat production in
% the crust
cp=850; % specific heat
rhoc=2700; % density of the crust
Tmantle = 1300+273; % temperature at lithosphere base
tend=1e7.*31536000; % stop calculation after tend Mio years
dz=L./(N-1); % grid spacing
dt=3e10; % time step
TN=round(tend./dt) % number of time steps
U0=30000./tend; % convergence velocity [m/s]
zi=0;
% setup inital temperature Tm, depth z and heat production q
for i=1:N
Tm(i) =Tmantle;
z(i)=zi;
% radioactive heat production in the crust
q(i) = H./cp;
% no radioactive heat production in the mantle
if(zi>=Lmoho)
q(i)=0.0;
end
zi=zi+dz;
end
% setup boundary conditions
Tm(1)=0;
Tm(N)=Tmantle;
% allocate memory for T
T=Tm;
48
% 1. calculate temperature distribution after 10 Ma with crustal thickening
t=0;
% initial Moho depth
Lmoho0=Lmoho;
for i=1:TN
% calculate temperature T at time step n
% from temperature Tm at time step n-1
% depth of the Moho is linear increasing with time
Lmoho=U0.*t + Lmoho0;
zi=0;
% setup heat production rate q
for j=1:N
% radioactive heat production in the crust
q(j) = H./cp;
z(j)=zi;
% no radioactive heat production in the mantle
if(zi>=Lmoho)
q(j)=0.0;
end
zi=zi+dz;
end
% solve advection-conduction equation with sources by iteration
for k=2:N-1
T(k) = Tm(k)+dt.*((kappa./(dz.^2)).*((Tm(k-1)+Tm(k+1)-2.*Tm(k)))...
+q(k)+(U0.*(z(k)./L).*(Tm(k)-Tm(k-1))./dz));
end
% schuffle vector elements
Tm=T;
t=t+dt;
end
% plot solution
figure
plot(T,z./1000);
axis ij;
% axis and title
af=xlabel(T/K);
bf=ylabel(z/km);
df=title(crustal thickening);
ef=legend(geotherm after 10 Ma crustal thickening,1);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
49
set(ef,FontSize,15,FontName,Times);
% output as eps-file
print -deps halfspace_cooling_adv.eps
% plot distribution of radioactive elements
figure
plot(q,z./1000);
axis ij;
hold on
% axis and title
af=xlabel(q/K/s);
bf=ylabel(z/km);
df=title(q-Distribution);
% fitting the fonts
set(gca,FontSize,15,FontName,Times);
set(af,FontSize,15,FontName,Times);
set(bf,FontSize,15,FontName,Times);
set(df,FontSize,15,FontName,Times);
% output as eps-file
print -deps q-distribution_1.eps
50
The results of the calculation are plotted in figure 21 and figure 22. figure 22 showsthe geotherm after 10 Ma with heat sources in the crust and crustal thickening. Thetemperature increases with depth.
0 0.5 1 1.5 2 2.5 3 3.5 4x 1013
0
50
100
150
200
250
300q/K/s
z/km
qDistribution
Abbildung 21: Distribution of q after 10 Ma of crustal thickening.
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
crustal thickening
geotherm after 10 Ma crustal thickening
Abbildung 22: The geotherm after 10 Ma of crustal thickening.
51
4. Assume the crust stays 60 km thick for 10 Ma and then thins to 30 km in another10 Ma. How does its temperature compare the original steady-state profile?
Using the same MATLAB-Code as in problem 3 we get the geotherms plotted in fi-gure 23. The geotherm after one cycle of 10 Ma crustal thickening, steady state for10 Ma and 10 Ma thining (dashed line) has a greater slope than the original steadystate profile (solid line), but a smaller slope than the geotherm after 10 Ma of crustalthickening (dotted line).
5. Assume the crust stays 60 km thick for 30 Ma and then thins in 10 Ma back to30 km. What are the differences between this and problem 4 ?
In figure 23 and figure 24 the problems 4 and 5 are compared. Cause the crust stays30 Ma in steady state the slope of the geotherm at the end of the simulation (dashedline) in problem 4 is greater, than in problem 5.
6. Assume the mantle beneath the crust is removed and replaced by 1300 C mantle(T = Tm). If no advection occurs (30 km crust and no deformation), what is themaximum increase in temperature in the crust at z=15 km depth ? (Before itgoes back to steady state). Say crust melts at 800 C. Where melts the lowercrust ?
At z=15 km depth the maximum temperature, after replacing the mantle beneath thecrust by 1300 C mantle, is Tmax 169 C (figure 25). By looking at figure 26 we canestimate, that the lower crust can melt at a depth of about 52 km.
52
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
crustal thickening and thining
steady state geothermgeotherm after 10 Ma crustal thickeninggeotherm after 30 Ma
Abbildung 23: Geotherm after 10 Ma of crustal thickening (dotted line) and thegeotherm after another 10 Ma of steady state and 10 Ma of crustal thining (dashedline), compared with a 30 Ma steady state geotherm (solid line).
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
crustal thickening and thining
steady state geothermgeotherm after 10 Ma crustal thickeninggeotherm after 50 Ma
Abbildung 24: Geotherm after 10 Ma of crustal thickening (dotted line) and thegeotherm after 30 Ma of steady state and 10 Ma of crustal thining (dashed line),compared with a 30 Ma steady state geotherm (solid line).
53
0 2 4 6 8 10410
415
420
425
430
435
440
445
t/Ma
T/K
temperature in 15 km depth
Abbildung 25: Temperature evolution at a depth of z = 15 km after replacing themantle beneath the crust by 1300C mantle.
0 200 400 600 800 1000 1200 1400 1600
0
50
100
150
200
250
300T/K
z/km
crustal thickening and thining
steady state geothermgeotherm after 10 Ma crustal thickeninggeotherm after 50 Ma
Abbildung 26: Geotherm after 10 Ma of crustal thickening (dotted line). The geothermafter 30 Ma of steady state, 10 Ma of crustal thining and replacing the mantle beneaththe crust by 1300C mantle (dashed line).The geotherm after another 10 Ma of steadystate (solid line).
54 LITERATUR
Literatur
[1] Donald L. Turcotte and Gerald Schubert. Geodynamics. Cambridge UniversityPress, 2nd edition, 2002.