summaryrefslogtreecommitdiff
path: root/Basic_Engineering_Thermodynamics_by_Rayner_Joel/Chapter8.ipynb
blob: 9280416cb485f1ac79ce102560b9b00823622863 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 8 - Combustion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.1\n",
      " The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) =  14.8\n"
     ]
    }
   ],
   "source": [
    "#pg 198\n",
    "print('Example 8.1');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the stoichiometric mass of air required to burn 1 kg the fuel \n",
    "\n",
    "#  Given values\n",
    "C = .72;#  mass fraction of C; [kg/kg]\n",
    "H2 = .20;#  mass fraction of H2;, [kg/kg]\n",
    "O2 = .08;#  mass fraction of O2, [kg/kg]\n",
    "aO2=.232;#  composition of oxygen in air\n",
    "\n",
    "#  solution\n",
    "#  for 1kg of fuel\n",
    "mO2  = 8./3*C+8*H2-O2;#  mass of O2, [kg]\n",
    "\n",
    "#  hence stoichiometric mass of O2 required is\n",
    "msO2  = mO2/aO2;# [kg]\n",
    "\n",
    "#results\n",
    "print ' The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) = ',round(msO2,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.2\n",
      " The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) =  15.18\n"
     ]
    }
   ],
   "source": [
    "#pg 198\n",
    "print('Example 8.2');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the stoichiometric mass of air required to burn 1 kg of heptane\n",
    "\n",
    "#  Given values\n",
    "C = .84;#  mass fraction of C; [kg/kg]\n",
    "H2 = .16;#  mass fraction of H2;, [kg/kg]\n",
    "x1 = 11.5;#  mass fraction of O2, [kg/kg]\n",
    "x2 = 34.5;#  composition of oxygen in air\n",
    "\n",
    "#  solution\n",
    "#  for 1kg of fuel\n",
    "mO2  = x1*C + x2*H2 ;#  mass of O2, [kg]\n",
    "\n",
    "mO22 = ((11*32)+100)/100\n",
    "mO2x = (mO22-1)/.232\n",
    "#results\n",
    "print ' The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) = ',round(mO2,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 199"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.3\n",
      " The stoichiometric mass of air is (kg/kg fuel) =  13.52\n",
      " CO2 produced  =  3.01  kg/kg fuel,  percentage composition  =  20.7 ,\n",
      " H2O produced  =  1.08  kg/kg fuel,  percentage composition  =  7.43 ,\n",
      " SO2 produced  =  0.02  kg/kg fuel,  percentage composition  =  0.14 ,\n",
      " N2 produced  =  10.43  kg/kg fuel,  percentage composition  =  71.74\n"
     ]
    }
   ],
   "source": [
    "#pg 199\n",
    "print('Example 8.3');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the stoichiometric mass of air\n",
    "#  the products of combustion both by mass and as percentage \n",
    "\n",
    "#  Given values\n",
    "C = .82;# mass composition C\n",
    "H2 = .12;# mass composition of H2\n",
    "O2 = .02;# mass composition of O2\n",
    "S = .01;# mass composition of S\n",
    "N2 = .03;# mass composition of N2\n",
    "\n",
    "#  solution\n",
    "#  for 1kg fuel\n",
    "mo2 = 8./3*C+8*H2-O2+S*1;# total mass of  O2 required, [kg]\n",
    "sa = mo2/.232;# stoichimetric  air, [kg]\n",
    "print ' The stoichiometric mass of air is (kg/kg fuel) = ',round(sa,2)\n",
    "\n",
    "# for one kg fuel\n",
    "mCO2 = C*11/3;# mass of CO2 produced, [kg]\n",
    "mH2O = H2*9;# mass of H2O produced, [kg]\n",
    "mSO2 = S*2;# mass of SO2 produce, [kg]\n",
    "mN2 = C*8.84+H2*26.5-O2*.768/.232+S*3.3+N2;# mass of N2 produced, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mSO2+mN2;# total mass of product, [kg]\n",
    "\n",
    "x1 = mCO2/mt*100;# %age mass composition of CO2 produced\n",
    "x2 = mH2O/mt*100;# %age mass composition of H2O produced\n",
    "x3 = mSO2/mt*100;# %age mass composition of SO2 produced\n",
    "x4 = mN2/mt*100;# %age mass composition of N2 produced\n",
    "\n",
    "print ' CO2 produced  = ',round(mCO2,2),' kg/kg fuel,  percentage composition  = ',round(x1,1),',\\n H2O produced  = ',mH2O,' kg/kg fuel,  percentage composition  = ',round(x2,2),',\\n SO2 produced  = ',mSO2,' kg/kg fuel,  percentage composition  = ',round(x3,2),',\\n N2 produced  = ',round(mN2,2),' kg/kg fuel,  percentage composition  = ',round(x4,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 202"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.4\n",
      " The  stoichiometric volume of air required for complete combustion is  (m^3/m^3  fuel) =  0.952\n"
     ]
    }
   ],
   "source": [
    "#pg 202\n",
    "print('Example 8.4');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the stoichiometric volume of air required for complete combution of 1 m^3 of the gas\n",
    "\n",
    "#  Given values\n",
    "H2 = .14;# volume fraction of H2\n",
    "CH4 = .02;# volume fraction of CH4\n",
    "CO = .22;# volume fraction of CO\n",
    "CO2 = .05;# volume fraction of CO2\n",
    "O2 = .02;# volume fraction of O2\n",
    "N2 = .55;# volume fraction of N2\n",
    "\n",
    "# solution\n",
    "#  for 1 m^3 of fuel\n",
    "Va = .5*H2+2*CH4+.5*CO-O2;# [m^3]\n",
    "\n",
    "#  stoichiometric air required is\n",
    "Vsa = Va/.21;#  [m^3]\n",
    "#results\n",
    "print ' The  stoichiometric volume of air required for complete combustion is  (m^3/m^3  fuel) = ',round(Vsa,3)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 203"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.5\n",
      " The volume of air required is(m^3/m^3 fuel) =  3.451\n",
      "Result in the book is misprinted\n"
     ]
    }
   ],
   "source": [
    "#pg 203\n",
    "print('Example 8.5');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the volume of the air required \n",
    "\n",
    "#  Given values\n",
    "H2 = .45;# volume fraction of H2\n",
    "CO = .40;# volume fraction of CO\n",
    "CH4 = .15;# volume fraction of CH4\n",
    "\n",
    "#  solution\n",
    "V = 2.38*(H2+CO)+9.52*CH4;# stoichimetric volume of air, [m^3]\n",
    "#results\n",
    "print ' The volume of air required is(m^3/m^3 fuel) = ',V\n",
    "\n",
    "print 'Result in the book is misprinted'\n",
    "\n",
    "# End\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6: pg 203"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.6\n",
      " Stoichiometric volume of air required is (m^3/m^3 fuel) =  3.15\n",
      " N2 in products  =  2.516  m^3/m^3  fuel,  percentage composition  =  66.8 ,\n",
      " CO2 in products =  0.561  m^3/m^3 fuel,  percentage composition  = 14.9 ,\n",
      " H2O in products  =  0.689 m^3/m^3  fuel,  percentage composition  = 18.3\n"
     ]
    }
   ],
   "source": [
    "#pg 203\n",
    "print('Example 8.6');\n",
    "\n",
    "# aim : To determine\n",
    "# the stoichiometric volume of air for the complete combustion\n",
    "# the products of combustion\n",
    "\n",
    "# given values\n",
    "CH4 = .142;# volumetric composition of CH4\n",
    "CO2 = .059;# volumetric composition of CO2\n",
    "CO = .360;# volumetric composition of CO\n",
    "H2 = .405;# volumetric composition of H2\n",
    "O2 = .005;# volumetric composition of O2\n",
    "N2 = .029;# volumetric composition of N2\n",
    "\n",
    "aO2 = .21;# O2 composition into air by volume\n",
    "\n",
    "#  solution\n",
    "svO2 = CH4*2+CO*.5+H2*.5-O2;# stroichiometric volume of O2 required, [m^3/m^3 fuel]\n",
    "svair = svO2/aO2;# stroichiometric volume of air required, [m^3/m^3 fuel]\n",
    "print ' Stoichiometric volume of air required is (m^3/m^3 fuel) = ',svair\n",
    "\n",
    "# for one m^3 fuel\n",
    "vN2 = CH4*7.52+CO*1.88+H2*1.88-O2*.79/.21+N2;# volume of N2 produced, [m^3]\n",
    "vCO2 = CH4*1+CO2+CO*1;# volume of CO2 produced, [m^3]\n",
    "vH2O = CH4*2+H2*1;# volume of H2O produced, [m^3]\n",
    "\n",
    "vt = vN2+vCO2+vH2O;# total volume of product, [m^3]\n",
    "\n",
    "x1 = vN2/vt*100;# %age composition of N2 in product,\n",
    "x2 = vCO2/vt*100;# %age composition of CO2 in product\n",
    "x3 = vH2O/vt*100;# %age composition of H2O in product\n",
    "\n",
    "print ' N2 in products  = ',round(vN2,3),' m^3/m^3  fuel,  percentage composition  = ',round(x1,1),',\\n CO2 in products = ',vCO2,' m^3/m^3 fuel,  percentage composition  =',round(x2,1),',\\n H2O in products  = ',vH2O,'m^3/m^3  fuel,  percentage composition  =',round(x3,1)\n",
    "\n",
    "# End \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7: pg 206"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.7\n",
      " Mass percentage of CO2 is  =  27.8  \n",
      "\n",
      " Mass percentage of N2 is  =  62.0  \n",
      "\n",
      " Mass percentage of O2 is  =   10.1\n"
     ]
    }
   ],
   "source": [
    "#pg 206\n",
    "print('Example 8.7');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the percentage analysis of the gas by mass\n",
    "\n",
    "#  Given values\n",
    "CO2 = 20.;# percentage volumetric composition  of CO2\n",
    "N2 = 70.;# percentage volumetric composition of N2\n",
    "O2 = 10.;# percentage volumetric composition  of O2\n",
    "\n",
    "mCO2 = 44.;#  moleculer mas of CO2\n",
    "mN2 = 28.;#  moleculer mass of N2\n",
    "mO2 = 32.;#  moleculer mass of O2\n",
    "\n",
    "#  solution\n",
    "mgas = CO2*mCO2+N2*mN2+O2*mO2;#  moleculer mass of gas \n",
    "m1 = CO2*mCO2/mgas*100;# percentage composition of CO2 by mass \n",
    "m2 = N2*mN2/mgas*100;# percentage composition of N2 by mass \n",
    "m3 = O2*mO2/mgas*100;# percentage composition of O2 by mass \n",
    "#results\n",
    "print ' Mass percentage of CO2 is  = ',round(m1,1),' \\n\\n Mass percentage of N2 is  = ',round(m2,1),' \\n\\n Mass percentage of O2 is  =  ',round(m3,1)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8: pg 206"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.8\n",
      " The percentage composition of CO by volume is  =  6.9  \n",
      ",\n",
      "The percentage composition of N2 by volume is  = 4.6 \n",
      "\n",
      "The percentage composition of CH4 by volume is  =  6.0 \n",
      "\n",
      "The percentage composition of H2 by volume is  =  80.5  \n",
      "\n",
      "The percentage composition of O2by volume is=  2.0\n"
     ]
    }
   ],
   "source": [
    "#pg 206\n",
    "print('Example 8.8');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the percentage composition of the gas by volume\n",
    "\n",
    "#  given values\n",
    "CO = 30.;# %age mass composition of CO\n",
    "N2 = 20.;# %age mass composition of N2\n",
    "CH4 = 15.;# %age mass composition of CH4\n",
    "H2 = 25.;# %age mass composition of H2\n",
    "O2 = 10.;# %age mass composition of O2\n",
    "\n",
    "mCO = 28.;# molculer mass of CO\n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mCH4 = 16.;# molculer mass of CH4\n",
    "mH2 = 2.;# molculer mass of H2\n",
    "mO2 = 32.;# molculer mass of O2\n",
    "\n",
    "# solution\n",
    "vg = CO/mCO+N2/mN2+CH4/mCH4+H2/mH2+O2/mO2;\n",
    "v1 = CO/mCO/vg*100;# %age volume composition of CO\n",
    "v2 = N2/mN2/vg*100;# %age volume composition of N2\n",
    "v3 = CH4/mCH4/vg*100;# %age volume composition of CH4\n",
    "v4 = H2/mH2/vg*100;# %age volume composition of H2\n",
    "v5 = O2/mO2/vg*100;# %age volume composition of O2\n",
    "#results\n",
    "print ' The percentage composition of CO by volume is  = ',round(v1,1),' \\n,\\nThe percentage composition of N2 by volume is  =',round(v2,1), '\\n\\nThe percentage composition of CH4 by volume is  = ',round(v3,1),'\\n\\nThe percentage composition of H2 by volume is  = ',round(v4,1),' \\n\\nThe percentage composition of O2by volume is= ',round(v5,1)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 9: pg 209"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.9\n",
      " The mass of air supplied per/kg of fuel burnt is (kg) =  21.1\n"
     ]
    }
   ],
   "source": [
    "#pg 209\n",
    "print('Example 8.9');\n",
    "\n",
    "# aim : To determine\n",
    "# the mass of air supplied per kilogram of fuel burnt\n",
    "\n",
    "# given values\n",
    "CO2 = 8.85;# volume composition of CO2\n",
    "CO = 1.2;#  volume composition of CO\n",
    "O2 = 6.8;#  volume composition of O2\n",
    "N2 = 83.15;#  volume composition of N2 \n",
    "\n",
    "# composition of gases in the fuel oil\n",
    "C = .84;# mass composition of carbon \n",
    "H = .14;# mass composition of hydrogen\n",
    "o2 = .02;# mass composition of oxygen\n",
    "\n",
    "mC = 12.;# moleculer mass of Carbon\n",
    "mCO2 = 44.;# molculer mass of CO2\n",
    "mCO = 28.;# molculer mass of CO\n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mO2 = 32.;# molculer mass of O2\n",
    "aO2 = .23;# mass composition of O2 in air\n",
    "\n",
    "# solution\n",
    "ma = (8./3*C+8*H-o2)/aO2;# theoretical mass of air/kg fuel, [kg]\n",
    "\n",
    "mgas = CO2*mCO2+CO*mCO+N2*mN2+O2*mO2;#  total mass of gas/kg fuel, [kg]\n",
    "x1 = CO2*mCO2/mgas;#  composition of CO2 by mass \n",
    "x2 = CO*mCO/mgas;# composition of CO by mass\n",
    "x3 = O2*mO2/mgas;#  composition of O2 by mass \n",
    "x4 = N2*mN2/mgas;#  composition of N2 by mass \n",
    "\n",
    "m1 = x1*mC/mCO2+x2*mC/mCO;# mass of C/kg of dry flue gas, [kg]\n",
    "m2 = C;# mass of C/kg fuel, [kg]\n",
    "mf = m2/m1;# mass of dry flue gas/kg fuel, [kg]\n",
    "mo2 = mf*x3;# mass of excess O2/kg fuel, [kg]\n",
    "mair = mo2/aO2;# mass of excess air/kg fuel, [kg]\n",
    "m = ma+mair;# mass of excess air supplied/kg fuel, [kg]\n",
    "#results\n",
    "print ' The mass of air supplied per/kg of fuel burnt is (kg) = ',round(m,1)\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10: pg 210"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.10\n",
      "The percentage composition of CO2 by volume is  = 10.98 \n",
      ",\n",
      "The percentage composition of H2O by volume is  =  10.72   \n",
      ",\n",
      "The percentage composition of O2 by volume is  =  3.27 \n",
      ",\n",
      "The percentage composition of N2 by volume is  =  75.03\n"
     ]
    }
   ],
   "source": [
    "#pg 210\n",
    "print('Example 8.10');\n",
    "\n",
    "# aim : To determine\n",
    "# volumetric composition of the products of combustion\n",
    "\n",
    "# given values\n",
    "C = .86;#  mass composition of carbon\n",
    "H = .14;# mass composition of hydrogen\n",
    "Ea = .20;#  excess air for combustion\n",
    "O2 = .23;# mass composition of O2 in air \n",
    "\n",
    "MCO2 = 44.;# moleculer mass of CO2\n",
    "MH2O = 18.;# moleculer mass of H2O\n",
    "MO2 = 32.;# moleculer mass of O2\n",
    "MN2 = 28.;# moleculer mass of N2,\n",
    "\n",
    "\n",
    "# solution\n",
    "sO2 = (8./3*C+8*H);# stoichiometric O2 required, [kg/kg petrol]\n",
    "sair = sO2/O2;# stoichiometric air required, [kg/kg petrol]\n",
    "# for one kg petrol\n",
    "mCO2 = 11./3*C;# mass of CO2,[kg]\n",
    "mH2O = 9*H;# mass of H2O, [kg]\n",
    "mO2 = Ea*sO2;# mass of O2, [kg]\n",
    "mN2 = 14.84*(1+Ea)*(1-O2);# mass of N2, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mO2+mN2;# total mass, [kg]\n",
    "# percentage mass composition\n",
    "x1 = mCO2/mt*100;# mass composition of CO2\n",
    "x2 = mH2O/mt*100;# mass composition of H2O\n",
    "x3 = mO2/mt*100;# mass composition of O2\n",
    "x4 = mN2/mt*100;# mass composition of N2\n",
    "\n",
    "vt = x1/MCO2+x2/MH2O+x3/MO2+x4/MN2;# total volume of petrol\n",
    "v1 = x1/MCO2/vt*100;# %age composition of CO2 by volume\n",
    "v2 = x2/MH2O/vt*100;# %age composition  of H2O by volume\n",
    "v3 = x3/MO2/vt*100;# %age composition of O2 by volume\n",
    "v4 = x4/MN2/vt*100;# %age composition of N2 by volume\n",
    " #results\n",
    "print 'The percentage composition of CO2 by volume is  =',round(v1,2),'\\n,\\nThe percentage composition of H2O by volume is  = ',round(v2,2),'  \\n,\\nThe percentage composition of O2 by volume is  = ',round(v3,2),'\\n,\\nThe percentage composition of N2 by volume is  = ',round(v4,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11: pg 211"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.11\n",
      " The energy carried away by the dry flue gas/kg is (kg) =  5000.0\n"
     ]
    }
   ],
   "source": [
    "#pg 211\n",
    "print('Example 8.11');\n",
    "\n",
    "# aim : To determine\n",
    "#  the energy carried away by the dry flue gas/kg of fuel burned\n",
    "\n",
    "# given values\n",
    "C = .78;#  mass composition of carbon\n",
    "H2 = .06;# mass composition of hydrogen\n",
    "O2 = .09;# mass composition of oxygen\n",
    "Ash = .07;# mass composition of ash\n",
    "Ea = .50;#  excess air for combustion\n",
    "aO2 = .23;# mass composition of O2 in air \n",
    "Tb = 273.+20;# boiler house temperature, [K]\n",
    "Tf = 273.+320;# flue gas temperature, [K]\n",
    "c = 1.006;# specific heat capacity of dry flue gas, [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "# for one kg of fuel\n",
    "sO2 = (8./3*C+8*H2);# stoichiometric O2 required, [kg/kg fuel]\n",
    "sO2a = sO2-O2;# stoichiometric O2 required from air, [kg/kg fuel]\n",
    "sair = sO2a/aO2;# stoichiometric air required, [kg/kg fuel]\n",
    "ma = sair*(1+Ea);# actual air supplied/kg of fuel, [kg]\n",
    "# total mass of flue gas/kg fuel is\n",
    "mf = ma+1;# [kg]\n",
    "mH2 = 9*H2;#H2 produced, [kg] \n",
    "# hence, mass of dry flue gas/kg coall is\n",
    "m = mf-mH2;# [kg]\n",
    "Q = m*c*(Tf-Tb);# energy carried away by flue gas, [kJ]\n",
    "#results\n",
    "print ' The energy carried away by the dry flue gas/kg is (kg) = ',round(Q)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12: pg 212"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.12\n",
      " (a) The stoichiometric volume of air for the complete combustion (m^3/m^3 gas) =  9.702\n",
      " (b) The percentage volumetric composition of CO2 in produced is  =   9.6  \n",
      ",\n",
      "     The percentage volumetric composition of H2O in produced is  =  18.8   \n",
      ",\n",
      "     The percentage volumetric composition of N2 in produced is  =  71.6\n"
     ]
    }
   ],
   "source": [
    "#pg 212\n",
    "print('Example 8.12');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the stoichiometric volume of air for the complete combustion of 1 m^3\n",
    "# (b) the percentage volumetric analysis of the products of combustion\n",
    "\n",
    "# given values\n",
    "N2 = .018;# volumetric composition of N2\n",
    "CH4 = .94;# volumetric composition of CH4\n",
    "C2H6 = .035;# volumetric composition of C2H6\n",
    "C3H8 = .007;# volumetric composition of C3H8\n",
    "aO2 = .21;# O2 composition in air\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "# for CH4\n",
    "# CH4 +2 O2= CO2 + 2 H2O\n",
    "sva1 = 2./aO2;# stoichiometric volume of air, [m^3/m^3 CH4]\n",
    "svn1 = sva1*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 CH4]\n",
    "\n",
    "# for C2H6\n",
    "# 2 C2H6 +7 O2= 4 CO2 + 6 H2O\n",
    "sva2 = 7./2/aO2;# stoichiometric volume of air, [m^3/m^3 C2H6]\n",
    "svn2 = sva2*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 C2H6]\n",
    "\n",
    "# for C3H8\n",
    "# C3H8 +5 O2=3 CO2 + 4 H2O\n",
    "sva3 = 5/aO2;# stoichiometric volume of air, [m^3/m^3 C3H8]\n",
    "svn3 = sva3*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 C3H8]\n",
    "\n",
    "Sva = CH4*sva1+C2H6*sva2+C3H8*sva3;# stoichiometric volume of air required, [m^3/m^3 gas]\n",
    "print ' (a) The stoichiometric volume of air for the complete combustion (m^3/m^3 gas) = ',round(Sva,3)\n",
    "\n",
    "# (b)\n",
    "# for one m^3 of natural gas\n",
    "vCO2 = CH4*1+C2H6*2+C3H8*3;# volume of CO2 produced, [m^3]\n",
    "vH2O = CH4*2+C2H6*3+C3H8*4;# volume of H2O produced, [m^3]\n",
    "vN2 = CH4*svn1+C2H6*svn2+C3H8*svn3+N2;# volume of N2 produced, [m^3]\n",
    "\n",
    "vg = vCO2+vH2O+vN2;# total volume of gas, [m^3]\n",
    "x1 = vCO2/vg*100;# volume percentage of CO2 produced\n",
    "x2 = vH2O/vg*100;# volume percentage of H2O produced\n",
    "x3 = vN2/vg*100;# volume percentage of N2 produced\n",
    "\n",
    "print ' (b) The percentage volumetric composition of CO2 in produced is  =  ',round(x1,1),' \\n,\\n     The percentage volumetric composition of H2O in produced is  = ',round(x2,1),'  \\n,\\n     The percentage volumetric composition of N2 in produced is  = ',round(x3,1)\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13: pg 214"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.13\n",
      " (a) Volume of air taken by fan is (m^3/s) =  2.51\n",
      " (b) Percentage mass composition of CO2 is (percent) =  18.77\n",
      "     Percentage mass composition of O2 is (percent) =  5.24\n",
      "     Percentage mass composition of N2 is (percent) =  75.99\n"
     ]
    }
   ],
   "source": [
    "#pg 214\n",
    "print('Example 8.13');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the volume of air taken by the fan\n",
    "# (b) the percentage composition of dry flue gas\n",
    "\n",
    "# gien values\n",
    "C = .82;# mass composition of carbon\n",
    "H = .08;# mass composition of hydrogen\n",
    "O = .03;# mass composition of oxygen\n",
    "A = .07;# mass composition of ash\n",
    "mc = .19;# coal uses, [kg/s] \n",
    "ea = .3;# percentage excess air of oxygen in the air required for combustion\n",
    "Oa = .23;# percentage of oxygen by mass in the air\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "P = 100.;# air pressure, [kN/m^2]\n",
    "T = 18.+273;# air temperature, [K]\n",
    "R = .287;# [kJ/kg K]\n",
    "# basis one kg coal\n",
    "sO2 = 8./3*C+8*H;# stoichiometric O2 required, [kg]\n",
    "aO2 = sO2-.03;# actual O2 required, [kg]\n",
    "tO2 = aO2/Oa;# theoretical O2 required, [kg]\n",
    "Aa = tO2*(1+ea);# actual air supplied, [kg]\n",
    "m = Aa*mc;# Air supplied, [kg/s]\n",
    "\n",
    "# now using P*V=m*R*T\n",
    "V = m*R*T/P;# volume of air taken ,[m^3/s]\n",
    "print ' (a) Volume of air taken by fan is (m^3/s) = ',round(V,2)\n",
    "\n",
    "# (b)\n",
    "mCO2 = 11./3*C;# mass of CO2 produced, [kg]\n",
    "mO2 = aO2*.3;# mass of O2 produces, [kg]\n",
    "mN2 = Aa*.77;# mass of N2 produced, [[kg]\n",
    "mt = mCO2+mO2+mN2;# total mass, [kg]\n",
    "\n",
    "print ' (b) Percentage mass composition of CO2 is (percent) = ',round(mCO2/mt*100,2)\n",
    "print '     Percentage mass composition of O2 is (percent) = ',round(mO2/mt*100,2)\n",
    "print '     Percentage mass composition of N2 is (percent) = ',round(mN2/mt*100,2)\n",
    "\n",
    "\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14: pg 215"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.14\n",
      " (a) Mass of fuel used per cycle is (g) =  0.444\n",
      " (b) The mass of air supplied per cycle is (kg) =  0.0136\n",
      " (c) The volume of air taken in per cycle is (m^3) =  0.0114\n"
     ]
    }
   ],
   "source": [
    "#pg 215\n",
    "print('Example 8.14');\n",
    "\n",
    "# aim : To determine \n",
    "# (a) the mass of fuel used per cycle\n",
    "# (b) the actual mass of air taken in per cycle\n",
    "# (c) the volume of air taken in per cycle\n",
    "\n",
    "# given values\n",
    "W = 15.;# work done, [kJ/s]\n",
    "N = 5.;# speed, [rev/s]\n",
    "C = .84;# mass composition of carbon\n",
    "H = .16;# mass composition of hydrogen\n",
    "ea = 1.;# percentage excess air supplied \n",
    "CV = 45000.;# calorificvalue of fuel, [kJ/kg]\n",
    "n_the = .3;# thermal efficiency\n",
    "P = 100.;# pressuer, [kN/m^2]\n",
    "T = 273.+15;# temperature, [K]\n",
    "R = .29;# gas constant, [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "E = W*2/N/n_the;# energy supplied, [kJ/cycle]\n",
    "mf = E/CV;# mass of fuell used, [kg]\n",
    "print ' (a) Mass of fuel used per cycle is (g) = ',round(mf*10**3,3)\n",
    "\n",
    "# (b)\n",
    "# basis 1 kg fuel\n",
    "mO2 = C*8./3+8*H;# mass of O2 requirea, [kg]\n",
    "smO2 = mO2/.23;# stoichiometric mass of air, [kg]\n",
    "ma = smO2*(1+ea);# actual mass of air supplied, [kg]\n",
    "m = ma*mf;# mass of air supplied, [kg/cycle]\n",
    "print ' (b) The mass of air supplied per cycle is (kg) = ',round(m,4)\n",
    "\n",
    "# (c)\n",
    "V = m*R*T/P;# volume of air, [m^3]\n",
    "print ' (c) The volume of air taken in per cycle is (m^3) = ',round(V,4)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15: pg 216"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.15\n",
      " (a) The mass of coal used per hour is (kg) =  95.7\n",
      " (b) The mass of air supplied per hour is (kg) =  1590.0\n",
      " (c) The mass percentage composition of CO2  =   20.83  ,\n",
      "      The mass percentage composition of H2O  =  3.08  ,\n",
      "      The mass percentage composition of O2  =  3.89  ,\n",
      "      The mass percentage composition of N2  = 72.2\n"
     ]
    }
   ],
   "source": [
    "#pg 216\n",
    "print('Example 8.15');\n",
    "\n",
    "#  aim : To determine\n",
    "#  (a) the mass of coal used per hour\n",
    "#  (b) the mass of air used per hour\n",
    "#  (c) the percentage analysis of the flue gases by mass\n",
    "\n",
    "#  given values\n",
    "m = 900.;# mass of steam boiler generate/h, [kg]\n",
    "x = .96;# steam dryness fraction\n",
    "P = 1400.;# steam pressure, [kN/m^2]\n",
    "Tf = 52.;# feed water temperature, [C]\n",
    "BE = .71;# boiler efficiency\n",
    "CV = 33000.;# calorific value  of coal, [kJkg[\n",
    "ea = .22;# excess air supply\n",
    "aO2 = .23;# oxygen composition in air\n",
    "c = 4.187;# specific heat capacity of water, [kJ/kg K]\n",
    "\n",
    "#  coal composition\n",
    "C = .83;# mass composition of carbon\n",
    "H2 = .05;# mass composition of hydrogen\n",
    "O2 = .03;# mass composition of oxygen\n",
    "ash = .09;# mass composition of ash\n",
    "\n",
    "# solution\n",
    "# from steam table at pressure P\n",
    "hf = 830.1;# specific enthalpy, [kJ/kg]\n",
    "hfg = 1957.1;# specific enthalpy, [kJ/kg]\n",
    "hg = 2728.8;# specific enthalpy, [kJ/kg]\n",
    "\n",
    "# (a)\n",
    "h = hf+x*hfg;# specific enthalpy of steam generated by boiler, [kJ/kg]\n",
    "hfw = c*Tf;# specific enthalpy of feed water, [kJ/kg]\n",
    "Q = m*(h-hfw);# energy to steam/h, [kJ]\n",
    "Qf = Q/BE;# energy required from fuel/h, [kJ]\n",
    "mc = Qf/CV;# mass of coal/h,[kg]\n",
    "print ' (a) The mass of coal used per hour is (kg) = ',round(mc,1)\n",
    "\n",
    "# (b)\n",
    "# for one kg coal\n",
    "mO2 = 8./3*C+8*H2-O2;# actual mass of O2 required, [kg]\n",
    "mta = mO2/aO2;# theoretical mass of air, [kg]\n",
    "ma = mta*(1+ea);# mass of air supplied, [kg]\n",
    "mas = ma*116;# mass of air supplied/h, [kg]\n",
    "print ' (b) The mass of air supplied per hour is (kg) = ',round(mas)\n",
    "\n",
    " \n",
    "# (c)\n",
    "# for one kg coal\n",
    "mCO2 = 11./3*C;# mass of CO2 produced, [kg]\n",
    "mH2O = 9*H2;# mass of H2O produced, [kg]\n",
    "mO2 = mO2*ea;# mass of excess O2 in flue gas, [kg]\n",
    "mN2 = ma*(1-aO2);# mass of N2 in flue gas, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mO2+mN2;# total mass of gas\n",
    "x1 = mCO2/mt*100;# mass percentage composition of CO2\n",
    "x2 = mH2O/mt*100;# mass percentage composition of H2O\n",
    "x3 = mO2/mt*100;# mass percentage composition of O2\n",
    "x4 = mN2/mt*100;# mass percentage composition of N2\n",
    "\n",
    "print ' (c) The mass percentage composition of CO2  =  ',round(x1,2),' ,\\n      The mass percentage composition of H2O  = ',round(x2,2),' ,\\n      The mass percentage composition of O2  = ',round(x3,2),' ,\\n      The mass percentage composition of N2  =',round(x4,2)\n",
    "#  mass of coal taken in part (b) is wrong so answer is not matching\n",
    "\n",
    "#  End\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16: pg 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.16\n",
      " (a) The volume of the gas is (m^3) =  22.4\n",
      " (b)(1) The average moleculer mass of air is (g/mol) =  28.84\n",
      "    (2) The value of R is (kJ/kg K) =  0.288\n",
      "    (3) The mass of one cubic metre of air at STP is (kg/m^3) =  1.287\n"
     ]
    }
   ],
   "source": [
    "#pg 223\n",
    "print('Example 8.16');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) volume of gas\n",
    "# (b) (1) the average molecular mass of air\n",
    "#       (2) the value of R\n",
    "#       (3) the mass of 1 m^3 of air at STP\n",
    "\n",
    "# given values\n",
    "n = 1.;# moles of gas, [kmol]\n",
    "P = 101.32;# standard pressure, [kN/m^2]\n",
    "T = 273.;# gas tempearture, [K]\n",
    "\n",
    "O2 = 21.;# percentage volume composition of oxygen in air\n",
    "N2 = 79.;# percentage volume composition of nitrogen in air\n",
    "R = 8.3143;# molar gas constant, [kJ/kg K]\n",
    "mO2 = 32.;# moleculer mass of O2\n",
    "mN2 = 28.;# moleculer mass of N2\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "V = n*R*T/P;# volume of gas, [m^3]\n",
    "print ' (a) The volume of the gas is (m^3) = ',round(V,1)\n",
    "\n",
    "# (b)\n",
    "#(1)\n",
    "Mav = (O2*mO2+N2*mN2)/(O2+N2);# average moleculer mass of air\n",
    "print ' (b)(1) The average moleculer mass of air is (g/mol) = ',Mav\n",
    "\n",
    "# (2)\n",
    "Rav = R/Mav;# characteristic gas constant, [kJ/kg k]\n",
    "print '    (2) The value of R is (kJ/kg K) = ',round(Rav,3)\n",
    "\n",
    "# (3)\n",
    "rho = Mav/V;# density of air, [kg/m^3]\n",
    "print '    (3) The mass of one cubic metre of air at STP is (kg/m^3) = ',round(rho,3)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17: pg 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.17\n",
      " (a)The partial pressure of O2 is (kN/m^2) =  104.0 ,\n",
      "   The partial pressure of N2 is (kN/m^2) =  104.0 \n",
      "    The partial pressure of CO2 is (kN/m^2) =  208.0\n",
      " (b) The volume of the container is (m^3) =  6.655\n",
      " (c) The new total pressure in the vessel is (kN/m^2) =  626.0\n"
     ]
    }
   ],
   "source": [
    "#pg 223\n",
    "print('Example 8.17');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the partial pressure of each gas in the vessel\n",
    "# (b) the volume of the vessel\n",
    "# (c)  the total pressure in the gas when temperature is raised to228 C\n",
    "\n",
    "# given values\n",
    "MO2 = 8.;#  mass of O2, [kg]\n",
    "MN2 = 7.;#  mass of N2, [kg]\n",
    "MCO2 = 22.;#  mass of CO2, [kg]\n",
    "\n",
    "P = 416.;# total pressure in the vessel, [kN/m^2]\n",
    "T = 273.+60;# vessel temperature, [K]\n",
    "R = 8.3143;# gas constant, [kJ/kmol K]\n",
    "\n",
    "mO2 = 32.;# molculer mass of O2 \n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mCO2 = 44.;# molculer mass of CO2\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "n1 = MO2/mO2;# moles of O2, [kmol]\n",
    "n2 = MN2/mN2;# moles of N2, [kmol]\n",
    "n3 = MCO2/mCO2;# moles of CO2, [kmol]\n",
    "\n",
    "n = n1+n2+n3;# total moles in the vessel, [kmol]\n",
    "# since,Partial pressure is proportinal, so\n",
    "P1 = n1*P/n;# partial pressure of O2, [kN/m^2]\n",
    "P2 = n2*P/n;# partial pressure of N2, [kN/m^2]\n",
    "P3 = n3*P/n;# partial pressure of CO2, [kN/m^2]\n",
    "\n",
    "print ' (a)The partial pressure of O2 is (kN/m^2) = ',P1,',\\n   The partial pressure of N2 is (kN/m^2) = ',P2,'\\n    The partial pressure of CO2 is (kN/m^2) = ',P3\n",
    "\n",
    "# (b)\n",
    "# assuming ideal gas \n",
    "V = n*R*T/P;# volume of the container, [m^3]\n",
    "print ' (b) The volume of the container is (m^3) = ',round(V,3)\n",
    "\n",
    "# (c)\n",
    "T2 = 273.+228;# raised vessel temperature, [K]\n",
    "# so volume of vessel  will constant , P/T=constant\n",
    "P2 = P*T2/T;# new pressure in the vessel , [kn/m62]\n",
    "print ' (c) The new total pressure in the vessel is (kN/m^2) = ',round(P2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18: pg 225"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.18\n",
      " The actual mass of air supplied is (kg/kg coal) =  13.64\n",
      " The velocity of flue gas is (m/s) =  3.99\n"
     ]
    }
   ],
   "source": [
    "#pg 225\n",
    "print('Example 8.18');\n",
    "\n",
    "# aim : To determine\n",
    "# the actual mass of air supplied/kg coal\n",
    "# the velocity of flue gas\n",
    "\n",
    "# given values\n",
    "mc = 635;# mass of coal burn/h, [kg]\n",
    "ea = .25;# excess air required\n",
    "C = .84;# mass composition of carbon\n",
    "H2 = .04;# mass composition of hydrogen\n",
    "O2 = .05;# mass composition of oxygen\n",
    "ash = 1-(C+H2+O2);# mass composition of ash\n",
    "\n",
    "P1 = 101.3;# pressure, [kJn/m^2]\n",
    "T1 = 273;# temperature, [K]\n",
    "V1 = 22.4;# volume, [m^3]\n",
    "\n",
    "T2 = 273.+344;# gas temperature, [K]\n",
    "P2 = 100.;# gas pressure, [kN/m^2]\n",
    "A = 1.1;# cross section area, [m^2]\n",
    "aO2 = .23;# composition of O2 in air\n",
    "\n",
    "mCO2 = 44.;# moleculer mass of carbon\n",
    "mH2O = 18.;# molecular mass of hydrogen\n",
    "mO2 = 32.;# moleculer mas of oxygen\n",
    "mN2 = 28.;# moleculer mass of nitrogen\n",
    "\n",
    "# solution\n",
    "mtO2 = 8./3*C+8*H2-O2;# theoretical O2 required/kg coal, [kg]\n",
    "msa= mtO2/aO2;# stoichiometric mass of  air supplied/kg coal, [kg]\n",
    "mas = msa*(1+ea);# actual mass of air supplied/kg coal, [kg]\n",
    "\n",
    "m1 = 11./3*C;# mass of CO2/kg coal produced, [kg]\n",
    "m2 = 9*H2;# mass of H2/kg coal produced, [kg]\n",
    "m3 = mtO2*ea;# mass of O2/kg coal produced, [kg]\n",
    "m4 = mas*(1-aO2);# mass of N2/kg coal produced, [kg]\n",
    "\n",
    "mt = m1+m2+m3+m4;# total mass, [kg]\n",
    "x1 = m1/mt*100;# %age mass composition of CO2 produced\n",
    "x2 = m2/mt*100;# %age mass composition of H2O produced\n",
    "x3 = m3/mt*100;# %age mass composition of O2 produced\n",
    "x4 = m4/mt*100;# %age mass composition of N2 produced\n",
    "\n",
    "vt = x1/mCO2+x2/mH2O+x3/mO2+x4/mN2;# total volume\n",
    "v1 = x1/mCO2/vt*100;# %age volume composition of CO2\n",
    "v2 = x2/mH2O/vt*100;# %age volume composition of H2O\n",
    "v3 = x3/mO2/vt*100;# %age volume composition of O2\n",
    "v4 = x4/mN2/vt*100;# %age volume composition of N2\n",
    "\n",
    "Mav = (v1*mCO2+v2*mH2O+v3*mO2+v4*mN2)/(v1+v2+v3+v4);# average moleculer mass, [kg/kmol]\n",
    "# since no of moles is constant so PV/T=constant\n",
    "V2 = P1*V1*T2/(P2*T1);#volume, [m^3]\n",
    "\n",
    "mp = mt*mc/3600.;# mass of product of combustion/s, [kg]\n",
    "\n",
    "V = V2*mp/Mav;# volume of flowing gas /s,[m^3]\n",
    "\n",
    "v = V/A;# velocity of flue gas, [m/s]\n",
    "print ' The actual mass of air supplied is (kg/kg coal) = ',round(mas,2)\n",
    "print ' The velocity of flue gas is (m/s) = ',round(v,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19: pg 227"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.19\n",
      " (a) The temperature of the gas after compression is (C) =  354.1\n",
      " (b) The density of air-gas mixture is (kg/m^3) =  1.133\n"
     ]
    }
   ],
   "source": [
    "#pg 227\n",
    "print('Example 8.19');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the temperature of the gas after compression\n",
    "# (b) the density of the air-gas mixture\n",
    "\n",
    "# given values\n",
    "CO = 26.;# %age volume composition of CO \n",
    "H2 = 16.;# %age volume composition of H2\n",
    "CH4 = 7.;# %age volume composition of CH4 \n",
    "N2 = 51.;# %age volume composition of N2\n",
    "\n",
    "P1 = 103.;# gas pressure, [kN/m^2]\n",
    "T1 = 273.+21;# gas temperature, [K]\n",
    "rv = 7.;# volume ratio\n",
    "\n",
    "aO2 = 21.;# %age volume composition of O2 in the air\n",
    "c = 21.;# specific heat capacity of diatomic gas, [kJ/kg K]\n",
    "cCH4 = 36.;# specific heat capacity of CH4, [kJ/kg K]\n",
    "R = 8.3143;# gas constant, [kJ/kg K]\n",
    "\n",
    "mCO = 28.;# moleculer mass of carbon\n",
    "mH2 = 2.;# molecular mass of hydrogen\n",
    "mCH4 = 16.;# moleculer mas of methane\n",
    "mN2 = 28.;# moleculer mass of nitrogen\n",
    "mO2 = 32.;# moleculer mass of oxygen\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "Cav = (CO*c+H2*c+CH4*cCH4+N2*c+100*2*c)/(100.+200);# heat capacity, [kJ/kg K]\n",
    "\n",
    "Gama = (Cav+R)/Cav;# heat capacity ratio\n",
    "# rv = V1/V2\n",
    "# process is polytropic, so\n",
    "T2 = T1*(rv)**(Gama-1);# final tempearture, [K]\n",
    "print ' (a) The temperature of the gas after compression is (C) = ',round(T2-273.15,1)\n",
    "\n",
    "# (b)\n",
    "\n",
    "Mav = (CO*mCO+H2*mH2+CH4*mCH4+N2*mN2+42*mO2+158*mN2)/(100.+200)\n",
    "\n",
    "# for 1 kmol of gas\n",
    "V = R*T1/P1;# volume of one kmol of gas, [m^3]\n",
    "# hence\n",
    "rho = Mav/V;# density of gas, [kg/m^3]\n",
    "\n",
    "print ' (b) The density of air-gas mixture is (kg/m^3) = ',round(rho,3)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20: pg 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.20\n",
      "The required stoichiometric equation is  =  \n",
      "2 H2+ O2+3.76 N2 = 2 H2O+3.76 N2\n"
     ]
    }
   ],
   "source": [
    "#pg 228\n",
    "print('Example 8.20');\n",
    "\n",
    "# aim : to determine \n",
    "# stoichiometric equation for combustion of hydrogen\n",
    "\n",
    "# solution\n",
    "# equation with algebric coefficient is\n",
    "# H2+aO2+79/21*aN2=bH2O+79/21*aN2\n",
    "# by equating coefficients\n",
    "b = 1;\n",
    "a = b/2.;\n",
    "# so equation becomes\n",
    "# 2 H2+ O2+3.76 N2=2 H2O+3.76 N2\n",
    "#results\n",
    "print('The required stoichiometric equation is  =  ');\n",
    "print('2 H2+ O2+3.76 N2 = 2 H2O+3.76 N2');\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 22: pg 229"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.22\n",
      " Percentage gravimetric composition of CO2  =  12.65   \n",
      " ,\n",
      " Percentage gravimetric composition of H2O  =  11.7   \n",
      "\n",
      " Percentage gravimetric composition of O2  =  2.77   \n",
      "\n",
      " Percentage gravimetric composition of N2  =  72.89\n"
     ]
    }
   ],
   "source": [
    "#pg 229\n",
    "print('Example 8.22');\n",
    "\n",
    "# aim : To determine\n",
    "# the percentage gravimetric analysis of the total products of combustion\n",
    "\n",
    "# given values\n",
    "CO = 12.;#  %age volume composition of CO\n",
    "H2 = 41.;#  %age volume composition of H2\n",
    "CH4 = 27.;#  %age volume composition of CH4\n",
    "O2 = 2.;#  %age volume composition of O2\n",
    "CO2 = 3.;#  %age volume composition of CO2\n",
    "N2 = 15.;#  %age volume composition of N2\n",
    "\n",
    "mCO2 = 44.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2O = 18.;# moleculer mass of H2O, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    " \n",
    "ea = 15.;# %age excess air required\n",
    "aO2 = 21.;# %age air composition in the air\n",
    "\n",
    "# solution\n",
    "# combustion equation by no. of moles\n",
    "# 12CO + 41H2 + 27CH4 + 2O2 + 3CO2 + 15N2 + aO2+79/21*aN2 = bCO2 + dH2O + eO2 + 15N2 +79/21*aN2\n",
    "# equating C coefficient\n",
    "b = 12.+27+3;# [mol]\n",
    "# equatimg H2 coefficient\n",
    "d = 41.+2*27;# [mol]\n",
    "# O2 required is 15 % extra,so\n",
    "# e/(e-a)=.15 so e=.13a\n",
    "# equating O2 coefficient\n",
    "# 2+3+a=b+d/2 +e\n",
    "\n",
    "a = (b+d/2.-5)/(1-.13);\n",
    "e = .13*a;# [mol]\n",
    "\n",
    "# gravimetric analysis of product\n",
    "v1 =  b*mCO2;# gravimetric volume of CO2 \n",
    "v2 =  d*mH2O ;# gravimetric volume of H2O \n",
    "v3 = e*mO2;# gravimetric volume of O2\n",
    "v4 = 15*mN2 +79./21*a*mN2;# gravimetric volume of N2 \n",
    "\n",
    "vt = v1+v2+v3+v4;# total\n",
    "x1 = v1/vt*100;# percentage gravimetric of CO2\n",
    "x2 = v2/vt*100;# percentage gravimetric of H2O\n",
    "x3 = v3/vt*100;# percentage gravimetric of O2\n",
    "x4 = v4/vt*100;# percentage gravimetric of N2\n",
    "#results\n",
    "print ' Percentage gravimetric composition of CO2  = ',round(x1,2),'  \\n ,\\n Percentage gravimetric composition of H2O  = ',round(x2,2),'  \\n\\n Percentage gravimetric composition of O2  = ',round(x3,2),'  \\n\\n Percentage gravimetric composition of N2  = ',round(x4,2)\n",
    "\n",
    "#  End \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23: pg 231"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.23\n",
      " (a) The mass of actual air supplied per kg of fuel is (kg) =  31.2\n",
      " (b) The volumetric efficiency of the engine is (percent) =  89.9\n"
     ]
    }
   ],
   "source": [
    "#pg 231\n",
    "print('Example 8.23');\n",
    "import math\n",
    "#  aim : To determine\n",
    "# (a) the actual quantity of air supplied/kg of fuel\n",
    "# (b) the volumetric efficiency of the engine\n",
    "\n",
    "# given values\n",
    "d = 300.*10**-3;# bore,[m]\n",
    "L = 460.*10**-3;# stroke,[m]\n",
    "N = 200.;# engine speed, [rev/min]\n",
    "\n",
    "C = 87.;#  %age mass composition of Carbon in the fuel\n",
    "H2 = 13.;#  %age mass composition of H2 in the fuel\n",
    "\n",
    "mc = 6.75;# fuel consumption, [kg/h]\n",
    "\n",
    "CO2 = 7.;# %age composition of CO2 by volume\n",
    "O2 = 10.5;# %age composition of O2 by volume\n",
    "N2 = 7.;# %age composition of N2 by volume\n",
    "\n",
    "mC = 12.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2 = 2.;# moleculer mass of H2, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    "\n",
    "T = 273.+17;# atmospheric temperature, [K]\n",
    "P = 100;# atmospheric pressure, [kn/m**2]\n",
    "R =.287;# gas constant, [kJ/kg k]\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "# combustion equation by no. of moles\n",
    "# 87/12 C + 13/2 H2 + a O2+79/21*a N2 = b CO2 + d H2O + eO2 + f N2\n",
    "# equating  coefficient\n",
    "b = 87./12;# [mol]\n",
    "a = 22.7;# [mol]\n",
    "e = 10.875;# [mol]\n",
    "f = 11.8*b;# [mol]\n",
    "# so fuel side combustion equation is\n",
    "# 87/12 C + 13/2 H2 +22.7 O2 +85.5 N2\n",
    "mair = ( 22.7*mO2 +85.5*mN2)/100;# mass of air/kg fuel, [kg]\n",
    "print ' (a) The mass of actual air supplied per kg of fuel is (kg) = ',round(mair,2)\n",
    "\n",
    "# (b)\n",
    "m = mair*mc/60;# mass of air/min, [kg]\n",
    "V = m*R*T/P;# volumetric flow of air/min, [m**3]\n",
    "SV = math.pi/4*d**2*L*N/2;# swept volume/min, [m**3]\n",
    "\n",
    "VE = V/SV;# volumetric efficiency\n",
    "print ' (b) The volumetric efficiency of the engine is (percent) = ',round(VE*100,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 24: pg 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.24\n",
      " The mass of air supplied per kg of fuel is (kg) =  21.07\n"
     ]
    }
   ],
   "source": [
    "#pg 232\n",
    "print('Example 8.24');\n",
    "\n",
    "# aim : To determine\n",
    "#  the mass of air supplied/kg of fuel burnt\n",
    "\n",
    "# given values\n",
    "# gas composition in the fuel\n",
    "C = 84.;#  %age mass composition of Carbon in the fuel\n",
    "H2 = 14.;#  %age mass composition of H2 in the fuel\n",
    "O2f = 2.;# %age mass composition of O2 in the fuel\n",
    "\n",
    "# exhaust gas composition\n",
    "CO2 = 8.85;# %age composition of CO2 by volume\n",
    "CO = 1.2# %age composition of CO by volume\n",
    "O2 = 6.8;# %age composition of O2 by volume\n",
    "N2 = 83.15;# %age composition of N2 by volume\n",
    "\n",
    "mC = 12.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2 = 2.;# moleculer mass of H2, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    "\n",
    "# solution\n",
    "# combustion equation by no. of moles\n",
    "# 84/12 C + 14/2 H2 +2/32 O2 + a O2+79.3/20.7*a N2 = b CO2 + d CO2+  eO2 + f N2 +g H2\n",
    "# equating  coefficient and given condition\n",
    "b = 6.16;# [mol]\n",
    "a = 15.14;# [mol]\n",
    "d = .836;# [mol]\n",
    "f = 69.3*d;# [mol]\n",
    "# so fuel side combustion equation is\n",
    "# 84/12 C + 14/2 H2 +2/32 O2 +  15.14 O2 +85.5 N2\n",
    "mair = ( a*mO2 +f*mN2)/100;# mass of air/kg fuel, [kg]\n",
    "#results\n",
    "print ' The mass of air supplied per kg of fuel is (kg) = ',round(mair,2)\n",
    "\n",
    "#  End\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}