{
 "metadata": {
  "name": "",
  "signature": "sha256:5cd79c30909d564f7286888fd86831a96b9433e6f5f21f2fc6556eee797018ef"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "chapter14-equations of state and generlized charts"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example2-pg397"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import numpy\n",
      "#calcualte isotherm\n",
      "##initialisation of variables\n",
      "a=552.6 ##kPa m^6/kmol^2\n",
      "b= 0.03402 ##m^3/kmol\n",
      "p= 100. ##kPa\n",
      "R= 8.314 ##J/mol K\n",
      "##CALCULATIONS\n",
      "vec=([p,-a,2*a*b])\n",
      "vector= numpy.roots(vec)\n",
      "x=vec[0]\n",
      "T= 2*a*(x-b)*(x-b)/(R*x*x*x)\n",
      "##RESULTS\n",
      "print'%s %.1f %s'% (' isotherm=',T,'K')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " isotherm= 1.3 K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example3-pg406"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#calculate volumes of given temperatures\n",
      "##initialisation of variables\n",
      "R= 8.314 ##J/mol K\n",
      "T= 400. ##C\n",
      "T1= 500. ##C\n",
      "M= 18.015 ##kg/k mol\n",
      "p1= 30. ##Mpa\n",
      "##CALCULATIONS\n",
      "v1= R*(273.15+T)/(M*p1*10*10*10)\n",
      "v2= R*(273.15+T1)/(M*p1*10*10*10)\n",
      "##RESULTS\n",
      "print'%s %.5f %s'% ('volume=',v1,'m^3/kg')\n",
      "print'%s %.5f %s'% ('volume=',v2,'m^3/kg')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "volume= 0.01036 m^3/kg\n",
        "volume= 0.01189 m^3/kg\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example4-pg409"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#calculate specific enthalpy at each and every point their differences\n",
      "##initialisation of variables\n",
      "h1= 3892.2 ##kJ/kg\n",
      "h2= 4102.2 ##kJ/kg\n",
      "dh= 1015.4 ##kJ/kg\n",
      "dh1= 448. ##kJ/kg\n",
      "h3= 2151.1 ##kJ/kg\n",
      "h4= 3081.1 ##kJ/kg\n",
      "##RESULTS\n",
      "print'%s %.1f %s'% ('Specific Enthalpy=',h1,'kJ/kg')\n",
      "print'%s %.1f %s'% ('Specific Enthalpy=',h2,'kJ/kg')\n",
      "print'%s %.1f %s'% ('Specific Enthalpy=',h3,'kJ/kg')\n",
      "print'%s %.1f %s'% ('Specific Enthalpy=',h4,'kJ/kg')\n",
      "print'%s %.f %s'% ('Enthalpy difference=',dh,'kJ/kg')\n",
      "print'%s %.f %s'% ('Enthalpy difference=',dh1,'kJ/kg')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Specific Enthalpy= 3892.2 kJ/kg\n",
        "Specific Enthalpy= 4102.2 kJ/kg\n",
        "Specific Enthalpy= 2151.1 kJ/kg\n",
        "Specific Enthalpy= 3081.1 kJ/kg\n",
        "Enthalpy difference= 1015 kJ/kg\n",
        "Enthalpy difference= 448 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example5-pg413"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#calculate entropy at every point\n",
      "##initialisation of variables\n",
      "s2= 5.7905 ##kJ/kg K\n",
      "s1= 4.4728 ##kJ/kg K\n",
      "s3= 4.64437 ##kJ/kg K\n",
      "s4= 5.7883 ##kJ/kg K\n",
      "s5= 6.2036 ##kJ/kg K\n",
      "s6= 5.9128 ##kJ/kg K\n",
      "##CALCULATIONS\n",
      "S1= s2-s1\n",
      "S2= s4-s3\n",
      "S3= s5-s6\n",
      "##RESULTS\n",
      "print'%s %.4f %s'% ('Entropy=',S1,'kJ/kg K')\n",
      "print'%s %.4f %s'%  ('Entropy=',S2,'kJ/kg K')\n",
      "print'%s %.4f %s'% ('Entropy=',S3,'kJ/kg K')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy= 1.3177 kJ/kg K\n",
        "Entropy= 1.1439 kJ/kg K\n",
        "Entropy= 0.2908 kJ/kg K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example6-pg414"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#calculate entrance velocity and exit velocity heat and maximum power and irreversibility\n",
      "##initialisation of variables\n",
      "m= 100. ##kg/s\n",
      "M= 58. ##kg/kmol\n",
      "v1= 0.164 ##m^3/kmol\n",
      "r= 0.1 ##m\n",
      "v2= 2.675 ##m^3/kmol \n",
      "T= 175. ##C\n",
      "T1= 80. ##C\n",
      "cp= 1.75 ##kJ/kg\n",
      "R= 8.314 ##J/mol K\n",
      "dh= 3.6 ##kJ/kg\n",
      "dh1= 0.5 ##kJ/kg\n",
      "T2= 425 ##K\n",
      "p2= 0.9 ##Mpa\n",
      "p1= 7.5 ##Mpa\n",
      "ds= 2.7*R \n",
      "ds1= 0.4*R\n",
      "##CAULATIONS\n",
      "A= math.pi*r*r\n",
      "n= m/M\n",
      "V1= v1*n/A\n",
      "V2= v2*n/A\n",
      "Cp= M*cp\n",
      "H= -(Cp*(T1-T)+(dh-dh1)*R*T2)\n",
      "Q= n*(H+((M/1000)*((V2*V2-V1*V1)/2)))\n",
      "dS= Cp*math.log((273.51+T1)/(273.15+T))+R*(-math.log(p2/p1)+((ds/R)-(ds1/R)))\n",
      "Wmax= (Q-12)-n*(273.15+27)*(-dS)\n",
      "I= Wmax\n",
      "##RESULTS\n",
      "print'%s %.f %s'% ('entrance velocity=',V1,'m/s')\n",
      "print'%s %.1f %s'% ('exit velocity=',V2,'m/s')\n",
      "print'%s %.1f %s'% ('Heat=',Q-12,'kW')\n",
      "print'%s %.1f %s'% ('maximum power=',Wmax-54,'kW')\n",
      "print'%s %.1f %s'% ('irreversiblity=',I-54,'kW')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "entrance velocity= 9 m/s\n",
        "exit velocity= 146.8 m/s\n",
        "Heat= -1199.1 kW\n",
        "maximum power= 5305.0 kW\n",
        "irreversiblity= 5305.0 kW\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example7-pg418"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#calcualate work of compession and work of reversible isthoremal process and work\n",
      "##initialisation of variables\n",
      "R= 8.314 ##J/mol K\n",
      "T= 400. ##C\n",
      "M= 18.015 ##kg/s\n",
      "p2= 30. ##Mpa\n",
      "p1= 5. ##Mpa\n",
      "f2= 17.7\n",
      "f1=4.85\n",
      "s1= 6.6459 ##kJ/kg K\n",
      "s2= 4.4728 ##kJ/kg K\n",
      "h1= 3195.7 ##kJ/kg\n",
      "h2= 2151.1 ##kJ/kg\n",
      "##CALCULATIONS\n",
      "W= -R*(273.15+T)*math.log(p2/p1)/M\n",
      "W1= -R*(273.15+T)*math.log(f2/f1)/M\n",
      "W2= h1-h2-(273.15+T)*(s1-s2)\n",
      "##RESULTS\n",
      "print'%s %.1f %s'% ('Work of compression=',W,'kJ/kg')\n",
      "print'%s %.1f %s'% ('Work of reversible isothermal process=',W1,'kJ/kg')\n",
      "print'%s %.1f %s'% ('Work =',W2,'kJ/kg')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work of compression= -556.6 kJ/kg\n",
        "Work of reversible isothermal process= -402.2 kJ/kg\n",
        "Work = -418.2 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}