1 Lecture 7: Pollutant Transfer in a Stream Introduction. Consider a river that has been polluted upstream. The concentration (amount per volume) will decay and disperse downstream. We would like to predict at any point in time and in space the concentration of the pollutant. The model of the concentration will also have the form newy = A oldy + b. Pollution in streams, lakes and underground aquifers has become a very serious common concern. It is important to be able to understand the consequences of possible pollution and to be able to make accurate predictions concerning "spills" and future "environmental" policy. Perhaps, the simplest model for chemical pollutant is based on chemical decay, and one model is similar to radioactive decay. A continuous model is ut = - d u where d is a chemical decay rate. A discrete version is uk+1 = uk + ∆t (-d) uk, and for stability this requires 1- ∆t d > 0. Here we will introduce a second model where the pollutant changes location because it is in a stream. We assume the concentration will depend on both space and time. The space variable will only be in one direction, which corresponds to the direction of flow in the stream. If the pollutant were in a deep lake, then space should have all three directions. Model. Discretize both space and time, and let the concentration equal to u(i∆x, k∆t) be approximated by uik where ∆t = T/maxk, ∆x = L/n and L is the length of the stream. The model will have the general form change in amount ≈ (amount entering from upstream) - (amount leaving to downstream) - (amount decaying in a time interval). This is depicted in the figure below where the time step has not been indicated entering volume = A vel ∆t A vel > 0 x - ∆x Figure: x Polluted Stream 2 Assume the stream is moving from left to right so that the velocity is positive, vel > 0. Let A be the cross sectional area of the stream. The amount entering the left side of the volume A ∆x (vel > 0) is A ∆t vel ui-1k. The amount leaving the right side of the volume A ∆x (vel > 0) is -A ∆t vel uik. Therefore, the change in the amount from the stream's velocity is A ∆t vel ui-1k - A ∆t vel uik. The amount pollutant in the volume A ∆x at time k∆t is A ∆x uik. The amount of the pollutant that has decayed, dec is decay rate, is -A ∆x ∆t dec uik. The change during the time interval in the amount of pollutant in the small volume A ∆x: A ∆x uik+1 - A ∆x uik = A ∆t vel ui-1k - A ∆t vel uik - A ∆x ∆t dec uik. Now, divide by A ∆x and explicitly solve for uik+1. Explicit Finite Difference Model of Flow and Decay of a Pollutant. uik+1 = vel (∆t/∆x) ui-1k + (1 - vel (∆t/∆x) - ∆t dec) uik where (1) i = 1,...,n-1, k = 0,...,maxk-1, ui0 = given for i = 1,...,n-1 and (2) k u0 = given for k = 1,...,maxk. (3) Equation (2) is the initial concentration, and (3) is the concentration far upstream. Equation (1) may be put into the matrix version of the first order finite difference method. For example, if the stream is divided into four equal parts, then n = 4 and (1) may be written as either three scalar equations, or one 3D vector equation: u1k+1 = vel (∆t/∆x) u0k + (1 - vel (∆t/∆x) - ∆t dec) u1k u2k+1 = vel (∆t/∆x) u1k + (1 - vel (∆t/∆x) - ∆t dec) u2k u3k+1 = vel (∆t/∆x) u2k + (1 - vel (∆t/∆x) - ∆t dec) u3k 3 uk+1 = A uk + b where d = vel (∆t / ∆x) and c = 1 − d − dec ∆t u1k +1 c k +1 u2 = d u3k +1 c d k k u1 du0 k u2 + 0 . c u3k 0 (4) An extremely important restriction on the time step ∆t is required to make sure the algorithm is stable. For example, consider the case n = 2 where the above is a scalar equation, and we have the simplest first order finite difference model. Here a = 1 - vel (∆t/∆x) - dec ∆t. If a = 1 - vel (∆t/∆x) - dec ∆t > 0 and vel, dec > 0, then this simple condition will imply that the matrix products Ak converge to the zero matrix. This will make sure there is no blowup, provided the source terms are bounded. Stability Condition for (1). 1 - vel (∆t/∆x) - dec ∆t and vel, dec > 0. In the case where dec = 0, then a = 1 - vel (∆t/∆x) > 0 means the entering fluid must must not travel more than one space step. This is often called the Courant condition on the time step. Method. In order to compute all uik+1, which we will henceforth denote by u(i,k+1), we must use a nested loop where the i loop (space) is inside and the k loop (time) is the outer loop. In this flow model u(i,k+1) depends directly on the two previously computed u(i-1,k) and u(i,k). This is different from the heat diffusion model which requires an additional value u(i+1,k) and a boundary condition to the right side. Implementation. We use a Matlab code for the explicit flow and decay model of a polluted stream. The first graph is the concentration versus time and space. Here the initial concentration was a trig function upstream and zero downstream. The farthest upstream location always had zero concentration. One expects the location of the maximum concentration to move downstream and to decay. 4 Matlab Code (flow1d.m) % Flow in a Stream clear; % Length of the Stream L = 1.0; % Duration of Time T = 20.; K = 200; dt = T/K; n = 10.; dx = L/n; vel = .1; decay = .1; % Initial Concentration for i = 1:n+1 x(i) =(i-1)*dx; u(i,1) =(i<=(n/2+1))*sin(pi*x(i)*2)+(i>(n/2+1))*0; end % Upstream Concentration for k=1:K+1 time(k) = (k-1)*dt; u(1,k) = -sin(pi*vel*0)+.2; end % Time Loop for k=1:K % Space Loop for i=2:n+1; u(i,k+1) =(1 - vel*dt/dx -decay*dt)*u(i,k) + vel*dt/dx*u(i-1,k); end end mesh(x,time,u') 5 Figure: Concentration as Function of (t,x) The second graph is a contour graph of the concentration in the time versus space plane. Here one can see time-space regions that have concentration of the pollutant between certain levels. contour(x,time,u') 20 18 16 14 12 10 8 6 4 2 0 0 0.1 Figure: 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Contours of Concentration 1 6 The following Matlab m-file will produces a frame by frame "movie" which does not require a great deal of memory. This code generates graphs of the concentration versus space for a sequence of times. In the pollution model it shows the pollutant moving down stream and decaying. Matlab Code (mov1d.m) flow1d; lim =[0 11 0 1]; for k=1:5:150 plot(u(:,k)) axis(lim); k = waitforbuttonpress; end Another way to view the output is collection of concentration versus time plot where one can observe the peak concentration moving downstream. plot(x,u(:,1),x,u(:,51),x,u(:,101),x,u(:,151)) 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 Figure: 0.2 0.4 0.6 0.8 1 Concentrations for Increasing Time 7 In the following calculation we let vel = 1.3, and this, with the same other constants, violates the stability condition. For the time step of 1/10 and the space step of 1/10, a flow rate equal to 1.3. means that the pollutant will travel 1.3/10 units in space which is more than one space step. flow Figure: Assessment. Unstable Computation with vel ∆t > ∆x The discrete model is accurate for suitably small step sizes. k+1 A ∆x ui - A ∆x uik = A ∆t vel ui-1k - A ∆t vel uik - A ∆x ∆t dec uik. Divide by A∆x ∆t (uik+1 - uik)/∆t = vel (ui-1k - uik)/ ∆x - dec uik. Approximate the first order partial derivatives ut(i∆x, k∆t + ∆t/2) = -vel ux(i∆x - ∆x/2, k∆t) - dec u(i∆x, k∆t). 8 The dispersion of the pollutant is a continuous process, which could be modeled by a partial differential equation and initial and boundary conditions: ut = -vel ux - dec u, u(x, 0) = given and u(0, t) = given. This is analogous to the discrete model in (1), (2) and (3). Like the heat models the step sizes should be carefully chosen. Often it is difficult to determine the exact values of the constants vel and dec. Exactly what is the effect of having measurement errors, say of 10%, on constants vel, dec or the initial and boundary conditions? What is interaction of the measurement errors with the numerical errors? The flow rate, vel, certainly is not always constant. Moreover, there may be fluid flow in more than one direction. Homework. 1. 2. 3. 4. Write a computer program and observe the consequences of not satisfying the stability condition. Experiment with the mesh size and observe convergence as the mesh size decreases. Vary the flow rate, vel, and the decay rate, dec. Explain your computed results. Consider the 3x3 A matrix in (4). Observe Ak for different values of vel so that the stability condition either does or does not hold.