#calculate the velocity and area
#Initialization of variables
import math
import numpy
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.
b=len(p)
V2=numpy.zeros(b)
A=numpy.zeros(b)
for i in range (1,b):
V2[i]=round(Fc*math.sqrt(2*J*g*(h1-h[i])),2)
A[i]=round(m*v[i] /V2[i],5)
V2 = 0+ V2
A =0+ A
#results
print '%s' %('velocity (ft/s)= ')
print(V2)
print '%s' %('Area (ft^2)= ')
print(A)
#The initial values of velocity and area are 0 and infinity respectively
#calculate the Area required in both cases
#Initialization of variables
import math
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*math.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*math.sqrt(cp*T1*(1-(p2/p1)**((k-1)/k)))
v2=v1*(p1/p2)**(1/k)
A2=m*v2/V2rev
#results
print '%s %.5f %s' %("Area required =",At," ft^2")
print '%s %.5f %s' %("\n Area in case 2 =",A2," ft^2")
#calculate the Throat area
#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 '%s %.4f %s' %("Throat area in case 2 =",A2d," ft^2")
#calculate the mass flow rate
#Initialization of variables
import math
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*math.sqrt(h1-h2)
m=math.pi/4 *1/144. *V2rev/v2
#results
print '%s %.3f %s' %("mass flow rate =",m," lbm/sec")
#calculate the Mass flow rate and Meta stable under cooling
#Initialization of variables
import math
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*math.sqrt(k/(k-1) *p1*v1*(1- (pr)**((k-1)/k)))
v2=v1*(1/pr)**(1/k)
m=math.pi/4 *1/144 *V2rev/v2
C=m/m1
T2=T1*(0.887)
t=250+460. #R
dt=t-T2
#results
print '%s %.3f %s' %("Mass flow rate =",m," lbm/sec")
print '%s %d %s' %("\n Meta stable under cooling =",dt,"F")
#calculate the average velocity and mass flow rate
#Initialization of variables
import math
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=math.sqrt(2*g*H)
m=math.pi/4 *d**2 *V*p1
#results
print '%s %.1f %s' %("average velocity =",V," ft/sec")
print '%s %.1f %s' %("\n mass flow rate =",m," lbm/sec")
#calculate the area of throat and area of exit
#Initialization of variables
import math
p0=50. #psia
T0=520. #R
rho0=0.259 #lbm/ft^3
p2=10. #psia
mf=1. #lbm
#calculations
print '%s' %("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*math.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 '%s %.5f %s' %("Area of throat =",As,"ft^2")
print '%s %.5f %s' %("\n Area of exit =",A2,"ft^2")
#calculate the Length of the pipe
#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 '%s %.1f %s' %("Length of pipe =",dl,"ft")
#calculate the change in entropy
#Initialization of variables
import math
py=20. #psia
px=3.55 #psia
R=1.986/29
#calculations
pr=py/px
print '%s' %("from table B-19")
Mx=2
My=0.577
pr2=0.721
ds=R*math.log(1./pr2)
#results
print '%s %.4f %s' %("Change in entropy =",ds,"Btu/lbm R")
#calculate the Internal and net thrust
#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 '%s %d %s' %("Internal thrust =",thru,"lbf")
print '%s %d %s' %("\n Net thrust =",net," lbf")
print '%s' %("The answers are a bit different due to rounding off error in textbook")