In [1]:

```
import math
#Input data
M1 = 0.25 #Mach number at entrance
M2 = 1 #Mach number at exit
D = 0.04 #inner tude diameter in m
f = 0.002 #frictional factor
#Calculation
X1 = 8.537 #frictional consmath.tant fanno parameter at entry from gas tables @M1 = 0.25
X2 = 0 #frictional consmath.tant fanno parameter at exit from gas tables @M2 = 1
X = X1-X2 #overall frictional consmath.tant fanno parameter i.e. (4*f*L)/D
L = (X*D)/(4*f) #Length of the pipe in m
#Output
print 'A)Length of the pipe is %3.3f m'%(L)
```

In [2]:

```
import math
#Input data
M1 = 0.1 #Mach number at entrance
M2 = 0.5 #Mach number at a section
M3 = 1 #Mach number at critical condition
D = 0.02 #Diameter of duct in m
f = 0.004 #Frictional factor
#Calculation
X1 = 66.922 #frictional consmath.tant fanno parameter from gas tables @M1 = 0.1
X2 = 1.069 #frictional consmath.tant fanno parameter from gas tables @M2 = 0.5
X3 = 0 #frictional consmath.tant fanno parameter from gas tables @M3 = 1
X4 = X1-X3 # #frictional consmath.tant fanno parameter from M2 = 0.1 to M3 = 1
L1 = (X4*D)/(4*f) #Length of the pipe in m
X5 = X2-X3 #frictional consmath.tant fanno parameter from M2 = 0.5 to M3 = 1
L2 = (X5*D)/(4*f) #Addition length of the pipe required to accelerate into critical condition in m
L = L1-L2 #Length of the pipe required to accelerate the flow from M1 = 0.1 to M2 = 0.5 in m
#Output
print 'A)Length of the pipe required to accelerate the flow from M1 = %3.1f to M2 = %3.1f is %3.3f m \
\nB)Additional length required to accelerate into critical condition is %3.5f m'%(M1,M2,L,L2)
```

In [3]:

```
import math
#Input data
D = 0.05 #inner pipe diameter in m
Po = 10 #Stagnation Pressure at reservoir in bar
To = 400 #Stagnation temperature at reservoir in K
f = 0.002 #frictional factor
M1 = 3 #Mach number at entrance
M2 = 1 #Mach number at end of pipe
R = 287 #Gas consmath.tant in J/kg-K
k = 1.4 #Adiabatic consmath.tant
#Calculation
X1 = 0.522 #frictional consmath.tant fanno parameter from gas tables @M1 = 3
X2 = 0 #frictional consmath.tant fanno parameter from gas tables @M2 = 1
X = X1-X2 #overall frictional consmath.tant fanno parameter
L = (X*D)/(4*f) #Length of the pipe in m
p1 = 0.0272 #Pressure ratio from gas tables (M = 3,k = 1.4,isentropiC)
P1 = p1*Po #Static pressure at entrance in bar
t1 = 0.3571 #Temperature ratio from gas tables (M = 3,k = 1.4,isentropic)
T1 = t1*To #Static temperature at entrance in K
d1 = (P1*10**5)/(R*T1) #Density of air in kg/m**3, P1 in Pa
a1 = math.sqrt(k*R*T1) #Sound velocity in m/s
C1 = a1*M1 #air velocity in m/s
A1 = (math.pi*D**2)/4 #Cross sectional area of pipe in m**2
m = d1*A1*C1 #Mass flow rate in kg/s
#Output
print 'A)Length of the pipe is %3.2f m \
\nB)Mass flow rate is %3.4f kg/s'%(L,m)
```

In [6]:

```
import math
#Input data
C1 = 235. #Velocity at entrance in m/s
P1 = 13. #Static Pressure at entry in bar
P2 = 10. #Static Pressure at a point in duct in bar
T1 = 543. #Static temperature at entry in Kelvin
D = 0.15 #inner duct diameter in m
f = 0.005 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
a1 = math.sqrt(k*R*T1) #Sound velocity in m/s
M1 = C1/a1 #Mach number at entry
p1 = 2.138 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Pt = P1/p1 #Static critical pressure in bar
t1 = 1.143 #Static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Tt = T1/t1 #Static critical temperature in K
c1 = 0.534 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Ct = C1/c1 #Critical velocity in m/s
p2 = 1.644 #Pressure ratio from gas tables (fanno flow tables,k = 1.4)
M2 = 0.64 #Mach number from gas tables (fanno flow tables,k = 1.4,p2)
c2 = 0.674 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,p2)
C2 = Ct*c2 #Air velocity at P2 in m/s
t2 = 1.109 #Temperature ratio from gas tables (fanno flow tables,k = 1.4,p2)
T2 = t2*Tt #Satic temperature at P2 is K
X1 = 1.06922 #frictional consmath.tant fanno parameter from gas tables @M1
X2 = 0.353 #frictional consmath.tant fanno parameter from gas tables @M2
X = X1-X2 #overall frictional consmath.tant fanno parameter
L = (X*D)/(4*f) #Length of the pipe in m
#Output
print 'A)Temperature and velocity at section of the duct where the pressure has dropped to %3i bar \
\ndue to friction are %3.1f K and %3.2f m/s \
\nB)The Distance between two section is %3.3f m'%(P2,T2,C2,L)
```

In [9]:

```
import math
#Input data
P1 = 120. #Static pressure at entrance in bar
T1 = 313. #Static temperature at entry in Kelvin
M1 = 2.5 #Mach number at entrance
M2 = 1.8 #Mach number at exit
D = 0.2 #inner pipe diameter in m
f = 0.01/4 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
a1 = math.sqrt(k*R*T1) #Sound velocity in m/s
C1 = a1*M1 #air velocity in m/s
p1 = 0.292 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 2.5)
Pt = P1/p1 #Static critical pressure in kPa
t1 = 0.533 #Static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 2.5)
Tt = T1/t1 #Static critical temperature in K
c1 = 1.826 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 2.5)
Ct = C1/c1 #Critical velocity in m/s
X1 = 0.432 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1 = 3
X2 = 0 #frictional consmath.tant fanno parameter from gas tables @M2 = 1
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L1 = (X3*D)/(4*f) #Maximum length of the pipe in m
p2 = 0.474 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 1.8)
P2 = Pt*p2 #Static pressure in kPa
t2 = 0.728 #static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 1.8)
T2 = Tt*t2 #Static temperature in K
c2 = 1.536 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 1.8)
C2 = c2*Ct #Critical velocity in m/s
X4 = 0.242 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M = 1.8
X5 = X4-X2 #overall frictional consmath.tant fanno parameter
L2 = (X5*D)/(4*f) #Length between sonic and oulet section
L = L1-L2 #Length of the pipe in m
#Output
print 'A)Maximum length of the pipe is %3.2f m \
\nB)Properties of air at sonic condition: \
\nPressure is %3i kPa \
\nTemperature is %3.2f K \
\nVelocity is %3.1f m/s \
\nC)Length of the pipe is %3.1f m \
\nD)Properties of air at M2 = %3.1f: \
\nPressure is %3i kPa \
\nTemperature is %3.2f K \
\nVelocity is %3.2f m/s'%(L1,Pt,Tt,Ct,L,M2,P2,T2,C2)
# note : rounding off error.
```

In [11]:

```
import math
#Input data
M1 = 0.25 #Mach number at entrance
ds = 0.124 #Change in entropy in kJ/kg-K
P1 = 700. #Static pressure at entrance in bar
T1 = 333. #Static temperature at entry in Kelvin
D = 0.05 #inner pipe diameter in m
f = 0.006 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 0.287 #Gas consmath.tant in kJ/kg-K
#Calculation
p1 = math.exp(ds/R) #Ratio of Stagnation pressure at inlet to outlet
t1 = 0.987 #Ratio of Static Temperature to Stagnation temperature at entry from gas tables @M1
To1 = T1/t1 #Stagnation temperature at entry in K
p2 = 0.957 #Ratio of Static pressure to Stagnation pressure at entry from gas tables @M1
Po1 = P1/p2 #Stagnation pressure at entry in kPa
Po2 = Po1/p1 #Stagnation pressure at exit in kPa
a1 = math.sqrt(k*R*10**3*T1) #Sound velocity in m/s, R in J/kg
C1 = a1*M1 #air velocity in m/s
p3 = 4.3615 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 0.25)
Pt = P1/p3 #Static critical pressure in kPa
t1 = 1.185 #Static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 0.25)
Tt = T1/t1 #Static critical temperature in K
c1 = 0.272 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 0.25)
Ct = C1/c1 #Critical velocity in m/s
p4 = 2.4065 #Pressure ratio at entry from gas tables @M1,k
Pot = Po1/p4 #Stagnation pressure at critical state in kPa
X1 = 8.537 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k
p5 = Po2/Pot #Pressure ratio
M2 = 0.41 #Mach number at exit from gas tables @p5
p6 = 2.629 #Pressure ratio at exit from gas tables @p5
P2 = Pt*p6 #Exit pressure in kPa
t2 = 1.161 #Temperature ratio at exit from gas tables @p5
T2 = Tt*t2 #Exit temperature in K
c2 = 0.4415 #Velocity ratio at exit from gas tables @p5
C2 = Ct*c2 #Exit velocity in m/s
X2 = 2.141 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L = (X3*D)/(4*f) #Length of the pipe in m
#Output
print 'A)Mach number at exitsection 2) is %3.2f \
\nB)Properties at exitsection 2): \
\nPressure is %3.2f kPa \
\nTemperature is %3i K \
\nVelocity is %3.3f m/s \
\nC)Length of the duct is %3.3f m'%(M2,P2,T2,C2,L)
```

In [12]:

```
import math
#Input data
M1 = 0.25 #Initial Mach number
M2 = 0.75 #Final mach number
P1 = 1.5 #Inlet pressure in bar
T1 = 300. #Inlet temperature in K
k = 1.4 #Adiabatic consmath.tant
R = 0.287 #Gas consmath.tant in kJ/kg-K
#Calculation
a1 = math.sqrt(k*R*10**3*T1) #Sound velocity in m/s, R in J/kg
C1 = a1*M1 #air velocity in m/s
p1 = 4.3615 #Pressure ratio at entry from gas tables @M1,k
Pt = P1/p1 #Static critical pressure in kPa
c1 = 0.272 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M1)
Ct = C1/c1 #Critical velocity in m/s
p2 = 1.385 #Pressure ratio at exit from gas tables @M2,k
P2 = Pt*p2 #Exit pressure in bar
c2 = 0.779 #Velocity ratio at exit from gas tables @M2,k
C2 = Ct*c2 #Exit velocity in m/s
#Output
print 'Final pressure and velocity are %3.4f bar and %3.2f m/s'%(P2,C2)
```

In [15]:

```
import math
#Input data
T1 = 333. #Inlet temperature in K
D = 0.05 #inner duct diameter in m
f = 0.005/4 #frictional factor
L = 5. #Length of the pipe in m
Pt = 101. #Exit pressure in kPa, Pt = P2 Since flow is choked
M2 = 1. #Mach number at exit math.since pipe is choked
k = 1.4 #Adiabatic consmath.tant
R = 0.287 #Gas consmath.tant in kJ/kg-K
#Calculation
X = (4*f*L)/D #frictional consmath.tant fanno parameter
M1 = 0.6 #Inlet mach number
t1 = 1.119 #Temperature ratio at entry from fanno flow gas tables @M1,k
Tt = T1/t1 #Static critical temperature in K
at = math.sqrt(k*R*10**3*Tt) #Sound velocity in m/s, R in J/kg
Ct = at #air velocity in m/s
d_t = Pt/(R*Tt) #Density at exit in kg/m**3
At = math.pi*D**2/4 #Critical area in m**2
m = d_t*At*Ct #Mass flow rate in kg/s
#Output
print 'A)Mach number at inlet is %3.1f \
\nB)Mass flow rate is %3.5f kg/s \
\nC)Exit temperature is %3.3f K'%(M1,m,Tt)
# note : rouding off error.
```

In [18]:

```
import math
#Input data
m = 8.25 #Mass flow rate in kg/s
M1 = 0.15 #Mach number at entrance
M2 = 0.5 #Mach number at exit
P1 = 345. #Static pressure at entrance in kPa
T1 = 38.+273 #Static temperature at entry in Kelvin
f = 0.005 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 0.287 #Gas consmath.tant in kJ/kg-K
#calculation
d1 = (P1*10**3)/(R*10**3*T1) #Density of air in kg/m**3, P1 in Pa
a1 = math.sqrt(k*R*10**3*T1) #Sound velocity in m/s, R in J/kg
C1 = a1*M1 #air velocity in m/s
A1 = m/(d1*C1) #Inlet area in m**2
D = (math.sqrt((4*A1)/(math.pi)))*10**3 #inner duct diameter in mm
p1 = 7.3195 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 0.15)
Pt = P1/p1 #Static critical pressure in kPa
t1 = 1.1945 #Static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 0.15)
Tt = T1/t1 #Static critical temperature in K
c1 = 0.164 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 0.15)
Ct = C1/c1 #Critical velocity in m/s
p2 = 0.984 #Pressure ratio at entry from gas tables (fanno flow tables,k = 1.4,M = 0.15)
Po1 = P1/p2 #Stagnation pressure at entry in kPa
p3 = 3.928 #Stagnation pressure ratio at entry from gas tables (fanno flow tables,k = 1.4,M = 0.15)
Pot = Po1/p3 #Stagnation pressure at critical state in kPa
X1 = 28.354 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k
p5 = 2.138 #Pressure ratio at exit from gas tables (fanno flow tables,k = 1.4,M2)
P2 = Pt*p5 #Exit pressure in kPa
t2 = 1.143 #Temperature ratio at exit from gas tables (fanno flow tables,k = 1.4,M2)
T2 = Tt*t2 #Exit temperature in K
c2 = 0.534 #Velocity ratio at exit from gas tables (fanno flow tables,k = 1.4,M2)
C2 = Ct*c2 #Exit velocity in m/s
p6 = 1.34 #Stagnation pressure ratio at exit from gas tables (fanno flow tables,k = 1.4,M2)
Po2 = Pot*p6 #Stagnation pressure at exit in kPa
SPL = Po1-Po2 #Stagnation Pressure lose in kPa
X2 = 1.069 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L = (X3*D*10**-3)/(4*f) #Length of the duct in m
#verification
a2 = math.sqrt(k*R*10**3*T2) #Sound velocity in m/s, R in J/kg
M2_v = C2/a2 #air velocity in m/s
#Output
print 'A)Length of the duct is %3.2f m \
\nB)Diameter of the duct is %3i mm \
\nC)Pressure and diameter at exit are %3.2f kPa, and %3i mm respectively \
\nD)Stagnation Pressure lose is %3i kPa \
\nE)using exit velocity %3.2f m/s, \
\ntemperature %3.2f K \
\nMach number is found to be %3.2f'%(L,D,P2,D,SPL,C2,T2,M2_v)
# note : rouding off error.
```

In [20]:

```
import math
#Input data
M1 = 0.25 #Mach number at entrance
f = 0.01/4 #frictional factor
D = 0.15 #inner pipe diameter in m
p1 = 0.8 #Stagnation pressure ratio at exit to entry when loss in stagnation pressure is 20%
M3 = 0.8 #Mach number at a section
#Calculation
p2 = 2.4065 #Ratio of Stagnation pressure at entry from gas tables @M1,k = 1.4
X1 = 8.537 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1
p3 = p1*p2 #Ratio of Stagnation pressure at exit
M2 = 0.32 #Exit mach number at p1 = 0.8
X2 = 4.447 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2
L1 = (X1*D)/(4*f) #Length of the pipe in m
L2 = (X2*D)/(4*f) #Length of the pipe in m
L = L1-L2 #Overall length of the duct in m
p4 = 1.038 #Stagnation pressure ratio from M = 1 to M3
PL = (1-(p4/p2))*100 #Percentage of stagnation pressure from inlet to section at which M3 in percent
#Output
print 'A)Length of the pipe is %3.2f m \
\nB)Mach number at this exit is %3.2f \
\nC)Percentage of stagnation pressure from inlet to section at which M = %3.1f is %3.2f percent \
\nD)Maximum length to reach choking condition is %3.3f m'%(L,M2,M3,PL,L1)
```

In [21]:

```
import math
#Input data
D = 0.3 #inner duct diameter in m
P1 = 10. #Static pressure at entrance in bar
T1 = 400. #Static temperature at entry in Kelvin
M1 = 3. #Mach number at entrance
M2 = 1. #Mach number at exit
k = 1.3 #Adiabatic consmath.tant
R = 287. #Specific Gas consmath.tant in J/kg-K, wrong printing in question
f = 0.002 #frictional factor
#Calculation
p1 = 0.233 #Pressure ratio from gas tables (M = 3,k = 1.4,isentropic)
Pt = P1/p1 #Static pressure at entrance in bar
t1 = 0.489 #Temperature ratio from gas tables (M = 3,k = 1.4,isentropic)
Tt = T1/t1 #Static temperature at entrance in K
X1 = 0.628 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.3
L1 = (X1*D)/(4*f) #Length of the pipe in m
d_t = (Pt*10**5)/(R*Tt) #Density at critical state in kg/m**3, Pt in Pa
at = math.sqrt(k*R*Tt) #Sound velocity in m/s, R in J/kg
Ct = at #air velocity in m/s
At = (math.pi*D**2)/4 #Critical area in m**2
m = d_t*At*Ct #Mass flow rate in kg/s
#Output
print 'A)Length of the pipe is %3.2f m \
\nB)Mass flow rate is %3.3f kg/s'%(L1,m)
```

In [23]:

```
import math
#Input data
M1 = 0.25 #Mach number at entrance
f = 0.04/4 #frictional factor
D = 0.15 #inner duct diameter in m
p1 = 0.9 #Stagnation pressure ratio at exit to entry when loss in stagnation pressure is 10%
ds = 190 #/Change in entropy in J/kg-K
k = 1.3 #Adiabatic consmath.tant
R = 287 #Specific Gas consmath.tant in J/kg-K, wrong printing in question
#Calculation
p2 = 2.4064 #Ratio of stagnation pressures at inlet to critical state from gas tables fanno flow tables @M1,k = 1.3
X1 = 8.537 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.3
p3 = p1*p2 #Ratio of stagnation pressures at exit to critical state from gas tables fanno flow tables @M1,k = 1.3
M2 = 0.28 #Mach number at p1 = 0.9 from gas tables @p3
X2 = 6.357 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.3
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L1 = (X3*D)/(4*f) #Length of the pipe in m
p4 = math.exp(ds/R) #Ratio of Stagnation pressure at entry to Stagnation pressure where ds = 190
p5 = p1/p4 #Ratio of Stagnation pressures where ds = 190 to critical state
M3 = 0.56 #Mach number where ds = 190
X4 = 0.674 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M3,k = 1.3
X5 = X1-X4 #overall frictional consmath.tant fanno parameter
L2 = (X5*D)/(4*f) #Length of the pipe in m
#Output
print 'A)Length of the pipe is %3.3f m \
\nB)Length of the pipe would require to rise entropy by %3i J/kg-K is %3.5f m \
\nC)Mach number is %3.2f'%(L1,ds,L2,M3)
```

In [25]:

```
import math
#Input data
Po1 = 200. #Stagantion pressure at inlet in kPa
To1 = 303. #Stagnation temperature at inlet in K
M1 = 0.2 #Inlet Mach number from diagram
D = 0.025 #inner tude diameter in m(mismath.sing data)
M2 = 0.8 #Outlet Mach number
f = 0.005/4 #frictional factor
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
t1 = 0.992 #Static to Stagnation temperature ratio at entry from gas tables (M1,k = 1.4,isentropic)
T1 = To1*t1 #Static temperature in K
p1 = 0.973 #Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropic)
P1 = Po1*p1 #Static pressure in kPa
p2 = 2.964 #Stagnation pressure ratio at inlet to critical state from gas tables (M1,k = 1.4,fanno flow)
Pot = Po1/p2 #Stagnation pressure at critical state in kPa
X1 = 14.533 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
p3 = 1.038 #Stagnation pressure ratio at outlet to critical state from gas tables (M1,k = 1.4,fanno flow)
Po2 = Pot*p3 #Stagnation pressure at exit in kPa
X2 = 0.073 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L1 = (X3*D)/(4*f) #Length of the pipe in m
SPL = (1-(p3/p2))*100 #Percentage decrease in stagnation pressure in percent
ds = R*math.log(Po1/Po2) #Change of entropy in kJ/kg-K
#Output
print 'A)Length of the pipe is %3.1f m \
\nB)Percentage decrease in stagnation pressure is %3.2f percent \
\nC)Change of entropy is %3.3f kJ/kg-K'%(L1,SPL,ds)
```

In [27]:

```
import math
#Input data
D1 = 0.03 #Inlet duct diameter in m
D2 = 0.015 #Throat diameter of duct in m
Po1 = 750. #Stagantion pressure at inlet in kPa
To1 = 450. #Stagnation temperature at inlet in K
f = 0.02/4 #frictional factor
L = 0.25 #Length of the duct in m
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
ar = (D1/D2)**2 #Ratio of areas
M1 = 2.94 #Mach number at inlet from gas tables (ar,k = 1.4,isentropic)
p1 = 0.0298 #Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropic)
P1 = Po1*p1 #Static pressure at inlet in kPa
t1 = 0.367 #Static to Stagnation temperature ratio at entry from gas tables (M1,k = 1.4,isentropic)
T1 = To1*t1 #Static temperature at inlet in K
a1 = math.sqrt(k*R*T1) #Sound velocity in m/s
C1 = a1*M1 #Air velocity at inlet in m/s
X1 = 0.513 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
p2 = 0.226 #Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
Pt = P1/p2 #Critical pressure in kPa
c1 = 1.949 #Static to Critical velocity ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
Ct = C1/c1 #Critical velocity in m/s
t2 = 0.439 #Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
Tt = T1/t2 #Critical temperature in K
L1 = (X1*D1)/(4*f) #Length of the pipe from inlet to critical state in m
L2 = L1-L #Length of the pipe from required point to critical state in m
X2 = (4*f*L2)/D2 #frictional consmath.tant fanno parameter
M2 = 2.14 #Mach number at inlet from gas tables (X2,k = 1.4,fanno flow)
p3 = 0.369 #Static to Critical pressure ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
P2 = Pt*p3 #Exit pressure in kPa
c2 = 1.694 #Static to Critical velocity ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
C2 = Ct*c2 #Exit velocity in m/s
t3 = 0.623 #Static to Critical temperature ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
T2 = t3*Tt #Exit temperature in K
#Output
print 'A)Maximum length of the pipe is %3.4f m \
\nB)Condition of air at exit: \
\nPressure is %3.2f kPa \
\nVelocity is %3.2f m/s \
\nTemperature is %3.2f K'%(L1,P2,C2,T2)
```

In [30]:

```
import math
#Input data
f = 0.002 #frictional factor
C1 = 130. #Air velocity at inlet in m/s
T1 = 400. #Inlet temperature at inlet in K
P1 = 250. #Inlet pressure at inlet in kPa
D = 0.16 #Inlet duct diameter in m
p1 = 0.8 #Stagnation pressure ratio at exit to entry when loss in stagnation pressure is 20%
L1 = 35. #Length of duct from inlet to required section
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
a1 = math.sqrt(k*R*T1) #Sound velocity in m/s
M1 = C1/a1 #Mach number at inlet
p2 = 0.9295 #Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropic)
Po1 = P1/p2 #Stagantion pressure at inlet in kPa
Po2 = 0.8*Po1 #Stagantion pressure at outlet in kPa
p3 = 1.89725 #Stagnation pressure ratio at inlet to critical state from gas tables (M1,k = 1.4,fanno flow)
Pot = Po1/p3 #Stagnation pressure at critical state in kPa
X1 = 4.273 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
p4 = 3.33725 #Static Pressure ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Pt = P1/p4 #Static critical pressure in kPa
t1 = 1.175 #Static temperature ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Tt = T1/t1 #Static critical temperature in K
c1 = 0.347 #Velocity ratio from gas tables (fanno flow tables,k = 1.4,M = 0.5)
Ct = C1/c1 #Critical velocity in m/s
p5 = Po2/Pot #Pressure ratio
M2 = 0.43 #Mach number at p1 = 0.8
X2 = 1.833 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L2 = (X3*D)/(4*f) #Length of the pipe in m, (from required section to critical state)
L3 = (X1*D)/(4*f) #Length of the pipe in m, (from required inlet to critical state)
L4 = L3-L1 #Length of the pipe in m
X4 = (4*f*L3)/D #frictional consmath.tant fanno parameter
M3 = 0.39 #Mach number at L1 = 35m
p6 = 2.767 #Static to Critical pressure ratio at outlet from gas tables,fanno flow tables @M3,k = 1.4
P2 = Pt*p6 #Exit pressure in kPa
t2 = 1.1645 #Static to Critical temperature ratio at outlet from gas tables,fanno flow tables @M3,k = 1.4
T2 = Tt*t2 #Exit temperature in K
c2 = 0.42087 #Static to Critical velocity ratio at outlet from gas tables,fanno flow tables @M3,k = 1.4
C2 = Ct*c2 #Exit velocity in m/s
#Output
print 'A)Length of pipe required for p = %3.1f m is %3.3f m \
\nB)Properties of air at section %3i from inlet: \
\nTemperature is %3.3f K \
\nPressure is %3.2f kPa \
\nVelocity is %3.1f m/s \
\nC)Maximum length of the pipe is %3.2f m'%(p1,L2,L1,T2,P2,C2,L3)
# rounding off error.
```

In [32]:

```
import math
#Input data
D = 0.3 #inner pipe diameter in m
Q = 1000. #Discharge in m**3/min
P2 = 150. #Exit pressure in kPa
T2 = 293. #Exit temperature in K
L1 = 50. #Length of the pipe in m
f = 0.005 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
A = math.pi*D**2/4 #Area of duct in m**2
C2 = Q/(A*60) #Exit air velocity in m/s
a2 = math.sqrt(k*R*T2) #Sound velocity in m/s
M2 = C2/a2 #Exit mach number
p1 = 1.54 # #Static to Critical pressure ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
Pt = P2/p1 #Critical pressure in kPa
t1 = 1.10 #Static to Critical temperature ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
Tt = T2/t1 #Critical temperature in K
X1 = 0.228 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
L2 = (X1*D)/(4*f) #Length of the pipe in m
L2 = L1+L2 #Overall length of pipe from inlet to critical state in m
X2 = (4*f*L2)/D #frictional consmath.tant fanno parameter for M1
M1 = 0.345 #Inlet Mach number from gas tables fanno flow tables @X2,k = 1.4
p2 = 3.14 #Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
P1 = Pt*p2 #Static pressure at inlet in kPa
t2 = 1.17 #Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
T1 = Tt*t2 #Static temperature at inlet in K
#Output
print 'A)Mach number at the exit is %3.3f \
\nB)Inlet pressure and temperature are %3.3f kPa and %3.2f K'%(M2,P1,T1)
```

In [34]:

```
import math
#Input data
D = 0.0254 #inner pipe diameter in m
f = 0.003 #frictional factor
M1 = 2.5 #Inlet Mach number
To1 = 310. #Stagnation temperature at inlet in K
P1 = 0.507 #Static pressure at inlet in kPa
M2 = 1.2 #Exit mach number
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
t1 = 0.4444 #Static to Stagnation temperature ratio at entry from gas tables (M1,k = 1.4,isentropic)
T1 = To1*t1 #Static temperature at inlet in K
p1 = 0.05853 #Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropic)
Po1 = P1/p1 #Stagantion pressure at inlet in kPa
a1 = math.sqrt(k*R*T1) #Sound velocity at inlet in m/s, R in J/kg
C1 = a1*M1 #air velocity at inlet in m/s
c1 = 2.95804 #Static to Critical velocity ratio at inlet from gas tables,isothermal tables @M1,k = 1.4
Ctt = C1/c1 #Critical velocity at isothermal state in m/s
p2 = 0.33806 #Static to Critical pressure ratio at inlet from gas tables,isothermal @M1,k = 1.4
Ptt = P1/p2 #Critical pressure at isothermal state in bar
p3 = 3.61691 #Stagnation pressure ratio at inlet to isothermal state from gas tables,isothermal tables @M1,k = 1.4
Pott = Po1/p3 #Critical pressure at isothermal state in K
t2 = 1.968748 #Stagnation temperature ratio at inlet to isothermal state from gas tables,isothermal tables @M1,k = 1.4
Tott = To1/t2 #Critical temperature at isothermal state in K
X1 = 1.28334 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
c2 = 1.4186 #Static to Critical velocity ratio at exit from gas tables,isothermal tables @M2,k = 1.4
C2 = Ctt*c2 #Exit velocity in m/s
p4 = 0.7043 #Static to Critical pressure ratio at inlet from gas tables,isothermal @M2,k = 1.4
P2 = Ptt*p4 #Exit pressure in bar
p5 = 1.07026 #Stagnation pressure ratio at inlet to isothermal state from gas tables,isothermal tables @M2,k = 1.4
Po2 = Pott*p5 #Stagnation pressure at exit in bar
t3 = 1.127 #Stagnation temperature ratio at inlet to isothermal state from gas tables,isothermal tables @M2,k = 1.4
To2 = Tott*t3 #Stagnation temperature at exit in bar
T2 = T1 #Exit temperature in K, Since isothermal flow
X2 = 0.19715 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
X3 = X1-X2 #Overall frictional consmath.tant fanno parameter
L1 = (X3*D)/(4*f) #Length of the pipe in m
d1 = (P1*10**5)/(R*T1) #Density of air in kg/m**3, P1 in Pa
A1 = (math.pi*D**2)/4 #Cross sectional area of pipe in m**2
m = d1*A1*C1 #Mass flow rate in kg/s
#Output
print 'At M = %3.1f : A)Static pressure and static temperature are %3.5f bar and %3.3f K respectively \
\nB)Stagnation pressure and temperature are %3.4f bar and %3.3f K respectively \
\nC)Velocity of air is %3.3f m/s \
\nD)Distance of the section from innlet is %3.3f m \
\nE)Mass flow rate is %3.5f kg/s'%(M2,P2,T2,Po2,To2,C2,L1,m)
```

In [38]:

```
import math
#Input data
D = 0.12 #inner duct diameter in m
f = 0.004 #frictional factor
M1 = 0.4 #Inlet Mach number
P1 = 300. #Static pressure at inlet in kPa
T1 = 310. #Static temperature at inlet in K
M2 = 0.6 #Exit mach number
k = 1.4 #Adiabatic consmath.tant
#Calculation
p1 = 2.118 #Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
Pt = P1/p1 #Critical pressure in kPa
X1 = 1.968 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
p2 = 1.408 #Static to Critical pressure ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
P2 = Pt*p2 #Exit pressure in kPa
X2 = 0.299 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
X3 = X1-X2 #Overall frictional consmath.tant fanno parameter
L1 = (X3*D)/(4*f) #Length of the pipe in m
T2 = T1 #Exit temperature in K, Since isothermal flow
Ttt = T1 #Critical temperature at critical state, Since isothermal flow
Mtt = 1/math.sqrt(k) #Limiting Mach number
L2 = (X1*D)/(4*f) #Length of the duct required to attain limiting mach number in m
#Output
print 'A)Length of the duct required to chnage the mach number to %3.1f is %3.4f m \
\nB)Pressure and temperature at M = %3.1f is %.f kPa and %3i K respectively \
\nC)Length of the duct required to attain limiting mach number is %3.3f m \
\nD)State of air at limiting mach number %3.3f is subsonic'%(M2,L1,M2,P2,T2,L2,Mtt)
# rounding off error.
```

In [1]:

```
import math
from numpy import roots
#Input data
m = 0.32 #Mass flow rate in kg/s
L = 140. #Length of the pipe in m
P1 = 800. #Inlet pressure in N/m**2, wrong units in textbook
T1 = 288. #Inlet temperature in K
P2 = 600. #Outlet pressure in N/m**2, wrong units in textbook
f = 0.006 #frictional factor
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
#Umath.sing Adiabatic Equation d = 1/((((((math.pi*(d/2)**2)**2)/(2*m**2*R*T))*(P1**2-P2**2))-(math.log(P1/P2)))/(2*f*L)) and converting into 5th degree polynomial of d
a = (math.pi**2*(P1**2-P2**2))/(32*m**2*R*T1) #Coefficient of power 5
b = math.log(P1/P2) #Coefficient of power 1
c = 2*f*L #Coefficient of consmath.tant
#p5 = poly([-c -b 0 0 0 a],'d','coeff') #Solving polynomial of degree 5
d = roots([a,0,0,0,-b, -c]) #Command to find roots
#Output
print ("Possible values for diameter of pipe are:") #Displays whatever within paranthesis
print (d) #To print lay roots
print 'Therefore Diameter of the pipe is : %.1f m'%d[0].real
```

In [43]:

```
import math
#Input data
Q = 225./60 #Discharge in m**3/s
T2 = 293. #Exit temperature in K
P2 = 1.25 #Exit pressure in bar
L1 = 30. #Length of the pipe in m
D = 0.15 #Duct diameter in m
f = 0.02/4 #frictional factor
k = 1.4 #Adiabatic consmath.tant
R = 287. #Gas consmath.tant in J/kg-K
#Calculation
A = math.pi*D**2/4 #area in m**2
C2 = Q/A #Exit air velocity in m/s
a2 = math.sqrt(k*R*T2) #Exit sound velocity in m/s
M2 = C2/a2 #Exit mach number
p1 = 1.703 #Static to Critical pressure ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
Pt = P2/p1 #Critical pressure in bar
c1 = 0.654 #Static to Critical velocity ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
Ct = C2/c1 #Critical velocity in m/s
t1 = 1.114 #Static to Critical temperature ratio at outlet from gas tables,fanno flow tables @M2,k = 1.4
Tt = T2/t1 #Critical temperature in K
X1 = 0.417 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
X2 = (4*f*L1)/D #frictional consmath.tant fanno parameter
X3 = X1+X2 #overall frictional consmath.tant fanno parameter
M1 = 0.32 #Mach number at entrance
p2 = 3.385 #Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
P1 = Pt*p2 #Static pressure at inlet in bar
c2 = 0.347 #Static to Critical velocity ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
C1 = Ct*c2 #Air velocity at inlet in m/s
t2 = 1.176 #Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4
T1 = Tt*t2 #Static temperature at inlet in K
#Output
print 'Required Inlet Condition: \
\nPressure is %3.4f bar \
\nVelocity is %3.3f m/s \
\nTemperature is %3.1f K'%(P1,C1,T1)
```

In [44]:

```
import math
#Input data
D1 = 0.134 #Inlet duct diameter in m
Po1 = 7 #Stagnation pressure at inlet in bar
P1 = 0.245 #Static pressure at 5*D1 i.e. L1 in bar
P2 = 0.5 #Static pressure at 33*D1 i.e. L2 in bar
D2 = 0.0646 #throat diameter in m
L1 = 5*D1 #Length of nozzle till section-1 in m
L2 = 33*D1 #Length of nozzle till section-2 in m
#Calculation
ar = (D1/D2)**2 #Ratio of areas
p1 = P1/Po1 #Pressure ratio
APR1 = p1*ar #Area Pressure ratio i.e. (A1*P1)/(At*Po1)
M1 = 2.54 #Mach number at inlet from isentropic gas tables @APR1
X1 = 0.44 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4
APR2 = 0.3073 #Area Pressure ratio i.e. (A2*P2)/(At*Po1)
M2 = 1.54 #Exit mach number
X2 = 0.151 #frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4
X3 = X1-X2 #overall frictional consmath.tant fanno parameter
L3 = L2-L1 #Length of the nozzle (Section-1 to Section-2) in m
f = (X3*D1)/(4*L3) #frictional factor
#Output
print 'A)Mach number at %3.3f m and %3.3f m are %3.2f and %3.2f respectively \
\nB)Mean value of friction between two sections is %3.5f'%(L1,L2,M1,M2,f)
```