Anda di halaman 1dari 5

440 Geophysics: Heat ow with nite differences

Thorsten Becker, University of Southern California, 03/2005

Some physical problems, such as heat ow, can be tricky or impossible to solve analytically in any but the simplest situations. This is why we use numerical methods to model system behavior. All numerical methods suffer from general limitations, such as nite accuracy (resolution) and stability (robustness against blowing up). This means that you will have to proceed carefully when using computers to get answers for geophysical problems, always being aware of the simplications and approximations. However, with (nowadays) basic computer tools, you can solve relevant problems. For example, you may estimate the temperature distribution around a dike intrusion as a function of time and space, and this distribution will be reected in the geological record. One method used to solve certain kinds of partial differential equations numerically is by nite differences (FD). Consider the heat ow equation in one dimension: 2 T H T = 2 + . t x c p (1)

where T is temperature, thermal diffusivity, H volumetric heat production rate, density, and c p heat capacity. T dependence on space, x, and time t is implied, but is assumed constant for eq. (1). Should the conductivity, k, be a function of x instead, we would have had to write 1 k(x) T c p x x
2

(2)

k instead of x2 T for the heat ow term, since = c p . In any numerical scheme, one has to discretize the spatial domain, and go from a continuous medium to individual points (or elements for the other main numerical scheme, nite elements). Lets subdivide the model region of extent 0 . . . L in x direction into n nodes so that the i-th location is xi = x0 + (i 1)x, (3)

with

x = L/(n 1),

(4)

which gives a range for x from xi=1 = 0 (for x0 = 0) to xi=n = L. A larger number of nodes n therefore gives you ner spatial resolution, x. What FD does then is approximate the /t and /x (as in eq. (1)) by nite differences between nodes, as opposed to innitesimal partial derivatives in a continuum. Say, you need f /x at xi , then you could approximate it from forward differences using the slope from the function value f (xi ) at xi to the next node at xi+1 = xi + x like f (xi+1 ) f (xi ) f f (xi ) x = . (5) x x This will be useful when you dont have a xi1 node, as on the left domain boundary. Alternatively, you could use

backward differences where

f (xi ) f (xi1 ) f (xi ) b = , (6) x x x for instance at the right domain boundary. However, it turns out that in general the best approximation to f /x error-wise is by
f

central differences. Those are obtained by averaging x and b such that x f x + b f (xi+1 ) f (xi1 ) x (xi ) c = = . x x 2 2x
f x f

(7)

If we need second-order derivatives, those can be obtained from the nite difference between and b as x f x b f (xi+1 ) 2 f (xi ) + f (xi1 ) 2 f x c (x ) x2 = = . (8) 2 i x x (x)2 (To be precise, the second order difference eq. (8) is properly derived by computing central differences of a forward difference at node xi+1/2 and a backward difference at node xi1/2 . This distinction can be important for k(x) type problems.) With those approximate nite differences at hand, we can now rewrite eq. (1). For simplicity, we will take constant and H = 0. The simplest way of rewriting the diffusion equation is by a Forward Time, Centered Space (FTCS) scheme t T (xi ,t j ) = c2 T (xi ,t j ) x T (xi ,t j+1 ) T (xi ,t j ) = T (xi+1 ,t j ) 2T (xi ,t j ) + T (xi1 ,t j ) . t (x)2
f

(9) (10)

Time therefore needs to be discretized as well, and we have used i indices for space, and j for time, i.e. the temperature at time t j+1 = t j + t is T (xi ,t j+1 ). We can march an initial solution at time t j forward by a time step t as T (xi ,t j+1 ) = T (xi ,t j ) + T = T (xi ,t j ) + t T (xi+1 ,t j ) 2T (xi ,t j ) + T (xi1 ,t j ) . (x)2 (11)

Because the incremental change of temperature from t j to t j+1 , T , can be directly determined from the old temperature solution at t j , this method is called explicit. While FTCS is a really bad idea for advection problems (the method blows up), it is an OK (not the most efcient) approach for our diffusion problem, under certain conditions. Those stability conditions will be explored in class (see appendix). The general solution strategy for any heat ow, nite difference problem is thus to dene an initial condition for T (x,t = 0), and boundary conditions (BCs) for the domain, i.e. at x = 0 and x = L. The latter are typically either constant temperature T = C (Dirichlet BC), or constant heat ow, T /x = C (Neumann BC). Then, discretize the spatial dimension, initialize the Ti, j variables, and march the solution forward in time according to eq. (11) with some adequately chosen t. The following is a Matlab computer program (a script, actually) written by my post-doc Boris Kaus which illustrates these concepts. We will go over this in detail in class, but the script is included here for completeness. A percent sign, %, is a comment, the rest are program instructions. 2

% % 1D Diffusion, explicit finite difference scheme % % Equation solved: % dT/dt = kappa*(d2 T/dx2) % % using Forward Time Centered Space (FTCS) % explicit method % % i.e. % % T(t_{i+1}) = T(t_i) + kappa * dt * (T(x_{j+1})-2*T(x_j)+T(x_{j-1})/dx2; % % Matlab script by Boris Kaus, March 2005 % clear all; % Input parameters L W_dike T_bg T_dike kappa dt = = = = = = 1000; 100; 1000; 1300; 1e-6; 1; % % % % % % length of model domain in m Width of intruding dike Background temperature [C] Temperature of intruding dike Thermal diffusivity [m2/s] Timestep in years

% Numerical parameters nx = num_time= year = dt = 101; % Number of gridpoints in x-direction 100; % Number of timesteps 3600*24*365.25; % Seconds/year dt*year;

% Initialization dx x T ind T(ind) = = = = = L/(nx-1); % Spacing in x-direction -L/2:dx:L/2; % Numerical grid in x-direction ones(1,nx)*T_bg; find(abs(x)<W_dike/2); % spatial region where dike is found T_dike; % Initial temperature

% Time loop for itime=1:num_time % save old temperature T_old = T; % Compute finite difference scheme ind = 2:nx-1; % index array T2nd = (T(ind+1)-2*T(ind)+T(ind-1))/dx2; % dT/dx2 T(ind) = kappa*dt*T2nd + T_old(ind); % Set BC (constant temperature) T(1) = T_old(1); T(nx) = T_old(nx); % Plotting figure(1), clf plot(x,T) xlabel(Distance [m]) ylabel(Temperature [o C]) title([Time = ,num2str(itime*dt/year), years]) drawnow pause(1/10) end The Matlab software allows you to write computer programs quickly, and plot the results easily. You can read more about the Matlab language at http://www.mathworks.com/access/helpdesk/ help/techdoc/matlab.html/. One nifty, yet sometimes perplexing, feature of Matlab is that it works with vectors. For instance, the lines dx x = = L/(nx-1); -L/2:dx:L/2; % Spacing in x-direction % Numerical grid in x-direction

tell the program to actually make an array x = {x1 , x2 , . . . , xn } with nx elements x1 = L/2, x2 = L/2+dx, x3 = L/2 + 2dx, . . . , xnx = L/2. More about that in class.

Addendum: stability of FTCS and more


As you noticed from the exercises in class, there exists a stability criterion for which the FTCS scheme works stably for the diffusion problem. The criterion says that you have to choose the time step t small enough for a given spatial resolution x and diffusivity so that t (x)2 2 (12)

holds. This condition can be derived by means of von Neumann stability analysis, and makes physical sense: t is of order of the characteristic diffusion time for numerical noise as determined by the grid spacing (note factor two). As you might have also noted, one needs to march the solution forward by a large number of time steps so that the essential processes of heat conduction can be captured if t is limited by the above criterion. This makes FTCS as an explicity method a bad idea if efciency is required. One would therefore rather use implicit schemes (such as Crank-Nicholson), but we dont have the time to discuss these in class. If you want to read more about solving the heat conduction (or any diffusion) equation, you might start with, e.g., Press et al. (1993), sec. 19.2. For advection problems, see sec. 19.1 in that same cookbook text. If you need more detail and explanations, a great resource is Spiegelman (2004). Marc teaches what has to be an awesome class (judging from his lecture notes) at Columbia University on numerical modeling. His chapter 6 (http://www.ldeo. columbia.edu/ mspieg/mmm/Diffusion.pdf) deals with diffusion problems.

References
Press, W. H., Teukolsky, S. A., Vetterling, W. T., and Flannery, B. P. (1993). Numerical Recipes in C: The Art of Scientic Computing. Cambridge University Press, Cambridge, 2 edition. Spiegelman, M. (2004). Myths and Methods in Modeling. Columbia University Course Lecture Notes, http://www.ldeo.columbia.edu/ mspieg/mmm/.

Anda mungkin juga menyukai