Sie sind auf Seite 1von 13

Solving selected equations and systems of equations in hydraulics using Matlab

By Gilberto E. Urroz, August/September 2004

In this document, the solution to four classical problems in hydraulics is discussed,


namely:

1. Darcy-Weisbach equation combined with Swame-Jains friction factor formula to


solve problems in single pipelines.
2. Mannings equation for a trapezoidal channel.
3. Pipeline-and-pump system: simultaneous solution of the mechanical energy
equation and a centrifugal pump equation.
4. Entrance into a long open channel: simultaneous solution of the specific energy
and the Mannings equation.

The solutions are obtained by using Matlab functions.

Flow in pipes
The Darcy-Weisbach equation describes the flow in a pipeline:

L V2
hf = f .
D 2g

In this equation hf = head loss, f = friction factor, L = pipe length, D = pipe diameter, V=
water velocity, g = acceleration of gravity ( = 9.806 m/s2= 32.2 ft/s2). In terms of the
discharge, Q, since V = 4Q/(D2), the Darcy-Weisbach equation becomes:

8 f L Q2
hf = 2 .
g D2

The friction factor f is a function of the relative roughness of the pipe, e/D, where e =
absolute roughness, and of the Reynolds number, Re = VD/, where = kinematic
viscosity of the fluid. The Swamee-Jain equation provides an expression for the friction
factor, namely,
1.3254
f = 2
.
e 5.74
ln 3.75 D + Re 0.9

In terms of the flow discharge, the Swamee-Jain equation becomes:

1.3254
f = 2
e D
0.9

ln + 4.618

3.75 D Q

1
With this expression for the friction factor, the Darcy-Weisbach equation now is written
as
1.074 L Q 2
hf = 2
.
e 0.9
D
g D 5 ln + 4.618
3.75 D Q

The equation to solve using numerical methods is:

1.074 L Q 2
f ( ) = 2
h f ,.
e D
0.9


g D ln
5 + 4.618
3.75 D Q

where could be either L, D, e, , hf, or Q.

The following Matlab function, DWSJ (Darcy-Weisbach with Swamee-Jain), provides a


way to solve for any of the following unknowns in the combined Darcy-Weisbach /
Swamee-Jain equation: L, D, e, nu, hf, or Q, in both the International System (SI) or the
English System(ES) of units.

function [result] = DWSJ(index,gindex,L,D,e,nu,hf,Q)


% This function solves for one of the variables
% in the Darcy-Weisbach equation with the friction
% factor approximated through the Swamee-Jain
% equation. The string variable 'index' determines
% which variable to solve for. Possible values of
% index are:
% 'L' - to solve for the length of the pipe
% 'D' - to solve for the diameter
% 'e' - to solve for the absolute wall roughness
% 'nu' - to solve for the kinematic viscosity
% 'hf' - to solve for the friction losses
% 'Q' - to solve for the discharge
% The variable 'gindex' can take the values 'SI' or
% 'ES' corresponding to the system of units to be used:
% 'SI' - for the Systeme International
% 'ES' - for the English (or Imperial) System
% Make sure that the values of the variables are given
% in consistent units, i.e.,
% L(m or ft), D(m or ft), e(m or ft),
% nu(m^2/s or ft^2/s), hf(m or ft), Q(m^3/s or ft^3/s)
% The order of the variables does not change in the call
% to the function. The user needs to provide an initial
% guess for the variable he/she is solving for in the
% appropriate position in the function call.
% global Q; global g; global e; global D; global nu; global hf; global
L;
if gindex == 'SI'
g = 9.806;

2
elseif gindex == 'ES'
g = 32.2;
else
error('DWSJ - wrong index for unit system');
break;
end;
if index == 'L'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'LL');
result = fzero(DWSJEq,L);
elseif index == 'D'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'DD');
result = fzero(DWSJEq,D);
elseif index == 'e'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'ee');
result = fzero(DWSJEq,e);
elseif index == 'nu'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'nnu');
result = fzero(DWSJEq,nu);
elseif index == 'hf'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'hhf');
result = fzero(DWSJEq,hf);
elseif index == 'Q'
DWSJEq = inline(formEquation(index,g,L,D,e,nu,hf,Q),'QQ');
result = fzero(DWSJEq,Q);
else
error('DWSJ - index must be either L, D, e, nu, hf, or Q enclosed in
quotes');
break;
end;

This function calls function formEquation to produce the expression for the required
equation to solve:

function [s] = formEquation(index,g,L,D,e,nu,hf,Q)


% This function creates the expression for the equation
% to be solved for a specific solution of the Darcy-
% Weisbach/Swamee-Jain combined equation in a pipeline.
s = '1.074*L*Q^2/(g*D^5*(r(e/(3.75*D)+4.618*(D*nu/Q)^0.9))^2)-hf';
s = strrep(s,'g',num2str(g));

switch index
case 'L'
s = strrep(s,'L','LL');
s = strrep(s,'Q',num2str(Q));
s = strrep(s,'D',num2str(D));
s = strrep(s,'e',num2str(e));
s = strrep(s,'nu',num2str(nu));
s = strrep(s,'hf',num2str(hf));
case 'D'
s = strrep(s,'L',num2str(L));
s = strrep(s,'Q',num2str(Q));
s = strrep(s,'D','DD');
s = strrep(s,'e',num2str(e));
s = strrep(s,'nu',num2str(nu));
s = strrep(s,'hf',num2str(hf));

3
case 'e'
s = strrep(s,'L',num2str(L));
s = strrep(s,'Q',num2str(Q));
s = strrep(s,'D',num2str(D));
s = strrep(s,'e','ee');
s = strrep(s,'nu',num2str(nu));
s = strrep(s,'hf',num2str(hf));
case 'nu'
s = strrep(s,'L',num2str(L));
s = strrep(s,'Q',num2str(Q));
s = strrep(s,'D',num2str(D));
s = strrep(s,'e',num2str(e));
s = strrep(s,'nu','nnu');
s = strrep(s,'hf',num2str(hf));
case 'hf'
s = strrep(s,'L',num2str(L));
s = strrep(s,'Q',num2str(Q));
s = strrep(s,'D',num2str(D));
s = strrep(s,'e',num2str(e));
s = strrep(s,'nu',num2str(nu));
s = strrep(s,'hf','hhf');
case 'Q'
s = strrep(s,'L',num2str(L));
s = strrep(s,'Q','QQ');
s = strrep(s,'D',num2str(D));
s = strrep(s,'e',num2str(e));
s = strrep(s,'nu',num2str(nu));
s = strrep(s,'hf',num2str(hf));
end
s = strrep(s,'r','log');

Some solutions obtained by using the SI system of units are shown next:

DWSJ('L','SI',100,0.1,0.00001,1e-6,1,0.02)
Zero found in the interval: [9.4903, 164].
ans = 19.1617

EDU DWSJ('D','SI',100,0.1,0.00001,1e-6,1,0.02)
Zero found in the interval: [0.054745, 0.14525].
ans = 0.1402

EDU DWSJ('hf','SI',100,0.1,0.0000001,1e-6,1,0.02)
Zero found in the interval: [-4.12, 6.12].
ans = 4.9036

EDU DWSJ('Q','SI',100,0.1,0.0000001,1e-6,1,0.02)
Zero found in the interval: [0.0072, 0.029051].
ans = 0.0083

Please notice that the solution for the absolute roughness, e, and the kinematic viscosity,
nu, is very sensitive to the initial value given. This solution may quickly produce a
negative estimate, which in turn produces a complex number estimated, and which will
stop the search for a solution. See the following examples:

DWSJ('e','SI',20,0.1,0.00001,1e-6,1,0.02)
Zero found in the interval: [9.4903e-007, 1.64e-005].

4
ans =

2.9233e-006

EDU DWSJ('e','SI',25,0.1,0.00001,1e-6,1,0.02)
Zero found in the interval: [-2.6204e-005, 3.56e-005].

ans =

-1.8657e-005

EDU DWSJ('nu','SI',25,0.1,0.00001,1e-6,1,0.02)
Exiting fzero: aborting search for an interval containing a sign change
because complex function value encountered during search
(Function value at -2.8e-007 is -0.2253+0.16041i)
Check function or try again with a different starting value.

ans =

NaN

EDU DWSJ('nu','SI',20,0.1,0.00001,1e-6,1,0.02)
Zero found in the interval: [6.8e-007, 1.2263e-006].

ans =

7.3594e-007

Solution to the Mannings equation for open channel flow

Uniform open channel flow is commonly described by using the Mannings equation,
namely,
C
Q = u A R 2 / 3 S 01 / 2 ,
n

where Q = discharge (m3/s or cfs), Cu is a constant (=1.0 in the SI system of units, or =


1.486 in the ES system of units), n = Mannings resistance coefficient (dimensionless), A
= cross-sectional area (m2 or ft2), R = hydraulic radius of the cross-section (m or ft), S0 =
slope of the channel bed (dimensionless). The hydraulic radius is defined as R = A/P,
where P = wetted perimeter of the channel (m or ft). With this definition of the hydraulic
radius, the Mannings equation becomes

Cu A5 / 3 1 / 2
Q= S0 .
n P2/3

For the purpose of solving this equation through numerical methods, it is more
convenient to write it as:

n Q P 2 / 3 C u A 5 / 3 S 01 / 2 = 0 .

5
Expressions for the area, A, and the wetted perimeter, P, are given in terms of the
geometric properties of the cross-section. For example, for a trapezoidal channel of base
width (m or ft), b, depth of flow (m or ft), y, and side slope (dimensionless), z, as shown
in the figure below, the expressions for A and P are:
A = (b + z y ) y, P = b + 2 y 1 + z 2 .

T rapezoidal cross-section

z
1 Y

Thus, the equation to solve can be written as

f ( ) = n Q (b + 2 y 1 + z 2 ) 2 / 3 C u ((b + z y ) y ) 5 / 3 S 01 / 2 = 0 ,

where could be Q, b, y, z, So, or n.

Exercise

[1]. Using the example of the solution to the combined Darcy-Weisbach/Swamee-Jain


equation shown above, develop a function Manning(index,gindex,Q,b,y,z,So,n) to solve
Mannings equation for one of the following variables: Q, b, y, z, So, or n. Try your
solution with the following values:

units Q b y z So n
SI ? 0.65 0.250 1.0 0.00001 0.010
SI 0.20 ? 0.100 0.0 0.0001 0.012
SI 0.25 0.00 ? 1.5 0.001 0.015
SI 0.30 0.00 0.250 ? 0.00005 0.020
SI 0.35 0.00 0.250 1.0 ? 0.008
SI 0.50 0.00 0.100 0.0 0.0001 ?
ES ? 2.00 0.50 1.0 0.00001 0.010
ES 25 ? 0.75 0.0 0.0001 0.012
ES 50 2.50 ? 1.5 0.001 0.015
ES 75 1.50 1.00 ? 0.00005 0.020
ES 100 3.50 1.20 1.0 ? 0.008
ES 75 5.00 1.10 0.0 0.0001 ?

6
Solving a pipe-pump system

The figure below shows two reservoirs connected by a pipe of length L, diameter D, and
absolute roughness e. Water, of kinematic viscosity and specific weight , is pumped
from reservoir (1) to reservoir (2), by a pump P that provides a hydraulic head H for a
discharge Q through the pipe. The elevation of the free surface in reservoir (2) above of
that of reservoir (1) is H. Besides friction losses in the pipe, the analysis should include
minor losses at the intake, coefficient = K1, and outlet, coefficient = K2.

Applying the energy equation between free-surface points (1) and (2), namely,

p1 V12 p 2 V22
z1 + + + H = z2 + + + h f + hL ,
2g 2g

with V1 0, p1 = 0, z1=0, V2 0, p2 = 0, z2 = H, hf = f(e/D,Re)*(L/D)*(V2/2g), Re =


V*D/, and hL = (K)*(V2/2g), results in the so-called system equation:

V2 e V D
H = H + f , + K L .
2g D

By replacing V = 4Q/(D2), the system equation is presented in terms of the discharge Q


as:
8Q 2 e 4Q
H = H + 2 4 f , + K L . (A)
gD D D

For the friction coefficient f, we will choose the Swamee-Jain equation presented earlier.

The centrifugal pump has its own quadratic equation (the pump equation) that relates the
pump head, H, to the pipe discharge, Q, namely:

H = a + b Q + c Q2 . (B)

7
The solution to this problem requires to solve equations (A) and (B) simultaneously for Q
and H. This can be accomplished by using function secantm (a secant method for
multiple non-linear equations), which is listed next:

function [x] = secantm(x0,dx,f)

% Secant-type method applied to a


% system of linear equations f(x) = 0,
% given the jacobian function J, with
% The Jacobian built by columns.
% x = [x1;x2;...;xn], f = [f1;f2;...;fn]
% x0 is the initial guess of the solution
% dx is an increment in x1,x2,... variables

N = 100; % define max. number of iterations


epsilon = 1.0e-10; % define tolerance
maxval = 10000.0; % define value for divergence

if abs(dx)<epsilon
error('dx = 0, use different values');
break;
end;

xn = x0; % load initial guess

[n m] = size(x0);

while (N>0)
JJ = [1,2;2,3]; xx = zeros(n,1);
for j = 1:n % Estimating
xx = xn; % Jacobian by
xx(j) = xn(j) + dx; % finite
fxx = feval(f,xx);
fxn = feval(f,xn);
JJ(:,j) = (fxx-fxn)/dx; % differences
end; % by columns

if abs(det(JJ))<epsilon
error('newtonm - Jacobian is singular - try new x0,dx');
break;
end;

xnp1 = xn - inv(JJ)*fxn;
fnp1 = feval(f,xnp1);

if abs(fnp1)<epsilon
x=xnp1;
disp(['iterations: ', num2str(100-N)]);
return;
end;

if abs(fnp1)>maxval
disp(['iterations: ', num2str(100-N)]);
error('Solution diverges');
break;
end;

N = N - 1;
xn = xnp1;
end;
error('No convergence');
break;
% end function

8
This function requires an m-file function f which takes as argument a column vector of n
elements and returns a column vector function of n elements representing the system of
linear equations:
f1(x1,x2,,xn) = 0
f2(x1,x2,,xn) = 0

fn(x1,x2,,xn) = 0

Thus, if we define the argument vector as


x1
x
x = 2 ,
M

xn

Then, the vector function f(x) is given by

f 1 ( x)
f ( x)
f ( x) = 2 .
M

f n ( x)

For the solution of the pipe-pump system, we let x1 = Q and x2 = H, and the components
of the vector function are:

8 x12 e 4x
f1 ( x1 , x 2 ) = H + f , 1 + K L x 2 ,
2 gD 4 D D

f1 ( x1 , x 2 ) = a + b x1 + c x12 x 2 .

The following script file, PumpPipe_Script.m, illustrate a solution of this system of


equations in units of the English system. The values of the know parameters are listed in
the script:

% Script for solution of pump-pipeline system


% prepared by Gilberto E. Urroz, September 2004
echo on
% This solution consists of solving the system equation:
% f1(Q,H) = DH+(8*Q^2/(pi^2*g*D^2)*(f(e/D,4*Q/(pi*nu*D))+SKL)-H = 0
% simultaneously with the pump equation:
% f2(Q,H) = a+b*Q+c*Q^2-H = 0
% using function 'secantm.m'
DH = 40; g = 32.2; e = 0.00001; D = 0.25; nu = 1e-5; SKL = 1.5;
a = 100; b = 0.50; c = -0.30;
pause
% Graph of the data:
QQ = [0:0.1:12]; ff = 0.25./(log10(e/(3.75*D)+5.74./(4*QQ/(pi*nu*D)).^0.9)).^2;
HA = DH+(8*QQ.^2./(pi^2*g*D^2).*(ff+SKL));
HB = a+b.*QQ+c.*QQ.^2;

9
plot(QQ,HA,'r',QQ,HB,'b');xlabel('Q');ylabel('H');
legend('system','pump'); grid on;
pause

% Form expressions for the equations:


s1 = 'DH+(8*Q^2/(pi^2*g*D^2)*(f+SKL)-H';
f = '0.25/(r10(e/(3.75*D)+5.74/(4*Q/(pi*nu*D))^0.9)^2))';
s2 = 'a+b*Q+c*Q^2-H';
pause

% Replace values of constants in expressions:


s1 = strrep(s1,'f',f);
s1 = strrep(s1,'DH',num2str(DH));
s1 = strrep(s1,'D',num2str(D));
s1 = strrep(s1,'pi',num2str(pi));
s1 = strrep(s1,'g',num2str('32.2'));
s1 = strrep(s1,'e',num2str(e));
s1 = strrep(s1,'nu',num2str(nu));
s1 = strrep(s1,'SKL',num2str(SKL));
s1 = strrep(s1,'Q','x(1)');
s1 = strrep(s1,'H','x(2)');
s1 = strrep(s1,'r','log');
s2 = strrep(s2,'a',num2str(a));
s2 = strrep(s2,'b',num2str(b));
s2 = strrep(s2,'c',num2str(c));
s2 = strrep(s2,'Q','x(1)');
s2 = strrep(s2,'H','x(2)');
s1
s2
pause;

% Define functions fPP(x)


funit = fopen('fPP.m','w');
fprintf(funit,'function [fP] = fPP(x)\r');
fprintf(funit,'\nf1 = %s;\r',s1);
fprintf(funit,'\nf2 = %s;\r',s2);
fprintf(funit,'\nfP = [f1;f2];');
fclose(funit);
pause

% Solve pipe-pump system of equations


x0 = [20;20]; dx = 0.01;
x = secantm(x0,dx,'fPP');
Q = x(1)
H = x(2)
% Solve pipe-pump system of equations

The several lines that start with s1 and s2 are used to generate the expressions for f1(x1,x2)
and f2(x1,x2) for the specific known parameters listed in the script. The statements
involving fopen, fprintf, and fclose actually create an m-file, named fPP.m, that represents
the vector function f(x) = [f1(x1,x2); f2(x1,x2)]. Thus, the script PipePump_Script.m
actually creates the function to be solved. The solution is accomplished by the call to
function secantm.

The script also includes the production of a plot of the pump head, H, vs. discharge, Q,
for equations (A) and (B). The plot shows two curves, one corresponding to the system
equation and one to the pump equation. The point of intersection of the two curves
represents the solution to the problem. This point is referred to as the operating point of
the pump-pipe system.

10
Entrance from a reservoir into a long channel

The conditions of open channel flow at the entrance from a reservoir are determined by
the simultaneous solution of the energy equation and Mannings equation. The energy
equation, for an available head of Ho at the reservoir, is written as

Q2
H0 = y + , (C)
2 g[ A( y )]2

while the Mannings equation is written as

C u [ A( y )]5 / 3
Q= S0 , (D)
n [ P( y )]2 / 3

where Cu is a coefficient that depends on the system of units used, with Cu = 1.0 for the
Systeme Internationale (S.I.) and Cu = 1.486 for the English (or Imperial) System of units
(E.S.), n is the Mannings coefficient (typically, between 0.001 and 0.3), A(y) is the
cross-sectional area, P(y) is the wetted perimeter of the cross-section (i.e., the length of
the cross-sectional boundary in contact with the water), and Q is the discharge. For a
trapezoidal cross-section of bottom width b and side slope z, the area and wetted
perimeter are given by

A( y ) = (b + zy ) y, P( y ) = b + 2 y 1 + z 2 . (E)

Typically the values of n, g, Cu, S0, and the geometry of the cross-section (b,z) are known.
The simultaneous solution of these two equations produces as a result the values of the
water depth, y, and the flow discharge, Q.

A graphical solution may be obtained by plotting the two curves of y vs. Q corresponding
to equations (C) and (D), respectively, after replacing the cross-sectional equations (E).
The figure below shows the energy equation (C) and the Manning equation (D) curves,
for cases in which the flow develops into a subcritical or a supercritical flow.

11
Notice that the energy equation curve shows a maximum value of Q = Qmax at the critical
flow depth, y = yc, for the available energy head Ho. For a subcritical or critical flows,
the operating point is the intersection of the energy equation and Manning equation
curves, which occurs for y yc, as shown in the figure to the left. However, for a
supercritical flow (y < yc), critical conditions occur at the entrance to the channel forcing
the discharge to be Q = Qmax. For supercritical flow, therefore, the flow depth in the
channel is calculated from Mannings equation alone with Q = Qmax.

The Froude number of the flow is defined by

V 2 T ( y) Q 2 T ( y)
Fr 2 = = ,
g A( y ) g [ A( y )]3

where T(y) is the top width of the cross-section. For a trapezoidal channel, T(y) = b+2zy.
According to the value of the Froude number, the flow is either subcritical (Fr2<1),
critical (Fr2=1), or supercritical (Fr2>1).

The critical conditions can be obtained from the expression for the discharge, namely

Q = A( y ) 2 g ( H o y ) . (F)

For critical flow, dQ/dy = 0. With dA/dy = T(y), the resulting critical conditions equation
is:

A( y ) 2 ( H 0 y ) T ( y ) = 0

Thus, for the trapezoidal cross-section:

(b + zy c ) y c 2 ( H 0 y c ) (b + 2 zy c ) = 0 . (G)

Exercise

[2]. Prepare a Matlab script to perform the following tasks. Use one of the set of values
in the table shown at the end of this document:

1. Plot the energy equation curve and the Mannings equation curve for a trapezoidal
channel entrance from a lake. Use equations (F) and (D).
2. Determine the critical depth for the trapezoidal cross-section for constant Ho using
equation (G). Then, calculate the critical (maximum) discharge, Qmax, with
equation (F).

12
3. Use function secantm.m to obtain the simultaneous solution of the energy and
Mannings equations at the entrance from a reservoir into an open channel. Use
x1 = Q and x2 = y, with x = [x1;x2] , f = [f1(x); f2(x)], and

x12
f1 ( x1 , x 2 ) = x 2 + H0 ,
2 g ((b + zx 2 ) x 2 ) 2

C u ((b + z x 2 ) x 2 ) 5 / 3
f 2 ( x1 , x 2 ) = S 0 x1 .
n (b + 2 x 2 1 + z 2 ) 2 / 3

4. Determine the type of flow (subcritical, critical, and supercritical) by calculating


the Froude number. Report the type of flow and the value of the Froude number.
5. If the flow is subcritical or critical, report the values of Q and y found in 3, and
end the program execution.
6. If the flow is supercritical, solve Mannings equation with Q = Qmax, to determine
the value of the flow depth y. (Note: The solution of Mannings equation is the
subject of exercise [1] in page 6.) Report Qmax and y as the solutions, and end
program execution.

Suggested table of data values for testing your script:

System
of
Case units Ho b z n So
(a) S.I. 4.5 1.2 1.5 0.012 0.0001
(b) S.I. 3.5 0.8 0.5 0.023 0.00001
(c) S.I. 2.5 0.4 1 0.01 0.001
(d) E.S. 6 5 1 0.012 0.0001
(e) E.S. 3 3 0.5 0.018 0.00001
(f) E.S. 10 7.5 0.75 0.015 0.0001

13

Das könnte Ihnen auch gefallen