{
 "metadata": {
  "name": "",
  "signature": "sha256:f0820b11a700821a3d31d338557194301893d84e5100c7860794ac7f11c2fe67"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 18 - Gas Compressors "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1 - Pg 374"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the theoretical horse power\n",
      "#Initalization of variables\n",
      "import math\n",
      "q=200. #cfm\n",
      "p2=90. #psia\n",
      "p1=14.5 #psia\n",
      "n=1.36\n",
      "#calculations\n",
      "hpp=n/(n-1) *144.*p1*q/33000. *(-1+math.pow(p2/p1, (n-1)/n))\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Theoretical horse power required =\",hpp,\" hp\")\n",
      "print '%s' %(\"The answer given in textbook is wrong. Please verify with a calculator\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical horse power required = 29.7  hp\n",
        "The answer given in textbook is wrong. Please verify with a calculator\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2 - Pg 377"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calcualte the indicated hp and shaft hp\n",
      "#Initalization of variables\n",
      "import math\n",
      "q=350. #cfm\n",
      "eff=0.78\n",
      "x=0.95\n",
      "p2=120. #psia\n",
      "p1=14.3 #psia\n",
      "#calculations\n",
      "cal=p1*144*q/550 *math.log(p2/p1) /100.\n",
      "ihp= cal/eff\n",
      "shp=ihp/x\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Indicated hp =\",ihp,\"hp\")\n",
      "print '%s %.1f %s' %(\"\\n Shaft hp =\",shp,\"hp\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Indicated hp = 35.7 hp\n",
        "\n",
        " Shaft hp = 37.6 hp\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - Pg 380"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the theoretical hp and piston displacement and max. temperature\n",
      "#Initalization of variables\n",
      "import math\n",
      "n=1.35\n",
      "p1=14.2\n",
      "q=400. #cfm\n",
      "p2=200. #psia\n",
      "p1=14.2 #psia\n",
      "ve=0.75\n",
      "t1=530. #R\n",
      "#calculations\n",
      "thp=-n/(n-1) *144 *p1*q/33000 *(1- math.pow(p2/p1,(n-1)/n))\n",
      "pd=q/ve\n",
      "Tmax=t1*math.pow(p2/p1,(n-1)/n)\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Theoretical hp =\",thp,\" hp\")\n",
      "print '%s %d %s' %(\"\\n Piston displacement =\",pd,\"cfm\")\n",
      "print '%s %d %s' %(\"\\n Max. Temperature =\",Tmax,\"R\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical hp = 94.2  hp\n",
        "\n",
        " Piston displacement = 533 cfm\n",
        "\n",
        " Max. Temperature = 1052 R\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4 - Pg 381"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the theoretical hp and piston displacement and max. temperature\n",
      "#Initalization of variables\n",
      "import math\n",
      "n=1.35\n",
      "p1=14.2 #psia\n",
      "p3=200. #psia\n",
      "q=400. #cfm\n",
      "ve=0.78\n",
      "t1=530. #R\n",
      "#calculations\n",
      "p2=math.sqrt(p3*p1) #psia\n",
      "thp=-2*n/(n-1) *144 *p1*q/33000 *(1- math.pow(p2/p1,(n-1)/n))\n",
      "pd=q/ve\n",
      "pd2=q*p1/p2 /ve\n",
      "Tmax=t1*math.pow(p2/p1,(n-1)/n)\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Theoretical hp =\",thp,\" hp\")\n",
      "print '%s %.1f %s' %(\"\\n For low pressure case, Piston displacement =\",pd,\"cfm\")\n",
      "print '%s %.1f %s' %(\"\\n For high pressure case, Piston displacement =\",pd2,\"cfm\")\n",
      "print '%s %.1f %s' %(\"\\n Max. Temperature =\",Tmax,\" R\")\n",
      "print '%s' %('The answers are a bit different due to rounding off error')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical hp = 78.2  hp\n",
        "\n",
        " For low pressure case, Piston displacement = 512.8 cfm\n",
        "\n",
        " For high pressure case, Piston displacement = 136.6 cfm\n",
        "\n",
        " Max. Temperature = 746.8  R\n",
        "The answers are a bit different due to rounding off error\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5 - Pg 386"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the theoretical pressure at exit\n",
      "#Initalization of variables\n",
      "import math\n",
      "dia=2 #ft\n",
      "rpm=6000. #rpm\n",
      "p=14.2 #psia\n",
      "t=75. #F\n",
      "g=32.17\n",
      "n=1.4\n",
      "R=53.35\n",
      "#calculations\n",
      "v=2*math.pi*rpm/60.\n",
      "wbym=v*v /g\n",
      "T=t+460.\n",
      "pr=1+ wbym*(n-1)/n /(R*T) \n",
      "pr2=math.pow(pr,(n/(n-1)))\n",
      "p2=pr2*p\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Theoretical pressure at exit =\",p2,\" psia\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Theoretical pressure at exit = 21.3  psia\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6 - Pg 391"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the velocity of air\n",
      "#Initalization of variables\n",
      "import math\n",
      "pa=14.7 #psia\n",
      "p1=12. #psia\n",
      "t1=560. #R\n",
      "n=1.4 #gamma\n",
      "J=778. #constant conversion\n",
      "g=32.2 #ft/s^2\n",
      "cp=0.24 #heat capacity\n",
      "eff=0.7 #efficiency\n",
      "m1=1.8 \n",
      "m3=1. \n",
      "#calculations\n",
      "t5=t1*math.pow(pa/p1,((n-1)/n))\n",
      "v4=math.sqrt(2*g*J*cp*(t5-t1)/eff) \n",
      "v3=(m1+m3)/m1 *v4\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Velocity of air =\",v3,\" ft/s\")\n",
      "print '%s' %(\"The answer given in textbook is wrong. Please verify with a calculator\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Velocity of air = 1178.8  ft/s\n",
        "The answer given in textbook is wrong. Please verify with a calculator\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7 - Pg 391"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the pressure required\n",
      "#Initalization of variables\n",
      "import math\n",
      "v2=1180. #ft/s\n",
      "etan=0.95\n",
      "cp=0.24\n",
      "n=1.4\n",
      "p2=12.\n",
      "#calculations\n",
      "dh=v2*v2 /(etan*223.8*223.8)\n",
      "dt=dh/cp\n",
      "t2d=560. #R\n",
      "t1=t2d+ etan*dt\n",
      "t2=554. #R\n",
      "pr=math.pow(t1/t2,(n/(n-1)))\n",
      "p1=p2*pr\n",
      "#results\n",
      "print '%s %.2f %s' %(\"Pressure required =\",p1,\"psia\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure required = 24.06 psia\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}