CASE STUDY PLINY’S INTERMITTENT FOUNTAIN CASE STUDY continued

23.5 CASE STUDY 609

23.5 CASE STUDY continued

Neglecting the volume of water in the pipe, compute and plot the level of the water in the tank as a function of time over 100 seconds. Assume an initial condition of an empty tank y = 0, and employ the following parameters for your computation: R T = 0.05 m r = 0.007 m y low = 0.025 m y high = 0.1 m C = 0.6 g = 9.81 ms 2 Q in = 50 × 10 −6 m 3 s Solution. When the fountain is running, the rate of change in the tank’s volume V m 3 is determined by a simple balance of inflow minus the outflow: d V dt = Q in − Q out 23.29 where V = volume m 3 . Because the tank is cylindrical, V = π R 2 t y. Substituting this re- lationship along with Eq. 23.28 into Eq. 23.29 gives d y dt = Q in − C √ 2gyπr 2 π R 2 t 23.30 When the fountain is not running, the second term in the numerator goes to zero. We can incorporate this mechanism in the model by introducing a new dimensionless variable siphon that equals zero when the fountain is off and equals one when it is flowing: d y dt = Q in − siphon × C √ 2gyπr 2 π R 2 t 23.31 In the present context, siphon can be thought of as a switch that turns the fountain off and on. Such two-state variables are called Boolean or logical variables, where zero is equiva- lent to false and one is equivalent to true. Q in Q out R T y = y high y = y low y = 0 r FIGURE 23.12 An intermittent fountain.

23.5 CASE STUDY continued

Next we must relate siphon to the dependent variable y. First, siphon is set to zero whenever the level falls below y low . Conversely, siphon is set to one whenever the level rises above y high . The following M-file function follows this logic in computing the derivative: function dy = Plinyodet,y global siphon Rt = 0.05; r = 0.007; yhi = 0.1; ylo = 0.025; C = 0.6; g = 9.81; Qin = 0.00005; if y1 = ylo siphon = 0; elseif y1 = yhi siphon = 1; end Qout = siphon C sqrt2 g y1 pi r 2; dy = Qin - Qout pi Rt 2; Notice that because its value must be maintained between function calls, siphon is de- clared as a global variable. Although the use of global variables is not encouraged partic- ularly in larger programs, it is useful in the present context. The following script employs the built-in ode45 function to integrate Plinyode and generate a plot of the solution: global siphon siphon = 0; tspan = [0 100]; y0 = 0; [tp,yp]=ode45Plinyode,tspan,y0; plottp,yp xlabeltime, s ylabelwater level in tank, m As shown in Fig. 23.13, the result is clearly incorrect. Except for the original filling period, the level seems to start emptying prior to reaching y high . Similarly, when it is drain- ing, the siphon shuts off well before the level drops to y low . At this point, suspecting that the problem demands more firepower than the trusty ode45 routine, you might be tempted to use one of the other MATLAB ODE solvers such as ode23s or ode23tb. But if you did, you would discover that although these routines yield somewhat different results, they would still generate incorrect solutions. The difficulty arises because the ODE is discontinuous at the point that the siphon switches on or off. For example, as the tank is filling, the derivative is dependent only on the constant inflow and for the present parameters has a constant value of 6.366 × 10 −3 ms. However, as soon as the level reaches y high , the outflow kicks in and the derivative abruptly drops to −1.013 × 10 −2 ms. Although the adaptive step-size routines used by MATLAB work marvelously for many problems, they often get heartburn when dealing with such discontinuities. Because they infer the behavior of the solution by comparing the results of different steps, a discontinuity represents something akin to stepping into a deep pothole on a dark street.

23.5 CASE STUDY continued