summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics/ch10.ipynb
diff options
context:
space:
mode:
authornice2014-08-27 16:12:51 +0530
committernice2014-08-27 16:12:51 +0530
commit238d7e632aecde748a97437c2b5774e136a3b4da (patch)
treea05d96f81cf72dc03ceec32af934961cf4ccf7dd /Chemical_Engineering_Thermodynamics/ch10.ipynb
parent7e82f054d405211e1e8760524da8ad7c9fd75286 (diff)
downloadPython-Textbook-Companions-238d7e632aecde748a97437c2b5774e136a3b4da.tar.gz
Python-Textbook-Companions-238d7e632aecde748a97437c2b5774e136a3b4da.tar.bz2
Python-Textbook-Companions-238d7e632aecde748a97437c2b5774e136a3b4da.zip
adding book
Diffstat (limited to 'Chemical_Engineering_Thermodynamics/ch10.ipynb')
-rwxr-xr-xChemical_Engineering_Thermodynamics/ch10.ipynb202
1 files changed, 202 insertions, 0 deletions
diff --git a/Chemical_Engineering_Thermodynamics/ch10.ipynb b/Chemical_Engineering_Thermodynamics/ch10.ipynb
new file mode 100755
index 00000000..5d1a66e8
--- /dev/null
+++ b/Chemical_Engineering_Thermodynamics/ch10.ipynb
@@ -0,0 +1,202 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 10 : Stability and phase transition in thermodynamic systems"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.2 Page No : 369"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "# Variables\n",
+ "P = 2;\t\t\t #number of phases (no unit)\n",
+ "C = 2;\t\t\t #number of components (no unit)\n",
+ "\n",
+ "# Calculations\n",
+ "F = C+2-P\n",
+ "\n",
+ "# Results\n",
+ "print \" The number of degrees of freedom = %d \"%(F);\n",
+ "print \"Two intensive properties are required to be specified to\\\n",
+ " describe the thermodynamic state of the system,and the fundamental relation in\\\n",
+ " the Gibbs free energy representation for this system is of the type, G = GT,P,N1,N2\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The number of degrees of freedom = 2 \n",
+ "Two intensive properties are required to be specified to describe the thermodynamic state of the system,and the fundamental relation in the Gibbs free energy representation for this system is of the type, G = GT,P,N1,N2\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example 10.3 Page No : 370"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "import cmath\n",
+ "import math\n",
+ "\n",
+ "# Variables\n",
+ "T = 427.85;\t\t\t #temperature of n-octane vapour in K\n",
+ "R = 8.314;\t\t\t #universal gas constant in J/molK\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",
+ "\n",
+ "# Calculations\n",
+ "Pguess = 0.215\n",
+ "\n",
+ "\n",
+ "Tr = T/Tc\n",
+ "Pr = (Pguess*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);\t\t\t \n",
+ "A = (a*Pguess*10**6)/(R*T)**2;\t\t\t \n",
+ "B = (b*Pguess*10**6)/(R*T);\t\t\t \n",
+ "alpha = -1+B\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);\t\t\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",
+ " Z_l = Z;\n",
+ " Z_v = Z;\n",
+ "elif D == 0:\n",
+ " Z1 = ((-2*(q/2))**(1./3))-(alpha/3);\t\t\t \n",
+ " Z2 = ((q/2)**(1./3))-(alpha/3);\n",
+ " Z3 = ((q/2)**(1./3))-(alpha/3);\n",
+ " Z = [Z1 ,Z2, Z3];\n",
+ " Z_l = min(Z);\n",
+ " Z_v = max(Z);\n",
+ "else:\n",
+ " r = math.sqrt((-(p**3)/27));\t\t\t \n",
+ " theta = math.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",
+ " Z_l = min(Z)\n",
+ " Z_v = max(Z)\n",
+ "\n",
+ "\n",
+ "phi_l = math.exp(Z_l-1-math.log(Z_l-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_l+(B*(1+math.sqrt(2))))/(Z_l+(B*(1-math.sqrt(2)))))));\n",
+ "phi_v = math.exp(Z_v-1-math.log(Z_v-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_v+(B*(1+math.sqrt(2))))/(Z_v+(B*(1-math.sqrt(2)))))));\n",
+ "fl = Pguess*phi_l;\t\t\t # Calculations of the fugacity of the liquid in MPa\n",
+ "fv = Pguess*phi_v;\t\t\t # Calculations of the fugacity of the vapour in MPa\n",
+ "tolerance = 1e-3;\t\t\t #defining the tolerance to compare fl and fv\n",
+ "\n",
+ "if abs(fl-fv)<tolerance:\n",
+ " P = Pguess;\t\t\t\n",
+ "else:\n",
+ " Prevised = Pguess*(fl/fv)\n",
+ "\n",
+ "while abs(fl-fv)>tolerance:\n",
+ " Tr = T/Tc\n",
+ " Pr = (Prevised*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);\t\t\t \n",
+ " A = (a*Prevised*10**6)/(R*T)**2;\t\t\n",
+ " B = (b*Prevised*10**6)/(R*T);\t\t\t\n",
+ " alpha = -1+B;\t\t\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);\t\n",
+ " \n",
+ " if D > 0:\n",
+ " Z=((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3); #One real root given by Eq.(3.32)\n",
+ " Z_l=Z;\n",
+ " Z_v=Z;\n",
+ " elif D==0:\n",
+ " Z1=((-2*(q/2))**(1./3))-(alpha/3); #Three real roots and two equal given by Eq.(3.33)\n",
+ " Z2=((q/2)**(1./3))-(alpha/3);\n",
+ " Z3=((q/2)**(1./3))-(alpha/3);\n",
+ " Z=[Z1, Z2, Z3];\n",
+ " Z_l=min(Z);\n",
+ " Z_v=max(Z);\n",
+ " else:\n",
+ " r = math.sqrt((-(p**3)/27));\t\t\t \n",
+ " theta = math.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",
+ " Z_l = Z[0];\n",
+ " Z_v = Z[1];\n",
+ "\n",
+ " phi_l = math.exp(Z_l-1-math.log(Z_l-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_l+(B*(1+math.sqrt(2))))/(Z_l+(B*(1-math.sqrt(2)))))));\n",
+ " phi_v = math.exp(Z_v-1-math.log(Z_v-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_v+(B*(1+math.sqrt(2))))/(Z_v+(B*(1-math.sqrt(2)))))));\n",
+ " fl = Prevised*phi_l;\t\n",
+ " fv = Prevised*phi_v;\t\n",
+ " Prevised = Prevised*fl/fv\n",
+ "\n",
+ "P = Prevised;\t\t\t\n",
+ "\n",
+ "# Results\n",
+ "print \" The vapour pressure of n-octane at 427.85K = %.5f\"%P,\" MPa\"\n",
+ "\n",
+ "# Note: answer is slightly differnt because of rounding off error."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The vapour pressure of n-octane at 427.85K = 0.21196 MPa\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file