print "Example 10.1"
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
#calculate and draw graph the gas generator pumping charcteristics as a fucntion of Nc2/Nc2,d
import numpy
import matplotlib
from matplotlib import pyplot
cmap=numpy.matrix([[14.1,6.50,20.0,0.82],[13.5,5.88,18.1,0.84],[13,5.32,16.4,0.83],[12.5,4.81,14.8,0.83],[12,4.36,13.4,0.83],[11.5,4,12.2,0.84]])
import warnings
warnings.filterwarnings('ignore')
print cmap,"Compressor map data in table:"
Cpc=1004.
Cpt=1156.
f=0.03 #fuel-to-air ratio
em=0.995 #efficiency
T=6. #T=Tt4/Tt2
pb=0.95 #burner pressure ratio
gmt=1.33 #gamma turbine
gmc=1.4
i=5
b=1
g1=numpy.zeros(6)
gc1=0;
g2=numpy.zeros(6)
gc2=0
g3=numpy.zeros(6)
gc3=0
g4=numpy.zeros(6)
gc4=0
z0=numpy.linspace(0.82,0.97,6)
for b in range (1,7):
Nc2=cmap[i,0]
pc=cmap[i,1]
mc2=cmap[i,2]
ec=cmap[i,3]
i=i-1;
tc=1+(1/ec)*(pc**((gmc-1)/gmc)-1)
ffp=T-tc
tt=1-(Cpc/Cpt)*((tc-1)/(em*(1+f)*(T)))
Nc4=Nc2/T**(1/2.)
mc4=mc2*((1+f)*(T)**(1./2.))/(pb*pc)
pt=(1-(1-tt)/ec)**(gmt/(gmt-1)) #Assuming et=ec i.e. same efficiency
var=T-tc #fuel flow parameter in gas generator
p52=pb*pc*pt
T52=T-(Cpc/Cpt)*(tc-1)/(em*(1+f))
g1[gc1]=p52
gc1=gc1+1
g3[gc3]=T52
gc3=gc3+1
g4[gc4]=var
gc4=gc4+1
pyplot.plot(z0,g1)
pyplot.xlabel("% Nc2 Design")
pyplot.ylabel("Ratios")
pyplot.title("GAS GENERATOR PUMPING CHARACTERISTCS")
pyplot.plot(z0,g3)
pyplot.plot(z0,g4)
pyplot.legend("pt5/pt2","Tt5/Tt2","Fuel flow prameter in gas generator")
#calcualte pressure combustor and compressor pressure ratio and mass flow rate
import math
import numpy
from numpy import roots
M0=0.
p0=0.1 ##in MPa
T0=15.+273.
pd=0.98
pc=25.
ec=0.9
Qr=42800000. ##in J/kg
pb=0.98
eb=0.99
Tt4=1500.+273.
et=0.85
em=0.995
mc2=73.
Nc2=6000. ##in rpm
Mz2=0.6
pn=0.97
p=1. ##p=p9/p0
##in this engine is operating in the following off-design conditions
Mo0=0.8
po0=33.
To0=-15.+273.
Tt4o=1375.+273.
pdo=0.995
po=1.
gm=1.4
td=T0/Tt4
tcd=pc**((gm-1.)/(ec*gm))
tod=(To0*(1+(gm-1.)*Mo0**2./2.)/Tt4o)
tcod=1.+(td/tod)*(tcd-1.)
pcod=(tcod)**((ec*gm)/(gm-1.))
print"%s %.4f %s"%("(a)pressure ratio in combustor,O-D :",pcod,"")
mratio=(pcod/pc)*(tod/td)**(1/2.)
mc2od=mc2*mratio
print"%s %.4f %s"%("(b)mc2,O-D (in kg/s) :",mc2od,"")
Nc2r=(td/tod)**(1/2.)
Nc2od=Nc2r*Nc2
print"%s %.4f %s"%("(c)Nc2,O-D (in rpm):",Nc2od,"")
pref=101.33 ##in kPa
pto0=po0*(1.+(gm-1.)/2.*Mo0**2.)**(gm/(gm-1.))
pto2=pdo*pto0
Tref=288.2
Tto2=To0*(1.+(gm-1.)/2.*Mo0**2.)
the2=Tto2/Tref
del2=pto2/pref
m2=mc2od*del2/(the2)**(1/2.)
pol=([0.6*((1.+(gm-1.)/2.)/(1.+(gm-1.)/2.*0.6**2.))**3.,-(73./64.5)])
rr=numpy.roots(pol)
rr=0.4974
print"%s %.4f %s"% ("(d)Mz2,O-D",rr,"")
#calculate the engine off design performance characteristices that correspond to the supersonic flight condition of aircraft at high attitude
print("Example 10.3")
M0=0.
po=101.33 ##in kPa
T0=288.2
gmc=1.4
Cpc=1004.
pd=0.95
pc=20.
ec=0.9
mc2=33.
Nc2=7120.
Mz2=0.6
Qr=428000000.
pb=0.98
eb=0.97
Tt4=1850.
gmt=1.33
Cpt=1156.
et=0.8
em=0.995
QrAB=4280000.
pAB=0.95
eAB=0.98
Tt7=2450.
pAB=1.3
CpcAB=1243.
pn=0.93
p=1. ##p=p9/p0
Mo0=2.
po0=20.
To0=223.
gm0=1.4
Cpc0=1004.
pdo=0.8
ec0=0.9
Qr=42800000.
pb0=0.98
ebo=0.97
Tt4o=1850.
gmto=1.33
cpto=1156.
eto=0.8
emo=0.995
QrABo=42800000.
pABo=0.95
eab=0.98
Tt7o=2450.
gmABo=1.3
Cpco=1243.
pno=0.93
po=1.
a0=276.4
Tt2=T0
tc=pc**((gmc-1.)/(ec*gmc))
Tt3=tc*Tt2
f=(Cpt*Tt4-Cpc*Tt3)/(Qr*eb-Cpt*Tt4)
tt=1.-(1./((1.+f)*em))*(Cpc*Tt2/(Cpt*Tt4))*(tc-1.)
print"%s %.4f %s"%("Turbine expansion parameter at on and off design :",tt,"")
##Off-design analysis:
Tt2o=To0*(1+(gmc-1.)/2.*(Mo0**2.))
tcOD=1+(1.036)*0.995*(1156.*1850./(1004.*401.4))*(1.-0.7915)
pcOD=tcOD**((gmc)*ec/((gmc-1.)))
print"%s %.4f %s"%("New compressor pressure ratio :",pcOD,"")
mc2D=pcOD/pc*((Tt4o/Tt2)/(Tt4o/Tt2o))**(1/2.)
mc2OD=mc2*mc2D
print"%s %.4f %s"%("Off-line mc2 rate in ",mc2OD,"Kg/s :")
Nc2r=((Tt4o/Tt2o)/(Tt4/Tt2))**(1/2.)
Nc2OD=Nc2r*Nc2
print"%s %.4f %s"%("Off-design Nc2,O-D in",Nc2OD, "rpm:")
pref=101.33 ##in kPa
pt0=po0*(1.+(gmc-1.)/2.*Mo0**2.)**((gmc)/(gmc-1.))
pt2=pdo*pt0
del2=pt2/pref
Tref=288.2
the2=Tt2o/Tref
m2=mc2OD*del2/(the2)**(1/2.)
print"%s %.4f %s"%("Off-design mass flow in",m2, "kg/s")
Tt3=859.2
Tt4=1850.
fOD=0.03305
tcr=(1.+fOD)/(1.+f)
pt5=413.7## kPa
pt7=393.04
fAB=0.0367
pt9=365.52
M9=2.524
T9=1253.
V9=1725.
ndst=(1.+f+fAB)*V9/a0-M9
print"%s %.4f %s"%("Nondimensional specific thrust :",ndst,"")
TSFC=55.94 ##in mg/s/N
print"%s %.4f %s"%("Thrust specific fuel consumption(TSFC) in",TSFC," mg/s/N :")