Pipe Flow (Matlab)

advertisement
1 -‫זרימה‬
)‫(עבודת בית‬
:‫להלן הנתונים עבור תוכנית המחשב לחישובי זרימה בצינור‬
input data:
p1
p2
v1
v2
z1
z2
ha
hr
hm
d
l
vis
e
sw
q
- gauge pressure at point 1 in kilopascals:
0.0
- gauge pressure at point 2 in kilopascals:
0.0
- velocity  0 if essentially zero, otherwise 1.0:
0.0
- velocity  0 if essentially zero, otherwise 1.0:
1.0
- elevation at point 1 in meters:
80.0
- elevation at point 2 in meters:
60.; 50.; 40.; 30.; 20.;
- energy added between points 1 and 2 in kilowatts: 0.; 50.; 100.;
- energy removed between points 1 and 2 in kilowatts:
0.
- minor losses between points 1 and 2 in meters:
0.;
- diameter of a pipe in millimeters:
from 300. – to 400. (delta=20 mm)
- length of a pipe in meters:
1000
- kinematic viscosity in m^2/s:
0.406e-6
- pipe material roughness in meters; zero for smooth: 0.0005
- specific weight of a fluid in kilonewtons/m^3:
7.05
- flow rate in m^3/s:
0. (unknown!)
.‫( בתחום הנתון‬d) ‫( עבור כל קוטר‬q) ‫( חשב את הספיקה‬z1-z2) ‫ עבור כל‬, ha ‫עבור כל‬
. q  q(d) ‫את התוצאות יש להציג באמצעות גראפים‬
.'‫ שבוע ימים לאחר המבחן מועד א‬:‫מועד האחרון להגשת העבודה‬
Shalom,
The attached is the Matlab program cpipe.m.
Input
0.0
0.0
0.0
1.0
39.0
0.0
67.0
0.0
0.0
300.
90.0
1.0e-6
0.000045
9.8
0.0
p1
- gauge pressure at point 1 in kilopascals
p2
- gauge pressure at point 2 in kilopascals
v1
- velocity - 0 if essentially zero, otherwise 1.0
v2
- velocity - 0 if essentially zero, otherwise 1.0
z1
- elevation at point 1 in meters
z2
- elevation at point 2 in meters
ha
- energy added between points 1 and 2 in kilowats
hr
- energy removed between points 1 and 2 in kilowats
hm
- minor losses between points 1 and 2 in meters
d
- diameter of conduit in millimeters
l
- length of conduit in meters
vis - kinematic viscosity in m^2/s
e
- conduit material roughness in meters; zero for smooth
sw
- specific weight of fluid in kilonewtons per m^3
q
- flow rate in m^3/s, =0 if unknown
%The program:
%
program cpipe, should be named cpipe.m
%
%
this program computes the flow rate or the required conduit
%
diameter. the international system of units is used.
%
the application of the program is limited to cases involving
%
a single pipe with constant diameter.
%
%
this program is based on solution of the bernoulli equation.
%
accordingly, certain data must be entered for each of two points
%
in a pipe system. however, both the velocity at point 1 and the
%
velocity at point 2 are not considered as known values initially.
%
%
%
%
%
if either value of velocity is essentially zero (such as at a
reservoir or tank surface) - enter 0 (zero) for that velocity or
for both velocities if both are essentially zero, otherwise - enter
1.0 for all other velocities.
pi = 4.*atan(1.0);
factor = 1000; % factor to convert mm into m
%-------------------------------------------------------------------------%
%
Input Data
p1=0; % gauge pressure at point 1 in kilopascals
p2=0; % gauge pressure at point 2 in kilopascals
v1=0; % velocity = if essentially zero, otherwise 1.0
v2=1; % velocity = if essentially zero, otherwise 1.0
z1=39; % elevation at point 1 in meters
z2=0; % elevation at point 2 in meters
ha=67; % energy added between points 1 and 2 in kilowats
hr=0; % energy removed between points 1 and 2 in kilowats
hm=0; % minor losses between points 1 and 2 in meters
d=300; % diameter of conduit in millimeters
l=90; % length of conduit in meters
vis=1e-6;
% kinematic viscosity in m^2/s
e=0.000045; % conduit material roughness in meters; zero for smooth
sw=9.8;
% specific weight of fluid in kilonewtons per m^3
q=0;
% flow rate in m^3/s, =0 if unknown
%-------------------------------------------------------------------------g = 9.807;
p1sw = p1/sw;
p2sw = p2/sw;
% friction coefficient initial guess
ff = 0.02;
%
%
for i=1,11 %do 333
d = 200 + (i-1)*50;
% d is known, find q
if v1>0.0001
v1 = 1/2/g;
end
if v2>0.0001
v2 = 1./2./g;
end
for j=1:10000
hf = ff*l/d*factor/2/g; %105
hat = ha/sw;
hrt = hr/sw;
% flow rate q first guess
q = 0.001;
vtry = (q/(pi*(d/factor)^2/4))^2;
try1 = p1sw+vtry*v1+z1+hat/q-hrt/q-(p2sw+vtry*v2+z2+hf*vtry);
for n=1:10000
q = q + 0.001;
vtry = (q/(pi*(d/factor)^2/4))^2;
try2 = p1sw+vtry*v1+z1+hat/q-hrt/q-(p2sw+vtry*v2+z2+hf*vtry);
if try1*try2>0
try1 = try2;
else
q = q - 0.0005;
break
end
end
v = q/(pi*(d/factor)^2/4);
rn = d/factor*v/vis;
ed = e/d*factor;
% compute friction coefficient
f=rough(ed,rn); % call rough
diff = abs(f-ff);
if diff<0.0001 % goto 104
break
else
ff = f;
continue %goto 105
end
end
if v1>=0.0001 % 104
v1 = v;
end
if v2>=0.0001
v2 = v;
end
% writing input and output on screen
fprintf('
\n')
fprintf('
sample analysis for a closed conduit carrying fluid \n')
fprintf('--------------------------------------------------------\n')
fprintf('
\n')
fprintf('
input data: \n')
fprintf('
\n')
fprintf('
pressure at point 1 = %4f kPa \n',p1)
fprintf('
pressure at point 2 = %4f kPa \n',p2)
fprintf('
elevation at point 1 = %4f m \n',z1)
fprintf('
elevation at point 2 = %4f m \n',z2)
fprintf('
actual energy added between points 1 and 2 = %4f m \n',hat)
fprintf('
actual energy removed between points 1 and 2 = %4f m \n',hrt)
fprintf('
minor losses between points 1 and 2 = %4f m \n',hm)
fprintf('
length of conduit = %4f m \n',l)
fprintf('
conduit material roughness = %4f mm \n',e*factor)
fprintf('
fluid viscosity = %4f m^2/s \n',vis)
fprintf('
\n')
fprintf('
computed data: \n')
fprintf('
\n')
fprintf('
flow rate will be %4f m^3/s \n',q)
fprintf('
velocity at point 1 = %4f m/s \n',v1)
fprintf('
velocity at point 2 = %4f m/s \n',v2)
fprintf('--------------------------------------------------------\n')
% writing output in a file: out.txt
fid = fopen('out.txt','w');
fprintf(fid,'computed data: ');
fprintf(fid,'%1f\n flow rate will be %4f m^3/s ;\n',q);
fprintf(fid,'%1f\n velocity at point 1 = %4f m/s ;\n',v1);
fprintf(fid,'1f\n velocity at point 2 = %4f m/s ;\n',v2);
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function rough, should be saved separately as rough.m
%
function f=rough(ed,rn)
if rn<2000
f = 64/rn;
return
end
% friction coefficient quess
f = 0.006;
try1 = 1/sqrt(f)+2*log10(ed/3.7+2.51/rn/sqrt(f));
for i=1:10000
f = f + 0.00001;
try2 = 1./sqrt(f)+2.*log10(ed/3.7+2.51/rn/sqrt(f));
if try1*try2>0
try1 = try2;
else
f = f - 0.000005;
return
end
end
======================================================================
output:
sample analysis for a closed conduit carrying fluid
--------------------------------------------------input data:
pressure at point 1 =
0.0 kpa
pressure at point 2 =
0.0 kpa
elevation at point 1 =
39.0 m
elevation at point 2 =
0.0 m
actual energy added between points 1 and 2
= 67.0m
actual energy removed between points 1 and 2 = 0.0m
minor losses between points 1 and 2 = 0.0 m
diameter of conduit = 300.0 mm
length of conduit =
90.0 m
conduit material roughness = 0.045 mm
fluid viscosity = 0.000001000 m^2/s
computed data:
flow rate will be 0.951 m^3/s
velocity at point 1 = 0.00 m/s
velocity at point 2 = 13.46 m/s
===================================================================
Download