{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER10:COMPRESSIBLE FLOW THROUGH NOZZLES DIFFUSERS AND WIND TUNNELS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E01 : Pg 345"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Me = 3.95\n",
      "pe = 0.035 atm\n",
      "Te = 80.89191 K\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in Si units\n",
    "area_ratio = 10.25;                        # exit to throat area ratio\n",
    "p0 = 5;                                    # reservoir pressure in atm\n",
    "T0 = 333.3;                                # reservoir temperature\n",
    "\n",
    "# from appendix A, for an area ratio of 10.25\n",
    "Me = 3.95;                                 # exit mach number\n",
    "pe = 0.007*p0;                             # exit pressure\n",
    "Te = 0.2427*T0;                            # exit temperature\n",
    "\n",
    "print\"Me =\",Me\n",
    "print\"pe =\",pe,\"atm\"\n",
    "print\"Te =\",Te,\"K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E02 : Pg 346"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "At throat: Mt = 1.0\n",
      "\n",
      "At throat: pt = 0.528 atm\n",
      "\n",
      "At throat: Tt =  239.904 K\n",
      "\n",
      "At throat: For supersonic exit: 2.2\n",
      "\n",
      "At throat: pe = 0.0935453695042 atm\n",
      "\n",
      "At throat: Te =  146.341463415 K\n",
      "\n",
      "For subrsonic exit: 0.3\n",
      "\n",
      "pe= 0.93984962406 atm\n",
      "\n",
      "Te= 282.907662083 K\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in Si units\n",
    "\n",
    "area_ratio = 2.;                            # exit to throat area ratio\n",
    "p0 = 1.;                                    # reservoir pressure in atm\n",
    "T0 = 288.;                                  # reservoir temperature\n",
    "\n",
    "# (a)\n",
    "# since M = 1 at the throat\n",
    "Mt = 1.;\n",
    "pt = 0.528*p0;                             # pressure at throat\n",
    "Tt = 0.833*T0;                             # temperature at throat\n",
    "\n",
    "# from appendix A for supersonic flow, for an area ratio of 2\n",
    "Me = 2.2;                                  # exit mach number\n",
    "pe = 1./10.69*p0;                           # exit pressure\n",
    "Te = 1./1.968*T0;                           # exit temperature\n",
    "\n",
    "print\"At throat: Mt =\",Mt\n",
    "print\"\\nAt throat: pt =\",pt,\"atm\"\n",
    "print\"\\nAt throat: Tt = \",Tt,\"K\"\n",
    "print\"\\nAt throat: For supersonic exit:\",Me\n",
    "print\"\\nAt throat: pe =\",pe,\"atm\"\n",
    "print\"\\nAt throat: Te = \",Te,\"K\"\n",
    "\n",
    "# (b)\n",
    "# from appendix A for subonic flow, for an area ratio of 2\n",
    "Me = 0.3;                                  # exit mach number\n",
    "pe = 1/1.064*p0;                           # exit pressure\n",
    "Te = 1/1.018*T0;                           # exit temperature\n",
    "\n",
    "print\"\\nFor subrsonic exit:\",Me\n",
    "print\"\\npe=\",pe,\"atm\"\n",
    "print\"\\nTe=\",Te,\"K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E03 : Pg 346"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Me = 0.2\n",
      "Mt = 0.44\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in Si units\n",
    "\n",
    "area_ratio = 2.;                            # exit to throat area ratio\n",
    "p0 = 1.;                                    # reservoir pressure in atm\n",
    "T0 = 288.;                                  # reservoir temperature\n",
    "pe = 0.973;                                # exit pressure in atm\n",
    "\n",
    "p_ratio = p0/pe;                           # ratio of reservoir to exit pressure\n",
    "\n",
    "# from appendix A for subsonic flow, for an pressure ratio of 1.028\n",
    "Me = 0.2;                                  # exit mach number\n",
    "area_ratio_exit_to_star = 2.964;           # A_exit/A_star\n",
    "\n",
    "# thus\n",
    "area_ratio_throat_to_star = area_ratio_exit_to_star/area_ratio;           # A_exit/A_star\n",
    "\n",
    "# from appendix A for subsonic flow, for an area ratio of 1.482\n",
    "Mt = 0.44;                                 # throat mach number\n",
    "\n",
    "print\"Me =\",Me\n",
    "print\"Mt =\",Mt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E04 : Pg 352"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)The thrust of the rocket is:T = 2.1702872295 N\n",
      "\n",
      "(b)The nozzle exit area is 487663.540469\n",
      "\n",
      "Ae = 16.7097500627 m2\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "p0 = 30.*101000.;                            # reservoir pressure\n",
    "T0 = 3500.;                                 # reservoir temperature\n",
    "R = 520.;                                   # specific gas constant\n",
    "gam = 1.22;                                # ratio of specific heats\n",
    "A_star = 0.4;                              # rocket nozzle throat area\n",
    "pe = 5529.;                                 # rocket nozzle exit pressure equal to ambient pressure at 20 km altitude\n",
    "\n",
    "# (a)\n",
    "# the density of air in the reservoir can be calculated as\n",
    "rho0 = p0/R/T0;\n",
    "\n",
    "# from eq.(8.46)\n",
    "rho_star = rho0*(2/(gam+1))**(1/(gam-1));\n",
    "\n",
    "# from eq.(8.44)\n",
    "T_star = T0*2/(gam+1);\n",
    "a_star = math.sqrt(gam*R*T_star);\n",
    "u_star = a_star;\n",
    "m_dot = rho_star*u_star*A_star;\n",
    "\n",
    "# rearranging eq.(8.42)\n",
    "Me = math.sqrt(2/(gam-1)*(((p0/pe)**((gam-1)/gam)) - 1));\n",
    "Te = T0/(1+(gam-1)/2*Me*Me);\n",
    "ae = math.sqrt(gam*R*Te);\n",
    "ue = Me*ae;\n",
    "\n",
    "# thus the thrust can be calculated as\n",
    "T = m_dot*ue;\n",
    "T_lb = T*0.2247;\n",
    "\n",
    "# (b)\n",
    "# rearranging eq.(10.32)\n",
    "Ae = A_star/Me*((2/(gam+1)*(1+(gam-1)/2*Me*Me))**((gam+1)/(gam-1)/2));\n",
    "\n",
    "print\"(a)The thrust of the rocket is:T =\" ,T/1e6, \"N\"\n",
    "print\"\\n(b)The nozzle exit area is\",T_lb   \n",
    "\n",
    "print\"\\nAe =\",Ae, \"m2\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E05 : Pg 353"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The mass flow rate is: m_dot = 586.100122081 kg/s\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "p0 = 30.*101000.;                            # reservoir pressure\n",
    "T0 = 3500.;                                 # reservoir temperature\n",
    "R = 520.;                                   # specific gas constant\n",
    "gam = 1.22;                                # ratio of specific heats\n",
    "A_star = 0.4;                              # rocket nozzle throat area\n",
    "\n",
    "# the mass flow rate using the closed form analytical expression\n",
    "# from problem 10.5 can be given as\n",
    "m_dot = p0*A_star*math.sqrt(gam/R/T0*((2/(gam+1))**((gam+1)/(gam-1))));\n",
    "\n",
    "print\"The mass flow rate is: m_dot =\",m_dot, \"kg/s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E06 : Pg 356"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The diffuser throat to nozzle throat area ratio is: = 1.38715494521\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "M = 2.;                        # Mach number\n",
    "# for this value M, for a normal shock, from Appendix B\n",
    "p0_ratio = 0.7209;\n",
    "# thus\n",
    "area_ratio = 1./p0_ratio;\n",
    "print\"The diffuser throat to nozzle throat area ratio is: =\",area_ratio"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "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.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
