{
 "metadata": {
  "name": "",
  "signature": "sha256:72e2616045657b51e34a7053265f42c549d2a5b15ca9a3b0a7fb70c4376d5ddc"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 17 : Compressible Fluid Flow"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.1 Page No : 694"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "import sys\n",
      "\n",
      "# Variables\n",
      "T0 = 37+273\n",
      "P = 40.\n",
      "g = 1.4;\n",
      "\n",
      "def speed(a,b,f):\n",
      "    N = 100.;\n",
      "    eps = 1e-5;\n",
      "    if((f(a)*f(b))>0):\n",
      "        print('no root possible f(a)*f(b)>0');\n",
      "        sys.exit(0)\n",
      "    if(abs(f(a))<eps):\n",
      "        print('solution at a');\n",
      "        sys.exit(0)\n",
      "    if(abs(f(b))<eps):\n",
      "        print('solution at b');\n",
      "        sys.exit(0)\n",
      "\n",
      "    while(N>0):\n",
      "        c = (a+b)/2.\n",
      "        if(abs(f(c))<eps):\n",
      "            x = c ;\n",
      "            return x;\n",
      "        if((f(a)*f(c))<0 ):\n",
      "            b = c ;\n",
      "        else:\n",
      "            a = c ;\n",
      "        N = N-1;\n",
      "\n",
      "    print('no convergence');\n",
      "    sys.exit(0)\n",
      "\n",
      "def p(x): \n",
      "\t return  x**4 + (5*(x**2)) - 3.225 \n",
      "x = speed(0.5,1,p);\n",
      "M = x; \t\t\t# Mach number\n",
      "g = 1.4; \t\t\t# gamma\n",
      "R = 0.287;\n",
      "\n",
      "# Calculation\n",
      "T = T0/(1+((g-1)/2)*M**2);\n",
      "c = math.sqrt(g*R*T*1000);\n",
      "V = c*M;\n",
      "P0 = P*((T0/T)**(g/(g-1)));\n",
      "\n",
      "# Results\n",
      "print \"Mach number is\",round(M,2)\n",
      "print \"Velocity is\",round(V,1),\"m/s\"\n",
      "print \"Stagnation pressure is\",round(P0,2),\"kPa\"\n",
      "\n",
      "# note: rounding off error is there."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mach number is 0.76\n",
        "Velocity is 254.1 m/s\n",
        "Stagnation pressure is 58.67 kPa\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.2 Page No : 695"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "P1 = 0.18e03; \t\t\t# in Kpa\n",
      "R = 0.287\n",
      "T1 = 310.; \n",
      "P0 = 0.1e03;\n",
      "A1 = 0.11; \n",
      "V1 = 267.;\n",
      "\n",
      "# Calculation\n",
      "w = (P1/(R*T1))*A1*V1;\n",
      "g = 1.4;\n",
      "c1 = math.sqrt(g*R*T1*1000);\n",
      "M1 = V1/c1;\n",
      "A1A_ = 1.0570; \t\t\t# A1./A* A* = A_\n",
      "P1P01 = 0.68207;\n",
      "T1T01 = 0.89644;\n",
      "F1F_ = 1.0284;\n",
      "A2A1 = 0.44/0.11 ; \t\t\t# A2A1 = A2/A1\n",
      "A2A_ = A2A1*A1A_;\n",
      "M2 = 0.135; \n",
      "P2P02 = 0.987; \n",
      "T2T02 = 0.996; \n",
      "F2F_ = 3.46;\n",
      "P2P1 = P2P02/P1P01;\n",
      "T2T1 = T2T02/T1T01;\n",
      "F2F1 = F2F_/F1F_;\n",
      "P2 = P2P1*P1;\n",
      "T2 = T2T1*T1;\n",
      "A2 = A2A1*A1;\n",
      "F1 = P1*A1*(1+g*M1**2);\n",
      "F2 = F2F1*F1;\n",
      "Tint = F2-F1;\n",
      "Text = P0*(A2-A1);\n",
      "NT = Tint - Text ;\n",
      "\n",
      "# Results\n",
      "print \"Net thrust is\",round(NT,2),\"kN\"\n",
      "\n",
      "# rounding off error is there."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Net thrust is 51.33 kN\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.3 Page No : 697"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "M2 = 2.197; \n",
      "P2P0 = 0.0939; \n",
      "T2T0 = 0.5089;\n",
      "P0 = 1000.\n",
      "T0 = 360.; \n",
      "g = 1.4; \n",
      "R = 0.287; \n",
      "\n",
      "# Calculation and Results\n",
      "P2 = P2P0*P0;\n",
      "T2 = T2T0*T0;\n",
      "c2 = math.sqrt(g*R*T2*1000);\n",
      "V2 = c2*M2;\n",
      "# for air\n",
      "P_P0 = 0.528; T_T0 = 0.833; \t\t\t# T_ == T*\n",
      "P_ = P_P0*P0; T_ = T_T0*T0;\n",
      "rho_ = P_/(R*T_);\n",
      "V_ = math.sqrt(g*R*T_*1000);\n",
      "At = 500e-06; \t\t\t# throat area\n",
      "w = At*V_*rho_;\n",
      "\n",
      "print (\"When divergent section act as a nozzle\")\n",
      "print \"Maximum flow rate of air is\",round(w,3),\"kg/s\"\n",
      "print \"Static temperature is\",round(T2,1),\"K\"\n",
      "print \"Static Pressure is\",P2,\"kPa\"\n",
      "print \"Velocity at the exit from the nozzle is\",round(V2,0),\"m/s\"\n",
      "\n",
      "# Part (b)\n",
      "Mb = 0.308; \n",
      "P2P0b = 0.936;\n",
      "T2T0b = 0.9812;\n",
      "P2b = P2P0b*P0;\n",
      "T2b = T2T0b*T0;\n",
      "c2b = math.sqrt(g*R*T2b*1000);\n",
      "V2b = c2b*Mb; \n",
      "\n",
      "print (\"\\nWhen divergent section act as a diffuser\")\n",
      "print \"Maximum flow rate of air is\",round(w,3),\"kg/s\"\n",
      "print \"Static temperature is\",round(T2b,1),\"K\"\n",
      "print \"Static Pressure is\",P2b,\"kPa\"\n",
      "print \"Velocity at the exit from the nozzle is\",round(V2b,0),\"m/s\"\n",
      "\n",
      " \n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "When divergent section act as a nozzle\n",
        "Maximum flow rate of air is 1.065 kg/s\n",
        "Static temperature is 183.2 K\n",
        "Static Pressure is 93.9 kPa\n",
        "Velocity at the exit from the nozzle is 596.0 m/s\n",
        "\n",
        "When divergent section act as a diffuser\n",
        "Maximum flow rate of air is 1.065 kg/s\n",
        "Static temperature is 353.2 K\n",
        "Static Pressure is 936.0 kPa\n",
        "Velocity at the exit from the nozzle is 116.0 m/s\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.4 Page No : 698"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "Px = 16.            #kPa; \n",
      "Poy = 70.           #kPa;\n",
      "Mx = 1.735; \n",
      "Pyx = 3.34; \t\t\t# Pyx = Py/Px\n",
      "rho_yx = 2.25;\n",
      "Tyx = 1.483; Poyox = 0.84; My = 0.631;\n",
      "Tox = 573; Toy = Tox;\n",
      "\n",
      "# Calculation\n",
      "Tx = Tox/(1+((g-1)/2.)*Mx**2);\n",
      "Ty = Tyx*Tx;\n",
      "Pox = Poy/Poyox ;\n",
      "# From table\n",
      "Mx = 1.735;\n",
      "\n",
      "# Results\n",
      "print \"Mach number of the tunnel is\",Mx\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mach number of the tunnel is 1.735\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.5 Page No : 699"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "Ax = 18.75; \n",
      "A_ = 12.50; \t\t\t# A_= A*\n",
      "AA_ = 1.5; \t\t\t# A/A*\n",
      "Mx = 1.86; \n",
      "Pxox = 0.159; \n",
      "R = 0.287;\n",
      "Pox = 0.21e03; \t\t\t# in kPa\n",
      "\n",
      "# Calculation\n",
      "Px = Pxox*Pox;\n",
      "# from the gas table on normal shock\n",
      "Mx = 1.86; My = 0.604; Pyx = 3.87; Poyx = 4.95; Poyox = 0.786;\n",
      "Py = Pyx*Px;\n",
      "Poy = Poyx*Px;\n",
      "My = 0.604;\n",
      "Ay_ = 1.183;\n",
      "A2 = 25.; Ay = 18.75;\n",
      "A2_ = (A2/Ay)*Ay_;\n",
      "# From isentropic table \n",
      "M2 = 0.402;\n",
      "P2oy = 0.895;\n",
      "P2 = P2oy*Poy;\n",
      "syx = -R*math.log(Poy/Pox); \t\t\t# sy-sx\n",
      "\n",
      "# Results\n",
      "print \"Exit mach number is M2\",M2\n",
      "print \"Exit pressure is\",round(P2,2),\"kPa\"\n",
      "print \"Exit Stagnation pressure is\",round((Pox-Poy),1),\"kPa\"\n",
      "print \"Entropy increase is\",round(syx,4),\"kJ/kg K\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exit mach number is M2 0.402\n",
        "Exit pressure is 147.93 kPa\n",
        "Exit Stagnation pressure is 44.7 kPa\n",
        "Entropy increase is 0.0687 kJ/kg K\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.6 Page No : 700"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "g = 1.4\n",
      "R = 0.287\n",
      "d = 1.4; \t\t\t# del \n",
      "P0 = 1.4; \t\t\t# in bar\n",
      "T0 = 280.\n",
      "T1 = T0;\n",
      "cp = 1.005\n",
      "A2 = 0.0013\n",
      "\n",
      "# Calculation\n",
      "P_ = P0/((g+1)/2.)**(d/(d-1)) ; \t\t\t# P_ = P*\n",
      "P1 = P0; Pb = 1.; P2 = Pb;\n",
      "T2 = T1*(P2/P1)**((d-1)/d);\n",
      "V2 = math.sqrt(2*cp*(T1-T2)*1000);\n",
      "m_dot = (A2*V2*P2*100)/(R*T2);\n",
      "\n",
      "# Results\n",
      "print \"Mass flow rate is\",round(m_dot,4),\"kg/s\"\n",
      "print \"The mass flow rate can be increased by raising the supply pressure\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass flow rate is 0.4045 kg/s\n",
        "The mass flow rate can be increased by raising the supply pressure\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.7 Page No : 701"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "Mx = 1.8\n",
      "Pyx = 3.6133;\n",
      "Px = 0.5; Tx = 280.; Ty = 429.;\n",
      "R = 0.287\n",
      "\n",
      "\n",
      "# Calculation and Results\n",
      "Py = Pyx*Px; cp = 1.005;\n",
      "print \"Pressure Py is\",round(Py,4),\"bar\"\n",
      "\n",
      "Pxox = 0.17404;\n",
      "Pox = Px/Pxox;\n",
      "print \"Stagnation pressure is\",round(Pox,2),\"bar\"\n",
      "\n",
      "Txox = 0.60680;\n",
      "Tox = Tx/Txox; \n",
      "print \"Stagnation temperature is\",round(Tox,1),\"K\"\n",
      "\n",
      "sysx = cp*math.log(Ty/Tx)-R*math.log(Py/Px);\n",
      "print \"The change in specific entropy is\",round(sysx,5),\"kJ/kg K\"\n",
      "\n",
      "# note : rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure Py is 1.8067 bar\n",
        "Stagnation pressure is 2.87 bar\n",
        "Stagnation temperature is 461.4 K\n",
        "The change in specific entropy is 0.06011 kJ/kg K\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17.8 Page no : 701"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# variables\n",
      "M1 = 0.39\n",
      "T1ox = 0.97032\n",
      "Tox = 546.2\n",
      "P1ox = 0.9\n",
      "pox = 3.778      # bar\n",
      "Mx = 2\n",
      "Pxox = 0.1278\n",
      "Px = 0.4828      # bar\n",
      "My = 0.57735\n",
      "Pyoy = 0.79737\n",
      "Poy = 2.735       # bar\n",
      "Toy = 546.2      #  K\n",
      "Tox = Toy\n",
      "\n",
      "# calculations and Results\n",
      "A1 = 0.5*0.287*530/(180*3.4*100)    # m**2\n",
      "print \"A1 = %.4e m**2\"%A1\n",
      "M1 = 0.39\n",
      "A1 = 1.6346\n",
      "Astar = 7.602*10**-4\n",
      "print \"A* = %.3e m**2\"%(Astar)\n",
      "M = 0.57735\n",
      "A2 = 1.25*Astar\n",
      "print \"A2 = Exit plane area = %.3e m**2\"%A2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A1 = 1.2427e-03 m**2\n",
        "A* = 7.602e-04 m**2\n",
        "A2 = Exit plane area = 9.503e-04 m**2\n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}