# Toy Turbojet

Was reading this post From Apprentice to Guru….,

Annoy your cubicle mates every time they present you with a Python class. Claim it could be “better” implemented as a dictionary plus some functions. Embrace functional programming.

The 9th point made me wonder and decided to write something using dictionary. As an aeronautical engineer, the first thing that came to mind was the thermal cyclic analysis of turbojet engine.

So here’s the toy turbojet program. Change some parameter and see how it changes the thrust and the specific fuel consumption, implemented using two simple dictionaries.

```
prgcon={"llp":10,"llt":4,"cp":1005,"r":287,"g":9.81,"tlr":6.5,
"cfuel":45868.0,"prc":2.0,"tet":800,"pa":1.1013,"ta":291.15,
"masc":0.1289,"effc":0.95,"effcom":0.99,"plcom":0.05,
"bleed":0.01,"efmech":0.98,"effct":0.84,"effn":0.95,"powreq":1.0
}

def toyturbojet(prgcon):
result={"temps":[],"prs":[],"thrust":0.0,"spthrust":0.0,"sfc":0.0}
prc=prgcon["prc"]
t03=prgcon["tet"]
gam=(prgcon["cp"]/prgcon["r"])/(prgcon["cp"]/prgcon["r"]-1)
gamx=prgcon["cp"]/prgcon["r"]
gamy=(gam-1.0)/2.0

macfl=0.0
r1=1.0
pa=prgcon["pa"]
ta=prgcon["ta"]

p01=pa*r1*((1.0+gamy*macfl**2)**gamx)
t01=ta*(1.0+gamy*macfl**2)
den1=(p01*10000.0*prgcon["g"])/(prgcon["r"]*t01)

#print p01,t01,den1
trais=prc**(1.0/gamx)
tdrpis=t01*(trais-1.0)
tdrp=tdrpis/prgcon["effc"]
powerc=prgcon["masc"]*prgcon["cp"]*tdrp/1000.0
p02=p01*prc
t02=t01+tdrp

mascom=prgcon["masc"]-prgcon["bleed"]*prgcon["masc"]
tracom=t03-t02

fara1=1.0
if(tracom > 000  and tracom < 400):
fara1=0.99 *((t03-t02-10)*(1.+t02/3250.))/(prgcon["cfuel"]*prgcon["effcom"])
elif(tracom > 400 and tracom < 9000):
fara1=1.10*((t03-t02-50.)*(1.+t02/3250.))/(prgcon["cfuel"]*prgcon["effcom"])

masfuel=fara1*mascom
p03=p02*(1.0-prgcon["plcom"])

powert=powerc/prgcon["efmech"]
masct=mascom+masfuel
cp34=950.0+0.21*t03
tdrpct=powert/(masct*cp34/1000.0)
gamxc=cp34/prgcon["r"]
tdctis=tdrpct/prgcon["effct"]
t04is=t03-tdctis
pract=(t03/t04is)**gamxc
p04=p03/pract
t04=t03-tdrpct

#print p01,p02,p03,p04,t01,t02,t03,t04

rthst=prgcon["powreq"]
p05i=p04
t05=t04
cp45=950.0+0.21*t04
gamxp=cp45/prgcon["r"]
gamn=gamxp/(gamxp-1.0)
popan=p05i/pa
if p05i < 1.1*pa:
result["temps"]=([t01,t02,t03,t04,t05])
result["prs"]=([p01,p02,p03,p04,0.0])
result["thrust"]=0.0
result["sfc"]=0.0
result["spthrust"]=0.0
return result
emach=math.sqrt(2*(popan**(1/gamxp)-1)/(gamn-1))
t5i=t05/(1+0.5*(gamn-1)*emach*emach)
t5=t05-prgcon["effn"]*(t05-t5i)
vjet=math.sqrt(2*cp45*(t05-t5))
p05=pa*((t05/t5)**(gamn/(gamn-1)))
massj=masct+prgcon["bleed"]+prgcon["masc"]
thst=massj*vjet/prgcon["g"]
ssp=thst/prgcon["masc"]
sfc=masfuel/thst*3600.

result["temps"]=([t01,t02,t03,t04,t05])
result["prs"]=([p01,p02,p03,p04,p05])
result["thrust"]=thst
result["sfc"]=sfc
result["spthrust"]=ssp

return result

```

view the entire code from github

or view the entire notebook by clicking this link