print "Example 8.1"
import numpy
%matplotlib inline
import matplotlib
from matplotlib import pyplot
z0=numpy.linspace(0.2,0.6,80)
g1=numpy.zeros(80)
gc1=0.
gm=1.4
i=0;
M1=z0
for i in range (0,80):
y=1./((1+((gm-1)/2.)*M1[i]**2)**(1./2))
g1[gc1]=y
gc1=gc1+1
pyplot.plot(z0,g1)
pyplot.xlabel("Inlet Mach no M1")
pyplot.ylabel("Ratio of index to the impeller tip tangential Mach no.")
pyplot.title("Ratio of Mach index to impeller tip Mach no.")
import math
#calculate static pressure ratio across the rotor and diffuser and estimate diffuser staic presure rise
print("Example 8.3")
M1=1.2 ##Mach no at impeller tip
gm=1.4 ##gamma
p31=(1+(gm-1)*M1**2)**(gm/(gm-1)) ##p=p3/p1
p32=p31**(1/2.) ##p31=p3/p2
Cp=(2/(gm*M1**2.))*(2.2-1) ##static pressure rise in radial diffuser
print"%s %.3f %s"%("(a)The static pressure the rotor and diffuser p3/p1 :",p31,"")
print"%s %.4f %s"%("The static pressure ratio across the diffuser p3/p2",p32,"")
print"%s %.3f %s"%("Diffuser static pressure rise :",Cp,"")
print "Example 8.4"
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
#calculate and graph the inducer D-factor for solidity of one and over a range of impeller tip mach number and radius ratios
import numpy
import matplotlib
from matplotlib import pyplot
M=2;
i=1;
sigma=1
z0=numpy.linspace(0.1,0.5,5)
gm=1.4;
for M in range(2,4):
g1=numpy.zeros(5)
gc1=0;
for r in z0:
y=1-(1/(1+(r**2)*(M**2)))+((M*r)/(2*sigma*(1+(r**2)*(M**2))**(1/2.)))
g1[gc1]=y
gc1=gc1+1;
number=0;
pyplot.plot(z0,g1)
i=i+1;
pyplot.xlabel("Eye-to-lip radius ratio (r1/r2)")
pyplot.ylabel("D inducer")
pyplot.title("Inducer performance and centrifugal compressor design parameters (solidity=1)")
pyplot.legend("Mt/Mz1=2","Mt/Mz1=3","Mt/Mz1=4")
import math
print("Example 8.6")
#calculate the compressor total to static efficency
Tt1=288.
Cp=1004.
gm=1.4
ett=0.8
p=6.8 ##pt3/pt1
C1=200.
pt1=101.
Tt3=Tt1*(1.+(1./ett)*(p**((gm-1.)/gm)-1.))
Tt2s=Tt1*p**((gm-1.)/gm)
T1=Tt1-C1**2./(2.*Cp)
ets=(Tt2s-T1)/(Tt3-T1)
print"%s %.4f %s"%("Compressor total-to-static efficiency :",ets,"")