{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER08:NORMAL SHOCK WAVES AND RELATED TOPICS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E01 : Pg 256"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)The Mach number at sea level is:M_inf = 0.73491785465\n",
      "(b)The Mach number at 5 km is: M_inf =  0.779955236945\n",
      "(c)The Mach number at 10 km is: M_inf = 0.834623638772\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import sqrt,pi\n",
    "R = 287.;\n",
    "gam = 1.4;\n",
    "V_inf = 250.;\n",
    "\n",
    "# (a)\n",
    "# At sea level\n",
    "T_inf = 288.;\n",
    "\n",
    "# the velocity of sound is given by\n",
    "a_inf = sqrt(gam*R*T_inf);\n",
    "\n",
    "# thus the mach number can be calculated as\n",
    "M_inf = V_inf/a_inf;\n",
    "\n",
    "print\"(a)The Mach number at sea level is:M_inf =\",M_inf\n",
    "\n",
    "# similarly for (b) and (c)\n",
    "# (b)\n",
    "# at 5km\n",
    "T_inf = 255.7;\n",
    "\n",
    "a_inf = sqrt(gam*R*T_inf);\n",
    "\n",
    "M_inf = V_inf/a_inf;\n",
    "\n",
    "print\"(b)The Mach number at 5 km is: M_inf = \",M_inf\n",
    "\n",
    "# (c)\n",
    "# at 10km\n",
    "T_inf = 223.3;\n",
    "\n",
    "a_inf = sqrt(gam*R*T_inf);\n",
    "\n",
    "M_inf = V_inf/a_inf;\n",
    "\n",
    "print\"(c)The Mach number at 10 km is: M_inf =\",M_inf"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E02 : Pg 256"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Mach number is:\n",
      "M = 2.78881717658\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "T = 320;            # static temperature\n",
    "V = 1000;           # velocity\n",
    "gam = 1.4;          # ratio of specific heats\n",
    "R = 287;            # universal gas constant\n",
    "\n",
    "# the speed of sound is given by\n",
    "a = math.sqrt(gam*R*T);\n",
    "\n",
    "# the mach number can be calculated as\n",
    "M = V/a;\n",
    "\n",
    "print\"The Mach number is:\\nM =\",M"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E03 : Pg 257"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a)The ratio of kinetic energy to internal energy is: 1.12\n",
      "\n",
      "(b)The ratio of kinetic energy to internal energy is: 112.0\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "gam = 1.4;                    # ratio of specific heats\n",
    "\n",
    "# (a)\n",
    "M = 2;                        # Mach number\n",
    "\n",
    "# the ratio of kinetic energy to internal energy is given by\n",
    "ratio = gam*(gam-1)*M*M/2;\n",
    "\n",
    "print\"(a)The ratio of kinetic energy to internal energy is:\",ratio\n",
    "\n",
    "# similarly for (b)\n",
    "# (b)\n",
    "M = 20;\n",
    "\n",
    "ratio = gam*(gam-1)*M*M/2;\n",
    "\n",
    "print\"\\n(b)The ratio of kinetic energy to internal energy is:\",ratio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E04 : Pg 259"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total temperature and pressure are:\n",
      "T0 = 818.1824 K \n",
      "P0 = 26.7270201929 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "M = 2.79;        # Mach number\n",
    "T = 320;         # static temperature from ex. 7.3\n",
    "p = 1;           # static pressure in atm\n",
    "gam = 1.4;\n",
    "\n",
    "# from eq. (8.40)\n",
    "T0 = T*(1+((gam-1)/2*M*M));\n",
    "\n",
    "# from eq. (8.42)\n",
    "p0 = p*((1+((gam-1)/2*M*M))**(gam/(gam-1)));\n",
    "\n",
    "print\"The total temperature and pressure are:\\nT0 =\",T0,\"K\",\"\\nP0 =\",p0,\"atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E05 : Pg 260"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "T0 = 621.0 K \n",
      "P0 = 22.8816894716 atm \n",
      "T* = 517.5 k \n",
      "a* = 455.995065763 m/s \n",
      "M* = 2.06418738617\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "M = 3.5;        # Mach number\n",
    "T = 180;         # static temperature from ex. 7.3\n",
    "p = 0.3;           # static pressure in atm\n",
    "gam = 1.4;\n",
    "R = 287;\n",
    "\n",
    "# from eq. (8.40)\n",
    "T0 = T*(1+((gam-1)/2*M*M));\n",
    "\n",
    "# from eq. (8.42)\n",
    "p0 = p*((1+((gam-1)/2*M*M))**(gam/(gam-1)));\n",
    "\n",
    "a = math.sqrt(gam*R*T);\n",
    "V = a*M;\n",
    "\n",
    "# the values at local sonic point are given by\n",
    "T_star = T0*2/(gam+1);\n",
    "a_star = math.sqrt(gam*R*T_star);\n",
    "M_star = V/a_star;\n",
    "\n",
    "print\"T0 =\",T0,\"K\",\"\\nP0 =\",p0,\"atm\",\"\\nT* =\",T_star,\"k\",\"\\na* =\",a_star,\"m/s\",\"\\nM* =\",M_star"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E06 : Pg 263"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The mach number at the given point is:\n",
      "M1 = 0.9\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "p_inf = 1;\n",
    "p1 = 0.7545;\n",
    "M_inf = 0.6;\n",
    "gam = 1.4;\n",
    "\n",
    "# from eq. (8.42)\n",
    "p0_inf = p_inf*((1+((gam-1)/2*M_inf*M_inf))**(gam/(gam-1)));\n",
    "\n",
    "p0_1 = p0_inf;\n",
    "\n",
    "# from eq. (8.42)\n",
    "ratio = p0_1/p1;\n",
    "\n",
    "# from appendix A, for this ratio, the Mach number is\n",
    "M1 = 0.9;\n",
    "\n",
    "print\"The mach number at the given point is:\\nM1 =\",M1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E07 : Pg 268"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The velocity at the given point is:\n",
      "V1 = 17.3590326624 m/s\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "T_inf = 288;                                        # freestream temperature\n",
    "p_inf = 1;                                          # freestream pressure\n",
    "p1 = 0.7545;                                        # pressure at point 1\n",
    "M = 0.9;                                            # mach number at point 1\n",
    "gam = 1.4;                                          # ratio of specific heats\n",
    "R=1.;#\n",
    "# for isentropic flow, from eq. (7.32)\n",
    "T1 = T_inf*((p1/p_inf)**((gam-1)/gam));\n",
    "\n",
    "# the speed of sound at that point is thus\n",
    "a1 = math.sqrt(gam*R*T1);\n",
    "\n",
    "# thus, the velocity can be given as\n",
    "V1 = M*a1;\n",
    "\n",
    "print\"The velocity at the given point is:\\nV1 =\",V1,\"m/s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E08 : Pg 268"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p2 = 4.5 atm \n",
      "T2 = 485.856 K \n",
      "u2 = 255.114727639 m/s\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "u1 = 680;                            # velocity upstream of shock\n",
    "T1 = 288;                            # temperature upstream of shock\n",
    "p1 = 1;                              # pressure upstream of shock\n",
    "gam = 1.4;                           # ratio of specific heats\n",
    "R = 287;                             # universal gas constant\n",
    "\n",
    "# the speed of sound is given by\n",
    "a1 = math.sqrt(gam*R*T1)\n",
    "\n",
    "# thus the mach number is\n",
    "M1 = 2;\n",
    "\n",
    "# from Appendix B, for M = 2, the relations between pressure and temperature are given by\n",
    "pressure_ratio = 4.5;                # ratio of pressure accross shock\n",
    "temperature_ratio = 1.687;           # ratio of temperature accross shock\n",
    "M2 = 0.5774;                         # mach number downstream of shock\n",
    "\n",
    "# thus the values downstream of the shock can be calculated as\n",
    "p2 = pressure_ratio*p1;\n",
    "T2 = temperature_ratio*T1;\n",
    "a2 = math.sqrt(gam*R*T2);\n",
    "u2 = M2*a2;\n",
    "\n",
    "print\"p2 =\",p2,\"atm\",\"\\nT2 =\",T2,\"K\",\"\\nu2 =\",u2,\"m/s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E09 : Pg 271"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The total pressure loss is:\n",
      "(a)P0_loss= 2.1836784 atm\n",
      "\n",
      "(b)P0_loss = 130.73016 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "p1 = 1;                                            # ambient pressure upstream of shock\n",
    "\n",
    "\n",
    "# (a)\n",
    "# for M = 2;\n",
    "p0_1 = 7.824*p1;                                   # total pressure upstream of shock\n",
    "pressure_ratio = 0.7209;                           # ratio of total pressure accross the shock\n",
    "p0_2 = pressure_ratio*p0_1;                        # total pressure downstream of shock\n",
    "\n",
    "# thus the total loss of pressure is given by\n",
    "pressure_loss = p0_1 - p0_2;\n",
    "\n",
    "print\"The total pressure loss is:\\n(a)P0_loss=\",pressure_loss,\"atm\"\n",
    "\n",
    "# similarly\n",
    "# (b)\n",
    "# for M = 4;\n",
    "p0_1 = 151.8*p1;\n",
    "pressure_ratio = 0.1388;\n",
    "p0_2 = pressure_ratio*p0_1;\n",
    "\n",
    "# thus the total loss of pressure is given by\n",
    "pressure_loss = p0_1 - p0_2;\n",
    "\n",
    "print\"\\n(b)P0_loss =\",pressure_loss,\"atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E10 : Pg 272"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The pressure at point 2 is:p2 = 1.42546466011 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "M_inf = 2.;                     # freestream mach number\n",
    "p_inf = 2.65e4;                # freestream pressure\n",
    "T_inf = 223.3;                 # freestream temperature\n",
    "\n",
    "# from Appendix A, for M = 2\n",
    "p0_inf = 7.824*p_inf;          # freestream total pressure\n",
    "T0_inf = 1.8*T_inf;            # freestream total temperature\n",
    "\n",
    "# from Appendix B, for M = 2\n",
    "p0_1 = 0.7209*p0_inf;          # total pressure downstream of the shock\n",
    "T0_1 = T0_inf;                 # total temperature accross the shock is conserved\n",
    "\n",
    "# since the flow downstream of the shock is isentropic\n",
    "p0_2 = p0_1;\n",
    "T0_2 = T0_1;\n",
    "\n",
    "# from Appendix A, for M = 0.2 at point 2\n",
    "p2 = p0_2/1.028;\n",
    "T2 = T0_2/1.008;\n",
    "\n",
    "p2_atm = p2/102000;\n",
    "\n",
    "print\"The pressure at point 2 is:p2 =\",p2_atm,\"atm\","
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E11 : Pg 273"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The pressure at point 2 is: p2 = 32.6599307622 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "M_inf = 10;                    # freestream mach number\n",
    "p_inf = 2.65e4;                # freestream pressure\n",
    "T_inf = 223.3;                 # freestream temperature\n",
    "\n",
    "# from Appendix A, for M = 2\n",
    "p0_inf = 0.4244e5*p_inf;       # freestream total pressure\n",
    "T0_inf = 21*T_inf;             # freestream total temperature\n",
    "\n",
    "# from Appendix B, for M = 2\n",
    "p0_1 = 0.003045*p0_inf;        # total pressure downstream of shock\n",
    "T0_1 = T0_inf;                 # total temperature downstream of shock is conserved\n",
    "\n",
    "# since the flow downstream of the shock is isentropic\n",
    "p0_2 = p0_1;\n",
    "T0_2 = T0_1;\n",
    "\n",
    "# from Appendix A, for M = 0.2 at point 2\n",
    "p2 = p0_2/1.028;\n",
    "T2 = T0_2/1.008;\n",
    "\n",
    "p2_atm = p2/102000;\n",
    "\n",
    "\n",
    "print\"The pressure at point 2 is: p2 =\",p2_atm,\"atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E13 : Pg 274"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The pressure at the nose is:\n",
      "p_s = 38.1218361303 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "\n",
    "p1 = 4.66e4;                                # ambient pressure\n",
    "M = 8;                                      # mach number\n",
    "\n",
    "# from Appendix B, for M = 8\n",
    "p0_2 = 82.87*p1;                            # total pressure downstream of the shock\n",
    "\n",
    "# since the flow is isentropic downstream of the shock, total pressure is conserved\n",
    "ps_atm = p0_2/101300;                       # pressure at the stagnation point\n",
    "\n",
    "print\"The pressure at the nose is:\\np_s =\",ps_atm,\"atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E14 : Pg 274"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Velocity of the airplane is:\n",
      "V1 = 1003.16703558 m/s\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressedin SI units\n",
    "import math \n",
    "p1 = 2527.3;                    # ambient pressure at the altitude of 25 km\n",
    "T1 = 216.66;                    # ambient temperature at the altitude of 25 km\n",
    "p0_1 = 38800;                   # total pressure\n",
    "gam = 1.4;                      # ratio of specific heats\n",
    "R = 287;                        # universal gas constant\n",
    "pressure_ratio = p0_1/p1;       # ratio of total to static pressure\n",
    "\n",
    "# for this value of pressure ratio, mach number is\n",
    "M1 = 3.4;\n",
    "\n",
    "# the speed of sound is given by\n",
    "a1 = math.sqrt(gam*R*T1)\n",
    "\n",
    "# thus the velocity can be calculated as\n",
    "V1 = M1*a1;\n",
    "\n",
    "print\"The Velocity of the airplane is:\\nV1 =\",V1,\"m/s\""
   ]
  }
 ],
 "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
}
