summaryrefslogtreecommitdiff
path: root/Gas_Dynamics_and_Jet_Propulsion_by_P._Murugaperumal/ch5.ipynb
blob: e48f9ea6e22f006f23fe56e7a0b2c8ede3b054eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
{
 "metadata": {
  "name": "",
  "signature": "sha256:48c3c13129b0ce3ee083feadd095d84beabf52cb58d3a61a7cd29360c1b4aee6"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5 : Normal and Oblique Shock"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.1 page : 18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Input data\n",
      "Px = 150. \t\t\t\t#Pressure before the shock in kPa\n",
      "Tx = 25.+273 \t\t\t\t#Temperature before the shock in K\n",
      "Py = 350. \t\t\t\t#Pressure just after the shock in kPa\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculations\n",
      "p1 = Py/Px \t\t\t\t#Pressure ratio \n",
      "Mx = 1.4638 \t\t\t\t#Mach number before the shock\n",
      "My = 0.716 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "t1 = 1.294 \t\t\t\t#Temperature ratio after and before the shock from gas tables @p1\n",
      "Ty = t1*Tx \t\t\t\t#Temperature ratio after the shock in K\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Cx = ax*Mx \t\t\t\t#Velocity of gas before the shock in m/s\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = ay*My \t\t\t\t#Velocity of gas after the shock in m/s\n",
      "p2 = 0.942 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @p1\n",
      "ds = R*math.log(1/p2) \t\t\t\t#Change in entropy in J/kg-K\n",
      "p3 = 3.265 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @p1\n",
      "Poy = p3*Px \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "Pox = Poy/p2 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "pr_loss = Pox-Poy \t\t\t\t#Loss of stagnation pressure of air in kPa\n",
      "dd = (1000/R)*((Py/Ty)-(Px/Tx)) \t\t\t\t#Increase in density of air in kg/m**3\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Mach number before shock is %3.4f \\\n",
      "\\nB)After shock:    \\\n",
      "\\nMach number is %3.3f    \\\n",
      "\\nStatic temperature is %3.3f K    \\\n",
      "\\nVelocity is %3.2f m/s \\\n",
      "\\nC)Increase in density of air is %3.2f kg/m**3 \\\n",
      "\\nD)Loss of stagnation pressure of air is %3.2f kPa \\\n",
      "\\nE)Change in entropy is %3.3f J/kg-K'%(Mx,My,Ty,Cy,dd,pr_loss,ds)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Mach number before shock is 1.4638 \n",
        "B)After shock:    \n",
        "Mach number is 0.716    \n",
        "Static temperature is 385.612 K    \n",
        "Velocity is 281.83 m/s \n",
        "C)Increase in density of air is 1.41 kg/m**3 \n",
        "D)Loss of stagnation pressure of air is 30.15 kPa \n",
        "E)Change in entropy is 17.148 J/kg-K\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2 page : 19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Tx = 350. \t\t\t\t#Temperature before the shock in K\n",
      "Px = 137.8 \t\t\t\t#Pressure before the shock in kPa\n",
      "Cx = 750. \t\t\t\t#Velocity before the shock in m/s\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Mx = Cx/ax \t\t\t\t#Mach number before the shock\n",
      "My = 0.577 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 4.5 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p1 \t\t\t\t#Static pressure after shock in kPa\n",
      "t1 = 1.687 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p2 = 5.641 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = Px*p2 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "p3 = 0.721 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Pox = Poy/p3 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "ds = R*math.log(1/p3) \t\t\t\t#Change in entropy in J/kg-K\n",
      "t2 = 0.555 \t\t\t\t#Static to Stagnation temperature ratio before shock from isentropic gas tables @Mx,k = 1.4\n",
      "Tox = Tx/t2  \t\t\t\t#Stagnation temperature before shock in K\n",
      "p4 = 0.128 \t\t\t\t#Static to Stagnation pressure ratio from isentropic gas tables @Mx,k = 1.4\n",
      "Pox = Px/p4 \t\t\t\t#Stagnation pressure in kPa\n",
      "t4 = 0.937 \t\t\t\t#Static to Stagnation temperature ratio before shock from normal shock gas tables @Mx,k = 1.4 (Tox = Toy CheckenD)\n",
      "Toy = Ty/t4 \t\t\t\t#Stagnation temperature after shock in K\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = (My*ay) \t\t\t\t#Velocity of gas after the shock in m/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)At inlet to shock:    \\\n",
      "\\nStagnation pressure is %3.1f kPa    \\\n",
      "\\nStagnation temperature is %3.2f K    \\\n",
      "\\nMach number is %3.0f \\\n",
      "\\nB)After shock:    \\\n",
      "\\nStagnation pressure is %3.2f kPa    \\\n",
      "\\nStagnation temperature is %3.2f K    \\\n",
      "\\nStatic pressure is %3.1f kPa    \\\n",
      "\\nStatic temperature is %3.2f K    \\\n",
      "\\nMach number is %3.3f    \\\n",
      "\\nVelocity is %3.2f m/s \\\n",
      "\\nC)Change in entropy across the shock is %3.2f J/kg-K'%(Pox,Tox,Mx,Poy,Toy,Py,Ty,My,Cy,ds)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)At inlet to shock:    \n",
        "Stagnation pressure is 1076.6 kPa    \n",
        "Stagnation temperature is 630.63 K    \n",
        "Mach number is   2 \n",
        "B)After shock:    \n",
        "Stagnation pressure is 777.33 kPa    \n",
        "Stagnation temperature is 630.15 K    \n",
        "Static pressure is 620.1 kPa    \n",
        "Static temperature is 590.45 K    \n",
        "Mach number is 0.577    \n",
        "Velocity is 281.04 m/s \n",
        "C)Change in entropy across the shock is 93.88 J/kg-K\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3 page: 20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Tx = 0+273 \t\t\t\t#Temperature before the shock in K\n",
      "Px = 60. \t\t\t\t#Pressure before the shock in kPa\n",
      "Cx = 497. \t\t\t\t#Air Velocity before the shock in m/s\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Mx = Cx/ax \t\t\t\t#Mach number before the shock\n",
      "My = 0.70109 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 2.45833 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py =  p1*Px \t\t\t\t#Static pressure after shock in kPa\n",
      "t1 = 1.32022 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p2 = 3.41327 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = p2*Px \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "p3 = 0.92979 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Pox = Poy/p3 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = ay*My \t\t\t\t#Velocity of air after the shock in m/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'After shock:    A)Mach number is %3.5f    \\\n",
      "\\nB)Velocity is %3.3f m/s    \\\n",
      "\\nC)Stagnation pressure is %3.3f kPa'%(My,Cy,Poy)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "After shock:    A)Mach number is 0.70109    \n",
        "B)Velocity is 266.798 m/s    \n",
        "C)Stagnation pressure is 204.796 kPa\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4 page : 21"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Px = 30. \t\t\t\t#Pressure before the shock in kPa\n",
      "Tx = -30+273 \t\t\t\t#Temperature before the shock in K\n",
      "pr = 2.6 \t\t\t\t#Pressure ratio across the shock wave\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "Mx = 1.54 \t\t\t\t#Mach number before the shock from gas tables @pr\n",
      "My = 0.687 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "t1 = 1.347 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = t1*Tx \t\t\t\t#Temperature ratio after the shock in K\n",
      "p1 = 3.567 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = p1*Px \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "p2 = 0.917 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Pox = Poy/p2 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "dP = Pox-Poy \t\t\t\t#Change in stagnation pressure in kPa\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Cx = (Mx*ax) \t\t\t\t#Air Velocity before the shock in m/s\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = (My*ay) \t\t\t\t#Velocity of air after the shock in m/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Velocities upstream and downstream of shock wave are %3.2f m/s and %3.2f m/s respectively \\\n",
      "\\nB)Change in stagnation pressure is %3.3f kPa'%(Cx,Cy,dP)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Velocities upstream and downstream of shock wave are 481.20 m/s and 249.14 m/s respectively \n",
        "B)Change in stagnation pressure is 9.686 kPa\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.5 page : 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Mol = 39.9 \t\t\t\t#Molar mass of a gas in kg/mol\n",
      "k = 1.67 \t\t\t\t#Specific heat ratio \n",
      "Mx = 2.5 \t\t\t\t#Mach number before the shock \n",
      "Px = 40 \t\t\t\t#Pressure before the shock in kPa \n",
      "Tx = -20+273 \t\t\t\t#Temperature before the shock in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "My = 0.554 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 7.567 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = p1*Px \t\t\t\t#Static pressure after shock in kPa\n",
      "t1 = 2.805 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'Downstream the normal shock:    \\\n",
      "\\nMach number is %3.3f    \\\n",
      "\\nPressure is %3.2f kPa    \\\n",
      "\\nTemperature is %3.3f K'%(My,Py,Ty)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Downstream the normal shock:    \n",
        "Mach number is 0.554    \n",
        "Pressure is 302.68 kPa    \n",
        "Temperature is 709.665 K\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.6 page : 22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Mx = 2 \t\t\t\t#Mach number before the shock \n",
      "Px = 50 \t\t\t\t#Pressure before the shock in kPa \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "p1 = 6.335 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @Mx\n",
      "Poy = p1*Px \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'Pressure acting on the front of the body is %3.2f kPa'%Poy\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure acting on the front of the body is 316.75 kPa\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.7 page : 23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Po = 800. \t\t\t\t#Pressure in reservoir in kPa\n",
      "To = 40.+273 \t\t\t\t#Temperature in reservoir in K\n",
      "M2a = 2.5 \t\t\t\t#Mach number at exit from diagram\n",
      "At = 25. \t\t\t\t#Throat Area in cm**2 \n",
      "Ax = 40. \t\t\t\t#Area just before the shock in cm**2\n",
      "Ay = 40. \t\t\t\t#Area just after the shock in cm**2\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "t1 = 0.834 \t\t\t\t#Ratio of critical temperature and stagnation temperature from gas tables @M = 1\n",
      "Tt = To*t1 \t\t\t\t#Critical temperature in K\n",
      "p1 = 0.528 \t\t\t\t#Ratio of critical pressure and stagnation pressure from gas tables @M = 1\n",
      "Pt = Po*p1 \t\t\t\t#Critical pressure in kPa\n",
      "dt = Pt*10**3/(R*Tt) \t\t\t\t#Density in kg/m**3, Pt in Pa\n",
      "at = math.sqrt(k*R*Tt) \t\t\t\t#Velocity of sound at throat in m/s\n",
      "Ct = at \t\t\t\t#Air Velocity of sound at throat in m/s\n",
      "m = dt*At*10**-4*Ct \t\t\t\t#Mass flow rate in kg/s\n",
      "p2 = 0.0585 \t\t\t\t#Ratio of exit to stagnation pressure from isentropic gas tables @M2 = 2.5\n",
      "a1 = 2.637 \t\t\t\t#Ratio of exit to critical area from isentropic gas tables @M2 = 2.5\n",
      "A2 = a1*At \t\t\t\t#Exit area in cm**2\n",
      "a2 = Ax/At \t\t\t\t#Area ratio\n",
      "M = 1.94 \t\t\t\t#Mach number upstream of shock from gas tables @a2\n",
      "p3 = 0.140 \t\t\t\t#Ratio of upstram of shock to stagnation pressures from isentropic gas tables @M\n",
      "Px = p3*Po \t\t\t\t#Pressure upstram of shock in kPa\n",
      "t2 = 0.570 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables @M\n",
      "Tx = t2*To \t\t\t\t#Temperature upstram of shock in K\n",
      "My = 0.588 \t\t\t\t#Mach number downstream of shock from normal shock gas tables @M\n",
      "p4 = 4.225 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p4 \t\t\t\t#Static pressure after shock in kPa\n",
      "t3 = 1.639 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t3 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p5 = 2.338 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = p5*Px \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "p6 = 0.749 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Pox = Poy/p6 \t\t\t\t#Stagnation pressure before shock in kPa \n",
      "#Here At2 = Aty, Po2 = Poy, Toy = To2 = To1 = To\n",
      "p7 = 0.79 \t\t\t\t#Static to stagnation pressure ratio after shock from isentropic gas tables @My\n",
      "Po2 = Py/p7 \t\t\t\t#Stagnation pressure at exit in kPa\n",
      "t4 = 0.935 \t\t\t\t#Static to stagnation temperature ratio after shock from isentropic gas tables @My\n",
      "To2 = Ty/t4 \t\t\t\t#Stagnation temperature in K (checkeD)\n",
      "a3 = 1.2 \t\t\t\t#Ratio of areas after shock i.e. (Ay/At2)\n",
      "At2 = Ay/a3 \t\t\t\t#Critical area after shock in cm**2\n",
      "a4 = A2/At2 \t\t\t\t#Ratio of areas \n",
      "M2b = 0.31 \t\t\t\t#Mach number at exit from gas tables @a4(as per sectionB)\n",
      "p8 = 0.936 \t\t\t\t#Static to stagnation pressure ratio at exit from isentropic gas tables @M2b\n",
      "P2 = Po2*p8 \t\t\t\t#Exit pressure in kPa\n",
      "t5 = 0.981 \t\t\t\t#Static to stagnation temperature ratio after shock from isentropic gas tables @M2b\n",
      "T2 = To2*t5 \t\t\t\t#Exit temperature in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'CASE-I:    A)Mass flow rate is %3.2f kg/s    \\\n",
      "\\nB)Exit area is %3.1f cm**2 CASE-II:    \\\n",
      "\\nA)Temperature is %3.3f K    \\\n",
      "\\nB)Pressure is %3.1f kPa'%(m,A2,T2,P2)\n",
      "\n",
      "# note : rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "CASE-I:    A)Mass flow rate is 4.56 kg/s    \n",
        "B)Exit area is 65.9 cm**2 CASE-II:    \n",
        "A)Temperature is 306.800 K    \n",
        "B)Pressure is 560.7 kPa\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.8 page : 24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Input data\n",
      "Px = 1. \t\t\t\t#Pressure before the shock in bar\n",
      "Tx = 17.+273 \t\t\t\t#Temperature before the shock in K\n",
      "Cx = 500. \t\t\t\t#Air Velocity before the shock in m/s\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Mx = Cx/ax \t\t\t\t#Mach number before the shock \n",
      "My = 0.715 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 2.335 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = p1*Px \t\t\t\t#Static pressure after shock in bar\n",
      "t1 = 1.297 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = ay*My \t\t\t\t#Velocity of air after the shock in m/s\n",
      "C_y = Cx-Cy \t\t\t\t#Velocity of air in m/s\n",
      "M_y = C_y/ay  \t\t\t\t#Mach number impared upstream of the wave front\n",
      "t2 = 0.939 \t\t\t\t#Static to stagnation temperature ratio after shock from isentropic gas tables @M_y\n",
      "T_oy = Ty/t2 \t\t\t\t#Stagnation temperature of air in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Pressure is %3.3f bar \\\n",
      "\\nB)Temperature is %3.2f K \\\n",
      "\\nC)Velocity of air is %3.2f m/s \\\n",
      "\\nD)Stagnation temperature is %3.2f K \\\n",
      "\\nE)Mach number is %3.3f'%(Py,Ty,C_y,T_oy,M_y)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Pressure is 2.335 bar \n",
        "B)Temperature is 376.13 K \n",
        "C)Velocity of air is 222.04 m/s \n",
        "D)Stagnation temperature is 400.56 K \n",
        "E)Mach number is 0.571\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.9 page : 25"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Mx = 3. \t\t\t\t#Mach number before the shock \n",
      "Tx = 27.+273 \t\t\t\t#Temperature before the shock in K\n",
      "Px = 1. \t\t\t\t#Pressure before the shock in bar\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      " \n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "My = 0.475 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 10.333 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = p1*Px \t\t\t\t#Static pressure after shock in bar\n",
      "t1 = 2.679 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p2 = 12.061 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = p2*Px \t\t\t\t#Stagnation pressure after shock in bar\n",
      "p3 = 0.328 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Pox = Poy/p3 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = ay*My \t\t\t\t#Velocity of air after the shock in m/s\n",
      "ds = R*math.log(1/p3) \t\t\t\t#Change in entropy in J/kg-K\n",
      "e = (Py-Px)/Px \t\t\t\t#Strength of shock\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'I)Downstream of the shock:    \\\n",
      "\\nA)Pressure is %3.3f bar    \\\n",
      "\\nB)Temperature is %3.1f K    \\\n",
      "\\nC)Gas velocity is %3.2f m/s    \\\n",
      "\\nD)Mach number is %3.3f \\nII)Total head pressure ratio is %3.3f \\nIII)Entropy change across the shock is %3.3f J/kg-K \\\n",
      "\\nIV)Strength of the shock is %3.3f'%(Py,Ty,Cy,My,p3,ds,e) \n",
      "\n",
      "# rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "I)Downstream of the shock:    \n",
        "A)Pressure is 10.333 bar    \n",
        "B)Temperature is 803.7 K    \n",
        "C)Gas velocity is 269.93 m/s    \n",
        "D)Mach number is 0.475 \n",
        "II)Total head pressure ratio is 0.328 \n",
        "III)Entropy change across the shock is 319.931 J/kg-K \n",
        "IV)Strength of the shock is 9.333\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.10 page : 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "a1 = 0.4 \t\t\t\t#Ratio of throat area to exit area \n",
      "p1 = 0.8 \t\t\t\t#Ratio of static pressure to Stagnation pressure at inlet\n",
      "At = 1. \t\t\t\t#Throat area in m**2\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "a2 = 1/a1 \t\t\t\t#reciprocal of a1 to find in gas tables\n",
      "\t\t\t\t#Pox = Po1 = Po, Poy = Po2\n",
      "a2p2 = a2*p1 \t\t\t\t#Area pressure ratio i.e. (A2*P2)/(At2*Po2)\n",
      "M2 = 0.28 \t\t\t\t#Exit mach number from gas tables @a2p2\n",
      "a3 = 2.166 \t\t\t\t#Ratio of exit area to throat area after shock from gas tables @a2p2 \n",
      "p2 = 0.947 \t\t\t\t#Static to stagnation pressure ratio at exit from gas tables @a2p2\n",
      "p3 = a2/a3 \t\t\t\t#Stagnation pressure ratio after and before shock \n",
      "Mx = 1.675 \t\t\t\t#Mach number before the shock @p3\n",
      "My = 0.647 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "a4 = 1.14 \t\t\t\t#Ratio of area after shock to throat area after shock from isentropic gas tables @My\n",
      "a5 = 1.315 \t\t\t\t#Ratio of area before shock to throat area before shock from isentropic gas tables @My\n",
      "Ax = a5*At \t\t\t\t#Area at shock in m**2\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'A)Mach number across the shock: Mx = %3.3f My = %3.3f) \\\n",
      "\\nB)Area at shock is %3.3f m**2'%(Mx,My,Ax)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Mach number across the shock: Mx = 1.675 My = 0.647) \n",
        "B)Area at shock is 1.315 m**2\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.11 page : 27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\t\n",
      "#Input data\n",
      "a1 = 1./3 \t\t\t\t#Ratio of throat area to exit area \n",
      "p1 = 0.4 \t\t\t\t#Ratio of static pressure to Stagnation pressure at inlet\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "a2 = 1/a1 \t\t\t\t#reciprocal of a1 to find in gas tables\n",
      "\t\t\t\t#we know Pox = Po1 = Po, Poy = Po2, At = Atx and Aty = At2\n",
      "a2p2 = a2*p1 \t\t\t\t#Area pressure ratio i.e. (A2*P2)/(At2*Po2)\n",
      "M2 = 0.472 \t\t\t\t#Exit mach number from gas tables @a2p2\n",
      "a3 = 1.397 \t\t\t\t#Ratio of exit area to throat area after shock from gas tables @a2p2 \n",
      "p2 = 0.858 \t\t\t\t#Static to stagnation pressure ratio at exit from gas tables @a2p2\n",
      "p3 = a3/a2 \t\t\t\t#Stagnation pressure ratio after and before shock \n",
      "Mx = 2.58 \t\t\t\t#Mach number before the shock @p3\n",
      "My = 0.506 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p4 = 9.145 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "a4 = 2.842 \t\t\t\t#Ratio of area before shock to throat area \n",
      "p5 = 0.051 \t\t\t\t#Ratio of Pressure before shock to Stagnation pressure at entry\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'At section where shock occurs:    \\\n",
      "\\nA)Mach number Mx = %3.2f and My = %3.3f    \\\n",
      "\\nB)Static Pressure is %3.3f*Po1 units depend on Po1)    \\\n",
      "\\nC)Area of cross section is %3.3f*At units depend on At)'%(Mx,My,p5,a4)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "At section where shock occurs:    \n",
        "A)Mach number Mx = 2.58 and My = 0.506    \n",
        "B)Static Pressure is 0.051*Po1 units depend on Po1)    \n",
        "C)Area of cross section is 2.842*At units depend on At)\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.12 page : 28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Po = 300. \t\t\t\t#Pressure in reservoir in kPa\n",
      "To = 500. \t\t\t\t#Temperature in reservoir in K\n",
      "At = 1. \t\t\t\t#Throat area in m**2\n",
      "Ax = 2. \t\t\t\t#Area just before the shock in m**2\n",
      "Ay = 2. \t\t\t\t#Area just after the shock in m**2\n",
      "A2 = 3. \t\t\t\t#Exit area in m**2\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "a1 = Ax/At \t\t\t\t#Area ratio \n",
      "Mx = 2.2 \t\t\t\t#Mach number upstream of shock\n",
      "p1 = 0.0935 \t\t\t\t#Ratio of pressure before shock to stagnation pressure before shock from gas tables @Mx\n",
      "Px = p1*Po \t\t\t\t#pressure before shock in kPa\n",
      "t1 = 0.50 \t\t\t\t#Ratio of temperature before shock to stagnation pressure before shock from gas tables @Mx\n",
      "Tx = t1*To \t\t\t\t#temperature before shock in K\n",
      "My = 0.547 \t\t\t\t#Mach number downstream of shock \n",
      "p2 = 5.480 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p2 \t\t\t\t#Static pressure after shock in kPa\n",
      "t2 = 1.857 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = t2*Tx \t\t\t\t#Temperature ratio after the shock in K\n",
      "p3 = 6.716 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy = Px*p3 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "Po2 = Poy \t\t\t\t#Exit stagnation pressure in kPa, Since total pressure remains same after shock\n",
      "t3 = 0.943 \t\t\t\t#Static to stagnation pressure after shock from isentropic gas tables @My\n",
      "Toy = Ty/t3 \t\t\t\t#Stagnation pressure after shock in K\n",
      "To2 = Toy \t\t\t\t#Exit stagnation temperature in K, Since temperature remains after shock\n",
      "a2 = 1.255 \t\t\t\t#Ratio of area after shock to throat area after shock from isentropic gas tables @My\n",
      "Aty = Ay/a2 \t\t\t\t#Throat area after shock in m**2\n",
      "At2 = Aty \t\t\t\t#Throat area at exit in m**2\n",
      "a3 = A2/At2 \t\t\t\t#Areas ratio\n",
      "M2 = 0.33 \t\t\t\t#Exit mach number from gas tables @a3\n",
      "p4 = 0.927 \t\t\t\t#Static to Stagnation pressure at exit from gas isentropic gas tables @a3\n",
      "P2 = Po2*p4 \t\t\t\t#Exit pressure in kPa\n",
      "t4 = 0.978 \t\t\t\t#Static to Stagnation temperature at exit from gas isentropic gas tables @a3\n",
      "T2 = To2*t4 \t\t\t\t#Exit temperature in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Pressure at section x) Px = %3.2f kPa \\\n",
      "\\nB)Pressure at section y) Px = %3.3f kPa \\\n",
      "\\nC)Stagnation pressure at section y) Poy = %3.2f kPa \\\n",
      "\\nD)Throat area of cross section at section y) Aty = %3.4f m**2 \\\n",
      "\\nE)Stagnation pressure at exit Po2 = %3.2f kPa \\\n",
      "\\nF)Throat area of cross section at exit At2 = %3.4f m**2 \\\n",
      "\\nG)Static Pressure at exit P2 = %3.2f kPa \\\n",
      "\\nH)Stagantion temperature at exit To2 = %3i K \\\n",
      "\\nI)Temperature at exit T2 = %3i k'%(Px,Py,Poy,Aty,Po2,At2,P2,To2,T2)\n",
      "\n",
      "# rounding off error. "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Pressure at section x) Px = 28.05 kPa \n",
        "B)Pressure at section y) Px = 153.714 kPa \n",
        "C)Stagnation pressure at section y) Poy = 188.38 kPa \n",
        "D)Throat area of cross section at section y) Aty = 1.5936 m**2 \n",
        "E)Stagnation pressure at exit Po2 = 188.38 kPa \n",
        "F)Throat area of cross section at exit At2 = 1.5936 m**2 \n",
        "G)Static Pressure at exit P2 = 174.63 kPa \n",
        "H)Stagantion temperature at exit To2 = 492 K \n",
        "I)Temperature at exit T2 = 481 k\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.13 page : 29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "#Input data\n",
      "Po1 = 500. \t\t\t\t#Stagnation pressure in kPa\n",
      "To1 = 600. \t\t\t\t#Stagnation temperature in K\n",
      "C1 = 100. \t\t\t\t#inlet velocity in m/s\n",
      "A1 = 0.01 \t\t\t\t#Inlet Area in m**2\n",
      "A2 = 0.01 \t\t\t\t#Exit Area in m**2\n",
      "Mx = 1.2 \t\t\t\t#Mach number before the shock\n",
      "Ax = 37.6 \t\t\t\t#Area just before the shock in cm**2\n",
      "Ay = 37.6 \t\t\t\t#Area just after the shock in cm**2\n",
      "Px = 109.9 \t\t\t\t#Pressure before the shock in kPa\n",
      "Poy = 350. \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "Cp = 1005. \t\t\t\t#Specific heat capacity at consmath.tant volume in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "T1 = To1+(C1**2/(2*Cp)) \t\t\t\t#Inlet static temperature in K\n",
      "ai_1 = math.sqrt(k*R*T1) \t\t\t\t#Velocity of sound at inlet in m/s\n",
      "M1 = C1/ai_1 \t\t\t\t#Inlet Mach number \n",
      "p1 = 0.973 \t\t\t\t#Static to Stagnation pressure ratio at entry from gas tables @M1 \n",
      "P1 = Po1*p1 \t\t\t\t#Inlet static pressure in kPa\n",
      "d1 = P1*10**3/(R*T1) \t\t\t\t#Density at inlet in kg/m**3, P1 in Pa\n",
      "m = d1*A1*C1 \t\t\t\t#Mass flow rate at inlet in kg/s\n",
      "p2 = 0.528 \t\t\t\t#Ratio of critical pressure to stagnation pressure from gas tables @M = 1\n",
      "Pt = Po1*p2 \t\t\t\t#Critical pressure in kPa\n",
      "t1 = 0.834 \t\t\t\t#Ratio of critical temperature to stagnation temperature from gas tables @M = 1\n",
      "Tt = t1*To1 \t\t\t\t#critical temperature in K\n",
      "ai_t = math.sqrt(k*R*Tt) \t\t\t\t#Velocity of sound at critical state in m/s\n",
      "Ct = ai_t \t\t\t\t#Velocity of air at critical state in m/s\n",
      "a1 = 2.964 \t\t\t\t#Ratio of inlet area to critical area from gas tables @M = 1\n",
      "At = A1/a1 \t\t\t\t#critical area in m**2\n",
      "dt = Pt/(R*Tt) \t\t\t\t#Density at critical state in kg/m**3\n",
      "mt = dt*At*Ct \t\t\t\t#Mass flow rate at critical satate in kg/s\n",
      "\t\t\t\t#Sub-division (a)\n",
      "a2 = 1.030 \t\t\t\t#Ratio of area after shock to critical area from gas tables @Mx\n",
      "Ay_a = At*a2 \t\t\t\t#Area after shock in cm**2\n",
      "p3 = 0.412 \t\t\t\t#Ratio of upstram of shock to stagnation pressures from isentropic gas tables @Mx\n",
      "Px_a = Po1*p3 \t\t\t\t#Pressure upstram of shock in kPa\n",
      "t2 = 0.776 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables @Mx\n",
      "Tx_a = To1*t2 \t\t\t\t#Temperature upstram of shock in K\n",
      "My_a = 0.84 \t\t\t\t#Mach number downstream of shock from normal shock gas tables @Mx\n",
      "p4 = 1.497 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py_a = Px_a*p4 \t\t\t\t#Static pressure after shock in kPa\n",
      "t3 = 1.099 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty_a = Tx_a*t3 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p5 = 2.407 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @My\n",
      "Poy_a = Px_a*p5 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "a3 = 1.204 \t\t\t\t#Ratio of area after shock to throat area after shock from isentropic gas tables @My\n",
      "At2_a = (Ay_a/a3)*10**4 \t\t\t\t#Throat area at exit in m**2, calculation mistake in textbook\n",
      "a4 = A2/At2_a \t\t\t\t#Ratio of areas to find gas tables \n",
      "M2_a = 0.2 \t\t\t\t#Exit mach number at section-A from gas tables @a4\n",
      "p5 = 0.973 \t\t\t\t#ratio of exit pressure to stagnation pressure after shock from gas tables\n",
      "P2_a = p5*Poy_a \t\t\t\t#exit pressure in kPa\n",
      "#Sub-division (B)\n",
      "a5 = Ax/At \t\t\t\t#Ratio of area before shock to critical area\n",
      "Mx_b = 1.4 \t\t\t\t#Mach number at section-B from gas tables @a5\n",
      "p6 = 0.314 \t\t\t\t#Ratio of upstram of shock to stagnation pressures from isentropic gas tables @Mx_b\n",
      "Px_b = Po1*p6 \t\t\t\t#Pressure upstram of shock in kPa\n",
      "t4 = 0.718 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables @Mx_b\n",
      "Tx_b = To1*t4 \t\t\t\t#Temperature upstram of shock in K\n",
      "p20 = 3.049 \t\t\t\t#Stagnation pressure ratio after shock to Static pressure before shock from gas tables \n",
      "Poy_b = Px_b*p20 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "My_b = 0.735 \t\t\t\t#Mach number downstream of shock from normal shock gas tables @Mx_b\n",
      "p7 = 2.085 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My_b\n",
      "Py_b = Px_b*p7 \t\t\t\t#Static pressure after shock in kPa\n",
      "t5 = 1.260 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My_b\n",
      "Ty_b = Tx_b*t5 \t\t\t\t#Temperature after the shock in K\n",
      "a6 = 1.071 \t\t\t\t#Ratio of area after shock to throat area after shock from isentropic gas tables My_b = 0.735\n",
      "At2_b = Ay/a6 \t\t\t\t#Throat area at exit in m**2\n",
      "a7 = A2/At2_b \t\t\t\t#Ratio of areas\n",
      "M2_b = 0.21 \t\t\t\t#Exit mach number at section-B from gas tables @a7\n",
      "p8 = 0.9697 \t\t\t\t#ratio of exit pressure to stagnation pressure after shock from gas tables\n",
      "P2_b = p8*Poy_b \t\t\t\t#exit pressure in kPa\n",
      "\t\t\t\t#Sub-division (C)\n",
      "p9 = Px/Po1 \t\t\t\t#Ratio of upstram of shock to stagnation pressures \n",
      "Mx_c = 1.65 \t\t\t\t#Mach number at section-B from gas tables @p9\n",
      "a8 = 1.292 \t\t\t\t#Ratio of area before shock to critical area from gas tables @p9\n",
      "Ax_c = At*a8*10**4 \t\t\t\t#Area before shock in cm**2\n",
      "t6 = 0.647 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables @p9\n",
      "Tx_c = To1*t6 \t\t\t\t#Temperature upstram of shock in K\n",
      "My_c = 0.654  \t\t\t\t#Mach number downstream of shock from normal shock gas tables @Mx_c\n",
      "p10 = 3.0095 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My_c\n",
      "Py_c = Px*p10 \t\t\t\t#Pressure downstram of shock in kPa\n",
      "t7 = 1.423 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My_c\n",
      "Ty_c = Tx_c*t7 \t\t\t\t#Temperature after the shock in K\n",
      "p12 = 4 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @Mx_c\n",
      "Poy_c = Px*p12 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "a9 = 1.136 \t\t\t\t#Ratio of area after shock to throat area after shock from gas tables My_c = 0.654\n",
      "At2_c = Ax_c/a9 \t\t\t\t#Throat area at exit in m**2\n",
      "a8 = A2/At2_c \t\t\t\t#Ratio of areas\n",
      "M2_c = 0.23 \t\t\t\t#Exit mach number at section-B from gas tables @a8\n",
      "p11 = 0.964 \t\t\t\t#ratio of exit pressure to stagnation pressure after shock from gas tables\n",
      "P2_c = p11*Poy_c \t\t\t\t#exit pressure in kPa\n",
      "\t\t\t\t#Sub-division (D)\n",
      "p13 = Poy/Po1 \t\t\t\t#Pressure ratio, Since Pox = Po1\n",
      "Mx_d = 2.04 \t\t\t\t#Mach number upstream of shock from gas tables @p13\n",
      "My_d = 0.571 \t\t\t\t#Mach number downstream of shock from gas tables @p13\n",
      "p14 = 4.688 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My_d\n",
      "t8 = 1.72 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My_d\n",
      "p15 = 5.847 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @Mx_d\n",
      "p16 = 0.120 \t\t\t\t#Ratio of upstram of shock to stagnation pressures from isentropic tables @Mx_d\n",
      "Px_d = Po1*p16 \t\t\t\t#Pressure upstram of shock in kPa\n",
      "t9 = 0.546 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables @Mx_d\n",
      "Tx_d = To1*t9 \t\t\t\t#Temperature upstram of shock in K\n",
      "p21 = 4.688 \t\t\t\t#Static pressure ratio after and before the shock from gas tables \n",
      "Py_d = Px_d*p21 \t\t\t\t#Pressure downstram of shock in kPa\n",
      "t12 = 1.72 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables \n",
      "Ty_d = Tx_d*t12 \t\t\t\t#Temperature after the shock in K\n",
      "a9 = 1.745 \t\t\t\t#Ratio of area before shock to throat area from isentropic gas tables \n",
      "Ax_d = At*a9*10**4 \t\t\t\t#Area before shock in cm**2\n",
      "a10 = 1.226 \t\t\t\t#Ratio of area after shock to throat area after shock from isentropic tables @My_d\n",
      "At2_d = (Ax_d/a10) \t\t\t\t#Throat area at exit in cm**2\n",
      "a11 = A2/At2_d \t\t\t\t#Ratio of areas\n",
      "M2_d = 0.29 \t\t\t\t#Exit mach number at section-B from gas tables @a11\n",
      "p17 = 0.943 \t\t\t\t#ratio of exit pressure to stagnation pressure after shock from gas tables\n",
      "P2_d = p17*Poy \t\t\t\t#exit pressure in kPa\n",
      "#Sub-division (E)\n",
      "a12 = Ax/At \t\t\t\t#Ratio of areas\n",
      "Mx_e = 2.62 \t\t\t\t#Mach number upstream of shock from gas tables @a12\n",
      "t10 = 0.421 \t\t\t\t#Ratio of upstram of shock to stagnation temperature from isentropic gas tables \n",
      "Tx_e = To1*t10 \t\t\t\t#Temperature upstram of shock in K\n",
      "p18 = 0.0486 \t\t\t\t#Ratio of upstram of shock to stagnation pressures from isentropic tables @Mx_e\n",
      "Px_e = p18*Po1 \t\t\t\t#Pressure upstram of shock in kPa\n",
      "My_e = 0.502 \t\t\t\t#Mach number downstream of shock from gas tables @Mx_e\n",
      "p19 = 7.842 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My_e\n",
      "Py_e = Px_e*p19 \t\t\t\t#Pressure downstram of shock in kPa\n",
      "P2_e = Py_e \t\t\t\t#Exit pressure in kPa\n",
      "t11 = 2.259 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My_d\n",
      "Ty_e = Tx_e*t11 \t\t\t\t#Temperaure downstram of shock in K\n",
      "T2_e = Ty_e \t\t\t\t#Exit temperature in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'At throat:    \\\n",
      "\\nMass flow rate is %3.2f kg/s    \\\n",
      "\\nArea at throat is %3.5f m**2    \\\n",
      "\\nPressure is %3i kPa    \\\n",
      "\\nTemperature is %3.1f K    \\\n",
      "\\nVelocity is %3.1f m/s \\\n",
      "\\na)At section \\\n",
      "\\nA):    Pressure upstream is %3i kPa    \\\n",
      "\\nTemperature upstream is %3.1f K    \\\n",
      "\\nMack number downstream is %3.2f    \\\n",
      "\\nPressure downstream is %3.3f kPa    \\\n",
      "\\nTemperature downstream is %3.3f K    \\\n",
      "\\nStagnation pressure downstream is %3.1f kPa    \\\n",
      "\\nArea is %3.3f cm**2  \\\n",
      "\\nAt exit:    Mach number is %3.1f    \\\n",
      "\\nPressure is %3.1f kPa \\\n",
      "\\nB)At section \\\n",
      "\\nB):    Pressure upstream is %3i kPa    \\\n",
      "\\nTemperature upstream is %3.1f K    \\\n",
      "\\nMack number upstream is %3.1f    \\\n",
      "\\nMack number downstream is %3.3f    \\\n",
      "\\nPressure downstream is %3.2f kPa    \\\n",
      "\\nTemperature downstream is %3.2f K    \\\n",
      "\\nStagnation pressure downstream is %3.1f kPa    \\\n",
      "\\nArea is %3.3f cm**2  At exit:    \\\n",
      "\\nMach number is %3.2f    Pressure is %3.1f kPa \\\n",
      "\\nC)At section \\\n",
      "\\nC):    Area upstream is %3.2f cm**2    \\\n",
      "\\nTemperature upstream is %3.1f K    \\\n",
      "\\nMack number upstream is %3.2f    \\\n",
      "\\nMack number downstream is %3.3f    \\\n",
      "\\nPressure downstream is %3.2f kPa    \\\n",
      "\\nTemperature downstream is %3.2f K    \\\n",
      "\\nStagnation pressure downstream is %3i kPa    \\\n",
      "\\nArea is %3.4f cm**2  At exit:    \\\n",
      "\\nMach number is %3.2f    \\\n",
      "\\nPressure is %3.1f kPa \\\n",
      "\\nD)At section \\\n",
      "\\nD):    Pressure upstream is %3i kPa    \\\n",
      "\\nTemperature upstream is %3.1f K    \\\n",
      "\\nArea upstream is %3.3f cm**2    \\\n",
      "\\nMack number upstream is %3.2f    \\\n",
      "\\nMack number downstream is %3.2f    \\\n",
      "\\nPressure downstream is %3.2f kPa    \\\n",
      "\\nTemperature downstream is %3.2f K    \\\n",
      "\\nArea is %3.3f cm**2  \\\n",
      "\\nAt exit:    Mach number is %3.2f    \\\n",
      "\\nPressure is %3.2f kPa \\\n",
      "\\nE)At section \\\n",
      "\\nE):    Pressure upstream is %3.1f kPa    \\\n",
      "\\nTemperature upstream is %3.1f K    \\\n",
      "\\nMack number upstream is %3.2f    \\\n",
      "\\nMack number downstream is %3.3f    \\\n",
      "\\nPressure downstream is %3.1f kPa    \\\n",
      "\\nTemperature downstream is %3.2f K  \\\n",
      "\\nAt exit:    Temperature is %3.2f K    \\\n",
      "\\nPressure is %3.1f kPa'%(m,At,Pt,Tt,Ct,Px_a,Tx_a,My_a,Py_a,Ty_a,Poy_a,At2_a,M2_a,P2_a,Px_b,Tx_b,Mx_b,My_b,Py_b,Ty_b,Poy_b,At2_b,M2_b,P2_b,Ax_c,Tx_c,Mx_c,My_c,Py_c,Ty_c,Poy_c,At2_c,M2_c,P2_c,Px_d,Tx_d,Ax_d,Mx_d,My_d,Py_d,Ty_d,At2_d,M2_d,P2_d,Px_e,Tx_e,Mx_e,My_e,Py_e,Ty_e,T2_e,P2_e)\n",
      "\n",
      "# note : rounding off error. kindly check using calculator."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "At throat:    \n",
        "Mass flow rate is 2.80 kg/s    \n",
        "Area at throat is 0.00337 m**2    \n",
        "Pressure is 264 kPa    \n",
        "Temperature is 500.4 K    \n",
        "Velocity is 448.4 m/s \n",
        "a)At section \n",
        "A):    Pressure upstream is 206 kPa    \n",
        "Temperature upstream is 465.6 K    \n",
        "Mack number downstream is 0.84    \n",
        "Pressure downstream is 308.382 kPa    \n",
        "Temperature downstream is 511.694 K    \n",
        "Stagnation pressure downstream is 495.8 kPa    \n",
        "Area is 28.862 cm**2  \n",
        "At exit:    Mach number is 0.2    \n",
        "Pressure is 482.5 kPa \n",
        "B)At section \n",
        "B):    Pressure upstream is 157 kPa    \n",
        "Temperature upstream is 430.8 K    \n",
        "Mack number upstream is 1.4    \n",
        "Mack number downstream is 0.735    \n",
        "Pressure downstream is 327.34 kPa    \n",
        "Temperature downstream is 542.81 K    \n",
        "Stagnation pressure downstream is 478.7 kPa    \n",
        "Area is 35.107 cm**2  At exit:    \n",
        "Mach number is 0.21    Pressure is 464.2 kPa \n",
        "C)At section \n",
        "C):    Area upstream is 43.59 cm**2    \n",
        "Temperature upstream is 388.2 K    \n",
        "Mack number upstream is 1.65    \n",
        "Mack number downstream is 0.654    \n",
        "Pressure downstream is 330.74 kPa    \n",
        "Temperature downstream is 552.41 K    \n",
        "Stagnation pressure downstream is 439 kPa    \n",
        "Area is 38.3713 cm**2  At exit:    \n",
        "Mach number is 0.23    \n",
        "Pressure is 423.8 kPa \n",
        "D)At section \n",
        "D):    Pressure upstream is  60 kPa    \n",
        "Temperature upstream is 327.6 K    \n",
        "Area upstream is 58.873 cm**2    \n",
        "Mack number upstream is 2.04    \n",
        "Mack number downstream is 0.57    \n",
        "Pressure downstream is 281.28 kPa    \n",
        "Temperature downstream is 563.47 K    \n",
        "Area is 48.021 cm**2  \n",
        "At exit:    Mach number is 0.29    \n",
        "Pressure is 330.05 kPa \n",
        "E)At section \n",
        "E):    Pressure upstream is 24.3 kPa    \n",
        "Temperature upstream is 252.6 K    \n",
        "Mack number upstream is 2.62    \n",
        "Mack number downstream is 0.502    \n",
        "Pressure downstream is 190.6 kPa    \n",
        "Temperature downstream is 570.62 K  \n",
        "At exit:    Temperature is 570.62 K    \n",
        "Pressure is 190.6 kPa\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.14 page : 33"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "T = 300. \t\t\t\t#Temperature in K\n",
      "P = 1.01325*10**5 \t\t\t\t#Absolute pressure in Pa\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "C_1 = 60. \t\t\t\t#Velocity of air in m/s\n",
      "C_2 = 200. \t\t\t\t#Velocity of air in m/s\n",
      "C_3 = 500. \t\t\t\t#Velocity of air in m/s\n",
      "d_hg = 13600. \t\t\t\t#Density of mercury in kg/m**3\n",
      "g = 9.81 \t\t\t\t#Acceleration due to gravity in m/s**2\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "a = math.sqrt(k*R*T) \t\t\t\t#Sound velocity in m/s\n",
      "M_1 = C_1/a \t\t\t\t#Mach number \n",
      "dP1 = (P*C_1**2)/(2*R*T) \t\t\t\t#Difference in mercury levels in Pa\n",
      "dP1_hg = (dP1/(d_hg*g))*1000 \t\t\t\t#Difference in mercury levels in mm of Hg\n",
      "M_2 = C_2/a \t\t\t\t#Mach number \n",
      "p1 = (1+((k-1)/2)*M_2**2)**(k/(k-1)) \t\t\t\t#Stagnation to static pressure ratio \n",
      "Po = p1*P \t\t\t\t#Stagnation pressure in Pa\n",
      "dP2 = abs(Po-P) \t\t\t\t#Difference in mercury levels in Pa\n",
      "dP2_hg = (dP2/(d_hg*g))*1000 \t\t\t\t#Difference in mercury levels in mm of Hg\n",
      "M_3 = C_3/a \t\t\t\t#Mach number & M_3 = Mach number just before shock\n",
      "My = 0.723 \t\t\t\t#Mach number just after shock\n",
      "p1 = 2.2530 \t\t\t\t#Ratio of pressure after shock to before shock from gas tables @My\n",
      "Py = p1*P \t\t\t\t#Pressure after shock in Pa\n",
      "p2 = 0.706 \t\t\t\t#Ratio of pressure after shock to Stagnation pressure from gas tables @My\n",
      "Po = Py/p2 \t\t\t\t#Stagnation pressure in Pa\n",
      "dP3 = Po-Py \t\t\t\t#Difference in mercury levels in Pa\n",
      "dP3_hg = (dP3/(d_hg*g))*1000 \t\t\t\t#Difference in mercury levels in mm of Hg\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'Difference in mercury levels at velocity equal to:    \\\n",
      "\\nA)%2i m/s is %3.3f mm of Hg    \\\n",
      "\\nB)%3i m/s is %3.1f mm of Hg    \\\n",
      "\\nC)%3i m/s is %3i mm of Hg'%(C_1,dP1_hg,C_2,dP2_hg,C_3,dP3_hg)\n",
      "\n",
      "# note : rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Difference in mercury levels at velocity equal to:    \n",
        "A)60 m/s is 15.877 mm of Hg    \n",
        "B)200 m/s is 191.5 mm of Hg    \n",
        "C)500 m/s is 712 mm of Hg\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.15 page : 35"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Px = 16. \t\t\t\t#Pressure before the shock in kPa\n",
      "Poy = 70. \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "To = 300.+273 \t\t\t\t#Stagnation temperature in K\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "p1 = Poy/Px \t\t\t\t#Pressure ratio \n",
      "Mx = 1.735 \t\t\t\t#Mach number upstream of shock \n",
      "My = 0.631 \t\t\t\t#Mach number downstream of shock \n",
      "p2 = 0.84 \t\t\t\t#Ratio of stagnation pressures after and before shock from gas tables\n",
      "t1 = 1.483 \t\t\t\t#Temperature ratio after and before shock from gas tables\n",
      "Tx = To/(1+((k-1)/2)*Mx**2) \t\t\t\t#Temperature upstream of shock in K\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature downstream of shock in K\n",
      "Pox = Poy/p2 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Mach number of the tunnal is Mx = %3.3f My = %3.3f) \\\n",
      "\\nB)Upstream of the tube:    \\\n",
      "\\nStatic temperature is %3i K    \\\n",
      "\\nTotal pressure is %3.1f kPa \\\n",
      "\\nC)Downstream of the tube:    \\\n",
      "\\nStatic temperature is %3i K    \\\n",
      "\\nTotal pressure is %3i kPa'%(Mx,My,Tx,Pox,Ty,Poy)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Mach number of the tunnal is Mx = 1.735 My = 0.631) \n",
        "B)Upstream of the tube:    \n",
        "Static temperature is 357 K    \n",
        "Total pressure is 83.3 kPa \n",
        "C)Downstream of the tube:    \n",
        "Static temperature is 530 K    \n",
        "Total pressure is  70 kPa\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.16 page : 35"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Py = 455. \t\t\t\t#Pressure downstream of shock in kPa\n",
      "Ty = 65.+273 \t\t\t\t#Temperature downstream of shock in K\n",
      "dP = 65. \t\t\t\t#Difference between dynamic and static pressure in kPa\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "Poy = dP+Py \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "p1 = Py/Poy \t\t\t\t#Pressure ratio \n",
      "My = 0.44 \t\t\t\t#Mach number downstream of shock from isentropic gas tables @p1\n",
      "Mx = 3.8 \t\t\t\t#Mach number upstream of shock from normal shock gas tables @My\n",
      "t1 = 3.743 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Tx = Ty/t1 \t\t\t\t#Temperature before the shock in K\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Cx = Mx*ax \t\t\t\t#Air Velocity before the shock in m/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'A)Mach number is Mx = %3.1f My = %3.2f) \\\n",
      "\\nB)Velocity is %3.2f m/s'%(Mx,My,Cx)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Mach number is Mx = 3.8 My = 0.44) \n",
        "B)Velocity is 723.83 m/s\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.17 page : 36"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "Px = 1.01325 \t\t\t\t#Pressure before the shock in bar\n",
      "Tx = 15+273 \t\t\t\t#Temperature before the shock in K\n",
      "Py = 13.789 \t\t\t\t#Pressure just after the shock in bar\n",
      "R = 287 \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "p1 = Py/Px \t\t\t\t#Pressure ratio \n",
      "Mx = 3.47 \t\t\t\t#Mach number upstream of shock from normal shock gas tables @p1\n",
      "My = 0.454 \t\t\t\t#Mach number downstream of shock from isentropic gas tables @p1\n",
      "t1 = 3.213 \t\t\t\t#Temperature ratio after and before the shock from gas tables @Mx\n",
      "Ty = Tx*t1 \t\t\t\t#Temperature downstream of shock in K\n",
      "p2 = 15.574 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @Mx\n",
      "Poy = Px*p2 \t\t\t\t#Stagnation pressure after shock in bar\n",
      "ax = math.sqrt(k*R*Tx) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Cx = Mx*ax  \t\t\t\t#Velocity of air before the shock in m/s \n",
      "Csh = Cx \t\t\t\t#Since Csh = Cx, see dig.\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Cy = My*ay \t\t\t\t#Velocity of air after the shock in m/s\n",
      "C_y = Cx-Cy \t\t\t\t#Air velocity just inside the shock in m/s\n",
      "P_y = Py \t\t\t\t#Pressure of air in bar, Since a powerful explosion creates a brief but intense blast wind as it passes\n",
      "a_y = math.sqrt(k*R*Ty) \t\t\t\t#\t\t\t\t#Velocity of sound after the shock in m/s\n",
      "M_y = C_y/a_y \t\t\t\t#Mach number\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Shock speed is %3.2f m/s \\\n",
      "\\nB)Air velocity just inside the shock is %3.2f m/s'%(Cx,C_y)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Shock speed is 1180.40 m/s \n",
        "B)Air velocity just inside the shock is 903.57 m/s\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.18 page : 37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "T = 300. \t\t\t\t#Temperature in K\n",
      "P = 1.5 \t\t\t\t#Pressure in bar\n",
      "C_y = 150. \t\t\t\t#Air velocity just inside the shock in m/s\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "  \n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "ax = math.sqrt(k*R*T) \t\t\t\t#Velocity of sound before the shock in m/s\n",
      "Mx = math.sqrt(((C_y*(k+1))/(2*ax))+1) \t\t\t\t#Mach number before the shock\n",
      "My = 0.79 \t\t\t\t#\t\t\t\t#Mach number after the shock from normal shock gas tables \n",
      "Cx = Mx*ax \t\t\t\t#Velocity of gas before the shock in m/s\n",
      "p1 = 1.775 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Py = P*p1 \t\t\t\t#Pressure just after the shock in bar\n",
      "t1 = 1.1845 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = T*t1 \t\t\t\t#Temperature ratio after the shock in K\n",
      "ay = math.sqrt(k*R*Ty) \t\t\t\t#Velocity of sound after the shock in m/s\n",
      "Csh = My*ay \t\t\t\t#Speed of the wave in m/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'A)Speed of the wave is %3.1f m/s \\\n",
      "\\nB)At rest condition:    \\\n",
      "\\nPressure is %3.4f bar    \\\n",
      "\\nTemperature is %3.2f K'%(Csh,Py,Ty)\n",
      "\n",
      "# note : rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Speed of the wave is 298.5 m/s \n",
        "B)At rest condition:    \n",
        "Pressure is 2.6625 bar    \n",
        "Temperature is 355.35 K\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.19 page : 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Mx = 2. \t\t\t\t#Mach number before the shock\n",
      "a1 = 3. \t\t\t\t#Diffuser area ratio\n",
      "Pox = 0.1 \t\t\t\t#Stagnation pressure before shock in bar\n",
      "Tx = 300. \t\t\t\t#Temperature before the shock in K\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "t1 = 0.555 \t\t\t\t#Static to stagnation temperature ratio before shock from isentropic gas tables @Mx,k = 1.4\n",
      "Tox = Tx/t1 \t\t\t\t#Stagnation temperature before shock in K\n",
      "p1 = 0.128 \t\t\t\t#Static to stagnation pressure ratio before shock from isentropic gas tables @Mx,k = 1.4\n",
      "Px = Pox*p1 \t\t\t\t#Pressure before the shock in bar\n",
      "My = 0.577 \t\t\t\t#Mach number after the shock\n",
      "p2 = 4.5 \t\t\t\t#Pressure ratio after and before the shock from gas tables @Mx\n",
      "Py = Px*p2 \t\t\t\t#Pressure just after the shock in bar\n",
      "t2 = 1.687 \t\t\t\t#Temperature ratio after and before the shock from gas tables @Mx\n",
      "Ty = Tx*t2 \t\t\t\t#Temperature ratio after the shock in K\n",
      "p3 = 0.721 \t\t\t\t#Stagnation pressure ratio after and before shock from gas tables @Mx\n",
      "Poy = Pox*p3 \t\t\t\t#Stagnation pressure after shock in kPa\n",
      "a2 = 1.2195 \t\t\t\t#Ratio of area after shock to throat area after shock from gas tables @My\n",
      "a3 = a2*a1 \t\t\t\t#Ratio of exit area to throat area at exit \n",
      "M2 = 0.16 \t\t\t\t#Exit mach number from gas tables @a3\n",
      "t3 = 0.9946 \t\t\t\t#Static to stagnation temperature ratio at exit from isentropic gas tables @Mx\n",
      "T2 = Tox*t3 \t\t\t\t#Exit Temperature in K, Since Tox = Toy = T02 in case of diffuser\n",
      "p4 = 0.982 \t\t\t\t#Static to stagnation pressure ratio at exit from isentropic gas tables @Mx\n",
      "P2 = Poy*p4 \t\t\t\t#Exit pressure in bar, Calculation mistake in textbook\n",
      "eff = ((((Tox/Tx)*(Poy/Pox)**((k-1)/k))-1)/(((k-1)/2)*Mx**2))*100 \t\t\t\t#Diffuser efficiency including shock in percent\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'A)At the diffuser exit:    \\\n",
      "\\nMach number is %3.2f    \\\n",
      "\\nPressure is %3.3f bar    \\\n",
      "\\nTemperature is %3.2f K \\\n",
      "\\nB)Diffuser efficiency including shock is %3.3f percent'%(M2,P2,T2,eff)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)At the diffuser exit:    \n",
        "Mach number is 0.16    \n",
        "Pressure is 0.071 bar    \n",
        "Temperature is 537.62 K \n",
        "B)Diffuser efficiency including shock is 80.129 percent\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.20 page : 39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "k = 1.3 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "P1 = 1. \t\t\t\t#Inlet pressure in bar\n",
      "T1 = 400. \t\t\t\t#Inlet temperature in K\n",
      "D = 0.3 \t\t\t\t#Duct diameter in m\n",
      "M1 = 2. \t\t\t\t#Mach number at entry\n",
      "Mx = 1.5 \t\t\t\t#Mach number upstream of shock \n",
      "M2 = 1. \t\t\t\t#Mach number at outlet\n",
      "f = 0.003 \t\t\t\t#Friction factor\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "d1 = P1*10**5/(R*T1) \t\t\t\t#Density at inlet in kg/m**3\n",
      "a1 = math.sqrt(k*R*T1) \t\t\t\t#Velocity of sound at inlet in m/s \n",
      "C1 = M1*a1 \t\t\t\t#Gas velocity at inlet in m/s\n",
      "A1 = math.pi*D**2/4 \t\t\t\t#Inlet Area of the duct in m**2\n",
      "m = d1*C1*A1 \t\t\t\t#Mass flow rate in kg/s\n",
      "p1 = 0.131 \t\t\t\t#Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropiC)\n",
      "Po1 = P1/p1 \t\t\t\t#Stagantion pressure at inlet in bar\n",
      "t1 = 0.625 \t\t\t\t#Static to Stagnation temperature ratio at entry from gas tables (M1,k = 1.4,isentropiC)\n",
      "To1 = T1/t1 \t\t\t\t#Stagnation temperature at inlet in K\n",
      "p2 = 0.424 \t\t\t\t#Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Pt1 = P1/p2 \t\t\t\t#Critical pressure in bar\n",
      "p3 = 1.773 \t\t\t\t#Stagnation pressure ratio at entry to critical state from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Pto1 = Po1/p3 \t\t\t\t#Stagnation pressure at critical state in bar \n",
      "t2 = 0.719 \t\t\t\t#Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Tt1 = T1/t2 \t\t\t\t#Critical temperature in K\n",
      "X1 = 0.357 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4\n",
      "p4 = 0.618 \t\t\t\t#Ratio of Static pressure before shock to critical pressure at entry from gas tables (fanno flow,Mx,k = 1.4) \n",
      "Px = Pt1*p4 \t\t\t\t#pressure before shock in bar\n",
      "t3 = 0.860 \t\t\t\t#Ratio of Static temperature before shock to critical temperature at entry from gas tables (fanno flow,Mx,k = 1.4) \n",
      "Tx = Tt1*t3 \t\t\t\t#Temperature before shock in K\n",
      "p5 = 1.189 \t\t\t\t#Ratio of Stagnation pressure before shock to Stagnation pressure at critical state at entry from gas tables (fanno flow,Mx,k = 1.4) \n",
      "Pox = Pto1*p5 \t\t\t\t#Stagnation pressure at critical state in bar\n",
      "Xx = 0.156 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @Mx,k = 1.4\n",
      "X3 = X1-Xx \t\t\t\t#Overall frictional consmath.tant fanno parameter upstream of duct\n",
      "L1 = (X3*D)/(4*f) \t\t\t\t#Length upstream of duct in m\n",
      "My = 0.7 \t\t\t\t#Mach number downstream of shock from gas tables @Mx\n",
      "p6 = 2.413 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p6 \t\t\t\t#Pressure after shock in bar\n",
      "t4 = 1.247 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t4 \t\t\t\t#temperature after shock in K\n",
      "p7 = 0.926 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @My\n",
      "Poy = Pox*p7 \t\t\t\t#Stagnation pressure after shock in bar\n",
      "p8 = 1.479 \t\t\t\t#Ratio of pressure after shock to pressure at critical state from gas tables @My\n",
      "Pt = Py/p8 \t\t\t\t#Critical pressure in bar\n",
      "p9 = 1.097 \t\t\t\t#Ratio of Stagnation pressure after shock to Stagnation pressure at critical state from gas tables @My\n",
      "Pot = Poy/p9 \t\t\t\t#Stagnation pressure at critical state in bar\n",
      "t5 = 1.071 \t\t\t\t#Ratio of temperature after shock to temperature at critical state from gas tables @My\n",
      "Tt = Ty/t5 \t\t\t\t#Critical temperature in K\n",
      "Xy = 0.231 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @My,k = 1.4\n",
      "X2 = 0 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M = 1,k = 1.4\n",
      "X4 = Xy-X2 \t\t\t\t#Overall frictional consmath.tant fanno parameter downstream of duct\n",
      "L2 = (X4*D)/(4*f) \t\t\t\t#Length downstream of duct in m\n",
      "ds1 = R*math.log(Po1/Pox) \t\t\t\t#Change of entropy upstream of the shock in J/kg-K\n",
      "ds2 = R*math.log(Pox/Poy) \t\t\t\t#Change of entropy across the shock in J/kg-K\n",
      "ds3 = R*math.log(Poy/Pot) \t\t\t\t#Change of entropy downstream of the shock in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Length of the duct upstream and downstream of the duct is %3.3f m and %3.3f m respectively \\\n",
      "\\nB)Mass flow rate of the gas is %3.3f kg/s \\\n",
      "\\nC)Change of entropy:    \\\n",
      "\\nUpstream of the shock is %3.2f J/kg-K    \\\n",
      "\\nAcross the shock is %3.3f J/kg-K    \\\n",
      "\\nDownstream of the shock is %3.4f J/kg-K'%(L1,L2,m,ds1,ds2,ds3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Length of the duct upstream and downstream of the duct is 5.025 m and 5.775 m respectively \n",
        "B)Mass flow rate of the gas is 47.573 kg/s \n",
        "C)Change of entropy:    \n",
        "Upstream of the shock is 114.67 J/kg-K    \n",
        "Across the shock is 22.065 J/kg-K    \n",
        "Downstream of the shock is 26.5702 J/kg-K\n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.21 page : 41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "P1 = 0.685 \t\t\t\t#Inlet pressure in bar\n",
      "T1 = 310. \t\t\t\t#Inlet temperature in K\n",
      "D = 0.6 \t\t\t\t#Duct diameter in m\n",
      "M1 = 3. \t\t\t\t#Mach number at entry\n",
      "Mx = 2.5 \t\t\t\t#Mach number upstream of shock \n",
      "M2 = 0.8 \t\t\t\t#Mach number at outlet\n",
      "f = 0.005 \t\t\t\t#Friction factor\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "R = 287. \t\t\t\t#Specific gas consmath.tant in J/kg-K\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "d1 = P1*10**5/(R*T1) \t\t\t\t#Density at inlet in kg/m**3\n",
      "a1 = math.sqrt(k*R*T1) \t\t\t\t#Velocity of sound at inlet in m/s \n",
      "C1 = M1*a1 \t\t\t\t#Air velocity at inlet in m/s\n",
      "A1 = math.pi*D**2/4 \t\t\t\t#Inlet Area of the duct in m**2\n",
      "m = d1*C1*A1 \t\t\t\t#Mass flow rate in kg/s\n",
      "p1 = 0.218 \t\t\t\t#Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Pt1 = P1/p1 \t\t\t\t#Critical pressure in bar \n",
      "t1 = 0.428 \t\t\t\t#Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Tt1 = T1/t1 \t\t\t\t#Critical temperature in K\n",
      "X1 = 0.522 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4\n",
      "p2 = 0.292 \t\t\t\t#Ratio of Static pressure before shock to critical pressure at entry from gas tables (fanno flow,Mx,k = 1.4)\n",
      "Px = Pt1*p2 \t\t\t\t#pressure before shock in bar\n",
      "t2 = 0.533 \t\t\t\t#Ratio of Static temperature before shock to critical temperature at entry from gas tables (fanno flow,Mx,k = 1.4) \n",
      "Tx = Tt1*t2 \t\t\t\t#Temperature before shock in K\n",
      "Xx = 0.432 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @Mx,k = 1.4\n",
      "X3 = X1-Xx \t\t\t\t#Overall frictional consmath.tant fanno parameter upstream of duct\n",
      "L1 = (X3*D)/(4*f) \t\t\t\t#Length upstream of duct in m\n",
      "My = 0.513 \t\t\t\t#Mach number downstream of shock from gas tables @Mx\n",
      "p3 = 7.125 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p3 \t\t\t\t#Pressure after shock in bar\n",
      "t3 = 2.138 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t3 \t\t\t\t#temperature after shock in K\n",
      "p4 = 2.138 \t\t\t\t#Ratio of pressure after shock to pressure at critical state from gas tables @My\n",
      "Pt = Py/p4 \t\t\t\t#Critical pressure in bar\n",
      "t4 = 1.143 \t\t\t\t#Ratio of temperature after shock to temperature at critical state from gas tables @My\n",
      "Tt = Ty/t4 \t\t\t\t#Critical temperature in K\n",
      "p5 = 1.289 \t\t\t\t#Ratio of pressure at exit to pressure at critical state from gas tables @M2\n",
      "P2 = Pt*p5 \t\t\t\t#Exit pressure in bar \n",
      "t5 = 1.064 \t\t\t\t#Ratio of temperature at exit to temperature at critical state from gas tables @M2 \n",
      "T2 = Tt*t5 \t\t\t\t#Exit temperature in K\n",
      "Xy = 1.069 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @My,k = 1.4\n",
      "X2 = 0.073 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M2,k = 1.4\n",
      "X4 = Xy-X2 \t\t\t\t#Overall frictional consmath.tant fanno parameter downstream of duct\n",
      "L2 = (X4*D)/(4*f) \t\t\t\t#Length downstream of duct in m\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Length L1 and L2 are %3.1f m and %3.2f m respectively \\\n",
      "\\nB)State of air at exit:    Pressure is %3.3f bar    Temperature is %3.1f K \\\n",
      "\\nC)Mass flow rate through the duct is %3.2f kg/s'%(L1,L2,P2,T2,m)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Length L1 and L2 are 2.7 m and 29.88 m respectively \n",
        "B)State of air at exit:    Pressure is 3.941 bar    Temperature is 768.3 K \n",
        "C)Mass flow rate through the duct is 230.49 kg/s\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.22 page : 42"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "At = 24. \t\t\t\t#Throat area in cm**2\n",
      "A2 = 50. \t\t\t\t#Exit area in cm**2\n",
      "Po = 700. \t\t\t\t#Stagnation pressure in kPa\n",
      "To = 100.+273 \t\t\t\t#Stagnation temperature in K\n",
      "Ax = 34. \t\t\t\t#Area before the shock in cm**2\n",
      "Ay = 34. \t\t\t\t#Area after the shock in cm**2\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "a1 = Ax/At \t\t\t\t#Ratio of areas\n",
      "Mx = 1.78 \t\t\t\t#Mach number upstream of shock from gas tables @a1\n",
      "t1 = 0.61212 \t\t\t\t#Ratio of temperature before shock to critical state from isentropic gas tables @Mx\n",
      "Tx = To*t1  \t\t\t\t#temperature before shock in K\n",
      "p1 = 0.179 \t\t\t\t#Ratio of pressure before shock to critical state from isentropic gas tables @Mx\n",
      "Px = Po*p1 \t\t\t\t#pressure before shock in kPa\n",
      "My = 0.621 \t\t\t\t#Mach number downstream of shock from gas tables @Mx\n",
      "p2 = 3.5298 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p2 \t\t\t\t#Pressure after shock in kPa\n",
      "t2 = 1.51669 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t2 \t\t\t\t#temperature after shock in K\n",
      "p3 = 4.578 \t\t\t\t#Ratio of Stagnation pressure after the shock to static pressure before shock from gas tables @My\n",
      "Po2 = Px*p3 \t\t\t\t#Stagnation pressure at exit in bar\n",
      "a2 = 1.16565 \t\t\t\t#Ratio of area after shock to critical area across shock from isentropic gas tables @My\n",
      "At2 = Ay/a2 \t\t\t\t#critical area at exit in cm**2\n",
      "a3 = A2/At2 \t\t\t\t#Ratio of areas \n",
      "M2 = 0.36 \t\t\t\t#Exit mach number from gas tables (a3,k = 1.4,isentropiC)\n",
      "p4 = 0.914 \t\t\t\t#Static to Stagnation pressure ratio at exit from gas tables (a3,k = 1.4,isentropiC) \n",
      "P2 = Po2*p4 \t\t\t\t#Stagnation pressure ratio at exit in kPa\n",
      "t3 = 0.975 \t\t\t\t#Static to Stagnation temperature ratio at exit from gas tables (a3,k = 1.4,isentropiC)\n",
      "T2 = To*t3 \t\t\t\t#Stagnation temperature at exit in K\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Properties of fluid just after shock:    \\\n",
      "\\nMach number My = %3.3f    \\\n",
      "\\nTemperature is %3.2f K    \\\n",
      "\\nPressure is %3.2f kPa \\\n",
      "\\nB)Exit mach number is %3.2f \\\n",
      "\\nC)Properties of fluid at exit:    \\\n",
      "\\nPressure is %3i kPa    \\\n",
      "\\nTemperature is %3.3f K'%(My,Ty,Py,M2,P2,T2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Properties of fluid just after shock:    \n",
        "Mach number My = 0.621    \n",
        "Temperature is 346.29 K    \n",
        "Pressure is 442.28 kPa \n",
        "B)Exit mach number is 0.36 \n",
        "C)Properties of fluid at exit:    \n",
        "Pressure is 524 kPa    \n",
        "Temperature is 363.675 K\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.23 page : 44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "D = 0.4 \t\t\t\t#Duct diameter in m\n",
      "Po = 12. \t\t\t\t#Stagnation pressure in kPa\n",
      "To = 600. \t\t\t\t#Stagnation temperature in K\n",
      "f = 0.0025 \t\t\t\t#Friction factor\n",
      "M1 = 1.8 \t\t\t\t#Mach number at entry\n",
      "M2 = 1. \t\t\t\t#Mach number at outlet\n",
      "Mx = 1.22 \t\t\t\t#Mach number upstream of shock \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculations\n",
      "A2 = math.pi*D**2/4 \t\t\t\t#Exit area in cm**2\n",
      "p1 = 0.174 \t\t\t\t#Static to Stagnation pressure ratio at entry from gas tables (M1,k = 1.4,isentropiC)\n",
      "P1 = Po*p1 \t\t\t\t#Inlet pressure in bar\n",
      "t1 = 0.607 \t\t\t\t#Static to Stagnation temperature ratio at entry from gas tables (M1,k = 1.4,isentropiC)\n",
      "T1 = To*t1 \t\t\t\t#Inlet temperature in K\n",
      "a1 = 1.094 \t\t\t\t#Ratio of area at exit to critical area across shock from isentropic gas tables @M1,k = 1.4\n",
      "Ax = A2/a1 \t\t\t\t#Area before the shock in cm**2\n",
      "Dt = math.sqrt((Ax*4)/(math.pi))*10**2 \t\t\t\t#Duct diameter at throat in cm\n",
      "p2 = 0.474 \t\t\t\t#Static to Critical pressure ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Pt = P1/p2 \t\t\t\t#Critical pressure in bar \n",
      "t2 = 0.728 \t\t\t\t#Static to Critical temperature ratio at inlet from gas tables,fanno flow tables @M1,k = 1.4\n",
      "Tt = T1/t2 \t\t\t\t#Critical temperature in K\n",
      "X1 = 0.242 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M1,k = 1.4\n",
      "p3 = 0.788 \t\t\t\t#Ratio of Static pressure before shock to critical pressure at entry from gas tables (fanno flow,Mx,k = 1.4)\n",
      "Px = Pt*p3 \t\t\t\t#pressure before shock in bar\n",
      "t3 = 0.925 \t\t\t\t#Ratio of Static temperature before shock to critical temperature at entry from gas tables (fanno flow,Mx,k = 1.4)\n",
      "Tx = Tt*t3 \t\t\t\t#Temperature before shock in K\n",
      "Xx = 0.039 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @Mx,k = 1.4\n",
      "X3 = X1-Xx \t\t\t\t#Overall frictional consmath.tant fanno parameter upstream of duct\n",
      "L1 = (X3*D)/(4*f) \t\t\t\t#Length upstream of duct in m\n",
      "My = 0.83 \t\t\t\t#Mach number downstream of shock from gas tables @Mx\n",
      "p4 = 1.57 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @My\n",
      "Py = Px*p4 \t\t\t\t#Pressure after shock in bar\n",
      "t4 = 1.141 \t\t\t\t#Temperature ratio after and before the shock from gas tables @My\n",
      "Ty = Tx*t4 \t\t\t\t#temperature after shock in K\n",
      "p5 = 1.2375 \t\t\t\t#Ratio of pressure after shock to pressure at critical state from gas tables @My\n",
      "Pt = Py/p5 \t\t\t\t#Critical pressure in bar\n",
      "t5 = 1.055 \t\t\t\t#Ratio of temperature after shock to temperature at critical state from gas tables @My\n",
      "Tt = Ty/t5 \t\t\t\t#Critical temperature in K\n",
      "Xy = 0.049 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @My,k = 1.4\n",
      "X2 = 0 \t\t\t\t#frictional consmath.tant fanno parameter from gas tables,fanno flow tables @M = 1,k = 1.4\n",
      "X4 = Xy-X2 \t\t\t\t#Overall frictional consmath.tant fanno parameter downstream of duct\n",
      "L2 = (X4*D)/(4*f) \t\t\t\t#Length downstream of duct in m\n",
      "L = L1+L2 \t\t\t\t#Length of duct in m\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Length of the pipe is %3.2f m \\\n",
      "\\nB)Diameter of the nozzle throat is %3.3f cm \\\n",
      "\\nC)At the pipe exit:    \\\n",
      "\\nPressure is %3.3f bar    \\\n",
      "\\nTemperature is %3.2f K'%(L,Dt,Pt,Tt)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Length of the pipe is 10.08 m \n",
        "B)Diameter of the nozzle throat is 38.243 cm \n",
        "C)At the pipe exit:    \n",
        "Pressure is 4.404 bar    \n",
        "Temperature is 500.48 K\n"
       ]
      }
     ],
     "prompt_number": 43
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.24 page : 45"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "Po = 700. \t\t\t\t#Stagnation pressure in kPa\n",
      "To = 500.+273 \t\t\t\t#Stagnation temperature in K\n",
      "a1 = 3.5 \t\t\t\t#Ratio of exit area to throat area\n",
      "m = 5.5 \t\t\t\t#Mass flow rate in kg/s\n",
      "Cp = 1.005 \t\t\t\t#Specific heat capacity at consmath.tant pressure in kJ/kg-K\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "My = 1/math.sqrt(k) \t\t\t\t#Mach number downstream of shock\n",
      "M2 = 2.8 \t\t\t\t#Mach number at outlet from gas tables @a1 \n",
      "t1 = 0.389 \t\t\t\t#Static to Stagnation temperature ratio at exit from gas tables (M1,k = 1.4,isentropiC)\n",
      "T2 = To*t1 \t\t\t\t#Exit temperature in K\n",
      "p1 = 0.0369 \t\t\t\t#Static to Stagnation pressure ratio at exit from gas tables (M1,k = 1.4,isentropiC)\n",
      "P2 = Po*p1 \t\t\t\t#exit pressure in kPa\n",
      "p2 = 0.2  \t\t\t\t#Ratio of pressure at exit to pressure at critical state at exit from Rayleigh flow gas tables @M2\n",
      "Pt2 = P2/p2 \t\t\t\t#Exit pressure at critical state in kPa\n",
      "t2 = 0.315 \t\t\t\t#Ratio of temperature at exit to temperature at critical state at exit from Rayleigh flow gas tables @M2\n",
      "Tt2 = T2/t2 \t\t\t\t#Exit temperature at critical state in K\n",
      "t3 = 0.674 \t\t\t\t#Ratio of Stagnation temperature at exit to stagnation temperature at critical state at exit from Rayleigh flow gas tables @M2\n",
      "Tto2 = To/t3 \t\t\t\t#Exit stagnation temperature at critical state in K\n",
      "Mx = 1.2 \t\t\t\t#Mach number upstream of shock from gas tables @My\n",
      "p3 = 0.796 \t\t\t\t#Ratio of Static pressure before shock to critical pressure at exit from gas tables (Rayleigh flow,Mx,k = 1.4)\n",
      "Px = Pt2*p3 \t\t\t\t#Static pressure before shock in kPa\n",
      "t4 = 0.912 \t\t\t\t#Ratio of Static temperature before shock to critical temperature at exit from gas tables (Rayleigh flow,Mx,k = 1.4)\n",
      "Tx = Tt2*t4 \t\t\t\t#Static temperature before shock in K\n",
      "t5 = 0.978 \t\t\t\t#Ratio of Stagnation temperature before shock to critical Stagnation temperature at exit from gas tables (Rayleigh flow,Mx,k = 1.4)\n",
      "Tox = Tto2*t5 \t\t\t\t#Stagnation temperature before shock in K\n",
      "p4 = 1.513 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @Mx \n",
      "Py = Px*p4 \t\t\t\t#Pressure after shock in kPa\n",
      "t6 = 1.128 \t\t\t\t#Temperature ratio after and before the shock from gas tables @Mx\n",
      "Ty = Tx*t6 \t\t\t\t#temperature after shock in K\n",
      "t7 = 0.875 \t\t\t\t#Ratio of Temperature after the shock to Stagnation temperature after shock from gas tables @Mx \n",
      "Toy = Ty/t7 \t\t\t\t#Stagnation temperature after shock in K,\n",
      "p5 = 1.207 \t\t\t\t#Ratio of pressure after shock to pressure at critical state from gas tables @My\n",
      "Pt = Py/p5 \t\t\t\t#Critical pressure in kPa\n",
      "t8 = 1.028 \t\t\t\t#Ratio of temperature after shock to temperature at critical state from gas tables @My\n",
      "Tt = Ty/t8 \t\t\t\t#Critical temperature in K\n",
      "t9 = 0.978 \t\t\t\t#Ratio of Stagnation temperature after shock to Stagnation temperature at critical state from gas tables @My\n",
      "Tot = Toy/t9 \t\t\t\t#Stagnation temperature at critical state in K, calculation mistake in textbbok \n",
      "q1 = Cp*(Tox-To) \t\t\t\t#Amount of heat added in upstream of shock in kJ/s\n",
      "q2 = Cp*(Tot-Toy) \t\t\t\t#Amount of heat added in downstream of shock in kJ/s\n",
      "Q = m*(q1+q2) \t\t\t\t#Amount of heat added in two pipe section in kJ/s\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Amount of heat added in two pipe section is %3.2f kJ/s \\\n",
      "\\nB)Properties: Upstream of shock:    \\\n",
      "\\nPressure is %3.1f kPa    \\\n",
      "\\nTemperature is %3.3f K    \\\n",
      "\\nStagnation temperature is %3.2f K    \\\n",
      "\\nMach number is %3.1f \\\n",
      "\\nDownstream of shock:    Pressure is %3.3f kPa    \\\n",
      "\\nTemperature is %3.3f K    \\\n",
      "\\nStagnation temperature is %3.1f K    \\\n",
      "\\nMach number is %3.3f \\\n",
      "\\nAt the throat:    Pressure is %3.2f kPa    \\\n",
      "\\nTemperature is %3.3f K    \\\n",
      "\\nStagnation temperature is %3.2f K \\\n",
      "\\nAt the exit:    Pressure is %3.2f kPa    \\\n",
      "\\nTemperature is %3.2f K    \\\n",
      "\\nMach number is %3.2f'%(Q,Px,Tx,Tox,Mx,Py,Ty,Toy,My,Pt,Tt,Tot,P2,T2,M2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Amount of heat added in two pipe section is 2066.73 kJ/s \n",
        "B)Properties: Upstream of shock:    \n",
        "Pressure is 102.8 kPa    \n",
        "Temperature is 870.589 K    \n",
        "Stagnation temperature is 1121.65 K    \n",
        "Mach number is 1.2 \n",
        "Downstream of shock:    Pressure is 155.542 kPa    \n",
        "Temperature is 982.025 K    \n",
        "Stagnation temperature is 1122.3 K    \n",
        "Mach number is 0.845 \n",
        "At the throat:    Pressure is 128.87 kPa    \n",
        "Temperature is 955.277 K    \n",
        "Stagnation temperature is 1147.56 K \n",
        "At the exit:    Pressure is 25.83 kPa    \n",
        "Temperature is 300.70 K    \n",
        "Mach number is 2.80\n"
       ]
      }
     ],
     "prompt_number": 45
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.25 page : 47"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "M1 = 2.8 \t\t\t\t#Inlet mach number \n",
      "sig = 42. \t\t\t\t#Shock wave angle in degree\n",
      "Px = 1. \t\t\t\t#Pressure upstream of shock in bar(Assuming)\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculations\n",
      "Mx = M1*math.sin(math.radians(sig)) \t\t\t\t#Mach number before the shock\n",
      "My = 0.601 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 3.98 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @Mx \n",
      "Py = Px*p1 \t\t\t\t#Pressure after shock in bar\n",
      "p2 = 4.994 \t\t\t\t#Stagnation pressure after shock to Static pressure before shock from gas tables @Mx\n",
      "Poy = Px*p2 \t\t\t\t#Stagnation pressure after shock in bar\n",
      "p3 = 0.788 \t\t\t\t#Stagnation pressure ratio after and before the shock from gas tables @Mx\n",
      "Pox = Poy/p3 \t\t\t\t#Stagnation pressure before shock in kPa\n",
      "dPl = Pox-Poy \t\t\t\t#Total pressure loss in bar\n",
      "#disp(((M1^2*sind(2*sig))-(2/tand(sig)))/(2+(M1^2*(k+cosd(2*sig)))))\n",
      "#def=atand(((M1^2*sind(2*sig))-(2/tand(sig)))/(2+(M1^2*(k+cosd(2*sig))))) //Deflection angle in degree\n",
      "def1 = (M1**2*math.sin(math.radians(2*sig)) - (2/math.tan(math.radians(sig))))/(2 + M1**2*(k+math.cos(math.radians(2*sig))))\n",
      "def1 = math.degrees(math.atan(def1))\n",
      "M2 = My/(math.sin(math.radians(sig-def1))) \t\t\t\t#Downstream mach number\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'A)Deflection angle is %3i degree \\\n",
      "\\nB)Downstream mach number is %3.3f \\\n",
      "\\nC)Static pressure is %3.3f bar \\\n",
      "\\nD)Total pressure loss is %3.3f bar'%(def1,M2,Py,dPl)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Deflection angle is  22 degree \n",
        "B)Downstream mach number is 1.758 \n",
        "C)Static pressure is 3.980 bar \n",
        "D)Total pressure loss is 1.344 bar\n"
       ]
      }
     ],
     "prompt_number": 46
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.26 page : 47"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "M1 = 2. \t\t\t\t#Inlet mach number \n",
      "sig = 40. \t\t\t\t#Shock wave angle in degree\n",
      "Px = 0.5 \t\t\t\t#Pressure upstream of shock in bar\n",
      "Tx = 273. \t\t\t\t#Temperature upstream of shock in K\n",
      "k = 1.4 \t\t\t\t#Adiabatic consmath.tant \n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "Mx = M1*math.sin(math.radians(sig)) \t\t\t\t#Mach number before the shock\n",
      "My = 0.796 \t\t\t\t#Mach number after the shock from gas tables @Mx\n",
      "p1 = 1.745 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @Mx \n",
      "Py = p1*Px \t\t\t\t#Pressure after shock in bar\n",
      "t1 = 1.178 \t\t\t\t#Static temperature ratio after and before the shock from gas tables @Mx \n",
      "Ty = Tx*t1 \t\t\t\t#Temperature after shock in K\n",
      "Ws = math.degrees(math.atan(((M1**2*math.sin(math.radians(2*sig))) - (2/math.tan(math.radians(sig)))) / (2+ (M1**2*(k+math.cos(math.radians(2*sig)))))))\n",
      "W = 2*Ws \t\t\t\t#Wedge angle in degree\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Static pressure is %3.4f bar \\\n",
      "\\nB)Temperature behind the wave is %3.2f K \\\n",
      "\\nC)Mach number of flow pasmath.sing over wedge is %3.3f \\\n",
      "\\nD)Wedge angle is %3.2f degree'%(Py,Ty,Mx,W)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Static pressure is 0.8725 bar \n",
        "B)Temperature behind the wave is 321.59 K \n",
        "C)Mach number of flow pasmath.sing over wedge is 1.286 \n",
        "D)Wedge angle is 21.25 degree\n"
       ]
      }
     ],
     "prompt_number": 47
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.27 page : 48"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "from numpy import roots\n",
      "\n",
      "\t\t\t\t\n",
      "#Input data\n",
      "def1 = 15.\n",
      "M1 = 2\n",
      "k = 1.4\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "#Umath.sing relation def = math.radians(math.tan((((M1**2*math.sin(math.radians(2*sig))-(2/math.radians(math.tan((sig)))/(2+(M1**2*(k+math.cos(math.radians(2*sig))))) and converting into 6th degree polynomial of math.sin(math.radians(sig) = x\n",
      "#C=((2*tand(def))+((M1^2)*k*tand(def))+((M1^2)*tand(def))) \n",
      "C = ((2*math.tan(math.radians(def1))) + ((M1**2)*k*math.tan(math.radians(def1))) + ((M1**2)*math.tan(math.radians(def1))))\n",
      "#C = ((2*math.radians(math.tan((def1))+((M1**2)*k*math.radians(math.tan((def1))+((M1**2)*math.radians(math.tan((def1))) \t\t\t\t#Consmath.tant value for convenience\n",
      "D = (2*M1**2*math.tan(math.radians(def1))) \t\t\t\t#Consmath.tant value for convenience\n",
      "a = 4 \t\t\t\t#Value of consmath.tant in polynomial  \n",
      "b = 0 \t\t\t\t#Coefficient of power 1 i.e. x**1\n",
      "c = (4+C**2+(8*M1**2)) \t\t\t\t#Coefficient of power 2 i.e. x**2\n",
      "d = 0 \t\t\t\t#Coefficient of power 3 i.e. x**3\n",
      "e = (4*(M1**4))+(2*C*D)+(8*M1**2) \t\t\t\t#Coefficient of power 4 i.e. x**4\n",
      "f = 0 \t\t\t\t#Coefficient of power 5 i.e. x**5\n",
      "g = (4*M1**4)+D**2 \t\t\t\t#Coefficient of power 6 i.e. x**6\n",
      "#p4 = poly([a b -c -d e f -g],'x','c') \t\t\t\t#Expression for solving 6th degree polynomial\n",
      "print ('Values for sine of wave angle are:')\n",
      "print (roots([-g,f,e,-d,-c,b,a]))\n",
      "sig1 = math.degrees(math.asin(0.9842)) \t\t\t\t#Strong shock wave angle in degree, nearer to 90 degree\n",
      "sig2 = math.degrees(math.asin(0.7113)) \t\t\t\t#Weak shock wave angle in degree, nearer to 45 degree\n",
      "\n",
      "#(a)Strong Shock Wave\n",
      "Mx_1 = M1*math.sin(math.radians(sig1)) \t\t\t\t#Mach number before the shock of stong shock wave\n",
      "My_1 = 0.584 \t\t\t\t#Mach number after the shock from gas tables @Mx_1\n",
      "p1 = 4.315 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @Mx_1\n",
      "t1 = 1.656 \t\t\t\t#Static temperature ratio after and before the shock from gas tables @Mx_1\n",
      "d1 = p1/t1 \t\t\t\t#Density ratio after and before the shock of stong shock wave\n",
      "M2_1 = My_1/(math.sin(math.radians(sig1-def1))) \t\t\t\t#Exit mach number of stong shock wave\n",
      "Mx_2 = M1*math.sin(math.radians(sig2)) \t\t\t\t#Mach number before the shock of weak shock wave\n",
      "My_2 = 0.731 \t\t\t\t#Mach number after the shock from gas tables @Mx_2\n",
      "p2 = 2.186 \t\t\t\t#Static pressure ratio after and before the shock from gas tables @Mx_2\n",
      "t2 = 1.267 \t\t\t\t#Static temperature ratio after and before the shock from gas tables @Mx_2\n",
      "d2 = p2/t2 \t\t\t\t#Density ratio after and before the shock of weak shock wave\n",
      "M2_2 = My_2/(math.sin(math.radians(sig2-def1))) \t\t\t\t#Exit mach number of weak shock wave\n",
      "\n",
      "\t\t\t\t\n",
      "#Output \n",
      "print 'Strong Shock Wave:    A)Wave angle is %3.1f degree    \\\n",
      "\\nB)Pressure ratio is %3.3f    \\\n",
      "\\nC)Density ratio is %3.3f    \\\n",
      "\\nD)Temperature ratio is %3.3f    \\\n",
      "\\nE)Downstream Mach number is %3.3f \\\n",
      "\\nWeak Shock Wave:    A)Wave angle is %3.1f degree    \\\n",
      "\\nB)Pressure ratio is %3.3f    \\\n",
      "\\nC)Density ratio is %3.3f    \\\n",
      "\\nD)Temperature ratio is %3.3f    \\\n",
      "\\nE)Downstream Mach number is %3.3f'%(sig1,p1,d1,t1,M2_1,sig2,p2,d2,t2,M2_2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Values for sine of wave angle are:\n",
        "[ 0.98429339 -0.98429339  0.71133473 -0.71133473 -0.34489365  0.34489365]\n",
        "Strong Shock Wave:    A)Wave angle is 79.8 degree    \n",
        "B)Pressure ratio is 4.315    \n",
        "C)Density ratio is 2.606    \n",
        "D)Temperature ratio is 1.656    \n",
        "E)Downstream Mach number is 0.645 \n",
        "Weak Shock Wave:    A)Wave angle is 45.3 degree    \n",
        "B)Pressure ratio is 2.186    \n",
        "C)Density ratio is 1.725    \n",
        "D)Temperature ratio is 1.267    \n",
        "E)Downstream Mach number is 1.447\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.28 page : 49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\t\n",
      "#Input data\n",
      "k = 1.3 \t\t\t\t#Adiabatic consmath.tant \n",
      "P1 = 0.345 \t\t\t\t#Inlet pressure in bar\n",
      "T1 = 350. \t\t\t\t#Inlet temperature in K\n",
      "M1 = 1.5 \t\t\t\t#Inlet mach number \n",
      "P2 = 0.138 \t\t\t\t#Exit pressure in bar\n",
      "\n",
      "\t\t\t\t\n",
      "#Calculation\n",
      "p1 = 0.284 \t\t\t\t#Pressure ratio at entry from gas tables @M1,k = 1.3\n",
      "Po = P1/p1 \t\t\t\t#Stagnation Pressure in bar\n",
      "t1 = 0.748 \t\t\t\t#Temperature ratio at entry from gas tables @M1,k = 1.3\n",
      "To = T1/t1 \t\t\t\t#Stagnation temperature in K\n",
      "p2 = P2/Po \t\t\t\t#Pressure ratio\n",
      "M2 = 2.08 \t\t\t\t#Final Mach number from isentropic gas tables @p2\n",
      "t2 = 0.606 \t\t\t\t#Temperature ratio at exit from gas tables @M2,k = 1.3\n",
      "T2 = To*t2 \t\t\t\t#The temperature of the gas in K\n",
      "w1 = 12.693 \t\t\t\t#Prandtl Merger function at M1 \n",
      "w2 = 31.12 \t\t\t\t#Prandtl Merger function at M2\n",
      "def1 = w2-w1 \t\t\t\t#Deflection Angle in degree\n",
      "\n",
      "\t\t\t\t\n",
      "#Output\n",
      "print 'A)Deflection Angle is %3.3f degree \\\n",
      "\\nB)Final Mach number is %3.2f \\\n",
      "\\nC)The temperature of the gas is %3.3f K'%(def1,M2,T2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A)Deflection Angle is 18.427 degree \n",
        "B)Final Mach number is 2.08 \n",
        "C)The temperature of the gas is 283.556 K\n"
       ]
      }
     ],
     "prompt_number": 49
    }
   ],
   "metadata": {}
  }
 ]
}