



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Finite difference methods are perhaps best understood with an example. Consider the one-dimensional, transient (i.e. time-dependent) heat conduction equation without heat generating sources
ρ cp
∂ t
∂ x
k
∂ x
where ρ is density, cp heat capacity, k thermal conductivity, T temperature, x distance, and t time. If the thermal conductivity, density and heat capacity are constant over the model domain, the equation can be simplified to
∂ T ∂ t
= κ
∂ x^2
where
κ =
k ρ cp
is the thermal diffusivity (a common value for rocks is κ = 10 −^6 m^2 s−^1 ; also see discussion in sec. ?? ). We are interested in the temperature evolution versus time, T(x, t), which satisfies eq. (2), given an initial temperature distribution (Fig. 1A). An example would be the in- trusion of a basaltic dike in cooler country rocks. How long does it take to cool the dike to a certain temperature? What is the maximum temperature that the country rock expe- riences? The first step in the finite differences method is to construct a grid with points on which we are interested in solving the equation (this is called discretization, see Fig. 1B). The next step is to replace the continuous derivatives of eq. (2) with their finite difference
approximations. The derivative of temperature versus time ∂ ∂ Tt can be approximated with a forward finite difference approximation as
∂ t
T in +^1 − Tin tn+^1 − tn^
T in +^1 − Tin ∆ t
Tinew − Ticurrent ∆ t
Here, n represents the temperature at the current time step whereas n + 1 represents the new (future) temperature. The subscript i refers to the location (Fig. 1B). Both n and i are integers; n varies from 1 to nt (total number of time steps) and i varies from 1 to nx (total number of grid points in x-direction). The spatial derivative of eq. (2) is replaced by a central finite difference approximation (cf. sec. ?? ), i.e.
∂ x^2
∂ x
∂ x
Tin+ 1 −Tin ∆ x −^
Tin −Tni− 1 ∆ x ∆ x
Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2
country rockcountry rock dike
x
T(x,0)
space
time
L
boundary nodes
Dx
Dt
i,n
i,n-
i,n+
i-1,n i+1,n
L
Figure 1: A) Setup of the thermal cooling model considered here. A hot basaltic dike intrudes cooler country rocks. Only variations in x-direction are considered; properties in the other di- rections are assumed to be constant. The initial temperature distribution T(x, 0) has a step-like perturbation, centered around the origin with [−W/2; W/2] B) Finite difference discretization of the 1D heat equation. The finite difference method approximates the temperature at given grid points, with spacing ∆ x. The time-evolution is also computed at given times with time step ∆ t.
Substituting eqs. (5) and (4) into eq. (2) gives
T in +^1 − Tin ∆ t
= κ
Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2
The third and last step is a rearrangement of the discretized equation, so that all known quantities (i.e. temperature at time n) are on the right hand side and the unknown quan- tities on the left-hand side (properties at n + 1). This results in:
T in +^1 = Tin + κ∆ t
Tin+ 1 − 2 Tin + Tin− 1 ( ∆ x)^2
Because the temperature at the current time step (n) is known, we can use eq. (7) to com- pute the new temperature without solving any additional equations. Such a scheme is and explicit finite difference method and was made possible by the choice to evaluate the temporal derivative with forward differences. We know that this numerical scheme will converge to the exact solution for small ∆ x and ∆ t because it has been shown to be con- sistent – that its discretization process can be reversed, through a Taylor series expansion, to recover the governing partial differential equation – and because it is stable for certain values of ∆ t and ∆ x: any spontaneous perturbations in the solution (such as round-off error) will either be bounded or will decay.
%heat1Dexplicit.m % % Solves the 1D heat equation with an explicit finite difference scheme clear %Physical parameters L = 100; % Length of modeled domain [m] Tmagma = 1200; % Temperature of magma [C] Trock = 300; % Temperature of country rock [C] kappa = 1e-6; % Thermal diffusivity of rock [m2/s] W = 5; % Width of dike [m] day = 360024; % # seconds per day dt = 1day; % Timestep [s] % Numerical parametersnx = 201; % Number of gridpoints in x-direction nt = 500; % Number of timesteps to compute dx = L/(nx-1); % Spacing of grid x = -L/2:dx:L/2;% Grid % Setup initial temperature profile T = ones(size(x))*Trock; T(find(abs(x)<=W/2)) = Tmagma; time = 0; for n=1:nt % Timestep loop % Compute new temperature Tnew = zeros(1,nx); for i=2:nx- Tnew(i) = T(i) + ?????; end % Set boundary conditions Tnew(1) = T(1); Tnew(nx) = T(nx); % Update temperature and time T = Tnew; time = time+dt; % Plot solution figure(1), clf plot(x,Tnew); xlabel(’x [m]’) ylabel(’Temperature [^oC]’) title([’Temperature evolution after ’,num2str(time/day),’ days’]) drawnow end
Figure 2: MATLAB script heat1Dexplicit.m to solve eq. (2) (once the blanks indicated by the questions marks are filled in... ).
uneven spacing between grid points should you so desire). Test the solution for the case of k = 10 inside the dike, and k = 3 in the country rock.