{
 "metadata": {
  "name": "",
  "signature": "sha256:277bc4cb4b4cbb4032c88d8fd8301e41a2fcfc6cb9b7c57adbca5a396d6c0dce"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 12:Compressible Flow"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-1, Page No:638"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "V_1=250 #Velocity in m/s\n",
      "c_p=1.005 #Constant Pressure specific heat in kJ/kg.K\n",
      "k=1.4 #Specific heat ratio \n",
      "T1=255.7 #\n",
      "C=10**-3 #COnversion factor\n",
      "P1=54.05 #Atmospheric Pressure in kPa\n",
      "SPR=8 #Stagnation pressure ratio \n",
      "\n",
      "#Calculations\n",
      "#Part(a)\n",
      "T_01=T1+((V_1**2/(2*c_p))*C) #Stagnation temperature in K\n",
      "\n",
      "P_01=P1*((T_01/T1)**(k/(k-1))) #Stagnation Pressure in kPa\n",
      "\n",
      "#Part(b)\n",
      "T_02=T_01*((SPR)**((k-1)/k)) #Stagnation Temperature at compressor exit in K\n",
      "\n",
      "Win=c_p*(T_02-T_01) #Work per unit mass of air in kJ/kg\n",
      "\n",
      "#Result\n",
      "print \"The stagnation pressure is\",round(P_01,2),\"kPa\"\n",
      "print \"The required compressor work per unit mass is\",round(Win,1),\"kJ/kg\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The stagnation pressure is 80.77 kPa\n",
        "The required compressor work per unit mass is 233.9 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-2, Page No:639"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "cp=0.846 #Specific Heat in kJ/kg.K\n",
      "k=1.289 #Specific heat ratio\n",
      "R=0.1889 #gas constant for Carbon dioxide in kJ/kg.K\n",
      "T_0=473 #Temperature in K\n",
      "P0=1.4*10**3 #Pressure in kPa\n",
      "P=1.2*10**3 #Pressure in kPa\n",
      "m_dot=3 #Mass flow rate in kg/s\n",
      "\n",
      "#Calcualtions\n",
      "x=((k-1)/k)\n",
      "b=float(P/P0)\n",
      "T=T_0*((b)**x) #Temperature where pressure is P in K\n",
      "V=(2*cp*(T0-T)*10**3)**0.5 #Velocity in m/s\n",
      "\n",
      "#Using The Ideal Gas relation\n",
      "rho=P/(R*T) #Density of the fluid in kg/m^3\n",
      "\n",
      "#Using the mass flow rate relation\n",
      "A=m_dot/(rho*V) #Area in m^2\n",
      "\n",
      "c=(k*R*T*10**3)**0.5 #speed of sound in m/s\n",
      "\n",
      "#Mach Number\n",
      "Ma=V/c #Mach's Number\n",
      "\n",
      "#Result\n",
      "print \"Similarly we can compute data for other pressures as well\"\n",
      "print \"The denisty of air is\",round(rho,5),\"kg/m^3\"\n",
      "print \"The area is\",A,\"m^2\"\n",
      "print \"The speed of sound is\",round(c,2),\"m/s\"\n",
      "print \"The Mach Number is\",round(Ma,3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Similarly we can compute data for other pressures as well\n",
        "The denisty of air is 13.90266 kg/m^3\n",
        "The area is 0.00130869674184 m^2\n",
        "The speed of sound is 333.56 m/s\n",
        "The Mach NUmber is 0.494\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-3,Page No:645"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "k=1.289 #Specific Heat Ratio\n",
      "To=473 #Stagnation temperature in K\n",
      "Po=1400 #Stagnation pressure in kPa\n",
      "\n",
      "#Calculations\n",
      "#Notation has been changed for simplicity of computation\n",
      "T_ratio=2/(k+1) #ratio of T star to To\n",
      "P_ratio=(2/(k+1))**(k/(k-1)) #Ratio of P star to Po\n",
      "\n",
      "T_star=T_ratio*To #Critical Temperature in K\n",
      "P_star=P_ratio*Po #Critical Pressure in kPa\n",
      "\n",
      "#Result\n",
      "print \"the critical temperature and pressrue are\",round(T_star),\"K and\",round(P_star),\"kPa\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the critical temperature and pressrue are 413.0 K and 767.0 kPa\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-4, Page No:648"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable decleration\n",
      "Vi=150 #Velocity at the inlet in m/s\n",
      "cp=1.005 #Specific heat in kJ/Kg.K\n",
      "k=1.4 #Specific heat ratio\n",
      "Ti=873 #Temperature at the inlet in K\n",
      "Pi=1 #Pressure at the inlet in Mpa\n",
      "Pb1=0.7 #Back pressure in part a in Mpa\n",
      "Pb2=0.4 #Back pressure in part b in Mpa\n",
      "R=0.287 #Gas Constant in kPa.m^3/kg.K\n",
      "At=50*10**-4 #Area in m^2\n",
      "\n",
      "#Values taken from the table\n",
      "P_ratio=0.67 #Presure ratio\n",
      "T_ratio=0.892 #Temperature ratio\n",
      "Mat=0.778 #Mach Number \n",
      "\n",
      "#Calculations\n",
      "Toi=Ti+((Vi**2/(2*cp))*10**-3) #Stagnation Temperature in K\n",
      "\n",
      "Poi=Pi*((Toi/Ti)**(k/(k-1))) #Stagnation Presure in mPa\n",
      "\n",
      "#Stagnation pressure and temperature values remain constant throughout\n",
      "\n",
      "#Part(A)\n",
      "#Notation will be changed to avoid computational complexicity\n",
      "BPR1=Pb1/Poi #Back Pressure ratio\n",
      "\n",
      "Tt=T_ratio*Toi #Temperature in K\n",
      "rhot=(Pb1*10**3)/(R*Tt) #Density in kg/m^3\n",
      "Vt=Mat*((k*R*Tt*10**3)**0.5) #Velocity in m/s\n",
      "m_dot1=rhot*At*Vt #Mass flow rate in kg/s\n",
      "\n",
      "#Part(B)\n",
      "#Notation will be changed\n",
      "BPR2=Pb2/Poi #Back pressure ratio\n",
      "\n",
      "m_dot2=(At*Poi*10**3)*((k/(Toi*R))**0.5)*((2/(k+1))**((k+1)/(2*(k-1))))*1000**0.5 #mass flow rate in kg/s\n",
      "\n",
      "#Result\n",
      "print \"The mass flow rate at the nozzle is\",round(m_dot1,2),\"kg/s\"\n",
      "print \"The mass flow rate through the nozzleis calculated to be\",round(m_dot2,2),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mass flow rate at the nozzle is 6.77 kg/s\n",
        "The mass flow rate through the nozzleis calculated to be 7.11 kg/s\n"
       ]
      }
     ],
     "prompt_number": 53
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-5, Page No:650"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "Pgauge=220 #Gauge Pressure in the tire in kPa\n",
      "Patm=94 #Atmospheric Pressure in kPa\n",
      "R=0.287 #Gas Constant in kPa.m^3/kg.K\n",
      "k=1.4 #Specific heat ratio\n",
      "T=298 #Temperature in K\n",
      "D=0.004 #Diamter in m\n",
      "\n",
      "#Calculations\n",
      "P=Pgauge+Patm #Absolute Pressure in the tre in kPa\n",
      "\n",
      "#Critical Presure in the tire from table\n",
      "Pstar=round(0.5283*P) #Critical Presure in kPa\n",
      "\n",
      "#Flow is choked\n",
      "rho0=P/(R*T) #Denisty of the fluid in kg/m^3\n",
      "rho_star=rho0*((2/(k+1))**(1/(k-1))) #Critical Density in kg/m^3\n",
      "T_star=(2/(k+1))*T #Critical Temperature in K\n",
      "\n",
      "V=(k*R*T_star*1000)**0.5 #Velocity in m/s\n",
      "m_dot=rho_star*((pi*D**2)/4)*V #mass flow rate in kg/s\n",
      "\n",
      "#Result\n",
      "print \"The initial mass flow rate is\",round(m_dot,5),\"kg/s\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The initial mass flow rate is 0.00924 kg/s\n"
       ]
      }
     ],
     "prompt_number": 63
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-6, Page No:653"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "k=1.4 #Specific Heat ratio\n",
      "R=0.287 #Gas Constant in kJ/kg.K\n",
      "Ma=2 #Mach Number\n",
      "A=20*10**-4 #Throat Area in m^2\n",
      "P0=1000 #Pressure in kPa\n",
      "T0=800 #Temperature in K\n",
      "\n",
      "#Calculations\n",
      "rho0=P0/(R*T0) #Density of the fluid in kg/m^3\n",
      "\n",
      "#Part(a) When Ma=1\n",
      "#Notation has been changed\n",
      "#Taking values from the table\n",
      "P_ratio=0.5283 #Pressure ratio\n",
      "T_ratio=0.8333 #Temperature Ratio\n",
      "rho_ratio=0.6339 #Density Ratio\n",
      "\n",
      "#Thus\n",
      "P_star=P_ratio*P0 #Critical Pressure in kPa\n",
      "T_star=T_ratio*T0 #Critical Temperature in K\n",
      "rho_star=rho_ratio*rho0 #Critical Denisty in kg/m^3\n",
      "\n",
      "V_star=(k*R*T_star*1000)**0.5 #Critical Velocity in m/s\n",
      "\n",
      "#Part(b) When Ma=2\n",
      "P_ratio2=0.1278 #Pressure ratio in part b\n",
      "T_ratio2=0.5556 #Temperature ratio in part b\n",
      "rho_ratio2=0.23 #Density ratio in part b\n",
      "Ma_star=1.633 #Critical Mach Number\n",
      "A_ratio=1.6875 #Area ratio in part b\n",
      "\n",
      "#Thus\n",
      "Pe=P_ratio2*P0 #Pressure at the exit plane in kPa\n",
      "Te=T_ratio2*T0 #Temperature at the exit plane in K\n",
      "rho_e=rho_ratio2*rho0 #Density at the exit plane in kg/m^3\n",
      "Ae=A_ratio*A #Area at the exit plane in m^2\n",
      "Ve=Ma_star*V_star #Velocity at the exit plane in m/s\n",
      "\n",
      "#Part(c)\n",
      "m_dot=rho_star*A*V_star #Mass flow rate in kg/s\n",
      "\n",
      "\n",
      "#Result\n",
      "print \"The throat conditions are as follows\"\n",
      "print \"P*=\",round(P_star),\"kPa\",\"T*=\",round(T_star,1),\"K\",\"rho*=\",round(rho_star,3),\"kg/m^3\"\n",
      "print \"The exit plane conditions are as follows\"\n",
      "print \"Pe=\",round(Pe),\"kPa\",\"Te=\",round(Te,1),\"K\",\"rho_e=\",round(rho_e,3),\"kg/m^3\"\n",
      "print \"Ae=\",Ae,\"m^2\"\n",
      "print \"The mass flow rate is\",round(m_dot,2),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The throat conditions are as follows\n",
        "P*= 528.0 kPa T*= 666.6 K rho*= 2.761 kg/m^3\n",
        "The exit plane conditions are as follows\n",
        "Pe= 128.0 kPa Te= 444.5 K rho_e= 1.002 kg/m^3\n",
        "Ae= 0.003375 m^2\n",
        "The mass flow rate is 2.86 kg/s\n"
       ]
      }
     ],
     "prompt_number": 69
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-8, Page No:659"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#NOTE:The variable names have been changed\n",
      "\n",
      "#Variable Decleration\n",
      "k=1.4 #Specific Heat ratio\n",
      "R=0.287 #gas Constant in kJ/kg.K\n",
      "cp=1.005 #Specfic heat at constant pressure in kJ/kg.K\n",
      "#Table Values\n",
      "P01=1 #pressure in MPa\n",
      "P1=0.1278 #Pressure in MPa\n",
      "T1=444.5 #Temperature in K\n",
      "rho1=1.002 #Denisty in kg/m^3\n",
      "Ma1=2 #Mach Number \n",
      "Ma2=0.5774 #Mach Number \n",
      "Po_ratio=0.7209 #Presure ratio\n",
      "P_ratio=4.5 #Pressure ratio\n",
      "T_ratio=1.6875 #Temperature Ratio\n",
      "rho_ratio=2.6667 #Density Ratio\n",
      "A=20*10**-4 #Area in m^2\n",
      "\n",
      "#Calculations\n",
      "#Part(a)\n",
      "\n",
      "P02=Po_ratio*P01 #Stagnation Pressure after the shockwave in MPa\n",
      "P2=P1*P_ratio #Static Pressure after the shockwave in MPa\n",
      "T2=T_ratio*T1 #Temperature after the shockwave in K\n",
      "rho2=rho_ratio*rho1 #Denisty after the shockwave in kg/m^3\n",
      "\n",
      "#Part(b)\n",
      "e_change=cp*(np.log(T2/T1))-(R*np.log(P2/P1)) #Entropy change across the shock in kJ/kg.K\n",
      "\n",
      "#Part(c)\n",
      "V2=Ma2*(k*R*T2*1000)**0.5 #Velocity in m/s\n",
      "\n",
      "#Part(d)\n",
      "#Same as example 12-6 above\n",
      "m_dot=2.86 #Mass Flow rate in kg/s\n",
      "\n",
      "#Result\n",
      "print \"The Following are the values\"\n",
      "print \"Stagnation Pressure\",round(P02,3),\"MPa\"\n",
      "print \"Static Pressure\",round(P2,3),\"MPa\"\n",
      "print \"Static Temperature\",round(T2,1),\"K\"\n",
      "print \"Static Denisty\",round(rho2,2),\"kg/m^3\"\n",
      "print \"The entropy change is\",round(e_change,5),\"kJ/kg.K\"\n",
      "print \"The exit velocity is\",round(V2),\"m/s\"\n",
      "print \"The mass flow rate is\",round(m_dot,3),\"kg/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Following are the values\n",
        "Stagnation Pressure 0.721 MPa\n",
        "Static Pressure 0.575 MPa\n",
        "Static Temperature 750.1 K\n",
        "Static Denisty 2.67 kg/m^3\n",
        "The entropy change is 0.09419 kJ/kg.K\n",
        "The exit velocity is 317.0 m/s\n",
        "The mass flow rate is 2.86 kg/s\n"
       ]
      }
     ],
     "prompt_number": 77
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-9, Page No:667"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "u=19 #angle of Mach lines in Degrees\n",
      "\n",
      "#Calculations\n",
      "Ma1=1/(sin((u*pi)/180)) #Mach Number \n",
      "\n",
      "#Result\n",
      "print \"The Mach Number is\",round(Ma1,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Mach Number is 3.07\n"
       ]
      }
     ],
     "prompt_number": 81
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-10, Page No:667"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#NOTE:Some Variable names have been changed\n",
      "\n",
      "#Variable Decleration\n",
      "Ma1=2 #Mach Number\n",
      "k=1.4 #Specific heat ratio\n",
      "theta=10 #Deflection in degrees\n",
      "beta_weak=39.3 #Oblique shock angle in degrees\n",
      "beta_strong=83.7 #Oblique shock angle in degrees\n",
      "P1=75 #Pressure in kPa\n",
      "Ma2_n_w=0.8032 #Mach Number on Downstream side\n",
      "Ma2_n_s=0.5794 #Mach Number on Downstream Side \n",
      "\n",
      "#Calculations\n",
      "\n",
      "#Weak shock\n",
      "Ma1_n_w=Ma1*sin((beta_weak*pi)/180) #Mach Number\n",
      "\n",
      "#Strong Shock\n",
      "Ma1_n_s=Ma1*sin((beta_strong*pi)/180) #Mach Number\n",
      "\n",
      "#Pressure Calculations\n",
      "\n",
      "#Weak Shock\n",
      "P2_w=((2*k*(Ma1_n_w**2)-k+1)/(k+1))*P1 #Pressure in kPa\n",
      "\n",
      "#Strong Shock\n",
      "P2_s=((2*k*(Ma1_n_s**2)-k+1)/(k+1))*P1 #Pressure in kPa\n",
      "\n",
      "Ma2_w=Ma2_n_w/sin(((beta_weak-theta)*pi)/180) #Mach NUmber on the downstream side\n",
      "\n",
      "Ma2_s=Ma2_n_s/sin(((beta_strong-theta)*pi)/180) #Mach NUmber on the downstream side\n",
      "\n",
      "#Result\n",
      "print \"The Mach number on the downstream side of the oblique shock are\"\n",
      "print \"Ma in weak shock\",round(Ma2_w,3),\"Ma in strong shock\",round(Ma2_s,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Mach number on the downstream side of the oblique shock are\n",
        "Ma in weak shock 1.641 Ma in strong shock 0.604\n"
       ]
      }
     ],
     "prompt_number": 85
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-11, Page no:668"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "Ma1=2 #Mach Number \n",
      "P1=230 #Pressure in kPa\n",
      "k=1.4 #Specific Heat ratio\n",
      "theta=10 #Degrees\n",
      "Ma2=2.38 #Mach Number \n",
      "\n",
      "#Calculations\n",
      "#Simplfying the calculation\n",
      "a=((k+1)/(k-1))**0.5\n",
      "b=((Ma1**2)-1)**0.5\n",
      "c=((k-1)/(k+1))**0.5\n",
      "d=arctan(b)*180*pi**-1\n",
      "e=arctan(c*b)*180*pi**-1\n",
      "\n",
      "vMa1=a*e-d #Upstream Prandtl-Meyer Function in degrees\n",
      "vMa2=theta+vMa1 #Degrees\n",
      "\n",
      "#Pressure Calculations\n",
      "#Simplifying Calculations\n",
      "a1=(k-1)*0.5\n",
      "b1=k/(k-1)\n",
      "f=(1+a1*Ma2**2)**(-b1)\n",
      "g=(1+a1*Ma1**2)**(-b1)\n",
      "P2=P1*(f/g) #Pressure in kPa\n",
      "\n",
      "#Result\n",
      "print \"The Mach Number on the Downstream Side is\",round(Ma2,2)\n",
      "print \"The Pressure at the downstream side is\",round(P2),\"kPa\"\n",
      "#The answer in the textbook has not been rounded and hence differes "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Mach Number on the Downstream Side is 2.38\n",
        "The Pressure at the downstream side is 127.0 kPa\n"
       ]
      }
     ],
     "prompt_number": 128
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-14, Page No:677"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "k=1.4 #Specific Heat Ratio\n",
      "cp=1.005 #Specific Heat in kJ/kg.K\n",
      "R=0.287 #Gas COnstant in kJ/kg.K\n",
      "P1=480 #Pressure in kPa\n",
      "T1=550 #Temperature in K\n",
      "D=0.15 #Diameter in m\n",
      "AF=40 #Air-Fuel mass ratio\n",
      "HV=42000 #Heating Value in kJ/kg\n",
      "V=80 #Velocity in m/s\n",
      "\n",
      "#Values from Tables\n",
      "T_ratio=0.1291 #Temperature ratio\n",
      "T_ratio1=0.1541 #Temperature Ratio\n",
      "P_ratio1=2.3065 #Pressure ratio\n",
      "V_ratio1=0.0668 #Velocity Ratio\n",
      "T_ratio2=0.4389 #Temperature Ratio\n",
      "P_ratio2=2.1086 #Pressure Ratio\n",
      "V_ratio2=0.2082 #Velocity ratio\n",
      "\n",
      "#Calculations\n",
      "rho1=P1/(R*T1) #Density in kg/m^3\n",
      "A1=(pi*D**2)/4 #Area in m^2\n",
      "m_dot_air=rho1*A1*V #Mass flow rate of air in kg/s\n",
      "m_dot_fuel=m_dot_air/AF #Mass flow rate of the fuel in kg/s\n",
      "Q_dot=m_dot_fuel*HV #Heat in kW\n",
      "q=Q_dot/m_dot_air #HEat Transfer rate in kJ/kg\n",
      "\n",
      "#Stagnation Temperature and Mach Number at INLET\n",
      "T01=T1+(V**2/(2*cp))*10**-3 #Stagnation Temperature in K\n",
      "c1=(k*R*T1*1000)**0.5 #Speed in m/s\n",
      "Ma1=V/c1 #Mach Number\n",
      "\n",
      "#EXIT stagnation Temperature and Mach Number\n",
      "T02=T01+(q/cp) #Stagnation Temperature in K\n",
      "\n",
      "T0_star=T01/T_ratio #Critical Temperature in K\n",
      "\n",
      "#Value for Ma2 is taken form the table corresponding to the Temperature ratio given below\n",
      "T_rat=T02/T0_star #Temperature Ratio\n",
      "Ma2=0.314 #Mach Number\n",
      "\n",
      "#Exit Values\n",
      "T2=T1*(T_ratio2/T_ratio1) #Temperature in K\n",
      "P2=P1*(P_ratio2/P_ratio1) #Pressure in kPa\n",
      "V2=V*(V_ratio2/V_ratio1) #Velocity in m/s\n",
      "\n",
      "#Result\n",
      "print \"The Temperature at the exit is\",round(T2),\"K\"\n",
      "print \"The pressure at the exit is\",round(P2),\"kPa\"\n",
      "print \"The velocity at the exit is\",round(V2),\"m/s\"\n",
      "#The answer for temperature in tetbook is incorrect\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Temperature at the exit is 1566.0 K\n",
        "The pressure at the exit is 439.0 kPa\n",
        "The velocity at the exit is 249.0 m/s\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-15, Page No:685"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Varialble Decleration\n",
      "k=1.4 #Specific Heat ratio\n",
      "cp=1.005 #Specific Heat in kJ/kg.K\n",
      "R=0.287 #Gas Constant in kJ/kg.K\n",
      "v=1.58*10**-5 #Kinematic Viscosity in m^2/s\n",
      "P1=150 #Pressure in kPa\n",
      "T1=300 #Temperature in K\n",
      "Ma1=0.4 #Mach Number\n",
      "D=0.03 #Diameter in m\n",
      "f=0.0148 #Friction factor\n",
      "#Values from tables\n",
      "P_ratio1=1.5901 \n",
      "T_ratio1=1.1628\n",
      "P_ratio2=2.6958\n",
      "V_ratio=0.4313\n",
      "fL1_D=2.3085\n",
      "\n",
      "#Calculations\n",
      "c1=(k*R*T1*1000)**0.5 #Inlet Velocity in m/s\n",
      "V1=Ma1*c1 #Velocity in m/s\n",
      "Re1=(V1*D)/v #Reynolds Number\n",
      "\n",
      "L1_star=(fL1_D*D)/f #Duct Length in m\n",
      "T_star=T1/T_ratio1 #Temperature in K\n",
      "P_star=P1/P_ratio2 #Pressure in kPa\n",
      "V_star=V1/V_ratio #Velocity in m/s\n",
      "\n",
      "fraction=1-(1/P_ratio1) #Fraction of the inlet stagnation pressure lost \n",
      "\n",
      "#Result\n",
      "print \"The duct length is\",round(L1_star,2),\"m\"\n",
      "print \"The Temperature is\",round(T_star),\"K\"\n",
      "print \"The Pressure is\",round(P_star,1),\"kPa\"\n",
      "print \"The Velocity is\",round(V_star),\"m/s\"\n",
      "print round(fraction,3),\"Fraction of the total stagnation pressure is lost in the duct\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The duct length is 4.68 m\n",
        "The Temperature is 258.0 K\n",
        "The Pressure is 55.6 kPa\n",
        "The Velocity is 322.0 m/s\n",
        "0.371 Fraction of the total stagnation pressure is lost in the duct\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12.12-16,Page No:686"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable Decleration\n",
      "k=1.4 #Specific Heat ratio\n",
      "cp=1.005 #Specific Heat in kJ/kg.K\n",
      "R=0.287 #Gas Constant in kJ/kg.K\n",
      "V1=85 #Velocity in m/s\n",
      "P1=220 #Pressure in kPa\n",
      "T1=450 #Temperature in K\n",
      "f=0.023 #Friction factor \n",
      "L=27 #Length in m\n",
      "D=0.05 #Diameter in m\n",
      "\n",
      "#Value from table\n",
      "fl_D=14.5333\n",
      "\n",
      "#Calculations\n",
      "c1=(k*R*T1*1000)**0.5 #Velocity in m/s\n",
      "Ma1=V1/c1 #Mach Number\n",
      "\n",
      "#Notation has been changed\n",
      "fL_D1=(f*L)/D #Function\n",
      "fL_D2=fl_D-fL_D1 #Function\n",
      "\n",
      "#Mach NUmber corresponding to this value is 0.42\n",
      "Ma2=0.420 #Mach Number\n",
      "\n",
      "rho1=P1/(R*T1) #Density of the fluid in kg/m^3\n",
      "A1=(pi*D**2)/4 #Area in m^2\n",
      "m_air=rho1*V1*A1 #Mass flow rate in kg/s\n",
      "\n",
      "#Discussion Calculations\n",
      "L_max1=(fl_D*D)/f #MAx Duct length in m\n",
      "L_max2=(fL_D2*D)/f #Max Duct length in m\n",
      "\n",
      "#Result\n",
      "print \"The Mach Number is\",round(Ma2,3)\n",
      "print \"The mass flow rate is\",round(m_air,3),\"kg/s\"\n",
      "print \"The max length at  inlet is\",round(L_max1,1),\"m\"\n",
      "print \"The max length at exit  is\",round(L_max2,1),\"m\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The Mach Number is 0.42\n",
        "The mass flow rate is 0.284 kg/s\n",
        "The max length at  inlet is 31.6 m\n",
        "The max length at exit  is 4.6 m\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}