from numpy import nditer
from math import sqrt
#Initialization of variables
h1=1329.1 #Btu/lbm
v1=6.218 #ft**3/lbm
J=778
g=32.174
m=1
#calculations
p=[80, 60 ,54.6, 40, 20]
h=[ 1304.1, 1273.8, 1265 ,1234.2, 1174.8]
v=[ 7.384, 9.208, 9.844 ,12.554, 21.279]
Fc=1
V2=[Fc*sqrt(2*J*g*(h1-hh)) for hh in h]
A=[m*v1/V21 for v1,V21 in nditer([v,V2])]
V2=[0]+V2
A=[0]+A
#results
print 'velocity in ft/s are:'
for vv in V2:
print '%.6f'%vv,'\t',
print '\n\nArea in ft**2 are:'
for aa in A:
print '%.6f'%aa,'\t',
print '\n\nThe initial values of velocity and area are 0 and infinity respectively. Since, Infinity in calculations stops the code to display an error. It has been mentioned separately.'
from math import sqrt
#Initialization of variables
n=1.4
p1=50 #psia
J=778
cp=0.24
T1=520 #R
k=n
R=1545/29
m=1
p2=10 #psia
#calculations
rpt=(2/(n+1))**(n/(n-1))
pt=p1*rpt
Vtrev=223.77*sqrt(cp*T1*(1- rpt**((k-1)/k)))
v1=R*T1/p1/144
vt=v1*(p1/pt)**(1/k)
At=m*vt/Vtrev
V2rev=223.77*sqrt(cp*T1*(1-(p2/p1)**((k-1)/k)))
v2=v1*(p1/p2)**(1/k)
A2=m*v2/V2rev
#results
print "Area required = %.5f ft**2"%(At)
print "\n Area in case 2 at the exit= %.5f ft**2"%(A2)
#Initialization of variables
J=778
g=32.2
pc=54.6 #psia
h1=1329.1 #Btu/lbm
h2=1265 #btu/lbm
V2rev=1790 #ft/s
cv=0.99
m=1 #lbm
cv2=0.96
#calculations
V2d=cv*V2rev
hd=cv**2 *(h1-h2)
h2d=h1-hd
v2d=9.946
A2d=m*v2d/V2d
#results
print "Throat area= %.4f ft**2"%(A2d)
from math import pi,sqrt
#Initialization of variables
zm=0.216
pm=62.3 #lbm/ft**2
p1=0.0736 #lbm/ft**2
g=32.2
d=4
#calculations
H=zm*(pm-p1)/12/p1
V=sqrt(2*g*H)
m=pi/4 *d**2 *V*p1
#results
print "average velocity = %.1f ft/sec"%(V)
print "\n mass flow rate = %.1f lbm/sec"%(m)
from math import sqrt
#Initialization of variables
p0=50 #psia
T0=520 #R
rho0=0.259 #lbm/ft**3
p2=10 #psia
mf=1 #lbm
#calculations
print "From table B-17,"
pr=0.528
Tr=0.833
rhor=0.634
ps=pr*p0
Ts=Tr*T0
rhos=rho0*rhor
Vs=49.1*sqrt(Ts)
As=mf/(Vs*rhos)
p2r=p2/p0
M2=1.71
V2=1.487*Vs
T2=0.632*Ts
A2=As*1.35
rho2=rhos*0.317
#results
print "Area of throat = %.5f ft**2"%(As)
print "\n Area of exit = %.5f ft**2"%(A2)
#Initialization of variables
M1=0.2
M2=0.4
D=0.5 #ft
f=0.015
#calculations
f1=14.5
f2=2.31
dl=(f1-f2)*D/f
#results
print "Length of pipe = %.1f ft"%(dl)
from math import log
#Initialization of variables
py=20 #psia
px=3.55 #psia
R=1.986/29
#calculations
pr=py/px
print "from table B-19"
Mx=2
My=0.577
pr2=0.721
ds=R*log(1/pr2)
#results
print "Change in entropy = %.4f Btu/lbm R"%(ds)
from math import pi,sqrt
#Initialization of variables
pi=50 #psia
pe=34.6 #psia
#calculations
print "From table B-18 and B-17,"
pr1=1.35
p0f=pi/pr1
pfs=0.528*p0f
per=pe/pfs
Me=0.6
p0e=1.19
pyx=p0e/pr1
Mx=1.64
My=0.658
px=0.22*pi
py=32.9 #psia
p2yx=0.852
pe2=1.65*pfs
#results
print "Mach numbers before and after are %.2f and %.3f respectively"%(Mx,My)
print "\n Pressure before and after are %.1f psia and %.1f psia"%(px,py)
print "\n Exhaust pressure = %.1f psia"%(pe2)
#Initialization of variables
T1=550 #R
T2=2660 #R
ts1=0.207
ts2=0.833
cp=0.24
#calculations
Ts=T1/ts1
Ts0=T2/ts2
print "From table B-20"
tr1=0.529
tr2=0.174
dq=cp*Ts0*(tr1-tr2)
#results
print "Heat required = %d Btu/lbm"%(dq)
#Initialization of variables
M1=0.5
M2=1
A1=0.5 #ft**2
A2=1 #ft**2
p1=14.7 #psia
p2=14.7 #psia
k=1.4
#calculations
thru=p2*144*A2*(1+k*M2**2)-p1*144*A1*(1+k*M1**2)
net=thru-p1*144*(A2-A1)
#results
print "Internal thrust = %d lbf"%(thru)
print "\n Net thrust = %d lbf"%(net)
print "The answers are a bit different due to rounding off error in textbook"
from math import pi,sqrt
#Initialization of variables
p1=50 #psia
pr=0.58
#calculations
p=p1*pr
s1=1.6585
h1=1174.1 #Btu/lbm
sf=0.3680
sfg=1.3313
hfg=945.3
vg=13.746
hf=218.82
x= (s1-sf)/sfg
v2=vg*x
h2=hf+x*hfg
V2rev=223.77*sqrt(h1-h2)
m=pi/4 *1/144 *V2rev/v2
#results
print "mass flow rate = %.3f lbm/sec"%(m)
from math import pi,sqrt
#Initialization of variables
k=1.31
p1=7200 #lbf/ft**2
v1=8.515 #ft**3/lbm
pr=0.6
m1=0.574
T1=741 #R
#calculations
V2rev=8.02*sqrt(k/(k-1) *p1*v1*(1- (pr)**((k-1)/k)))
v2=v1*(1/pr)**(1/k)
m=pi/4 *1/144 *V2rev/v2
C=m/m1
T2=T1*(0.887)
t=250+460 #R
dt=t-T2
#results
print "Mass flow rate = %.3f lbm/sec"%(m)
print "\n Meta stable under cooling = %d F"%(dt)
from math import pi,sqrt
#Initialization of variables
C=0.98
m=1
v=12.55 #ft**3/lbm
V=1372 #ft/s
#calculations
A=m*v/(C*V) *144
D=sqrt(A*4/pi)
#results
print "Area = %.3f in**2"%(A)
print "\n diameter = %.2f in"%(D)
from math import pi,sqrt
#Initialization of variables
nn=0.95
p1=50 #psia
p2=30 #psia
v1=8.515
m=1 #lbm
#calculations
cv=sqrt(nn)
V2rev=1372
V2act=cv*V2rev
n=1.283
v2=v1*(p1/p2)**(1/n)
A=m*v2/V2act *144
D=sqrt(A*4/pi)
#results
print "Area = %.2f in**2"%(A)
print "\n diameter = %.3f in"%(D)
#Initialization of variables
dFf=110.5 #ft-lbf/lbm
Vd=1028 #ft/s
gc=32.2 #ft/s**2
p0=100 #psia
k=1.4
v0=2.08
p1=55 #psia
p2=99.2 #psia
#calculations
dFe=0.01*Vd**2 /(2*gc)
dF=dFf+dFe
V2ig=(p0*144)**(1/k) *v0/(1-1/k) *((p1*144)**(1-1/k) -(p2*144)**(1-1/k))
C2=(V2ig+dF)/V2ig
C=sqrt(C2)
#results
print "Coefficient of discharge = %.3f "%(C)
from __future__ import division
from math import pi,sqrt
#Initialization of variables
dL=1/6 #ft
mf=0.430 #lbm/sec
rho=62.4
gc=32.2 #ft/s**2
d=0.81/12 #ft
#calculations
V=mf*4/(rho*pi)
VD=V/dL**2
Vd=1.92 #ft/s
dFf=0.031/(2*gc) *2.31
dFe=0.04*Vd**2 /(2*gc)
dF=dFf+dFe
dp=rho*(3.5/(2*gc) +dF)
vd22=(2*gc)/rho *dp /(1-(d/dL)**4)
vd2=sqrt(vd22)
C=Vd/vd2
#results
print "Pressure drop in the nozzle = %.2f lbf/ft**2"%(dp)
print "\n Coefficient of discharge = %.3f "%(C)
#Initialization of variables
K=0.6003
Y1=0.91
D1=6.065
D2=1.820
rho1=0.156
p1=30
p2=20.18
#calculations
bet=D2/D1
m=0.525*K*Y1 *D2**2 *sqrt(rho1*(p1-p2))
C=K*sqrt(1-bet**4)
#results
print "mass flow rate = %.3f lbm/sec"%(m)
print "\n Coefficient of discharge = %.3f"%(C)