{
 "metadata": {
  "name": "",
  "signature": "sha256:e77c793709c88cc39a2de404e997a6f1eed32d352c214c1580d822fd7a5a83a2"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 17: COMPRESSIBLE FLOW"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.1:PG-710"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques1\n",
      "#to determine isentropic stagnation pressure and temperature \n",
      "\n",
      "T=300;#Temperature of air in K\n",
      "P=150;#Pressure of air in kPa\n",
      "v=200;#velocity of air flow n m/s\n",
      "Cp=1.004;#specific heat at constant pressure in kJ/kg\n",
      "To=v**2/(2000*Cp)+T;#stagnation temperature in K\n",
      "k=1.4;#constant\n",
      "Po=P*(To/T)**(k/(k-1));#stagnation pressure in kPa\n",
      "print 'Stagnation Temperature is ',round(To,1),' K \\n'\n",
      "print 'Stagnation Pressure is ',round(Po,2),'kPa \\n'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Stagnation Temperature is  319.9  K \n",
        "\n",
        "Stagnation Pressure is  187.85 kPa \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.2:PG-713"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques2\n",
      "#to determine the force\n",
      "\n",
      "#initializing variables\n",
      "mdot=-1 # mass flow rate out of control volume in kg/s\n",
      "Vx=-1 # x component of velocity of control volume in m/s\n",
      "Vy=10 # y component of velocity of control volume in m/s\n",
      "\n",
      "Fx=mdot*Vx # Force in X direction\n",
      "\n",
      "Fy=mdot*Vy # Force in Y direction\n",
      "\n",
      "print \"the force the man exert on the wheelbarrow\",round(Fx),\"N\"\n",
      "print \"the force the floor exerts on the wheelbarrow\",round(Fy),\"N\"\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the force the man exert on the wheelbarrow 1.0 N\n",
        "the force the floor exerts on the wheelbarrow -10.0 N\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.3:PG-715"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques3\n",
      "#determining the thrust acting on a control surface\n",
      "\n",
      "#i-inlet\n",
      "#e-exit\n",
      "#using momentum equation on control surface in x direction\n",
      "me=20.4;#mass exiting in kg\n",
      "mi=20;#mass entering in kg\n",
      "ve=450;#exit velocity in m/s\n",
      "vi=100;#inlet velocity in m/s\n",
      "Pi=95;#Pressure at inlet in kPa\n",
      "Pe=125;#Pressure at exit in kPa\n",
      "Po=100;#surrounding pressure in kPa\n",
      "Ai=0.2;#inlet area in m^2\n",
      "Ae=0.1;#exit area in m^2\n",
      "Rx=(me*ve-mi*vi)/1000-(Pi-Po)*Ai+(Pe-Po)*Ae;#thrust in x direction in kN\n",
      "\n",
      "print \"Thrust acting in x direction is \",round(Rx,2),\"kN\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thrust acting in x direction is  10.68 kN\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.4:PG-717"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques4\n",
      "#to determine increase in enthalpy\n",
      "#initializing variables\n",
      "#i-inlet\n",
      "#e-exit\n",
      "\n",
      "T=25+273 # temperature in kelvin\n",
      "v=0.001003 # specific volume of water in kg/m^3 at 25 *c from table B.1.1 \n",
      "ve=7;#exit velocity in m/s\n",
      "vi=30;#inlet velocity in m/s\n",
      "Pi=350;#Pressure at inlet in kPa\n",
      "Pe=600;#Pressure at exit in kPa\n",
      "\n",
      "#using momentum equation on control surface \n",
      "Pes= (vi**2-ve**2)/(2*v*1000)+Pi # exit pressure for reversible diffuser\n",
      "delH=(vi**2-ve**2)/(2*1000.0) # change in enthalpy from first law in kJ/kg\n",
      "delU=delH-v*(Pe-Pi) # change in internal energy in kJ/kg\n",
      "delS=delU/T # change in entropy in kJ/kg.K\n",
      "print\"the exit pressure for reversible diffuser is \",round(Pes),\"kPa\"\n",
      "print\"the increase in enthalpy is \",round(delH,5),\"kJ/kg\"\n",
      "print\"the increase in internal energy is \",round(delU,5),\"kJ/kg\"\n",
      "print\"the increase in entropy is \",round(delS,6),\"kJ/kg.K\"\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the exit pressure for reversible diffuser is  774.0 kPa\n",
        "the increase in enthalpy is  0.4255 kJ/kg\n",
        "the increase in internal energy is  0.17475 kJ/kg\n",
        "the increase in entropy is  0.000586 kJ/kg.K\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.5:PG-720"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques5\n",
      "#determining velocity of sound in air\n",
      "import math\n",
      "k=1.4;#constant\n",
      "R=0.287;#gas constant\n",
      "#at 300K\n",
      "T1=300;# temperature in kelvin\n",
      "c1=math.sqrt(k*R*T1*1000)\n",
      "print \"Speed of sound at 300 K is\",round(c1,1),\" m/s\" \n",
      "#at 1000K\n",
      "T2=1000;# temperature in kelvin\n",
      "c2=math.sqrt(k*R*T2*1000)\n",
      "print \"Speed of sound at 1000 K is\",round(c2,1),\" m/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Speed of sound at 300 K is 347.2  m/s\n",
        "Speed of sound at 1000 K is 633.9  m/s\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.6:PG-727"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques6\n",
      "#determining mass flow rate through control volume\n",
      "import math\n",
      "k=1.4;#constant\n",
      "R=0.287;#gas constant\n",
      "To=360;#stagnation Temperature in K \n",
      "T=To*0.8333;#Temperature of air in K, 0.8333 stagnation ratio from table\n",
      "v=math.sqrt(k*R*T*1000);#velocity in m/s\n",
      "P=528;#stagnation pressure in kPa\n",
      "d=P/(R*T);#stagnation density in kg/m^3\n",
      "A=500*10**-6;#area in m^2\n",
      "ms=d*A*v;#mass flow rate in kg/s\n",
      "print\" Mass flow rate at the throat section is\",round(ms,4),\"kg/s\"\n",
      "#e-exit state\n",
      "Te=To*0.9381;#exit temperature in K, ratio from table\n",
      "ce=math.sqrt(k*R*Te*1000);#exit velocity of sound in m/s\n",
      "Me=0.573;#Mach number\n",
      "ve=Me*ce;\n",
      "Pe=800;#exit pressure in kPa\n",
      "de=Pe/R/Te;\n",
      "mse=de*A*ve;\n",
      "print\" Mass flow rate at the exit section is\",round(mse,4),\" kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Mass flow rate at the throat section is 1.0646 kg/s\n",
        " Mass flow rate at the exit section is 0.8711  kg/s\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.7:PG-728"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques7\n",
      "#determining exit properties in a control volume\n",
      "import math\n",
      "Po=1000;#stagnation pressure in kPa\n",
      "To=360;#stagnation temperature in K\n",
      "\n",
      "#when diverging section acting as nozzle\n",
      "\n",
      "Pe1=0.0939*Po;#exit pressure of air in kPa\n",
      "Te1=0.5089*To;#exit temperature in K\n",
      "k=1.4;#constant\n",
      "R=0.287;#gas constant for air\n",
      "ce=math.sqrt(k*R*Te1*1000);#velocity of sound in exit section in m/s\n",
      "Me=2.197;#mach number from table\n",
      "ve1=Me*ce;#velocity of air at exit section in m/s\n",
      "print \"When diverging section act as a nozzle :-\"\n",
      "print \"Exit pressure is\",round(Pe1,4),\" kPa\"\n",
      "print \"Exit Temperature\",round(Te1,1),\" K\"\n",
      "print \"Exit velocity is\",round(ve1,1),\" m/s \"\n",
      "\n",
      "#when diverging section act as diffuser\n",
      "\n",
      "Me=0.308;\n",
      "Pe2=0.0936*Po;#exit pressure of air in kPa\n",
      "Te2=0.9812*To;#exit temperature in K\n",
      "ce=math.sqrt(k*R*Te2*1000);#velocity of sound in exit section in m/s\n",
      "ve2=Me*ce;\n",
      "print \"When diverging section act as a diffuser :-\"\n",
      "print \"Exit pressure is\",round(Pe2,1),\" kPa\"\n",
      "print \"Exit Temperature\",round(Te2,2),\" K\"\n",
      "print \"Exit velocity is\",round(ve2,),\" m/s \"\n",
      "\n",
      "# The value of Exit pressure when diverging section acts as diffuser is wrong\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "When diverging section act as a nozzle :-\n",
        "Exit pressure is 93.9  kPa\n",
        "Exit Temperature 183.2  K\n",
        "Exit velocity is 596.1  m/s \n",
        "When diverging section act as a diffuser :-\n",
        "Exit pressure is 93.6  kPa\n",
        "Exit Temperature 353.23  K\n",
        "Exit velocity is 116.0  m/s \n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.8:PG-731"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques8\n",
      "#Determine the static pressure and temperature of supersonic nozzle\n",
      "#x-inlet\n",
      "#y-exit\n",
      "# using  the data from previous example\n",
      "Mx=2.197 # Mach number at x\n",
      "Px=93.9 # IN kPa\n",
      "Tx=183.2 # IN K\n",
      "P0x=1000 # IN kPa\n",
      "T0x = 360 # in K\n",
      "My=0.547 # Mach number at y From Table A.13\n",
      "Py = 5.46*Px # From Table A.13\n",
      "Ty = 1.854 * Tx # From Table A.13\n",
      "P0y= 0.630 * P0x # From Table A.13\n",
      "print \"Exit pressure after shock is\",round(Py,1),\" kPa\"\n",
      "print \"Exit Temperature after shock is\",round(Ty,1),\" K\"\n",
      "print \"Exit stagnation pressure after shock is\",round(P0y,1),\" kPa\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exit pressure after shock is 512.7  kPa\n",
        "Exit Temperature after shock is 339.7  K\n",
        "Exit stagnation pressure after shock is 630.0  kPa\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17.9:PG-733"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#ques9\n",
      "#determining exit plane properties in control volume\n",
      "\n",
      "#x-inlet\n",
      "#y-exit\n",
      "Mx=1.5;#mach number for inlet\n",
      "My=0.7011;#mach number for exit\n",
      "Px=272.4;#inlet pressure in kPa\n",
      "Tx=248.3;#inlet temperature in K\n",
      "Tox=360 # stagnation temperature in Kelvin\n",
      "Pox=1000.0;#stagnation pressure for inlet\n",
      "Py=2.4583*Px;# Pressure at 1.5 mach in kPa\n",
      "Ty=1.320*Tx;# temperature at 1.5 mach in K\n",
      "Poy=0.9298*Pox;# pressure at 1.5 mach in kPa\n",
      "\n",
      "Toy=Tox # constant\n",
      "Me=0.339 # from table with A/A*=1.860 and M < 1\n",
      "Pe=0.9222*Py;#Exit Pressure in kPa\n",
      "Te=0.9771*Toy;#Exit temperature in K\n",
      "Poe=0.9222*Poy;#Exit pressure in kPa\n",
      "\n",
      "print \"Exit Mach no.=\",Me\n",
      "print \"Exit temperature =\",round(Te,2),\"K \"\n",
      "print \"Exit pressure =\",round(Poe,1),\"kPa\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Exit Mach no.= 0.339\n",
        "Exit temperature = 351.76 K \n",
        "Exit pressure = 857.5 kPa\n"
       ]
      }
     ],
     "prompt_number": 50
    }
   ],
   "metadata": {}
  }
 ]
}