import math
#calculate "Density at plane 1 and tagnation temperature and temperautre and density
p1=1.5*10**5; ## N/m^2
R=287.; ## J/kg.K
T1=271.; ## K
rho1=p1/R/T1;
print'%s %.1f %s'%("Density at plane 1 =",rho1,"kg/m^3")
print("the stagnation temperature")
u1=270.; ## m/s
cp=1005.; ## J/Kg.K
T0=T1+u1**2./(2.*cp);
print'%s %.1f %s'%("The stagnation temperature =",T0,"K")
print("the temperature and density at plane 2")
u2=320; ## m/s
p2=1.2*10**5; ## N/m^2
T2=T0-u2**2/(2*cp);
print'%s %.1f %s'%("Temperature = ",T2,"K")
rho2=p2/(R*T2);
print'%s %.2f %s'%("density =",rho2,"kg/m^3")
import math
#calculate Deflection angle and the final Mach number and the pressure ratio across the wave
y=1.4;
R=287.; ## J/kg.K
T1=238.; ## K
u1=773.; ## m/s
beta1=38.; ## degrees
cp=1005.; ## J/kg.K
a1=math.sqrt(y*R*T1);
M1=u1/a1;
beta2=math.atan(math.tan(beta1)*((2.+(y-1.)*M1**2.*(math.sin(beta1))**2.)/((y+1.)*M1**2.*(math.sin(beta1))**2.)));
deflection_angle=beta1-beta2;
print'%s %.1f %s'%("Deflection angle =",deflection_angle,"degrees")
print("the final Mach number")
u2=u1*math.cos(beta1)/math.cos(beta2);
T2=T1+1./(2.*cp)*(u1**2.-u2**2.);
a2=math.sqrt(y*R*T2);
M2=u2/a2;
print'%s %.2f %s'%("Final Mach number =",M2,"")
print(" the pressure ratio across the wave.")
ratio=T2/T1*(math.tan(beta1)/math.tan(beta2));
print'%s %.2f %s'%("Pressure ratio =",ratio,"")
import math
#calculate Pressure after the bend
M1=1.8;
theta1=20.73; ## degrees
theta2=30.73; ## degrees
M2=2.162;
p1=50; ## kPa
y=1.4;
p2=p1*((1.+(y-1.)/2.*M1**2.)/(1.+(y-1.)/2.*M2**2.))**(y/(y-1.));
print'%s %.1f %s'%("Pressure after the bend =",p2,"kPa")
import math
#calculate the pressures in the reservoir and at the nozzle throat and Pressure in the reservoir and Pressure at the nozzle throat and the temperature and velocity of the air at the exit
p=28*10**3; ## N/m^2
y=1.4;
M1=2.4;
M2=1.;
T0=291.; ## K
R=287.; ## J/kg.K
print("the pressures in the reservoir and at the nozzle throat")
p0=p*(1+(y-1)/2*M1**2)**(y/(y-1));
pc=p0*(1+(y-1)/2*M2**2)**(-y/(y-1));
print'%s %.2f %s'%("Pressure in the reservoir =",p0,"N/m^2")
print'%s %.2f %s'%("Pressure at the nozzle throat =",pc,"N/m^2")
print("the temperature and velocity of the air at the exit.")
T=T0*(1+(y-1)/2*M1**2)**(-1);
print'%s %.1f %s'%("Temperature =",T,"K")
a=math.sqrt(y*R*T)
u=M1*a;
print'%s %.1f %s'%("Velocity =",u,"m/s")
import math
#calculate Mach number before the shock and Stagnation Pressure
M_He=1.8;
y_He=5/3;
y_air=1.4;
p2=30; ## kPa
## (A/At)=(1+(y-1)/2*M^2)^((y+1)/(y-1))/M^2*(2/(y+1))^((y+1)/(y-1))
## = (1+1/3*1.8^2)^(4)/1.8^(2)*(3/4)^(4) = 1.828 for helium
## = (1+0.2*M^2)^6/M^2*1/1.2^6 for air
## Hence by trial
M1=1.715;
print'%s %.3f %s'%("Mach number before the shock =",M1,"")
p1=p2/((2*y_air*M1**2-(y_air-1))/(y_air+1));
p0_1=p1*(1+(y_air-1)/2*M1**2)**(y_air/(y_air-1));
print'%s %.1f %s'%("Stagnation Pressure =",p0_1,"kPa")
import math
#calculate the value of the friction factor for the pipe and friction factor and the overall length of the pipe, L, if the flow exhausts to atmosphere
p0=510.; ## kPa
pA=500.; ## kPa
pB=280.; ## kPa
d=0.02; ## m
l_max=12.; ## m
print(" the value of the friction factor for the pipe");
## At A, pA/p0 = 500/510 = 0.980. From the Isentropic Flow Tables (Appendix 3), M_A = 0.17.
pC=pA*0.1556;
## From the Fanno Tables at pc/pB = 0.278,M_B = 0.302 and (fl_maxP/A)B = 5.21. For a circular pipe P/A=4/d
M_B=0.302;
f=(21.37-5.21)/l_max/4*d;
print'%s %.3f %s'%("friction factor =",f,"")
print(" the overall length of the pipe, L, if the flow exhausts to atmosphere")
p=100; ## kPa
## At exit, pc/p = 77.8/100 = 0.778. From the Fanno Tables, (fl_maxP/A) = 0.07
L=l_max*(21.37-0.07)/(21.37-5.21);
print'%s %.1f %s'%("Overall Length =",L,"m")
print(" the mass flow rate if the reservoir temperature is 294 K.")
T0=294.; ## K
R=287.; ## J/kg.K
y=1.4;
M=0.302;
m=math.pi/4.*d**2.*pB*10.**3.*M_B*(y*(1.+(y-1.)*M**2./2.)/R/T0)**(1/2.);
print'%s %.3f %s'%("mass flow rate =",m,"kg/s")
import math
#calculate Diameter of pipe and Entry and Exit Mach number and at various points
p1=8.*10.**5.; ## N/m**2
p2=5.*10.**5.; ## N/m**2
f=0.006;
l=145.; ## m
m=0.32; ## kg/s
R=287.; ## J/kg.K
T=288.; ## K
y=1.4;
d=(4.*f*l*m**2.*R*T/(math.pi/4.)**2./(p1**2.-p2**2.))**(1/5.);
print'%s %.3f %s'%(" Diameter of pipe =",d,"m")
rho=p1/R/T;
A=math.pi/4.*d**2.;
u=m/rho/A;
a=math.sqrt(y*R*T);
M1=u/a;
M2=p1/p2*M1;
print(" Entry and Exit Mach number =")
print'%s %.3f %s'%("Entry Mach number =",M1,"")
print'%s %.2f %s'%("Exit Mach number =",M2,"")
print(" Determine the pressure halfway along the pipe.")
px=math.sqrt((p1**2.+p2**2.)/2.);
print'%s %.1f %s'%("Pressure =",px,"N/m**2")