{
 "metadata": {
  "name": "",
  "signature": "sha256:dc464f4ef08695f8cec0668d0c21cb89b005d8581737f852d592d0e688b3aa48"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 16 - Gas cycles"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1 - Pg 330"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the max. pressure, temperature and thermal efficiency\n",
      "#Initalization of variables\n",
      "import math\n",
      "cr=9.\n",
      "p1=14. #psia\n",
      "t1=80.+460 #R\n",
      "n=1.4\n",
      "heat=800. #Btu\n",
      "c=0.1715\n",
      "R=53.35\n",
      "J=778.\n",
      "#calculations\n",
      "p2=p1*math.pow(cr,n)\n",
      "t2=t1*math.pow(cr,(n-1))\n",
      "t3=heat/c +t2\n",
      "p3=p2*t3/t2\n",
      "eff=(1-1/math.pow(cr,(n-1)))*100\n",
      "t4=t3/math.pow(cr,(n-1))\n",
      "Qr=c*(t4-t1)\n",
      "cyclework=heat-Qr\n",
      "eff2= cyclework/heat *100\n",
      "V1=R*t1/(144*p1)\n",
      "pd=(1-1/cr)*V1\n",
      "mep=cyclework*J/(pd*144)\n",
      "#results\n",
      "print '%s %d %s' %(\"Max. temperature =\",t3,\"R\")\n",
      "print '%s %d %s' %(\"\\n Max. pressure =\",p3,\"psia\")\n",
      "print '%s %.1f %s' %(\"\\n In method 1,Thermal efficiency =\",eff,\" percent\")\n",
      "print '%s %.1f %s' %(\"\\n In method 2,Thermal efficiency =\",eff2,\" percent\")\n",
      "print '%s %.1f %s' %(\"\\n Mean effective pressure mep =\",mep,\" psia\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Max. temperature = 5965 R\n",
        "\n",
        " Max. pressure = 1391 psia\n",
        "\n",
        " In method 1,Thermal efficiency = 58.5  percent\n",
        "\n",
        " In method 2,Thermal efficiency = 58.5  percent\n",
        "\n",
        " Mean effective pressure mep = 199.0  psia\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2 - Pg 333"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the max temperature, pressure and thermal efficiency\n",
      "#Initalization of variables\n",
      "import math\n",
      "t1=80+460. #R\n",
      "p1=14. #psia\n",
      "n=1.4\n",
      "cr=16.\n",
      "heat=800. #Btu\n",
      "cp=0.24\n",
      "c=0.1715\n",
      "#calculations\n",
      "t2=t1*math.pow(cr,(n-1))\n",
      "p2=p1*math.pow(cr,n)\n",
      "t3=t2 +heat/cp\n",
      "v32=t3/t2\n",
      "v43=cr/v32\n",
      "t4=t3/math.pow(v43,(n-1))\n",
      "Qr=c*(t4-t1)\n",
      "etat=(heat-Qr)/heat *100\n",
      "#results\n",
      "print '%s %d %s' %(\"Max. Temperature =\",t3,\" R\")\n",
      "print '%s %d %s' %(\"\\n Max. Pressure =\",p2,\"psia\")\n",
      "print '%s %.1f %s' %(\"\\n Thermal efficiency =\",etat,\" percent\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Max. Temperature = 4970  R\n",
        "\n",
        " Max. Pressure = 679 psia\n",
        "\n",
        " Thermal efficiency = 56.8  percent\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3 - Pg 335"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the Mean effective pressure\n",
      "#Initalization of variables\n",
      "eff=0.585\n",
      "heat=800. #Btu\n",
      "t1=80+460. #R\n",
      "p1=14. #psia\n",
      "n=1.4\n",
      "R=53.35\n",
      "cr=9.\n",
      "cp=0.24\n",
      "J=778.\n",
      "#calculations\n",
      "W=eff*heat\n",
      "v1=R*t1/(144*p1)\n",
      "v2=v1/cr\n",
      "t2=1301 #R\n",
      "t3=t2+ heat/cp\n",
      "v3=v2*t3/t2\n",
      "v4=cr*v3\n",
      "mep=W*J/(144*(v4-v2))\n",
      "#results\n",
      "print '%s %.1f %s' %(\"Mean effective pressure =\",mep,\" psia\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mean effective pressure = 51.3  psia\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4 - Pg 340"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#calculate the max temperature, pressure, thermal efficiency, mean effective pressure\n",
      "#Initalization of variables\n",
      "import math\n",
      "eff=0.585\n",
      "heat=500. #Btu\n",
      "heat1=300. #Btu\n",
      "t1=80+460. #R\n",
      "p1=14. #psia\n",
      "n=1.4\n",
      "R=53.35\n",
      "cr=9.\n",
      "J=778.\n",
      "c=0.1715\n",
      "cp=0.24\n",
      "t2=1301. #R\n",
      "p2=308. #psia\n",
      "#calculations\n",
      "t3=t2+ heat/c\n",
      "p3=p2*t3/t2\n",
      "t4=t3+ heat1/cp\n",
      "v43=t4/t3\n",
      "v54=cr/v43\n",
      "t5=t4/math.pow(v54,(n-1))\n",
      "Qr=c*(t5-t1)\n",
      "etat=(heat+heat1-Qr)/(heat+heat1) *100\n",
      "mep=(heat+heat1-Qr)*J/(12.69*144)\n",
      "#results\n",
      "print '%s %d %s' %(\"Max. Temperature =\",t4,\" R\")\n",
      "print '%s %d %s' %(\"\\n Max. Pressure =\",p3,\"psia\")\n",
      "print '%s %.1f %s' %(\"\\n Thermal efficiency =\",etat,\"percent\")\n",
      "print '%s %.1f %s' %(\"\\n Mean effective pressure =\",mep,\" psia\")\n",
      "print '%s' %(\"The calculations are a bit different due to rounding off error in textbook\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Max. Temperature = 5466  R\n",
        "\n",
        " Max. Pressure = 998 psia\n",
        "\n",
        " Thermal efficiency = 57.6 percent\n",
        "\n",
        " Mean effective pressure = 196.2  psia\n",
        "The calculations are a bit different due to rounding off error in textbook\n"
       ]
      }
     ],
     "prompt_number": 4
    }
   ],
   "metadata": {}
  }
 ]
}