#Calculate the efficiency, mean effective pressure and work per machine cycle
#initialization of varaibles
print '%s' %("from chart")
T6=2600 #R
mratio=0.05
V6d=82 #cu ft
E6d=465 #Btu
H6d=655 #Btu
T6d=2480 #R
Hs=58 #Btu
LHV=19256
#calculations
H1=mratio*H6d + (1-mratio)*Hs
dV=22-3.67
PD=0.12
Work=446*PD/dV
pm=Work*778/(144.*PD)
eta=446./((1-mratio)*(LHV*0.0665))
#results
print '%s %.3f' %("Efficiency = ",eta)
print '%s %d %s' %("\n Mean effective pressure =",pm,"psi")
print '%s %.2f %s' %("\n Work per machine cycle =",Work,"Btu")
#Calculate the efficiency of the machine
#initialization of varaibles
f=0.03
T6=1500. #R
print '%s' %("from air tables,")
hi=131.46 #B/lb
h6=381 #B/lb
vratio=1/15.
v1r=120.7
P1=15. #psi
T1=580. #R
x=0.5
Tb=520. #R
H=18500 #B/lb
mh=0.0345
m3=1.065
#calculations
h1=f*h6+(1-f)*hi
v2r=v1r*vratio
T2=1615 #R
u2=289.05 #B/lb
P2=T2*1/vratio *P1/T1
theo=0.069 #lb/lb of air
m=theo*x
h3B=0.242*Tb
m3=1+0.03+0.0345
h3=(638+284)/1.065 +h3B
T3=3520 #R
P3=626 #psi
v3=53.34*T3/(P3*144)
v3p=v3*m3
v1=53.35*T1/(144*P1)
v2=14.7/P1
m1=1.03
h3=992.
h4=531.
T3=3520. #R
T4=2030. #R
W12=m1*(98.9-289.05)
W23=P2*(v3p-v2)*144/778.
W34=m3*(h3-h4-53.4*(T3-T4)/778.)
W=W12+W23+W34
eta=W/(mh*H)
#results
print '%s %.3f' %("Efficiency = ",eta)
#calculate the efficiency, Air rate and back work ratio of the process
#initialization of varaibles
print '%s' %("Using air tables,")
h1=124.27
pr1=1.2147
p2byp1=6.
p1=15.
p4=15.
eta=0.8
#calculations
pr2=p2byp1*pr1
h2s=197.5
h2=h1+(h2s-h1)/eta
h2B=124.3
dhB=-18500 #B/lb
dh2=h2B-h2
T3=1910 #R
h3=479.85
pr3=144.53
h3B=h2B
dh3=h3-h3B
wratio=(-dh3-dh2)/(dh3+dhB)
pr4=28.91
h4s=306.9
h4=h3-eta*(h3-h4s)
Wt=(1+wratio)*(h3-h4)
Wc=(h2-h2B)
Wnet=Wt-Wc
E=Wnet/(wratio*-dhB)
rate=2545./Wnet
BWratio=Wc/Wnet
#results
print '%s %.3f' %("Efficiency = ",E)
print '%s %.1f %s' %("\n Air rate =",rate,"lb air/hp hr")
print '%s %.2f' %("\n Back work ratio = ",BWratio)
#Calculate the specific impulse, thrust and efficiency of the process
#initialization of varaibles
import math
V1=587. #fps
etaD=0.9
etaC=0.8
h1=114.69
P1=10. #psia
P6=P1
P3=626 #psia
dhB=-19100. #B/lb
T1=480. #R
#calculations
h2s=etaD*V1*V1 /(778.*2*32.2) +h1
print '%s' %("From tables,")
Pr2s=1.104
Pr1=0.9182
P2=P1*Pr2s/Pr1
h2=h1+(h2s-h1)/etaD
T2=509. #R
Pr2=1.127
Pr3s=Pr2*P3/P2
Pr3s=6.76
h3s=203.2
h3=(h3s-h2)/etaC +h2
T3=930. #R
P3=6*P2
T4=2160. #R
h4=549.35
Pr4=238.
h4B=126.66
dh4=422.7
h3B=h4B
dh3=h3-h3B
cp=0.5
Ta=480. #R
Tb=530. #R
dhf=cp*(Tb-Ta)
wratio=(-dh4+dh3)/(dh4+dhf+dhB)
h5s=425.3
Pr5s=93.1
P5=27.6
T5=1801 #R
Pr5=114.28
Pr6s=Pr5*P6/P5
h5=450.
h6=351.
V6=math.sqrt(2*32.2*778*(h5-h6))
SI=((1+wratio)*V6 -V1)/(32.2)
v1=53.34*T1/(P1*144.)
wa=V1/v1
thrust = wa*SI
SC=wa*0.0174*3600/1840.
eff=2545/(SC*-dhB)
#results
print '%s %.1f %s' %("Specific impulse =",SI,"lb/lb per sec of air")
print '%s %d %s' %("\n Thrust =",thrust,"lb")
print '%s %.3f' %("\n Efficiency = ",eff)