summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_Y_V_C_Rao/ch3.ipynb
blob: 2b39d6e02caf427b20e01d77ecbc8086c3bce8b1 (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
{
 "metadata": {
  "name": "",
  "signature": "sha256:8d10c3a8d696216084bffc2404a32e0b3c15831ac555c05fcb7016ab7d75d0e7"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : PvT relations of fluids"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.1  Page No : 48"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "X = 0.8;    \t\t\t #Quality of wet steam (no unit)\n",
      "T = 150.;\t    \t\t #Temperature of the wet steam in degree celsius\n",
      "vf = 0.0010908;\t\t\t #molar volume of saturated liquid in m**3/kg\n",
      "vg = 0.3924;\t\t\t #molar volume of saturated vapour in m**3/kg\n",
      "uf = 631.63;\t\t\t #molar internal energy of the saturated liquid in kJ/kg\n",
      "ug = 2558.6;\t\t\t #molar internal energy of the saturated vapour in kJ/kg\n",
      "\n",
      "# Calculations\n",
      "V = (X*vg)+((1-X)*vf);\t\t\t # Calculations of specific volume in m**3/kg using Eq.(3.3)\n",
      "U = (X*ug)+((1-X)*uf);\t\t\t # Calculations of specific internal energy in kJ/kg using Eq.(3.6)\n",
      "\n",
      "# Results\n",
      "print 'The specific volume of wet steam =  %0.4f m**3/kg '%(V);\n",
      "print 'The specific internal energy of wet steam =  %0.1f kJ/kg '%(U);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The specific volume of wet steam =  0.3141 m**3/kg \n",
        "The specific internal energy of wet steam =  2173.2 kJ/kg \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.2  Page No : 49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 1.42;\t\t\t #specific volume of wet steam in m**3/kg\n",
      "T = 100.;\t\t\t #temperature of wet steam in degree celsius\n",
      "vf = 0.0010437;\t\t #molar volume of saturated liquid in m**3/kg\n",
      "vg = 1.673;\t\t\t #molar volume of saturated vapour in m**3/kg\n",
      "\n",
      "# Calculations\n",
      "X = (V-vf)/(vg-vf);\t\t\t # Calculations of the quality of wet steam using Eq.(3.3) (no unit)\n",
      "\n",
      "# Results\n",
      "print ' The quality of wet steam =  %0.4f '%(X);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The quality of wet steam =  0.8487 \n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.3  Page No : 49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T = 100.;\t\t\t #temperature inside the vessel in degree celsius\n",
      "V = 0.00317;\t\t\t #specific volume of water at the critical point in m**3/kg\n",
      "vf = 0.0010437;\t\t\t #molar volume of saturated liquid in m**3/kg\n",
      "vg = 1.673;\t\t\t #molar volume of saturated vapour in m**3/kg\n",
      "\n",
      "# Calculations\n",
      "X = (V-vf)/(vg-vf);\t\t\t          # Calculations of the quality of wet steam using Eq.(3.3) (no unit)\n",
      "ratio = (X*vg)/((1-X)*vf);\t\t\t # Calculations of volume ratio of saturated vapour to the saturated liquid (no unit)\n",
      "\n",
      "# Results\n",
      "print ' The volume ratio of saturated vapour to the saturated liquid =  %0.2f '%(ratio);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume ratio of saturated vapour to the saturated liquid =  2.04 \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.4  Page No : 49"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "U = 2000.\t\t\t #specific internal energy of liquid-vapour mixture in kJ/kg\n",
      "uf = 850.6\t\t\t #specific internal energy of saturated liquid in kJ/kg\n",
      "ug = 2593.2\t\t\t #specific internal energy of saturated vapour in kJ/kg\n",
      "\n",
      "# Calculations\n",
      "mass_ratio = (U-uf)/(ug-U);\t\t\t # Calculations of the mass ratio of vapour to liquid using the lever rule (no unit)\n",
      "\n",
      "# Results\n",
      "print ' The mass ratio of vapour to liquid =  %0.4f '%(mass_ratio);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The mass ratio of vapour to liquid =  1.9376 \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.5  Page No : 52"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "n = 1.\t\t\t #number of moles of n-octane vapour in mol\n",
      "T = 427.85;\t\t\t #tempearture of n-octane vapour in K\n",
      "P = 0.215;\t\t\t #pressure n-octane vapour in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in (kPa m**3)/(kmol K)\n",
      "\n",
      "# Calculations\n",
      "V = ((n*10**-3)*R*T)/(P*10**3);\t\t\t # Calculations of volume using ideal gas law-Eq.(3.9) in m**3\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane vapour =  %f m**3 '%(V);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane vapour =  0.016545 m**3 \n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.6  Page No : 54"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "n = 1.; \t\t\t #number of moles occupied by n-octane vapour in mol\n",
      "T = 427.85;\t\t\t #temperature in K\n",
      "P = 0.215;\t\t\t #saturation pressure in MPa\n",
      "a = 3.789;\t\t\t #van der Waals constant in Pa(m**3/mol)**2\n",
      "b = 2.37*10**-4;\t #van der Waals constant in m**3/mol\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "Vguess = (n*R*T)/(P*10**6);\t\t\t \n",
      "Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b\n",
      "tolerance = 1e-6\n",
      "\n",
      "while abs(Vguess-Vnew)>tolerance:\n",
      "    Vguess = Vnew;\n",
      "    Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b;\t\t\t #the iteration process to solve the system of equation\n",
      "\n",
      "V = Vnew;\t\t\t #The volume calculated using the van der Waals equation in m**3/mol\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane vapour obtained by van der Waals equation =  %f m**3/mol'%(V);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane vapour obtained by van der Waals equation =  0.015675 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.7  Page No : 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "n = 1.; \t\t\t #number of moles occupied by n-octane liquid in mol\n",
      "T = 427.85;\t\t\t #temperature in K\n",
      "P = 0.215;\t\t\t #saturation pressure in MPa\n",
      "a = 3.789;\t\t\t #van der Waals constant in Pa(m**3/mol)**2\n",
      "b = 2.37*10**-4;\t\t\t #van der Waals constant in m**3/mol\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "Vguess = b\n",
      "Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b\n",
      "tolerance = 1e-6\n",
      "while abs(Vguess-Vnew)>tolerance:\n",
      "    Vguess = Vnew;\n",
      "    Vnew = (R*T)/((P*10**6)+(a/Vguess**2))+b;\t\t\t #the iteration process to solve the system of equation\n",
      "\n",
      "V = Vnew;\t\t\t #The volume calculated using the van der Waals equation in m**3/mol\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane liquid obtained by van der Waals equation =  %e m**3/mol'%(V);\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane liquid obtained by van der Waals equation =  3.517652e-04 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.8  Page No : 57"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# Variables\n",
      "T = 427.85; \t\t    \t #temperature in K\n",
      "P = 0.215;\t    \t\t     #saturation pressure in MPa\n",
      "a = 3.789;\t\t    \t     #van der Waals constant in Pa(m**3/mol)**2\n",
      "b = 2.37*10**-4;\t\t\t #van der Waals constant in m**3/mol\n",
      "R = 8.314;\t\t        \t #universal gas constant in (Pa m**3)/(mol K)\n",
      "Pcvc = 3\n",
      "RTc = 8.\n",
      "# Calculations\n",
      "#The Cardan's method simplifies the equation of state into a cubic equation which can be solved easily\n",
      "#The general form of the cubic equation is (Z**3)+(alpha*Z**2)+(beeta*Z)+gaamma = 0, where alpha,beeta and gaamma are determined using established relations\n",
      "\n",
      "A = (a*P*10**6)/(R*T)**2;\t\t\t\n",
      "B = (b*P*10**6)/(R*T);\t\t\t \n",
      "alpha = -1-B;\t\t\t \n",
      "beeta = A;\t\t\t \n",
      "gaamma = -(A*B);\t\n",
      "p = round(beeta-(alpha**2)/3,4)\n",
      "q = round(((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma,4)\n",
      "D = (q**2/4)+(p**3/27);\t\n",
      "\n",
      "\n",
      "if D>0 :\n",
      "        Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3);\n",
      "        vf = ((Z)*R*T)/(P*10**6);\t\t\n",
      "        vg = ((Z)*R*T)/(P*10**6);\t\t\n",
      "elif D == 0:\n",
      "        Z1 = ((-2*(q/2))**(1./3))-(alpha/3);\t\n",
      "        Z2 = ((q/2)**(1./3))-(alpha/3);\n",
      "        Z3 = ((q/2)**(1./3))-(alpha/3);\n",
      "        Z = [Z1 ,Z2, Z3];\n",
      "        vf = (min(Z)*R*T)/(P*10**6)\n",
      "        vg = (max(Z)*R*T)/(P*10**6)\n",
      "else:\n",
      "        r = math.sqrt((-(p**3)/27));\t\t\t # Calculations of r using Eq.(3.38)\n",
      "        theta = math.cos((-(q)/2)*(1./r));\t\t\t # Calculations of theta in radians using Eq.(3.37)\n",
      "        Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "        Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);\t\t\t #Three unequal real roots given by Eqs.(3.34,3.35 and 3.36)\n",
      "        Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);\n",
      "        Z = [Z1, Z2, Z3];\n",
      "        vf = (min(Z)*R*T)/(P*10**6)\n",
      "        vg = (max(Z)*R*T)/(P*10**6)\n",
      "\n",
      "crit = Pcvc/RTc        \n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane saturated liquid obtained by Cardans method =  %.3e m**3/mol'%(vf);\n",
      "print ' The volume occupied by n-octane saturated vapour obtained by Cardans method =  %.2e m**3/mol'%(vg);\n",
      "print \" At the critical point, PcVc/RTc = %.3f\"%crit\n",
      "\n",
      "# Note: value of D is calculated wrongly in book. Please calculate manually."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane saturated liquid obtained by Cardans method =  -9.345e-04 m**3/mol\n",
        " The volume occupied by n-octane saturated vapour obtained by Cardans method =  1.55e-02 m**3/mol\n",
        " At the critical point, PcVc/RTc = 0.375\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.9  Page No : 60"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from numpy import *\n",
      "import math\n",
      "\n",
      "# Variables\n",
      "T = 427.85;\t\t\t #temperature in K\n",
      "P = 0.215;\t\t\t #saturation pressure in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "Pc = 24.97;\t\t\t #critical pressure of n-octane in bar\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "\n",
      "# Calculations\n",
      "a = (0.42748*R**2*Tc**2.5)/(Pc*100*10**3*math.sqrt(T));\t\t\t \n",
      "b = (0.08664*R*Tc)/(Pc*100*10**3);\t\t\t\n",
      "\n",
      "\n",
      "A = (a*P*10**6)/(R*T)**2;\t\t\t \n",
      "B = (b*P*10**6)/(R*T);\n",
      "alpha = -1.;\t\t\t\n",
      "beeta = A-B-B**2.;\t\n",
      "gaamma = -(A*B);\t\n",
      "p = beeta-(alpha**2)/3.\n",
      "q = ((2*alpha**3.)/27.)-((alpha*beeta)/3)+gaamma\n",
      "D = (((q)**2)/4.)+(((p)**3)/27.);\t\t\t \n",
      "#if D>0 then:\n",
      " #       Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)\n",
      "  #      vf = ((Z)*R*T)/(P*10**6)\n",
      "   #     vg = ((Z)*R*T)/(P*10**6)\n",
      "#elif D == 0:\n",
      " #       Z1 = ((-2*(q/2))**(1./3))-(alpha/3);\n",
      "  #      Z2 = ((q/2)**(1./3))-(alpha/3);\n",
      "   #     Z3 = ((q/2)**(1./3))-(alpha/3);\n",
      "    #    Z = [Z1 ,Z2, Z3];\n",
      "     #   vf = (min(Z)*R*T)/(P*10**6);\t\t\n",
      "      #  vg = (max(Z)*R*T)/(P*10**6);\t\t\n",
      "#else:\n",
      "\n",
      "r = math.sqrt((-(p**3)/27));\t\t\t\n",
      "theta = (math.acos((-(q)/2)*(1./r)));\n",
      "Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);\t\n",
      "Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);\n",
      "Z = [Z1, Z2, Z3];\n",
      "vf = (min(Z)*R*T)/(P*10**6);\t\t\n",
      "vg = (max(Z)*R*T)/(P*10**6);\t\t\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane saturated vapour) using Redlich-Kwong equation of state =  %f m**3/mol'%(vg);\n",
      "print ' The volume occupied by n-octane saturated liquid) using Redlich-Kwong equation of state =  %f m**3/mol'%(vf);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane saturated vapour) using Redlich-Kwong equation of state =  0.015401 m**3/mol\n",
        " The volume occupied by n-octane saturated liquid) using Redlich-Kwong equation of state =  0.000244 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.10  Page No : 67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variables\n",
      "T = 180.;\t\t\t #temperature of water in degree celsius\n",
      "P = 1.0027;\t\t\t #saturation pressure of water in MPa\n",
      "Tc = 647.3;\t\t\t #critical temperature of water in K\n",
      "Pc = 221.2;\t\t\t #critical pressure of water in bar\n",
      "Tr = 0.7;\t\t\t #reduced temperature at which acentric factor was defined by Pitzer \n",
      "\n",
      "# Calculations\n",
      "T1 = Tr*Tc; \t\t\t #calculating temperature  in K using reduced temperature value\n",
      "T1 = T1-273.15;\t\t\t #conversion to degree celsius\n",
      "Pr = (P*10)/Pc;\t\t\t # Calculations of reduced pressure (no unit) using saturation pressure at t1. In this case t1 equals t, therefore the given saturation pressure is taken\n",
      "w = -math.log10(Pr)-1.0;\t\t\t # Calculations of acentric factor using Eq.(3.62)\n",
      "\n",
      "# Results\n",
      "print ' The acentric factor of water =  %f '%(w);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The acentric factor of water =  0.343614 \n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.11  Page No : 72"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T = 409.41;\t\t\t #temperature of n-octane in degree celsius\n",
      "P = 4.98;\t\t\t #pressure in bar\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "Pc = 24.97;\t\t\t #critical pressure of n-octane in bar\n",
      "w = 0.398;\t\t\t #acentric factor (no unit)\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "Tr = (T+273.15)/Tc;\t\n",
      "Pr = P/Pc;\t\t\t\n",
      "z0 = 0.96;\t\t\t\n",
      "V1 = (z0*R*(T+273.15))/(P*10**5);\t\t\t \n",
      "z1 = 0.01;\t\t\t \n",
      "z = z0+(w*z1);\t\t\n",
      "V2 = (z*R*(T+273.15))/(P*10**5)\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane obtained by the two parameter compressibilty \\\n",
      " factor correlation =  %f m**3/mol'%(V1);\n",
      "print ' The volume occupied by n-octane obtained by the three parameter compressibility \\\n",
      "factor correlation =  %f m**3/mol'%(V2);\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane obtained by the two parameter compressibilty  factor correlation =  0.010939 m**3/mol\n",
        " The volume occupied by n-octane obtained by the three parameter compressibility factor correlation =  0.010985 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.12  Page No : 72"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 1.;\t    \t\t #volume of the tank in m**3\n",
      "m = 180.;\t\t\t #mass of carbon dioxide in kg\n",
      "T = 91.8;\t\t\t #temperature of the tank in degree celsius after it is placed in the vicinity of a furnace\n",
      "Tc = 304.2;\t\t\t #critical temperature of carbon dioxide in K\n",
      "Pc = 73.87;\t\t\t #critical pressure of carbon dioxide in bar\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "mwt = 44.*10**-3\t #molecular weight of carbon dioxide in kg/mol\n",
      "n = m/mwt;\t\t\t # Calculations of number of moles of carbon dioxide in the tank in moles\n",
      "MV = V/n;\t\t\t # Calculations of molar volume in m**3/mol\n",
      "slope = (MV*Pc*10**5)/(R*(T+273.15));\t\t\t #slope of the straight line formed when z0 is plotted against Pr formed by using the relation z0 = (V*Pc*Pr)/(R*T)\n",
      "Tr = (T+273.15)/Tc;\t\t\t # Calculations of reduced temperature (no unit)\n",
      "\n",
      "#At the given conditions, the state of CO2 must lie on the curve corresponding to the obtained value of Tr. To determine the state of CO2, a straight line passing through the origin, with the obtained value of slope is drawn on the z0 vs Pr plot of Fig.3.12 and the point of intersection of this straight line with the Tr curve is obtained to get the value of z0\n",
      "z0 = 0.725;\t\t\t #value of compressibilty factor obtained by doing the above mentioned procedure\n",
      "P = (z0*R*10**-6*(T+273.15))/(MV)\t\t\t # Calculations of pressure in MPa using Eq.(3.59)\n",
      "\n",
      "# Results\n",
      "print ' The pressure developed by carbon dioxide =  %.0f MPa'%(P);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The pressure developed by carbon dioxide =  9 MPa\n"
       ]
      }
     ],
     "prompt_number": 69
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.13  Page No : 73"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "\n",
      "# Variables\n",
      "V = 1.;\t\t\t #volume of the tank in m**3\n",
      "m = 180.;\t\t\t #mass of carbon dioxide in kg\n",
      "T = 91.8;\t\t\t #temperature of the tank in degree celsius after it is placed in the vicinity of a furnace\n",
      "Tc = 304.2;\t\t\t #critical temperature of carbon dioxide in K\n",
      "Pc = 73.87;\t\t\t #critical pressure of carbon dioxide in bar\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "w = 0.239;\t\t\t #acentric factor (no unit)\n",
      "\n",
      "# Calculations\n",
      "mwt = 44.*10**-3\n",
      "n = m/mwt\n",
      "MV = V/n;\t\t\t\n",
      "Tr = (T+273.15)/Tc\n",
      "z0 = 0.725\n",
      "z_init = z0;\t\t\t \n",
      "slope = (MV*Pc*10**5)/(R*(T+273.15));\t\t\t \n",
      "Prguess = z_init/slope;\t\n",
      "z1guess = 0.1;\t\t\t \n",
      "tolerance = 1e-6;\t\t\t \n",
      "\n",
      "def solver_function(zi):\n",
      "    return zi-(z0+(w*z1guess))\n",
      "\n",
      "z = fsolve(solver_function,z1guess)\n",
      "Pr = z/slope;\t\t\t \n",
      "P = ((Pc*10**5)*Pr)*10**-6\n",
      "\n",
      "# Results\n",
      "print ' The pressure developed by carbon dioxide =  %f MPa'%(P);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The pressure developed by carbon dioxide =  9.295806 MPa\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.14  Page No : 75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from scipy.optimize import fsolve\n",
      "\n",
      "\n",
      "# Variables\n",
      "T = 427.85;\t\t\t #temperature of n-octane vapour in K\n",
      "P = 0.215;\t\t\t #pressure of n-ocatne vapour in MPa\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "Pc = 2.497;\t\t\t #critical pressure of n-octane in MPa\n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "Tr = T/Tc\n",
      "Pr = P/Pc\n",
      "z_init = 1\n",
      "h = (0.08664*Pr)/(z_init*Tr)\n",
      "tolerance = 1e-6;\t\t\t\n",
      "\n",
      "def solver_func(zi):\n",
      "    return zi-((1./(1-h))-((h/(1+h))*(4.93398/(Tr**(3./2)))))\n",
      "\n",
      "z = fsolve(solver_func,h)\n",
      "V = (z*R*T)/(P*10**6);\t\t\t\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane vapour obtained by the generalized form of \\\n",
      " \\n Redlich-Kwong equation of state =  %.2e m**3/mol'%(V);\n",
      "\n",
      "\n",
      "# Note : Answer may vary because of rouding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane vapour obtained by the generalized form of  \n",
        " Redlich-Kwong equation of state =  1.55e-02 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.15  Page No : 77"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Variables\n",
      "T = 427.85;\t\t\t #temperature in K\n",
      "P = 0.215;\t\t\t #saturation pressure in MPa\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "Pc = 24.97;\t\t\t #critical pressure of n-octane in bar\n",
      "w = 0.398;\t\t\t #acentric factor (no unit) \n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "#The Cardan's method simplifies the equation of state into a cubic equation which can be solved easily\n",
      "#The general form of the cubic equation is (Z**3)+(alpha*Z**2)+(beeta*Z)+gaamma = 0, where alpha,beeta and gaamma are determined using established relations\n",
      "\n",
      "Tr = T/Tc\n",
      "Pr = (P*10**6)/(Pc*10**5)\n",
      "S = 0.48+(1.574*w)-(0.176*w**2)\n",
      "alpha1 = (1+(S*(1-math.sqrt(Tr))))**2\n",
      "a = (0.42748*R**2*Tc**2*alpha1)/(Pc*10**5)\n",
      "b = (0.08664*R*Tc)/(Pc*10**5)\n",
      "A = (a*P*10**6)/(R*T)**2\n",
      "B = (b*P*10**6)/(R*T)\n",
      "alpha = -1.\n",
      "beeta = A-B-B**2\n",
      "gaamma = -(A*B)\n",
      "p = beeta-(alpha**2)/3\n",
      "q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma\n",
      "D = (((q)**2)/4.)+(((p)**3)/27.)\n",
      "\n",
      "if D>0:\n",
      "    Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)\n",
      "    vf = ((Z)*R*T)/(P*10**6)\n",
      "    vg = ((Z)*R*T)/(P*10**6)\n",
      "elif D == 0:\n",
      "    Z1 = ((-2*(q/2))**(1./3))-(alpha/3)\n",
      "    Z2 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z3 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z = [Z1, Z2, Z3];\n",
      "    vf = (min(Z)*R*T)/(P*10**6);\t\t\n",
      "    vg = (max(Z)*R*T)/(P*10**6);\t\t\n",
      "else:\n",
      "    r = math.sqrt((-(p**3)/27));\t\t\n",
      "    theta = acos((-(q)/2)*(1./r));\t\t\n",
      "    Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "    Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)\n",
      "    Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);\n",
      "    Z = [Z1, Z2, Z3];\n",
      "    vf = (min(Z)*R*T)/(P*10**6)\n",
      "    vg = (max(Z)*R*T)/(P*10**6)\n",
      "\n",
      "# Results\n",
      "print ' The volume occupied by n-octane saturated vapour obtained by Soave-Redlich-Kwong \\\n",
      " equation of state =  %f m**3/mol'%(vg);\n",
      "print ' The volume occupied by n-octane saturated liquid obtained by Soave-Redlich-Kwong \\\n",
      " equation of state =  %f m**3/mol'%(vf);\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane saturated vapour obtained by Soave-Redlich-Kwong  equation of state =  0.015207 m**3/mol\n",
        " The volume occupied by n-octane saturated liquid obtained by Soave-Redlich-Kwong  equation of state =  0.000227 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 74
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.16  Page No : 78"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Variables\n",
      "T = 427.85;\t\t\t #temperature in K\n",
      "P = 0.215;\t\t\t #saturation pressure in MPa\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "Pc = 24.97;\t\t\t #critical pressure of n-octane in bar\n",
      "w = 0.398;\t\t\t #acentric factor (no unit) \n",
      "R = 8.314;\t\t\t #universal gas constant in (Pa m**3)/(mol K)\n",
      "\n",
      "# Calculations\n",
      "Tr = T/Tc;\t\t\t\n",
      "Pr = (P*10**6)/(Pc*10**5)\n",
      "S = 0.37464+(1.54226*w)-(0.26992*w**2)\n",
      "alpha1 = (1+(S*(1-math.sqrt(Tr))))**2\n",
      "a = (0.45724*R**2*Tc**2*alpha1)/(Pc*10**5)\n",
      "b = (0.07780*R*Tc)/(Pc*10**5)\n",
      "A = (a*P*10**6)/(R*T)**2\n",
      "B = (b*P*10**6)/(R*T)\n",
      "alpha = -1+B;\t\n",
      "beeta = A-(2*B)-(3*B**2)\n",
      "gaamma = -(A*B)+(B**2)+(B**3)\n",
      "p = beeta-(alpha**2)/3;\t\t\n",
      "q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma\n",
      "D = (((q)**2)/4)+(((p)**3)/27)\n",
      "\n",
      "if D>0:\n",
      "    Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3)\n",
      "    vf = ((Z)*R*t)/(P*10**6)\n",
      "    vg = ((Z)*R*t)/(P*10**6)\n",
      "elif D == 0:\n",
      "    Z1 = ((-2*(q/2))**(1./3))-(alpha/3)\n",
      "    Z2 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z3 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z = [Z1 ,Z2, Z3];\n",
      "    vf = (min(Z)*R*T)/(P*10**6)\n",
      "    vg = (max(Z)*R*T)/(P*10**6)\n",
      "else:\n",
      "    r = math.sqrt((-(p**3)/27))\n",
      "    theta = .1533\n",
      "    Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "    Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3);\t\t\n",
      "    Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);\n",
      "    Z = [Z1, Z2, Z3];\n",
      "    vf = (min(Z)*R*T)/(P*10**6)\n",
      "    vg = (max(Z)*R*T)/(P*10**6)\n",
      "    \n",
      "# Results\n",
      "print ' The volume occupied by n-octane saturated vapour, obtained by Peng\\\n",
      "-Robinson equation of state =  %.3e m**3/mol'%(vg);\n",
      "print ' The volume occupied by n-octane saturated liquid, obtained by Peng-Robinson\\\n",
      " equation of state =  %.3e m**3/mol'%(vf);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The volume occupied by n-octane saturated vapour, obtained by Peng-Robinson equation of state =  1.514e-02 m**3/mol\n",
        " The volume occupied by n-octane saturated liquid, obtained by Peng-Robinson equation of state =  2.003e-04 m**3/mol\n"
       ]
      }
     ],
     "prompt_number": 33
    }
   ],
   "metadata": {}
  }
 ]
}