Lab Project 4a MATLAB Model of Oscillatory Flow Goals Prepare analytical and computational solutions for transient flow between the two upright arms of a U-shaped tube Compare the theoretical solutions to experimental data Background: Oscillating systems are commonly described by second order differential equations of the form Ax" + Bx' + Cx = q(t) where x is a state variable such as position, volume, or electrical charge, and q(t) is a forcing function. For a mass-and-spring system, A is the mass, B is a damping coefficient, C is the spring constant, and x is the position of the mass. The equation is typically written as a balance of forces, so every term should have units of force. Liquid oscillations between the two upright tubes in our flow system can be described by this equation IF we assume that flow is laminar, making the pressure drop a linear function of flow rate. If x is a liquid volume, then x' is the flow rate and x" is the acceleration (rate of change of flow). To generate our differential equation, we write a dynamic force balance on the water in the tube. The driving force due to the different heights in the two water columns is Cx, Bx' is the drag force due to viscosity in the tube, and Ax" is the net force that accelerates the fluid. The driving force q(t) is the part of the driving pressure that is not due to the difference in column heights, and is a constant (based on the equilibrium height) for our experiments with transient oscillations. In fluid mechanics it is often convenient to make every term have units of pressure, and the forces can be converted to pressure by dividing x and q(t) by the cross-sectional area of the tube. When flow is turbulent, the pressure drop through a smooth pipe is approximately a function of velocity to the 1.8 power, and the equation becomes non-linear: Ax" + D(x') 1.8 + Cx = q(t). This derivation is not particularly difficult, IF you are familiar with the diagram that relates the Reynolds number to the friction factor for turbulent flow through a tube. Because you might not be familiar with it, it will be derived in lab for any interested students so you may include it with your homework. On the other hand, it is extremely difficult to solve the equation analytically. Instead, we will calculate the time course of the oscillations using a finite difference algorithm in MATLAB. Data collection and MATLAB computation in the turbulent-flow case are just as easy as they are when flow is laminar. print date: 11/11/11 1
Previous cohorts of bioengineers have done an experiment to measure the transient behavior of water sloshing back and forth in a U-shaped tube. The basic procedure from 2010 is this: A long tube was mounted as a vertical U, as shown in figure 1. It was filled with enough water so the level, at equilibrium, is about halfway between the curve and the top of the tube. Food coloring and a ruler/meter stick were used to enable video data collection. Using a syringe, water was lifted into one arm of the U, and the water was released and allowed to come to equilibrium. The event was captured on video, and the water height h(t) was extracted from the video. The experiment was repeated for multiple sizes of tubing. Examples of the video and data sets will be provided for you. You do not need to analyze the video yourself; you may use the tabulated data. Procedure Part 1 a) Plot the water heights for one experimental trial from each of the tubing sizes. Do not include the plots here. Instead, categorize each response as over-, under-, or critically damped. b) Estimate the maximum Reynolds number for each of the trials that you plotted. c) Categorize each trial as mostly laminar or mostly turbulent flow. Part 2 Assume that water is contained in a U-shaped tube as shown in Fig. 1. When both ends are open to atmosphere, the water level is the same at some equilibrium height on both sides of the U. A syringe was attached to the left end of the U and was used to draw water up to some level h 1 (0). The water was then released and allowed to come to equilibrium. a) Assuming that flow is laminar, derive a differential equation that describes the transient solution, h(t), for the height of water in one side of the tube after it is released from the initial height h 1 (0). You should get a linear differential equation. b) Find an analytical solution to the linear differential equation in terms of system dimensions and liquid density. c) Starting with the MATLAB code provided for you, create a computational solution to the linear differential equation. Include the relevant lines of code in your MATLAB appendix. d) For each of the trials that you categorized as laminar in part 1, plot the experimental result, analytical solution and computational solution on the same axes. print date: 11/11/11 2
h 1 (0) h 1 (t) h 2 (t) Equilibrium height h eq R BEND h 1 (0) is chosen such that the water level never drops below this point. Tube of diameter D Figure 1 U-tube arrangement for flow oscillation experiments. The tube is filled up to the dashed line, before it is pulled up to h 1 (0) on the left side, and released. Part 3 a) Assuming that flow is turbulent, derive a nonlinear differential equation that describes the transient solution, h(t), for the height of water in one side of the tube after it is released from the initial height h 1 (0). Note: One of the steps should be to derive a formula that relates the Fanning friction factor to the velocity of the water in the tube. The steps are shown in the BIOEN 325 course notes, but I expect you will not get exactly the same answer as shown in the notes because you should draw your own tangent line on the Moody diagram. However, your answer might be the same after you round to one decimal place. b) Start with the MATLAB code provided for you. For each of the trials that you categorized as turbulent in part 1, plot the experimental result and computational solution on the same axes. If you did not find any to be turbulent, just compare the one with the highest Reynolds number. Part 4 a) Using the analytical solution from part 2, find the initial height necessary to make the Reynolds number reach 10,000 in the 1 U-tube. Note that this is a linear differential equation, so the starting height is proportional to the maximum Re. print date: 11/11/11 3
b) Starting with the MATLAB code provided for you, create and plot the following curves. Assume the starting height h 1 (0) is the one you found in the previous step. o A computational solution to the linear differential equation (assumes laminar flow). o A computational solution to the nonlinear differential equation; Reporting The main challenge in this assignment is to create and solve initial value problems (differential equation plus initial conditions). The experimental results are what they are, and you do not need to match the experimental and simulated data exactly. You should, however, see the same trends over the range of tubing sizes. Discussion: Discuss why some flow arrangements reach equilibrium without oscillating, while others respond with a decaying sinusoid. Some responses look like a combination of monotonically decaying exponential followed by oscillations. Use the equations you derived for laminar and turbulent flow to explain these cases where flow oscillates but does not match a simple decaying sinusoid. Sources of Error: Discuss approximations or simplifications made in the flow-resistance calculations and the initial value problems. State, with justification, how much effect you expect each simplification to have (large or small -- no quantitative error analysis is necessary). Lengthy calculations and new MATLAB code may be stowed in an appendix. You do not need to include MATLAB code if you did not modify it. print date: 11/11/11 4
Supplement Creating a numerical solution for a second-order initial value problem Consider the following initial value problem, which is composed of a linear second-order differential equation and initial conditions for position and velocity. Ax" + Bx' + Cx = q(t) x(0) = <initial height>, x'(0)=0. The ODE solvers in MATLAB operate on first-order differential equations, so we first want to reduce our second-order ODE to a system of first-order differential equations. First, we introduce the vector y: x y = x Next, we rewrite the second-order equation above as a system of first-order equations. d x 0 1 x 0 = + dt x C/ A B/ A x q( t)/ A We then create a MATLAB function that calculates the increments in x and x' (i.e., in y) for single time steps. function dy = secondode(t,y) % function to be integrated A=?; B=?; C=?; % Enter values for A, B, C dy = zeros(2,1); dy(1) = y(2); dy(2) = -C/A*y(1)- B/A*y(2) + <Enter q(t) here>/a; Let us suppose that our initial value is 20 cm, 1 our initial velocity is zero, and we want to find the solution from 0 to 9 seconds. These values would be set as follows: y0 = [1; 0]; tspan = [0 9]; Now we can solve the system using ode45(). [t, y] = ode45(@secondode, tspan, y0); The variable t will be a column vector of time values; the output y will be an array in which the first column is x(t) and the second column is x'(t). 1 The units that you use are not going to change your answer when the differential equation is linear, but they can make a big difference if the equation is non-linear. print date: 11/11/11 1
If the flow is turbulent, then pressure drop is no longer a linear function of flow rate. In this case the differential equation becomes non-linear in the x' term. Ax" + B(x') β + Cx = q(t) Typically β is some value between 1 and 2, and can be approximated from the Moody friction factor chart and Darcy's pressure drop equation. The MATLAB solution is the same as before except that the y(2) term in the last line includes the exponent β. function dy = secondodenonlin(t,y) % function to be integrated A=?; B=?; C=?; g=? % Enter values for A, B, C dy = zeros(2,1); dy(1) = y(2); dy(2) = -C/A*y(1)- B/A*(y(2))^beta + q/a; This code will return an error when y(2) is negative. Two more changes are needed to complete the y(2) term the first change gets rid of the MATLAB error but introduces a model error (ie the result is wrong). Can you find the new problem and fix it? print date: 11/11/11 2