{
 "metadata": {
  "name": "",
  "signature": "sha256:e6f28e03dfd837b5aed00ee85654c1040a3b0c8129a67f41e8f2e4ba487b8f35"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 9 : Steady Flow of Compressible Fluids"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.1 Page No : 268"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\n",
      "#Initialization of variables\n",
      "T2 = 30. \t#C\n",
      "T1 = 20. \t#C\n",
      "cv = 716.\n",
      "m = 15. \t#kg\n",
      "cp = 1003.\n",
      "\t\n",
      "#calculations\n",
      "di = cv*(T2-T1)\n",
      "dU = di*m\n",
      "dh = cp*(T2-T1)\n",
      "dH = dh*m\n",
      "\t\n",
      "#Results\n",
      "print \"Change in Internal energy  =  %d N m\"%(dU)\n",
      "print \" Change in Enthalpy  =  %d Nm\"%(round(dH,-3))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in Internal energy  =  107400 N m\n",
        " Change in Enthalpy  =  150000 Nm\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.2 Page No : 268"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\n",
      "#Initialization of variables\n",
      "cv = 716.\n",
      "m = 15. \t#kg\n",
      "cp = 1003.\n",
      "T1 = 20.+273 \t#K\n",
      "k = 1.4\n",
      "ratio = 0.4\n",
      "\t\n",
      "#calculations\n",
      "T2 = int((T1)*(1/ratio)**(k-1))\n",
      "P1 = 95. \t#kN/m**2\n",
      "P2 = int(P1*T2/(T1)/ratio)\n",
      "di = round(cv*(T2-T1),-2)\n",
      "dU = di*m\n",
      "dh = round(cp*(T2-T1),-2)\n",
      "dH = dh*m\n",
      "\n",
      "\n",
      "#Results\n",
      "print \"Final temperature  =  %d K\"%(T2)\n",
      "print \" Final pressure  =  %d kN/m**2\"%(P2)\n",
      "print \" Change in Internal energy  =  %d N m\"%(dU)\n",
      "print \" Change in Enthalpy  =  %d Nm\"%(dH)\n",
      "\n",
      "#The answers are a bit different due to rounding off error.please check.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final temperature  =  422 K\n",
        " Final pressure  =  342 kN/m**2\n",
        " Change in Internal energy  =  1386000 N m\n",
        " Change in Enthalpy  =  1941000 Nm\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.3 Page No : 271"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\n",
      "#Initialization of variables\n",
      "k = 1.4\n",
      "R = 1773.\n",
      "v = 600. \t#fps\n",
      "T = 660. \t#K\n",
      "P = 100. \t#psia\n",
      "cp = 6210.\n",
      "g = 32.2\n",
      "\t\n",
      "#calculations\n",
      "c = math.sqrt(k*R*T)\n",
      "M = v/c\n",
      "rho = k*P*144/c**2\n",
      "Ps = P*144 + 0.5*(rho)*v**2 *(1+ 0.25*M**2)\n",
      "Ts =  (cp/g *T + v**2 /(2*g))*g/cp\n",
      "\t\n",
      "#Results\n",
      "print \"Stagnation pressure  =  %d lb/ft**2\"%(Ps)\n",
      "print \" Stagnation temperature  =  %.f R\"%(Ts)\n",
      "\n",
      "\n",
      "# note :Please check the units of the answer.\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Stagnation pressure  =  16736 lb/ft**2\n",
        " Stagnation temperature  =  689 R\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.4 Page No : 275"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\n",
      "#Initialization of variables\n",
      "g = 32.2\n",
      "A = 0.0218 \t#ft**2\n",
      "P1 = 25.6 \t#psia\n",
      "T1 = 540. \t#K\n",
      "k = 1.4\n",
      "R = 1715.\n",
      "\t\n",
      "#calculations\n",
      "G = g*A*P1*144/math.sqrt(T1) *math.sqrt(k/R *(2/(k+1))**((k+1)/(k-1)))\n",
      "\t\n",
      "#Results\n",
      "print \"Flow rate   =  %.2f lb/s\"%(G)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Flow rate   =  1.84 lb/s\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.5 Page No : 278"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\n",
      "#Initialization of variables\n",
      "P1 = 50.    \t#psia\n",
      "T1 = 540.   \t#K\n",
      "g = 32.2\n",
      "R = 1715.\n",
      "k = 1.4\n",
      "P3 = 13.5 \t    #psia\n",
      "A2 = 0.0218 \t#ft**2\n",
      "cp = 6000.\n",
      "\t\n",
      "#calculations\n",
      "Pc = 0.528*P1\n",
      "V32 = round(R*T1/g *k/(k-1) *(1- (P3/P1)**((k-1)/k)),-2)\n",
      "V3 = round(math.sqrt(V32*2*g),-1)\n",
      "G3 = g*A2*P1*144/math.sqrt(T1) *math.sqrt(k/R *(2/(k+1))**((k+1)/(k-1)))\n",
      "T3 =  T1 - V3**2 /(2*cp) \n",
      "gam3 =  g*P3*144/(R*T3)\n",
      "gam2 =  (Pc/P3 *gam3**k )**(1/k)\n",
      "V2 = G3/gam2/A2\n",
      "T2 =  (V3**2 -V2**2)/(2*cp) + T3\n",
      "A3 = G3/gam3/V3\n",
      "D3 =  math.sqrt(4/math.pi *A3)\n",
      "G2 = G3\n",
      "\n",
      "#Results\n",
      "print \" velocity at section 3  =  %d fps\"%(V3)\n",
      "print \" Flow rate at section 3  =  %.3f lb/s\"%(G3)\n",
      "print \" temperature at section 3   =  %d R\"%(T3)\n",
      "print \" velocity at section 2  =  %d fps\"%(V2)\n",
      "print \" Flow rate at section 2  =  %.3f lb/s\"%(G2)\n",
      "print \" temperature at section 2   =  %d R\"%(T2)\n",
      "print \" Required Diameter  =  %.2f in\"%(D3*12)\n",
      "\n",
      "# book anwers are wrong. please check."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " velocity at section 3  =  1420 fps\n",
        " Flow rate at section 3  =  3.596 lb/s\n",
        " temperature at section 3   =  371 R\n",
        " velocity at section 2  =  1041 fps\n",
        " Flow rate at section 2  =  3.596 lb/s\n",
        " temperature at section 2   =  449 R\n",
        " Required Diameter  =  2.18 in\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.6 Page No : 281"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\n",
      "#Initialization of variables\n",
      "P1 = 10.     \t#psia\n",
      "T1 = 460+40. \t#R\n",
      "R = 1715.\n",
      "k = 1.4\n",
      "V1 = 1400.   \t#fps\n",
      "\t\n",
      "#calculations\n",
      "rho1 = P1/(R*T1)\n",
      "c1 = math.sqrt(k*R*T1)\n",
      "M1 = V1/c1\n",
      "P2 =  P1 * (2*k*M1**2  - (k-1))/(k+1)\n",
      "V2  = V1*((k-1)*M1**2 +2)/((k+1)*M1**2) \n",
      "rho2 = rho1*V1/V2\n",
      "T2 = P2/rho2/R\n",
      "P22 = 122.5\n",
      "V22 = 286\n",
      "T22 = 328\n",
      "\t\n",
      "#Results\n",
      "print \"Pressure at point 2  =  %.1f psia and %.1f N/m**2\"%(P2,P22)\n",
      "print \" Velocity at point 2  =  %d fps and %d m/s\"%(V2,V22)\n",
      "print \" Temperature at point 2  =  %d R and %d K\"%(T2,T22)\n",
      "print (\"Similarly it can be done for SI units\")\n",
      "\n",
      "# note : ronding off error. please check."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure at point 2  =  17.4 psia and 122.5 N/m**2\n",
        " Velocity at point 2  =  947 fps and 286 m/s\n",
        " Temperature at point 2  =  588 R and 328 K\n",
        "Similarly it can be done for SI units\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.7 Page No : 286"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\n",
      "#Initialization of variables\n",
      "A = 140. \t#in**2\n",
      "P = 48. \t#lb/in**2\n",
      "mu = 3.78*10**-7\n",
      "g = 32.2\n",
      "G = 100. \t#lb/s\n",
      "p = 80. \t#lb/in**2\n",
      "T = 65.+460 \t#R\n",
      "k = 1.4\n",
      "R = 1715.\n",
      "\t\n",
      "#calculations\n",
      "Rh = A/P /12\n",
      "R1 = G*4*Rh/ (mu*g*A/144)\n",
      "R2 = R1\n",
      "f = 0.0083\n",
      "gam1 = p*g*144/(R*T)\n",
      "V1 = G*144/gam1/A\n",
      "c = math.sqrt(k*R*T)\n",
      "M1 = V1/c\n",
      "M2 = 1/math.sqrt(k)\n",
      "D = 4*Rh\n",
      "L =  ((1-M1**2 /M2**2)/(k*M1**2) - 2*math.log(M2/M1) )*D/f\n",
      "Ln = 500 \t#ft\n",
      "P2 = math.sqrt((p*144)**2 - G**2 *R*T/(g**2 *(A/144)**2 *f*Ln/D))\n",
      "Pa = 12.2\n",
      "\t\n",
      "#Results\n",
      "print \"Max. length  =  %d ft\"%(round(L,-1))\n",
      "print \" Pressure required  =  %.1f psia\"%(P2/144 -Pa)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Max. length  =  1260 ft\n",
        " Pressure required  =  67.1 psia\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.8 Page No : 287"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\n",
      "#Initialization of variables\n",
      "G = 100. \t#lb/s\n",
      "g = 32.2\n",
      "V2 = 300. \t#fps\n",
      "V1 = 250. \t#fps\n",
      "\t\n",
      "#calculations\n",
      "Qh =  (V2**2 -V1**2)/(2*g)\n",
      "Q = Qh*G\n",
      "\t\n",
      "#Results\n",
      "print \"Thermal energy added  =  %.2f ft lb/s\"%(Q)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thermal energy added  =  42701.86 ft lb/s\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.9 Page No : 290"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\n",
      "#Initialization of variables\n",
      "gam1 = 0.41\n",
      "g = 32.2\n",
      "V1 = 250. \t#fps\n",
      "R1 = 8.2*10**6\n",
      "f = 0.0083\n",
      "A = 0.97 \t#ft**2\n",
      "G = 100. \t#lb/s\n",
      "k = 1.4\n",
      "P = 80. \t#pressure - psia\n",
      "ratio = 0.8\n",
      "R = 1715\n",
      "\t\n",
      "#calculations\n",
      "rho1 = gam1/g\n",
      "X  =  G**2 /(gam1*A)**2 + 2*k/(k-1) *(P*144/rho1)\n",
      "P2 = (k-1)/2/k *(X*ratio*rho1 - G**2 /(g**2 *A**2 *ratio*rho1))\n",
      "L = 563 \t#ft\n",
      "rho2 = ratio*rho1\n",
      "V2 = G/(rho2*g*A)\n",
      "T2 = P2/(rho2*R)\n",
      "\t\n",
      "#Results\n",
      "print \"Length  =  %d ft\"%(L)\n",
      "print \" velocity  =  %.f fps\"%(V2)\n",
      "print \" Temperature  =  %d R\"%(T2)\n",
      "\n",
      "# note : rounding off error"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Length  =  563 ft\n",
        " velocity  =  314 fps\n",
        " Temperature  =  524 R\n"
       ]
      }
     ],
     "prompt_number": 19
    }
   ],
   "metadata": {}
  }
 ]
}