import math
#calculate the
##given data
T01 = 293.;##in K
pi = 5.;##pressure ratio
R = 0.5;##stage reaction
Um = 275.;##in m/s
phi = 0.5;##flow coefficient
psi = 0.3;##stage loading factor
eff_stage = 0.888;##stage efficiency
Cp = 1005.;##J/(kgC)
gamma = 1.4;
##Calculations
beta1 = (180./math.pi)*math.atan((R + 0.5*psi)/phi);
beta2 = (180./math.pi)*math.atan((R - 0.5*psi)/phi);
alpha2 = beta1;
alpha1 = beta2;
delT0 = psi*(Um**2)/Cp;
N = (T01/delT0)*((pi**((gamma-1.)/(eff_stage*gamma))) - 1.);
N = math.ceil(N);
eff_ov = ((pi**((gamma-1.)/gamma)) - 1.)/((pi**((gamma-1.)/(eff_stage*gamma))) - 1.);
print'%s %.2f %s %.2f %s'%('The flow angles are: beta1 = alpha2 = ',beta1,' deg' and 'beta2 = alpha1 = ',math.ceil(beta2),' deg.');
print'%s %.2f %s '%('\n The number of stages required = ',N,'');
print'%s %.2f %s'%('\n The overall efficiency = ',eff_ov*100,' percentage');
##there is a small error in the answer given in textbook
import math
#calculate the
##given data
R = 0.5;##stage reaction
s_c = 0.9;##space-chord ratio
beta1_ = 44.5;##in deg
beta2_ = -0.5;##in deg
h_c = 2.0;##height-chord ratio
lamda = 0.86;##work done factor
i = 0.4;##mean radius relative incidence
rho = 3.5;##density in kg/m^3
Um = 242.;##in m/s
eps_max = 37.5;##in deg
eps = 37.5;##in deg
delp0 = 0.032;##the profile total pressure loss coefficient
##Calculations
theta = beta1_ - beta2_;
deltaN = (0.229*theta*(s_c**0.5))/(1 - (theta*(s_c**0.5)/500.));
beta2N = deltaN + beta2_;
eps_ = 0.8*eps_max;
i_ = beta2N + eps_ - beta1_;
i = 0.4*eps_ + i_;
beta1 = beta1_ + i;
beta2 = beta1 - eps;
alpha2 = beta1;
alpha1 = beta2;
phi = 1/(math.tan(alpha1*math.pi/180.) + math.tan(beta1*math.pi/180.));
psi = lamda*phi*(math.tan(alpha2*math.pi/180.) - math.tan(alpha1*math.pi/180.));
betam = (180./math.pi)*math.atan(0.5*(math.tan(beta1*math.pi/180.) + math.tan(beta2*math.pi/180.)));
CL = 2*s_c*math.cos(betam*math.pi/180.)*(math.tan(beta1*math.pi/180.) - math.tan(beta2*math.pi/180.));
CDp = s_c*(delp0)*((math.cos(betam*math.pi/180.))**3)/((math.cos(beta1*math.pi/180.))**2);
CDa = 0.02*s_c/h_c;
CDx = 0.018*CL**2;
CD = CDp + CDa + CDx;
eff_tt = 1. - (CD*phi**2)/(psi*s_c*((math.cos(betam*math.pi/180.))**3));
delp = eff_tt*psi*rho*Um**2;
##Results
print'%s %.2f %s %.2f %s'%('(i)The nominal deflection= ',eps_,' deg'and '.\n the nominal incidence = ',i_,' deg.');
print'%s %.2f %s %.2f %s '%('\n (ii)The inlet flow angle, beta1 = alpha2 = ',beta1,' deg'and '\n outlet flow angle beta2 = alpha1 = ',beta2,' deg.');
print'%s %.2f %s %.2f %s '%('\n (iii)The flow coefficient = ',phi,''and '\nThe stage loading factor = ',psi,'');
print'%s %.2f %s'%('\n (iv) The rotor lift coefficient = ',CL,'');
print'%s %.2f %s '%('\n (v) The overall drag coefficient of each row = ',CD,'');
print'%s %.2f %s %.2f %s'%('\n (vi) The total-to-total stage efficiency = ',eff_tt,''and '\n The pressure rise across the stage =',delp/1000,' kPa');
##there are small errors in the answers given in textbook