In [7]:

```
%matplotlib inline
import math
from numpy import linspace
from matplotlib.pyplot import plot,legend,suptitle,xlabel,ylabel
#Input data
m = 0.75 #Mass of air in kg
T1 = 800. #Intial Temperature in K
P1 = 400. #Initial Pressure in kPa
P2 = 150. #Final Pressure in kPa
k = 1.4 #Adiabatic consmath.tant
R = 0.287 #Specific Gas consmath.tant in J/kg-K
#Calculation
p1 = P2/P1 #pressure ratio of process
T2 = T1*p1**((k-1)/k) #Final temperature in K
W = ((m*R*(T1-T2))/(k-1)) #Workdone in kJ
#P-V Diagram
V1 = (((m*R*T1)/P1)**(1/k))*10**3 #Inlet volume in cc
V2 = (((m*R*T2)/P2)**(1/k))*10**3 #Final volume in cc
V = linspace(V1,V2,101) #Representing volume on graph, adiabatic expansion
P = P1*V1**k/V**k #Representing pressure on graph
plot(V, P) #Plotting
legend('P*V**k = C') #Defining curve
suptitle("PV Diagram")
xlabel("V (cc)")
ylabel("P (kPa)") #Titles of axes
#Output
print 'Workdone is %3.2f kJ'%(W)
```

In [8]:

```
%matplotlib inline
import math
from numpy import linspace
from matplotlib.pyplot import plot,legend,suptitle,xlabel,ylabel
#Input data
V1 = 0.35 #Volume of gas in m**3
P1 = 110. #Initial Pressure in kPa
T1 = 300. #Intial Temperature in K
P2 = 600. #Final Pressure in kPa,mismath.sing data
k = 1.4 #Adiabatic consmath.tant
Cv = 718. #Specific heat at consmath.tant volume in J/kg-K
R = 287. #Specific Gas consmath.tant in J/kg-K
#Calculation
dQ = 0 #Heat transfer in J, Since Adiabatic process
m = (P1*10**3*V1)/(R*T1) #Mass of air in kg
p1 = P2/P1 #Pressure ratio
T2 = T1*p1**((k-1)/k) #Final temperature in K
dU = (m*Cv*(T2-T1))*10**-3 #Change in internal energy in kJ
dW = -dU #Workdone in kJ, Since dQ = 0
#P-V Diagram
V1cc = V1*10**3 #Inlet volume in cc
V2cc = V1cc*(T2/T1)**(1/(k-1)) #Final volume in cc
V = linspace(V1cc,V2cc,101) #Representing volume on graph, adiabatic expansion
P = P2*V1cc**k/V**k #Representing pressure on graph
plot(V, P) #Plotting
legend('P*V**k = C') #Defining curve
suptitle("PV Diagram")
xlabel("V (cc)")
ylabel("P (kPa)") #Titles of axes
#Output
print 'A)Heat transfer is %3i J \nB)Change in internal energy is %3.3f kJ \nC)Workdone is %3.3f kJ'%(dQ,dU,dW)
```

In [4]:

```
import math
#Input data
P1 = 3.2 #Initial Pressure in bar
P2 = 1. #Final Pressure in bar
T1 = 475. #Initial temperature in K
Mol = 44. #Molecular weight of carbondioxide in kg/mol
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
k = 1.3 #Adiabatic consmath.tant
#Calculation
R = Ri/Mol #Specific gas consmath.tant in J/kg-K
Cp = (k*R)/(k-1) #Specific heat capacity at consmath.tant pressure in J/kg-K
Cv = Cp/k #Specific heat capacity at consmath.tant volume in J/kg-K
p1 = P2/P1 #Pressure ratio
T2 = T1*p1**((k-1)/k) #Final Temperature
dh = Cp*(T1-T2)*10**-3 #Enthalpy drop in kJ/kg
dU = Cv*(T2-T1)*10**-3 #Change in internal energy in kJ/kg, -ve sign indicates loss
#Output
print 'A)Temperature is %3.3f K \nB)Enthalpy drop is %3.3f kJ/kg \
\nC)Change in internal energy is %3.2f kJ/kg i.e. %3.2f kJ/kgloss'%(T2,dh,dU,abs(dU))
```

In [7]:

```
import math
#Input data
P1 = 0.5 #Initial Pressure in bar
T1 = 50.+273 #Intial Temperature in K
C1 = 240. #Inlet velocity in m/s
C2 = 120. #Outlet velocity in m/s, mismath.sing data
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
k = 1.4 #Adiabatic consmath.tant
#Calculation
T2 = T1+((C1**2-C2**2)/(2*Cp)) #Final Temperature in K
t1 = T2/T1 #Temperature ratio
P2 = P1*t1**(k/(k-1)) #Final Pressure in bar
ar = (P1*T2*C1)/(P2*T1*C2) #Ratio of outlet to inlet area
#Output
print 'A)At outlet: Temperature is %3.2f K \
\nPressure is %3.4f bar \
\nB)Ratio of outlet to inlet area is %3.4f'%(T2,P2,ar)
```

In [9]:

```
import math
#Input data
m = 25. #Mass flow rate of air in kg/s
C2 = 115. #Outlet velocity in m/s
P1 = 100. # #Initial Pressure in kPa
T1 = 300. #Intial Temperature in K
C1 = 40. #Inlet velocity in m/s
R = 0.287 #Specific gas consmath.tant in kJ/kg-K
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
k = 1.4 #Adiabatic consmath.tant
#Calculation
T2 = T1+((C1**2-C2**2)/(2*Cp)) #Final Temperature in K
t1 = T2/T1 #Temperature ratio
P2 = P1*t1**(k/(k-1)) #Final Pressure in bar
A1 = (m*R*T1)/(P1*C1) #Area at inlet in m**2
A2 = (m*R*T2)/(P2*C2) #Area at outlet in m**2
F = ((P1*A1)-(P2*A2))+(m*(C1-C2))*10**-3 #Axial force on mouthpiece resulting from acceleration of air in kN
#Output
print 'A)Static pressure at intake face is %3.3f kPa \
\nB)Magnitude of axial force on mouthpiece resulting from acceleration of air is %3.3f kN'%(P2,F)
```

In [10]:

```
import math
#Input data
P = 200. #Pressure in kPa
C = 50. #Velocity of air in m/s
d = 2.9 #Density in kg/m**3
Mol = 32. #Molecular weight of oxygen in kg/mol
k = 1.4 #Adiabatic consmath.tant
Ri = 8314 #Ideal gas consmath.tant in J/mol-K
#Calculation
R = Ri/Mol #Specific gas consmath.tant in J/kg-K
T = P*10**3/(R*d) #Temperature in K
a = math.sqrt(k*R*T) #Velocity of sound in m/s
M = C/a #Mach number
#Output
print 'Mach number is %3.2f'%(M)
```

In [11]:

```
import math
#Input data
Pa = 1.3 #Pressure at section-A in bar
Ta = 50.+273 #Temperature at section-A in K
Pb = 1. #Pressure at section-B in bar
Tb = 13.+273 #Temperature at section-B in K
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
R = 287. #Specific gas consmath.tant in J/kg-K
#Calculation
ds = ((Cp*math.log(Tb/Ta))-(R*math.log(Pb/Pa)))*10**-3 #The change in the entropy is kJ/kg
#+ve sign indicates A to B
#-ve sign indicates B to A
#Output
print 'The change in the entropy is %3.4f kJ/kg Since value is -ve, process must takes place from B to A'%(ds)
```

In [12]:

```
import math
#Input data
V1 = 8. #Intial volume in litre
V2 = 7.8 #Final volume in litre
P1 = 0.7 #Intial Pressure in MPa
P2 = 2.7 #Final Pressure in MPa
#Calculations
K = (P2-P1)/(math.log(V1/V2)) #Bulk modulus of liquid in kPa
#Output
print 'Bulk modulus of liquid is %3.3f kPa'%(K)
```

In [13]:

```
import math
#Input data
V1 = 0.5 #Voume of Water required to fill pressure vessel in m**3
P = 3000. #Test pressure in bar
dv = 0.6 #Change of empty volume of container due to pressurisation in percentage
K = 20000. #Bulk modulus of water in MPa
#Calculation
m1 = V1*10**3 #Mass of water required to fill pressure vessel in kg
Vr = (P*V1)/K #Reduced volume of water due to compression in m**3
Vi = dv*V1/100 #Increased volume of container in m**3
V = Vr+Vi #Volume of additional water required in m**3
m = V*10**3 #Mass of additional water required in kg
mt = m1+m #Total mass of water required in litre, Since 1kg = 1Lit
#Output
print 'Mass of water to be pumped into the vesel to obtain the desired pressure is %3i lit'%(mt)
```

In [15]:

```
import math
#Input data
SG_oil = 0.8 #Specific gravity of crude oil
K_oil = 153036.*10**4 #Bulk modulus of Oil in N/m**2
K_hg = 2648700.*10**4 #Bulk modulus of Mercury in N/m**2
d_steel = 7860. #Density of steel in kg/m**3
E_steel = 200.*10**9 #Modulus of elasticity in Pa
d_hg = 13600. #Density of mercury in kg/m**3
d_water = 1000. #Density of water in kg/m**3
#Calculation
d_oil = SG_oil*d_water #Density of oil in kg/m**3
a_oil = math.sqrt(K_oil/d_oil) #Sonic velocity of crude oil in m/s
a_hg = math.sqrt(K_hg/d_hg) #Sonic velocity of mercury in m/s
a_steel = math.sqrt(E_steel/d_steel) #Sonic velocity of steel in m/s
#Output
print 'A)Sonic velocity of crude oil is %3.2f m/s \
\nB)Sonic velocity of mercury is %3.2f m/s \
\nA)Sonic velocity of steel is %3.1f m/s'%(a_oil,a_hg,a_steel)
```

In [17]:

```
import math
#Input data
T = 20.+273 #Temperarture of medium in K
Cp_fr = 678. #Specific heat capacity at consmath.tant pressure of freon in J/kg-K
Cv_fr = 543. #Specific heat capacity at consmath.tant volime of freon in J/kg-K
T_air = 0.+273 #Temperature of air in K
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
mol_h = 2. #Molecular weight of Hydrogen in kg/mol
mol_water = 18. #Molecular weight of water in kg/mol
R_air = 287. #Specific gas consmath.tant of air in J/kg-K
k = 1.4 #Adiabatic consmath.tant of hydrogen
k_water = 1.3 #Adiabatic consmath.tant of water
#Calculation
R_h = Ri/mol_h #Specific gas consmath.tant of hydrogen in J/kg-K
a_h = math.sqrt(k*R_h*T) #Velocity of sound in hydrogen in m/s
R_water = Ri/mol_water #Specific gas consmath.tant of water in J/kg-K
a_water = math.sqrt(k_water*R_water*T) #Velocity of sound in water vapour in m/s
k_fr = Cp_fr/Cv_fr #Adiabatic consmath.tant of feoan
R_fr = Cp_fr-Cv_fr #Specific gas consmath.tant of freon in J/kg-K
a_fr = math.sqrt(k_fr*R_fr*T) #Velocity of sound in freon in m/s
a_air = math.sqrt(k*R_air*T_air) #Sonic Velocity of air at in m/s
#Output
print 'A)Velocity of sound in hydrogen is %3.2f m/s \
\nB)Velocity of sound in water vapour is %3.2f m/s \
\nC)Velocity of sound in freon is %3.2f m/s \
\nD)Sonic Velocity of air at %3i K is %3.4f m/s'%(a_h,a_water,a_fr,T_air,a_air)
```

In [18]:

```
import math
#Input data
M = 0.85 #Mach number
P = 80. #Pressure in kPa
k = 1.4 #Adiabatic Consmath.tant
#Calculation
Po = P*(1+(((k-1)/2)*M**2))**(k/(k-1)) #Pressure acting on the surface of the body in kPa
#Output
print 'The highest pressure acting on the surface of the body is %3.1f kPa'%(Po)
```

In [21]:

```
import math
#Input data
P = 96. #Pressure in kPa
T = 27.+273 #Temperature in K
dP = 32. #Difference between pivot and static pressure
k = 1.4 #Adiabatic Consmath.tant
R = 287. #Specific Gas consmath.tant in J/kg-K
#Calculation
d = (P*10**3)/(R*T) #Density in kg/m**3
Ci = math.sqrt((2*(dP*10**3))/d) #Velocity of incompressible flow in m/s
pr = (dP)/P #Pressure ratio
p1 = pr+1 #Stagnation to static pressure ratio
M = math.sqrt(((p1**((k-1)/k)-1)*2)/(k-1)) #Mach number
Cc = M*math.sqrt(k*R*T) #Velocity of compressible flow in m/s
#Output
print 'A)Air velocity in incompressible flow is %3.1f m/s \
\nB)Air velocity if flow is compressible is %3.3f m/s'%(Ci,Cc)
# note : rounding off error.
```

In [23]:

```
import math
#Input data
T1 = 200.+273 #Intial Temperature in K
P1 = 1.7 #Initial Pressure in bar
P2 = 1. #Final Pressure in bar
C1 = 30. #Inlet velocity in m/s
m = 1. #Mass flow rate in kg/s
D = 0.025 #Nozzle diameter in m
k = 1.4 #Adiabatic Consmath.tant
R = 287. #Specific Gas consmath.tant in J/kg-K
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
p1 = P2/P1 #Pressure ratio
T2 = T1*p1**((k-1)/k) #Final temperature in K
E1 = T1+(C1**2/(2*Cp)) #LHS of Steady flow energy equation
C2 = math.sqrt((E1-T2)*2*Cp) #Exit velocity of the air in m/s
d2 = (P2*10**5)/(R*T2) #Density at outlet in kg/m**3
A2 = math.pi*D**2/4 #Area at outlet in m**2
n = ceil(m/(d2*A2*C2)) #Number of nozzles to be used
#Output
print 'A)Exit velocity of the air is %3.2f m/s \
\nB)Number of nozzles to be used are %1.0f'%(C2,n)
```

In [25]:

```
import math
#Input data
Po = 300. #Pressure in the vessel in kPa
To = 50.+273 #Temperature in vessel in K
M = 1. #Mach number
k = 1.667 #Adiabatic consmath.tant
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
Mol = 4. #Molecular weight of helium in kg/mol
#Calculation
R = Ri/Mol #Specific gas consmath.tant in J/kg-K
Cp = (k*R)/(k-1) #Specific heat capacity at consmath.tant pressure in J/kg-K
p1 = (2/(k+1))**(k/(k-1)) #Pressure ratio
Pt = Po*p1 #Pressure at test condition in kPa
t1 = (2/(k+1)) #Temperature ratio
Tt = To*t1 #Temperature at test condition in K
at = math.sqrt(k*R*Tt) #Velocity of sound in m/s
Ct = at #Velocity of gas at test condition in m/s
Cmax = math.sqrt(2*Cp*To) #Maximum velocity due to expanding of gases through nozzle system in m/s
#Output
print 'A)At test point: \
\nPressure is %3.2f kPa \
\nTemperature is %3.2f K \
\nVelocity is %3.1f m/s \
\nB)Maximum velocity due to expanding of gases through nozzle system is %3.2f m/s'%(Pt,Tt,Ct,Cmax)
```

In [26]:

```
import math
#Input data
T = 40+273 #Temperature in K
p1 = 0.5 #Static to Stagnation pressure ratio
k = 1.67 #Adiabatic consmath.tant
Ri = 8314 #Ideal gas consmath.tant in J/mol-K
Mol = 39.94 #Molecular weight of argon in kg/mol
#Calculation
R = Ri/Mol #Specific gas consmath.tant in J/kg-K
p2 = 1/p1 #Pressure ratio
M = math.sqrt(((p2**((k-1)/k)-1)*2)/(k-1)) #Mach number
C = M*math.sqrt(k*R*T) #Velocity in the flow in m/s
#Output
print 'A)Mach number is %3.3f \
\nB)Velocity in the flow is %3.1f m/s'%(M,C)
```

In [37]:

```
import math
#Input data
M = 2.5 #Mach number
h = 10 #Height in km
#Calculation
alp = math.asin((1/M)) #Mach cone angle in degree
d = 10/math.tan((alp)) #Distance the jet would cover before a sonic boom is heard on ground in km
#Output
print 'Distance the jet would cover before a sonic boom is heard on ground is %3.2f km'%(d)
```

In [43]:

```
import math
#Input data
h = 1100 #Height in m
M1 = 2.5 #Mach number of aircraft @h
T = 280 #Temperature @h
M2 = 0.5 #Mach number of observer
k = 1.4 #Adiabatic Consmath.tant
R = 287 #Specific gas consmath.tant in J/kg-K
#Calculation
alp = math.sin((1/M1)) #Mach cone angle in degree
a = math.sqrt(k*R*T) #Velocity of sound in m/s
C1 = M1*a #Velocity of aircraft when the observer is stationary in m/s
t1 = h/(C1*(math.tan(alp))) #Time elapsed when the observer is stationary in sec
C2 = (M1-M2)*a #Velocity of aircraft when the observer is moving in the direction of aircraft in m/s
t2 = h/(C2*(math.tan(alp))) #Time elapsed when the observer is moving in the direction of aircraft in sec
C3 = (M1+M2)*a #Velocity of aircraft when the observer is moving in the opposite direction in m/s
t3 = h/(C3*(math.tan(alp))) #Time elapsed when the observer is moving in the opposite direction in sec
#Output
print 'A)Time elapsed when the observer is stationary is %3.3f sec \
\nB)Time elapsed when the observer is moving in the direction of aircraft with M = %3.1f is %3.2f sec \
\nC)Time elapsed when the observer is moving in the opposite direction is %3.2f sec'%(t1,M2,t2,t3)
# note : rounding off error .
```

In [45]:

```
import math
#Input data
P = 200. #Pressure in kPa
d = 2.9 #Density in kg/m**3
C = 50. #Velocity in m/s
mol = 32. #Molecular weight of oxygen in kg/mol
k = 1.4 #Adiabatic consmath.tant
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
#Calculation
R = Ri/mol #Specific gas Consmath.tant in J/kg-k
T = (P*10**3)/(R*d) #Temperature in K
a = math.sqrt(k*R*T) #Velocity of sound in m/s
M = C/a #Mach number
#Output
print 'Mach number is %3.4f'%(M)
```

In [46]:

```
import math
#Input data
C = 200 #Velocity of object in m/s
mol = 4 #Molecular weight of helium in kg/mol
k = 1.67 #Adiabatic consmath.tant
Ri = 8314 #Ideal gas consmath.tant in J/mol-K
T = 288 #Temperature in K
#Calculation
R = Ri/mol #Specific gas Consmath.tant in J/kg-k
a = math.sqrt(k*R*T) #Velocity of sound in m/s
M = C/a #Mach number
#Output
print 'Mach number is %3.1f'%(M)
```

In [50]:

```
import math
#Input data
Z1 = 0. #Height from sea level in m
Z2 = 11. #Height from sea level in m
T1 = 288. #Temperature @Z1 in K, from gas tables
T2 = 216.5 #Temperature @Z2 in K, from gas tables
C = 1000.*(5./18) #Velocity in m/s
k = 1.4 #Adiabatic Consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
a1 = math.sqrt(k*R*T1) #Sound velocity @Z1 in m/s
M1 = C/a1 #Mach number @Z1
a2 = math.sqrt(k*R*T2) #Sound velocity @Z2 in m/s
M2 = C/a2 #Mach number @Z2
#Output
print 'A)Speed of sound at: \
\nsea level is %3.2f and altitude of %3i km is %3.2f m/s \
\nB)Mach numbeer at: sea level is %3.2f an altitude of %3i km is %3.2f'%(a1,Z2,a2,M1,Z2,M2)
```

In [52]:

```
import math
#Input data
T = 300+273 #Static Temperature in K
C = 200 #Velocity in m/s
Cp = 1005 #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
To = T+(C**2/(2*Cp)) #Stagnation Temperature in K
C_max = math.sqrt(2*Cp*To) #Maximum possible velocity obtained by air in m/s
#Output
print 'Maximum possible velocity obtained by air is %3.f m/s'%(C_max)
# rounding off error.
```

In [53]:

```
import math
#Input data
dT = 37 #Temperature difference between air inside the tyre and nozzle exit
Cp = 1005 #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
C = math.sqrt(2*Cp*dT) #Exit velocity of air in m/s
#Output
print 'Exit velocity of air is %3.1f m/s'%(C)
```

In [54]:

```
import math
#Input data
C = 800*(5./18) #Velocity in m/s
Po = 105. #Stagnation pressure in kPa
To = 35.+273 #Stagnation temperature in K
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
k = 1.4 #Adiabatic Consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
T = To-(C**2/(2*Cp)) #Static temperature in K
P = Po*(T/To)**(k/(k-1)) #Static pressure in kPa
a = math.sqrt(k*R*T) #Sound Velocity in m/s
M = C/a #Mach number
#Output
print 'A)Static conditions: \
\nPressure is %3.2f kPa \
\nTemperature is %3.2f K \
\nSound Velocity is %3.2f m/s \
\nB)Mach number is %3.2f'%(P,T,a,M)
```

In [55]:

```
import math
#Input data
C = 215 #Velocity in m/s
T = 30+273 #Static temperature in K
P = 5 #Static pressure in bar
R = 287 #Specific gas consmath.tant in J/kg-k
k = 1.4 #Adiabatic Consmath.tant
#Calculations
a = math.sqrt(k*R*T) #Sound Velocity in m/s
M = C/a #Mach number
To = T*(1+(((k-1)/2)*M**2)) #Stagnation temperature in K
Po = P*(To/T)**(k/(k-1)) #Stagnation pressure in kPa
#Output
print 'A)Stagnation Pressure is %3.4f bar \
\nB)Mach number is %3.3f'%(Po,M)
```

In [57]:

```
import math
#Input data
T = 400. #Static temperature in K
k = 1.4 #Adiabatic Consmath.tant
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
a = math.sqrt(k*R*T) #Sound velocity in m/s
C = a #Velocity of jet in m/s, Since jet has sonic velocity
To = T+(C**2/(2*Cp)) #Stagnation temperature in K
ao = math.sqrt(k*R*To) #Sound velocity at Stagnation condition in m/s
ho = (Cp*To)*10**-3 #Stagnation enthalpy in kJ/kg
C_max = math.sqrt(2*Cp*To) #Maximum velocity of jet in m/s
cr = C/C_max #Crocco number
#Output
print 'A)Velocity of sound at %3i K is %3.3f m/s \
\nB)Velocity of sound at stagnation condition is %3.3f m/s \
\nC)Maximum velocity of jet is %3.3f m/s \
\nD)Stagnation enthalpy is %3.3f kJ/kg \
\nE)Crocco number is %3.4f'%(T,C,ao,C_max,ho,cr)
# rounding off error.
```

In [58]:

```
import math
#Input data
C = 250. #Velocity of air in m/s
D = 10. #Diameter in duct in cm
T = 5.+273 #Static temperature in K
P = 40. #Static pressure in kPa
k = 1.4 #Adiabatic consmath.tant
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
To = T+(C**2/(2*Cp)) #Stagnation temperature in K
Po = P*(To/T)**(k/(k-1)) #Stagnation pressure in kPa
d = (P*10**3)/(R*T) #Density in kg/m**3
A = (math.pi*D**2/4)*10**-4 #Area in m**2
m = d*A*C #Mass flow rate in kg/s
#Output
print 'A)Stagnation pressure is %3.2f kPa \
\nB)Stagnation temperature is %3.2f K \
\nC)Mass flow rate is %3.4f kg/s'%(Po,To,m)
```

In [59]:

```
import math
#Input data
C = 300. #Velocity of air in m/s
P = 1. #Static pressure in kPa
T = 290. #Static temperature in K
k = 1.4 #Adiabatic consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
To = T+(C**2/(2*Cp)) #Stagnation temperature in K
Po = P*(To/T)**(k/(k-1)) #Stagnation pressure in kPa
a = math.sqrt(k*R*T) #Sound velocity in m/s
Co = math.sqrt(k*R*To) #Sound velocity at Stagnation condition in m/s
#Output
print 'A)Stagnation pressure and temperature are %3.4f bar and %3.2f K \
\nB)Velocity of sound in the dynamic and stagnation conditions are %3.2f m/s and %3.2f m/s'%(Po,To,a,Co)
```

In [60]:

```
import math
#Input data
dP = 490*(1.01325/760) #Pressure in pivot tube in bar
P = 0.3546+1.01325 #Static pressure(absolute) in bar
To = 25.+273 #Stagnation temperature in K
k = 1.4 #Adiabaatic consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
Po = dP+P #Stagnation pressure in bar
T = To*(P/Po)**((k-1)/k) #Static temperature
C1 = math.sqrt(2*Cp*(To-T)) #Flow velocity for Compressible flow in m/s
di = Po/(R*To) #Density in kg/m**3
C2 = math.sqrt((2*dP)/di) #Flow velocity for incompressible flow in m/s
#Output
print 'Flow velocity for: A)Compressible flow is %3.2f m/s \
\nB)Incompressible flow is %3.2f m/s'%(C1,C2)
```

In [61]:

```
import math
#Input data
To = 27.+273 #Stagnation temperature in K
Po = 8. #Stagnation Pressure in bar
P = 5.6 #Static pressure in bar, taken from diagram given
m = 2. #Mass flow rate in kg/s
k = 1.4 #Adiabaatic consmath.tant
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
T = To*(P/Po)**((k-1)/k) #Static temperature in K
a = math.sqrt(k*R*T) #Sound velocity in m/s
C = math.sqrt(2*Cp*(To-T)) #Velocity in m/s
M = C/a #Mach number
A = ((m*R*T)/(P*10**5*C))*10**4 #Area at a point in the channal in cm**2
#Output
print 'A)Mach number is %3.4f \
\nB)Velocity is %3.1f m/s \
\nC)Area at a point in the channal is %3.3f cm**2'%(M,C,A)
```

In [63]:

```
import math
#Input data
Po = 1.8 #Stagnation pressure in atm
To = 20+273 #Stagnation temperature in K
P = 1 #Surrounding pressure in atm
k = 1.4 #Adiabatic consmath.tant
R = 287 #Specific gas consmath.tant in J/kg-k
#Calculation
p1 = 0.528 #Static to Stagnation pressure ratio @Mach number = 1, from gas tables
Pt = p1*Po #Critical pressure in atm, Since Pt<P the flow is not chocked
di = (Po*10**5)/(R*To) #Density in kg/m**3
ao = math.sqrt(k*R*To) #Sound velocity at Stagnation condition in m/s
Cp = (k*R)/(k-1) #Specific heat capacity at consmath.tant pressure in J/kg-K
C = math.sqrt(2*Cp*To*(1-(P/Po)**((k-1)/k))) #Velocity of air flow which will take place from chamber to the outside through a unit area hole in m/s
G = di*ao*math.sqrt(2/(k-1))*(P/Po)**(1/k)*math.sqrt((1-(P/Po)**((k-1)/k))) #Mass flow rate per unit area in kg/s-m**2
#Output
print 'A)Velocity of air flow which will take place from chamber to the outside through a unit area hole is %3.3f m/s \
\nB)Mass flow rate per unit area is %3.3f kg/s-m**2'%(C,G)
# note : rounding off error.
```

In [65]:

```
import math
#Input data
A1 = 465.125 #Cross sectional area at entry in cm**2
T1 = 26.66+273 #Static temperature at section-1 in K
P1 = 3.4473 #Static Pressure at section-1 in bar
C1 = 152.5 #Velocity at section-1 in m/s
P2 = 2.06838 #Static Pressure at section-2 in bar
T2 = 277.44 #Static temperature at section-2 in K
C2 = 260.775 #Velocity at section-2 in m/s
Cp = 1005 #Specific heat capacity at consmath.tant pressure in J/kg-K
k = 1.4 #Adiabatic consmath.tant
R = 287 #Specific gas consmath.tant in J/kg-k
#Calculations
To1 = T1+(C1**2/(2*Cp)) #Stagnation temperature at entry in K
To2 = T2+(C2**2/(2*Cp)) #Stagnation temperature at exit in K
#here To1 = To2 from answers
d1 = (P1*10**5)/(R*T1) #Density at section-1
d2 = (P2*10**5)/(R*T2) #Density at section-2
ar = (d2*C2)/(d1*C1) #Ratio of inlet to outlet area
A2 = A1/ar #Cross sectional area at exit in cm**2
C_max = math.sqrt(2*Cp*To1) #Maximum velocity at exit in m/s
m = d1*A1*C1*10**-4 #Mass flow rate in kg/s
F = ((P1*10**5*A1*10**-4)-(P2*10**5*A2*10**-4))+(m*(C1-C2)) #Force acting on the duct wall between two sections in N
#Output
print 'A)Maximum velocity and stagnation temperature at exit are %3.2f m/s and %3.2f K \
\nB)Since Stagnation temperature %3i K at entry and %3i K at exit are equal, the flow is adiabatic \
\nC)Cross sectional area at exit is %3.2f cm**2 \
\nD)Force acting on the duct wall between two sections is %3.2f N'%(C_max,To2,To1,To2,A2,F)
# rounding off error.
```

In [67]:

```
import math
#Input data
P1 = 250. #Static Pressure at section-1 in kPa
T1 = 26.+273 #Static temperature at section-1 in K
M1 = 1.4 #Mach number at entry
M2 = 2.5 #Mach number at exit
k = 1.4 #Adiabatic consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
#Calculation
C1 = math.sqrt(k*R*T1)*M1 #Air velocity at entry in m/s
To = T1*(1+(((k-1)/2)*M1**2)) #Stagnation temperature in K
t1 = (1+(((k-1)/2)*M2**2)) #Stagnation to exit Temperature ratio
T2 = To/t1 #Exit temperature in K
C2 = math.sqrt(k*R*T2)*M2 #Air velocity at exit in m/s
P2 = P1*(T2/T1)**(k/(k-1)) #Exit static pressure in kPa
d2 = (P2*10**3)/(R*T2) #Density at section-2 in kg/m**3
G = d2*C2 #)Mass flow rate through the duct per square metre in kg/s-m**2
#Output
print 'A)At second section: \
\nTemperature is %3.2f K \
\nPressure is %3.2f kPa \
\nVelocity is %3.4f m/s \
\nB)Mass flow rate through the duct per square metre is %3.1f kg/s-m**2'%(T2,P2,C2,G)
```

In [68]:

```
import math
#Input data
M = 2. #Mach number
h = 20. #Altitude in km
Tc = -56. #Ambient temperature in degree Centigrade
Ta = -56.+273 #Ambient temperature in K
k = 1.4 #Adiabatic consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-k
Cp = 1005. #Specific heat capacity at consmath.tant pressure in J/kg-K
#Calculation
a = math.sqrt(k*R*Ta) #Sound velocity in m/s
C = M*a #Velocity of flight in m/s
To = Tc+(C**2/(2*Cp)) #The maximum temperature encountered is %3.1f degree Centigrade
#Output
print 'The maximum temperature encountered is %3.1f degree Centigrade'%(To)
```

In [71]:

```
import math
#Input data
W = 20000. #Power developed in kW
m = 12. #Mass flow rate in kg/s
C1 = 50. #Velocity of air entering in m/s
T1 = 700.+273 #Temperature of air entering in K
T2 = 298. #Temperature of air leaving in K
C2 = 125. #Velocity of air leaving in m/s
Cp = 1.005 #Specific heat capacity at consmath.tant pressure in kJ/kg-K
#Calculation
dh = Cp*(T2-T1) #Change in enthalpy in kJ/kg
Q = ((m*dh)+W-(m*(1./2000)*(C2**2-C1**2))) #The rate of heat transfer in kJ/s
#Output
print 'The rate of heat transfer is %3.2f kJ/s'%(Q)
# rounding off error. kindly check.
```

In [73]:

```
import math
#Input data
mol = 39.9 #Molecular weight of gas in kg/mol
k = 1.67 #Adiabatic consmath.tant
Po = 500. #Pressure in chamber in kPa
To = 30.+273 #Temperature in chamber in K
P1 = 80. #Pressure of nozzle at given section in kPa
D = 0.012 #Cross section diameter of nozzle in m
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
#Calculation
R = Ri/mol #Specific gas consmath.tant in J/kg-K
p1 = Po/P1 #Stagnation to static pressure ratio
M1 = math.sqrt((((p1**((k-1)/k))-1)*2)/(k-1)) #Mach number at section
T1 = To*((1+(((k-1)/2)*M1**2))**(-1)) #Temperature at section in K
a = math.sqrt(k*R*T1) #Sound Velocity in m/s
C1 = M1*a #Gas Velocity at section in m/s
d = (P1*10**3)/(R*T1) #Density in kg/m**3
A1 = math.pi*D**2/4 #Cross-sectional Area
m = d*A1*C1 #Mass flow rate through nozzle in kg/s
#Output
print 'A)At section: \
\nMach number is %3.1f \
\nTemperature is %3.1f K \
\nVelocity is %3.3f m/s \
\nB)Mass flow rate through nozzle is %3.3f kg/s'%(M1,T1,C1,m)
```

In [75]:

```
import math
#Input data
mol = 4. #Molecular weight of gas in kg/mol
k = 1.3 #Adiabatic consmath.tant
C1 = 150. #Gas Velocity at section-1 in m/s
P1 = 100. #Pressure of duct at section-1 in kPa
T1 = 15.+273 #Temperature at section-1 in K
T2 = -10.+273 #Temperature at section-2 in K
Ri = 8314. #Ideal gas consmath.tant in J/mol-K
#Calculation
R = Ri/mol #Specific gas consmath.tant in J/kg-K
a1 = math.sqrt(k*R*T1) #Sound velocity at section-1 in m/s
M1 = C1/a1 #Mach number at section-1
t1 = 0.9955 #Static to Stagnation temperature ratio at entry from gas tables @M1,k = 1.3
To = T1/t1 #Stagantion temperature in K
p1 = 0.9815 #Static to Stagnation pressure ratio at entry from gas tables @M1,k = 1.3
Po = P1/p1 #Stagnation pressure in kPa
t2 = T2/To #Static to Stagnation temperature ratio at exit
M2 = 0.82 #Amch number at section-2 from gas tables @t2,k = 1.3
p2 = 0.659 #Static to Stagnation pressure ratio at exit from gas tables @M2,k = 1.3
P2 = Po*p2 #Pressure at section-2 in kPa
a2 = math.sqrt(k*R*T2) #Sound velocity at section-2 in m/s
C2 = M2*a2 #Gas Velocity at section-2 in m/s
#Output
print 'At the second point: \
\nMach number is %3.2f \
\nPressure is %3.3f kPa \
\nVelocity is %3.2f m/s'%(M2,P2,C2)
```

In [76]:

```
import math
#Input data
A1 = 10. #Inlet area in cm**2
C1 = 80. #Inlet Air velocity in m/s
T1 = 28.+273 #Inlet temperature in K
P1 = 700. #Inlet Pressure in kPa
P2 = 250. #Exit pressure in kPa
k = 1.4 #Adiabatic consmath.tant
R = 287. #Specific gas consmath.tant in J/kg-K
#Calculation
a1 = math.sqrt(k*R*T1) #Sound velocity at inlet in m/s
M1 = C1/a1 #Mach number at inlet
t1 = 0.989 #Static to Stagnation temperature ratio at entry from gas tables @M1,k = 1.4
To = T1/t1 #Stagantion temperature in K
p1 = 0.964 #Static to Stagnation pressure ratio at entry from gas tables @M1,k = 1.4
Po = P1/p1 #Stagnation pressure in kPa
p2 = P2/Po #Static to Stagnation pressure ratio
M2 = 1.335 #Mach number at exit
t2 = 0.737 #Static to Stagnation temperature ratio at exit from gas tables @M2,k = 1.4
T2 = To*t2 #Stagnation temperatur in K
a2 = math.sqrt(k*R*T2) #Sound velocity at exit in m/s
C2 = M2*a2 #Exit Air velocity in m/s
d1 = (P1*10**3)/(R*T1) #Density at inlet in kg/m**3
m = d1*A1*C1*10**-4 #Mass flow rate in kg/s
#Output
print 'A)Mass flow rate is %3.3f kg/s \
\nB)Velocity at the exit is %3.2f m/s'%(m,C2)
```

In [78]:

```
import math
#Input data
V = 5. #Volume of air in m**3
Ae = 10.*10**-4 #Exit area in cm**2
To = 60.+273 #Temperature inside in the math.tank in K
Po1 = 40. #Intial total pressure in bar
Po2 = 2. #Final total pressure in bar
P = 1. #Discharge pressure in bar
R = 287. #Specific gas consmath.tant in J/kg-K
#Calculation
#Here pressure ratios P/Po1 and P/Po2 are always less than critical pressure ratio therefore flow is choked i.e. M = 1 at exit
Gp = (0.0404184*Ae)/math.sqrt(To) #Mass flow rate by Stagnation pressure i.e. m/Po
#Differentiating m = (P*V)/(R*To) w.r.t. time and intrgrating resulting equation we get following expression.
t = -(V/(R*To*Gp))*math.log(Po2/Po1) #The time required for math.tank pressure to decrease from Po1 to Po2 in sec
#Output
print 'The time required for tank pressure to decrease from %i bar to %i bar is %3.2f sec'%(Po1,Po2,t)
```