Parabolic Pdes - Explicit Method: Heat Flow and Diffusion
Parabolic Pdes - Explicit Method: Heat Flow and Diffusion
124
125
which is called the porus-media equation. This equation models diusion in a solid, but porus, material, such as sandstone or an earthen structure. We will not solve this equation numerically, but the methods introduced here would work. Many equations that involve 1 time derivative and 2 spatial derivatives are parabolic and the methods introduced in this lecture will work for most of them.
ck . (35.5) h2 The formula (35.4) allows us to calculate all the values of u at step j + 1 using the values at step j. Notice that ui,j+1 depends on ui,j , ui1,j and ui+1,j . That is u at grid point i depends on its previous value and the values of its two nearest neighbors at the previous step (see Figure 35.1).
Initial Condition
To solve the partial dierential equation (35.1) or (35.2) we need an initial condition. This represents the state of the system when we begin, i.e. the initial temperature distribution or initial concentration prole. This is represented by u(x, 0) = f (x). To implement this in a program we let ui,0 = f (xi ).
126
tj+1
ui,j+1
T
tj
xi1
xi
xi+1
Figure 35.1: The value at grid point i depends on its previous values and the previous values of its nearest neighbors.
Boundary Conditions
To solve the partial dierential equation (35.1) or (35.2) we also need boundary conditions. Just as in the previous section we will have to specify something about the ends of the domain, i.e. at x = 0 and x = L. One possibility is xed boundary conditions, which we can implement just as we did for the ODE boundary value problem. A second possibility is called variable boundary conditions. This is represented by timedependent functions, u(0, t) = g1 (t) and u(L, t) = g2 (t). In a heat problem, g1 and g2 would represent heating or cooling applied to the ends. These are easily implemented in a program by letting u0,j = g1 (tj ) and um,j = g2 (tj ). A third possibility is insulating boundary conditions, which we also did for the ODE boundary value problem. To implement this condition, we need to copy values from inside the region to ctional points just outside the region. See Figure 35.2 for an illustration.
127
z z z z j
tj+1
T s T s T s d d d d d d d d d z dz dz dj T s T s T s d d d d d d d d d z dz dz dj T s T s T s d d d d d d d d d z dz dz dj
tj
xm1
xm
xm+1
Figure 35.2: Illustration of information ow for the explicit method with an insulated boundary condition. The open circles are the ctional points and the curved arrows represent copying the value.
Implementation
The following program (also available on the web page) implements the explicit method. It incorporates variable boundary conditions at both ends. To run it you must dene functions f , g1 and g2 . Notice that the main loop has only one line. The values of u are kept as a matrix. It is often convenient to dene a matrix of the right dimension containing all zeros, and then ll in the calculated values as the program runs. Run this program using L = 2, T = 20, f (x) = .5x, g1 (t) = 0, and g2 (t) = cos(t). Note that g1 (t) must be input as g1 = inline(0*t).
128
function [t x u] = myheat(f,g1,g2,L,T,m,n,c) % function [t x u] = myheat(f,g1,g2,L,T,m,n,c) % solve u_t = c u_xx for 0<=x<=L, 0<=t<=T % BC: u(0, t) = g1(t); u(L,t) = g2(t) % IC: u(x, 0) = f(x) % Inputs: % f -- inline function for IC % g1,g2 -- inline functions for BC % L -- length of rod % T -- length of time interval % m -- number of subintervals for x % n -- number of subintervals for t % c -- rate constant in equation % Outputs: % t -- vector of time points % x -- vector of x points % u -- matrix of the solution, u(i,j)~=u(x(i),t(j)) h r x t = = = = L/m; k = T/n; c*k/h^2; rr = 1 - 2*r; linspace(0,L,m+1); linspace(0,T,n+1);
%Set up the matrix for u: u = zeros(m+1,n+1); % assign initial conditions u(:,1) = f(x); % assign boundary conditions u(1,:) = g1(t); u(m+1,:) = g2(t); % find solution at remaining time steps for j = 1:n u(2:m,j+1) = r*u(1:m-1,j) + rr*u(2:m,j) + r*u(3:m+1,j); end % plot the results mesh(x,t,u)
Exercises
35.1 Modify the program myheat.m to have an insulated boundary at x = L (rather than u(L, t) = g2 (t)). Run the program with L = 2, T = 20, c = .5, g1 (t) = sin(t) and f (x) = sin(x/4). Set m = 20 and experiment with n. Get a plot when the program is stable and one when it isnt. Turn in your program and plots.