import math
#calculate the
##given data
dt = 1.0;##tip diameter in m
dh = 0.9;##hub diameter in m
alpha1 = 30.;##in deg
beta1 = 60.;##in deg
alpha2 = 60.;##in deg
beta2 = 30.;##in deg
N = 6000.;##rotational speed in rev/min
rhog = 1.5;##gas density in kg/m^3
Rt = 0.5;##degree of reaction at the tip
##Calculations
omega = 2.*math.pi*N/60.;
Ut = omega*0.5*dt;
Uh = omega*0.5*dh;
cx = Ut/(math.tan(alpha1*math.pi/180.) + math.tan(beta1*math.pi/180.));
mdot = math.pi*((0.5*dt)**2 - (0.5*dh)**2)*rhog*cx;
Wcdot = mdot*Ut*cx*(math.tan(alpha2*math.pi/180.)- math.tan(alpha1*math.pi/180.));
ctheta1t = cx*math.tan(alpha1*math.pi/180.);
ctheta1h = ctheta1t*(dt/dh);
ctheta2t = cx*math.tan(alpha2*math.pi/180.);
ctheta2h = ctheta2t*(dt/dh);
alpha1_ = (180./math.pi)*math.atan(ctheta1h/cx);
beta1_ = (180./math.pi)*math.atan((Uh/cx) - math.tan(alpha1_*math.pi/180.));
alpha2_ = (180./math.pi)*math.atan(ctheta2h/cx);
beta2_ = (180./math.pi)*math.atan((Uh/cx) - math.tan(alpha2_*math.pi/180.));
k = Rt*(0.5*dt)**2;
Rh = 1 - (k/(0.5*dh)**2);
##Results
print'%s %.2f %s'%('(i)The axial velocity, cx = ',cx,' m/s');
print'%s %.2f %s'%('\n (ii)The mass flow rate =',mdot,' kg/s');
print'%s %.2f %s'%('\n (iii)The power absorbed by the stage = ',Wcdot/10**6,' MW');
print'%s %.2f %s %.2f %s %.2f %s %.2f %s'%('\n (iv)The flow angles at the hub are:\n alpha1 = ',alpha1_,' deg'and '\n beta1 =',beta1_,'deg'and '\n alpha2 = ',alpha2_,'deg' and'\n beta2 = ',beta2_, 'deg.')
print'%s %.2f %s'%('\n (v)The reaction ratio of the stage at the hub, R =.',Rh,'');
##there are small errors in the answers given in textbook
import math
#calculate the
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
from math import log
import numpy
##given data
R = 0.5;##degree of reaction
Cp = 1005.;##kJ/(kgC)
cx1_Ut_rt = 0.4;
delT0 = 16.1;##temperature rise
Ut = 300.;##in m/s
##calculations
A1 = cx1_Ut_rt**2 +(0.5-0.18*math.log(1));
c1 = 2*(1.-R);
c2 = Cp*delT0/(2.*Ut**2 *(1.-R));
A2 = 0.56;
k = numpy.linspace(0.4,1.0,num=61);
i=len(k)
cx1_Ut=numpy.zeros(i)
cx2_Ut=numpy.zeros(i)
R_=numpy.zeros(i)
Rn=numpy.zeros(i)
import numpy
import matplotlib
from matplotlib import pyplot
for i in range(1,61):
cx1_Ut[i] = math.sqrt(A1 - (c1**2)*(0.5*k[i]**2 - c2*math.log(k[i])));
cx2_Ut[i] = math.sqrt(A2 - (c1**2)*(0.5*k[i]**2 + c2*math.log(k[i])));
R_[i] = 0.778+math.log(k[i]);
Rn[i] = 0.5;
##Results
pyplot.plot(k,cx1_Ut);
pyplot.plot(k,cx2_Ut);
pyplot.title("Solution of exit axial-velocity profile for a first power stage")
pyplot.plot(k,R_);
pyplot.plot(k,Rn);
#ylabel("Reaction","fontsize",3) ;##y label
#legend(["True Reaction";"Nominal Reaction"] , opt=1); ##legend box