{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 17:Compressible Fluid Flow"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex17.2:pg-717"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 17.2 \n",
      "\n",
      "\n",
      " Mass flow rate of air through diffuser is  59.4200292233  Kg/s\n",
      "\n",
      "  Mach number of leaving air is  0.135\n",
      "\n",
      "  Temperature of leaving air is  71.4290750078  degree celcius\n",
      "\n",
      "  Pressure of leaving air is  0.260471799082  MPa \n",
      "\n",
      " Net thrust is  51.3284455434  kN\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "P1 = 0.18 # Diffuser static pressure in MPa\n",
    "R = 0.287 # Gas constant\n",
    "T1 = 37 # Static temperature \n",
    "P0 = 0.1# Atmospheric pressure in MPa\n",
    "A1 = 0.11 # intake area in m**2\n",
    "V1 = 267 # Inlet velocity in m/s\n",
    "w = (P1*1e3/(R*(T1+273)))*A1*V1 # mass flow rate\n",
    "g = 1.4 # Heat capacity ratio\n",
    "c1 = math.sqrt(g*R*(T1+273)*1000) # velocity\n",
    "M1 = V1/c1 # Mach number\n",
    "A1A_ = 1.0570 # A1/A* A* = A_\n",
    "P1P01 = 0.68207 # pressure ratio\n",
    "T1T01 = 0.89644# Temperature ratio\n",
    "F1F_ = 1.0284# Impulse function ratio\n",
    "A2A1 = 0.44/0.11  # Area ratio\n",
    "A2A_ = A2A1*A1A_# Area ratio\n",
    "M2 = 0.135 # Mach number\n",
    "P2P02 = 0.987 # Pressure ratio\n",
    "T2T02 = 0.996 # Temperature ratio\n",
    "F2F_ = 3.46# Impulse function ratio\n",
    "P2P1 = P2P02/P1P01 # Pressure ratio\n",
    "T2T1 = T2T02/T1T01# Temperature ratio\n",
    "F2F1 = F2F_/F1F_ # Impulse function ratio\n",
    "P2 = P2P1*P1 # Outlet  pressure\n",
    "T2 = T2T1*(T1+273) # Outlet temperature\n",
    "A2 = A2A1*A1 # Exit area\n",
    "F1 = P1*A1*(1+g*M1**2) # Impulse function\n",
    "F2 = F2F1*F1 # Impulse function\n",
    "Tint = F2-F1 # Internal thrust\n",
    "Text = P0*(A2-A1) # External thrust\n",
    "NT = Tint - Text  # Net thrust\n",
    "\n",
    "print \"\\n Example 17.2 \\n\"\n",
    "print \"\\n Mass flow rate of air through diffuser is \",w ,\" Kg/s\"\n",
    "print \"\\n  Mach number of leaving air is \",M2\n",
    "print \"\\n  Temperature of leaving air is \",T2-273 ,\" degree celcius\"\n",
    "print \"\\n  Pressure of leaving air is \",P2 ,\" MPa \"\n",
    "print \"\\n Net thrust is \",NT*1e3 ,\" kN\"\n",
    "\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex17.3:pg-718"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 17.3\n",
      "\n",
      "\n",
      " When divergent section act as a nozzle\n",
      "\n",
      " Maximum flow rate of air is  1.06476372092  kg/s\n",
      "\n",
      " Static temperature is  183.204  K\n",
      "\n",
      " Static Pressure is  93.9  kPa\n",
      "\n",
      " Velocity at the exit from the nozzle is  596.077184351  m/s\n",
      "\n",
      "\n",
      " When divergent section act as a diffuser\n",
      "\n",
      " Maximum flow rate of air is  1.06476372092  kg/s\n",
      "\n",
      " Static temperature is  353.232  K\n",
      "\n",
      " Static Pressure is  936.0  kPa\n",
      "\n",
      " Velocity at the exit from the nozzle is  116.03411731  m/s\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "M2 = 2.197 # Mach number\n",
    "P2P0 = 0.0939 # pressure ratio\n",
    "T2T0 = 0.5089 # Temperature ratio\n",
    "P0 = 1 # Stagnation pressure in MPa \n",
    "T0 = 360 # Stagnation temperature in K\n",
    "g = 1.4 # Heat capacity ratio\n",
    "R = 0.287 # Gas constant\n",
    "P2 = P2P0*P0*1e3 # Static Pressure\n",
    "T2 = T2T0*T0 # Static temperature\n",
    "c2 = math.sqrt(g*R*T2*1000)\n",
    "V2 = c2*M2 #velocity at the exit from the nozzle\n",
    "# for air\n",
    "P_P0 = 0.528 # pressure ratio\n",
    "T_T0 = 0.833 # Temperature ratio\n",
    "P_ = P_P0*P0*1e3 # Static Pressure\n",
    "T_ = T_T0*T0 #Static temperature\n",
    "rho_ = P_/(R*T_) # density\n",
    "V_ = math.sqrt(g*R*T_*1000) # Velocity at the exit from the nozzle \n",
    "At = 500e-06 # throat area\n",
    "w = At*V_*rho_# Maximum flow rate of air\n",
    "\n",
    "print \"\\n Example 17.3\\n\"\n",
    "print \"\\n When divergent section act as a nozzle\"\n",
    "print \"\\n Maximum flow rate of air is \",w ,\" kg/s\"\n",
    "print \"\\n Static temperature is \",T2 ,\" K\"\n",
    "print \"\\n Static Pressure is \",P2 ,\" kPa\"\n",
    "print \"\\n Velocity at the exit from the nozzle is \",V2 ,\" m/s\"\n",
    "#The answers vary due to round off error\n",
    "\n",
    "# Part (b)\n",
    "Mb = 0.308  # Mach number\n",
    "P2P0b = 0.936 # Pressure ratio\n",
    "T2T0b = 0.9812 # Temperature ratio\n",
    "P2b = P2P0b*P0*1e3#Static Pressure \n",
    "T2b = T2T0b*T0 # Static temperature\n",
    "c2b = math.sqrt(g*R*T2b*1000) # Velocity \n",
    "V2b = c2b*Mb #Velocity at the exit from the nozzle\n",
    "print \"\\n\\n When divergent section act as a diffuser\"\n",
    "print \"\\n Maximum flow rate of air is \",w ,\" kg/s\"\n",
    "print \"\\n Static temperature is \",T2b ,\" K\"\n",
    "print \"\\n Static Pressure is \",P2b ,\" kPa\"\n",
    "print \"\\n Velocity at the exit from the nozzle is \",V2b ,\" m/s\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex17.4:pg-720"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 17.4\n",
      "\n",
      "\n",
      " Mach number of the tunnel is  1.735\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "Px = 16.0 # pressure in kPa\n",
    "Poy = 70.0 #pressure in kPa \n",
    "Mx = 1.735 # Mach number\n",
    "Pyx = 3.34 # Pressure ratio\n",
    "rho_yx = 2.25 # Density ratio\n",
    "Tyx = 1.483  # Temperature ratio\n",
    "Poyox = 0.84 # pressure ratio\n",
    "My = 0.631 # Mach number\n",
    "g = 1.4 # Ratio of heat capacities\n",
    "Tox = 573.0 # stagnation temperature in K \n",
    "Toy = Tox # temperature equivalence\n",
    "Tx = Tox/(1+((g-1)/2.0)*Mx**2) # temperature at x\n",
    "Ty = Tyx*Tx # temperature at y\n",
    "Pox = Poy/Poyox  # total pressure \n",
    "# From table\n",
    "Mx = 1.735\n",
    "\n",
    "print \"\\n Example 17.4\\n\"\n",
    "print \"\\n Mach number of the tunnel is \",Mx\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex17.5:pg-721"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Example 17.5\n",
      "\n",
      "\n",
      " Exit Mach number is  0.402\n",
      "\n",
      " Exit pressure is  147.9260475  kPa\n",
      "\n",
      " Exit Stagnation pressure is  44.7195  kPa\n",
      "\n",
      " Entropy increase is  0.068726024552  kJ/kg K\n"
     ]
    }
   ],
   "source": [
    "import math\n",
    "Ax = 18.75 # cross sectional area in divergent part in m**2\n",
    "A_ = 12.50 # throat area in m**2\n",
    "AA_ = 1.5 # Area ratio\n",
    "Pxox = 0.159 # pressure ratio from table\n",
    "R = 0.287 # Gas constant\n",
    "Pox = 0.21e03 # pressure in kPa\n",
    "Px = Pxox*Pox # pressure calculation\n",
    "# from the gas table on normal shock\n",
    "Mx = 1.86 \n",
    "My = 0.604 \n",
    "Pyx = 3.87 \n",
    "Poyx = 4.95 \n",
    "Poyox = 0.786\n",
    "Py = Pyx*Px\n",
    "Poy = Poyx*Px\n",
    "My = 0.604\n",
    "Ay_ = 1.183\n",
    "A2 = 25 \n",
    "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) # sy-sx\n",
    "\n",
    "print \"\\n Example 17.5\\n\"\n",
    "print \"\\n Exit Mach number is \",M2\n",
    "print \"\\n Exit pressure is \",P2 ,\" kPa\"\n",
    "print \"\\n Exit Stagnation pressure is \",Pox-Poy ,\" kPa\"\n",
    "print \"\\n Entropy increase is \",syx ,\" kJ/kg K\"\n",
    "#The answers vary due to round off error\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}