{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER09:OBLIGUE SHOCK AND EXPANSION WAVES"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E01 : Pg 302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The plane is ahead of the bystander by a distance of:\n",
      "d = 27.7128129211 km\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math\n",
    "M = 2.;                    # mach number\n",
    "h = 16000.;                   # altitude of the plane\n",
    "\n",
    "# the mach angle can be calculated from eq.(9.1) as\n",
    "mue = math.asin(1./M);          # mach angle\n",
    "\n",
    "d = h/math.tan(mue);\n",
    "\n",
    "print\"The plane is ahead of the bystander by a distance of:\\nd =\",d/1000.,\"km\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E02 : Pg 302"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M2 = 1.214211418 \n",
      "p2 = 2.82 atm \n",
      "T2 = 399.744 K \n",
      "p0,2 = 7.0040448 atm \n",
      "T0,2 = 518.4 K\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi, sin,cos\n",
    "M1 = 2.;                               # mach number\n",
    "p1 = 1.;                                # ambient pressure\n",
    "T1 = 288.;                              # ambient temperature\n",
    "theta = 20.*pi/180.;                   # flow deflection\n",
    "\n",
    "# from figure 9.9, for M = 2, theta = 20\n",
    "b = 53.4*pi/180.;                     # beta\n",
    "Mn_1 = M1*sin(b);                     # upstream mach number normal to shock\n",
    "\n",
    "# for this value of Mn,1 = 1.60, from Appendix B we have\n",
    "Mn_2 = 0.6684;                        # downstream mach number normal to shock\n",
    "M2 = Mn_2/sin(b-theta);               # mach number downstream of shock\n",
    "p2 = 2.82*p1;\n",
    "T2 = 1.388*T1;\n",
    "\n",
    "# for M = 2, from appendix A we have\n",
    "p0_2 = 0.8952*7.824*p1;\n",
    "T0_1 = 1.8*T1;\n",
    "T0_2 = T0_1;\n",
    "\n",
    "print\"M2 =\",M2,\"\\np2 =\",p2,\"atm\",\"\\nT2 =\",T2,\"K\",\"\\np0,2 =\",p0_2,\"atm\",\"\\nT0,2 =\",T0_2,\"K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E03 : Pg 305"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "theta = 6.5 degrees \n",
      "p2/p1 = 1.513 \n",
      "T2/T1 = 1.128 \n",
      "M2 = 2.11210524521\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin\n",
    "b = 30.*pi/180.;                        # oblique shock wave angle\n",
    "M1 = 2.4;                              # upstream mach number\n",
    "\n",
    "# from figure 9.9, for these value of M and beta, we have\n",
    "theta = 6.5*pi/180.;\n",
    "\n",
    "Mn_1 = M1*sin(b);                      # upstream mach number normal to shock\n",
    "\n",
    "# from Appendix B\n",
    "pressure_ratio = 1.513;\n",
    "temperature_ratio = 1.128;\n",
    "Mn_2 = 0.8422;\n",
    "\n",
    "M2 = Mn_2/sin(b-theta);\n",
    "\n",
    "print\"theta =\",theta*180./pi,\"degrees\",\"\\np2/p1 =\",pressure_ratio,\"\\nT2/T1 =\",temperature_ratio,\"\\nM2 =\",M2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E04 : Pg 309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The upstream mach number is:\n",
      "M = 2.85925274482\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin\n",
    "b = 35.*pi/180.;                    # oblique shock wave angle\n",
    "pressure_ratio = 3.;                # upstream and downstream pressure ratio\n",
    "\n",
    "# from appendix B\n",
    "Mn_1 = 1.64;\n",
    "M1 = Mn_1/sin(b);\n",
    "\n",
    "print\"The upstream mach number is:\\nM =\",M1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E05 : Pg 309"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ans = 1.76130338105\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin\n",
    "M1 = 3.;\n",
    "b = 40.*pi/180.;\n",
    "\n",
    "# for case 1, for M = 3, from Appendix B, we have\n",
    "p0_ratio_case1 = 0.3283;\n",
    "\n",
    "# for case 2\n",
    "Mn_1 = M1*sin(b);\n",
    "\n",
    "# from Appendix B\n",
    "p0_ratio1 = 0.7535;\n",
    "Mn_2 = 0.588;\n",
    "\n",
    "# from fig. 9.9, for M1 = 3 and beta = 40, we have\n",
    "theta = 22.*pi/180.;\n",
    "M2 = Mn_2/sin(b-theta);\n",
    "\n",
    "# from appendix B for M = 1.9; we have\n",
    "p0_ratio2 = 0.7674;\n",
    "p0_ratio_case2 = p0_ratio1*p0_ratio2;\n",
    "\n",
    "ratio = p0_ratio_case2/p0_ratio_case1;\n",
    "\n",
    "print\"Ans =\",ratio"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E06 : Pg 310"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The drag coefficient is given by:\n",
      "cd = 0.114406649477\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin,tan\n",
    "M1 = 5.;\n",
    "theta = 15.*pi/180.;\n",
    "gam = 1.4;\n",
    "\n",
    "# for these values of M and theta, from fig. 9.9\n",
    "b = 24.2*pi/180;\n",
    "Mn_1 = M1*sin(b);\n",
    "\n",
    "# from Appendix B, for Mn,1 = 2.05, we have\n",
    "p_ratio = 4.736;\n",
    "\n",
    "# hence\n",
    "c_d = 4.*tan(theta)/gam/(M1**2.)*(p_ratio-1.);\n",
    "\n",
    "print\"The drag coefficient is given by:\\ncd =\",c_d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E07 : Pg 311"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p3 = 4.67916856 x 10**5 N/m2 \n",
      "T3 = 458.013888 K\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin,tan\n",
    "M1 = 3.5;\n",
    "theta1 = 10.*pi/180.;\n",
    "gam = 1.4;\n",
    "p1 = 101300.;\n",
    "T1 = 288.;\n",
    "b=1.;#\n",
    "# for these values of M and theta, from fig. 9.9\n",
    "b1 = 24.*pi/180.;\n",
    "Mn_1 = M1*sin(b);\n",
    "\n",
    "# from Appendix B, for Mn,1 = 2.05, we have\n",
    "Mn_2 = 0.7157;\n",
    "p_ratio1 = 2.32;\n",
    "T_ratio1 = 1.294;\n",
    "M2 = Mn_2/sin(b1-theta1);\n",
    "\n",
    "# now\n",
    "theta2 = 10.*pi/180.;\n",
    "\n",
    "# from fig. 9.9\n",
    "b2 = 27.3*pi/180.;\n",
    "phi = b2 - theta2;\n",
    "\n",
    "# from Appendix B\n",
    "p_ratio2 = 1.991;\n",
    "T_ratio2 = 1.229;\n",
    "Mn_3 = 0.7572;\n",
    "M3 = Mn_3/sin(b2-theta2);\n",
    "\n",
    "# thus\n",
    "p3 = p_ratio1*p_ratio2*p1;\n",
    "T3 = T_ratio1*T_ratio2*T1;\n",
    "\n",
    "print\"p3 =\",p3/1e5,\"x 10**5 N/m2\",\"\\nT3 =\",T3,\"K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E08 : Pg 312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p2 = 0.469197341513 atm \n",
      "T2 = 232.0 K \n",
      "p0,2 = 3.671 atm \n",
      "T0,2 = 417.6 K \n",
      "Angle of forward Mach line = 41.81 degrees \n",
      "Angle of rear Mach line = 15.0 degrees\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi,sin,tan\n",
    "M1 = 1.5;                        # upstream mach number\n",
    "theta = 15.*pi/180.;              # deflection angle\n",
    "p1 = 1.;                          # ambient pressure in atm\n",
    "T1 = 288.;                        # ambient temperature\n",
    "\n",
    "# from appendix C, for M1 = 1.5 we have\n",
    "v1 = 11.91*pi/180.;\n",
    "\n",
    "# from eq.(9.43)\n",
    "v2 = v1 + theta;\n",
    "\n",
    "# for this value of v2, from appendix C\n",
    "M2 = 2.;\n",
    "\n",
    "# from Appendix A for M1 = 1.5 and M2 = 2.0, we have\n",
    "p2 = 1./7.824*1.*3.671*p1;\n",
    "T2 = 1./1.8*1.*1.45*T1;\n",
    "p0_1 = 3.671*p1;\n",
    "p0_2 = p0_1;\n",
    "T0_1 = 1.45*T1;\n",
    "T0_2 = T0_1;\n",
    "\n",
    "# from fig. 9.25, we have\n",
    "fml = 41.81;                    # Angle of forward Mach line\n",
    "rml = 30. - 15.;                  # Angle of rear Mach line\n",
    "\n",
    "print\"p2 =\",p2,\"atm\",\"\\nT2 =\",T2,\"K\",\"\\np0,2 =\",p0_2,\"atm\",\"\\nT0,2 =\",T0_2,\"K\",\"\\nAngle of forward Mach line =\",fml,\"degrees\",\"\\nAngle of rear Mach line =\",rml,\"degrees\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E09 : Pg 312"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M2 = 6.4 \n",
      "p2 = 18.0212314225 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "from math import pi\n",
    "M1 = 10.;                        # upstream mach number\n",
    "theta = 15.*pi/180.;              # deflection angle\n",
    "p1 = 1.;                          # ambient pressure in atm\n",
    "# from appendix C, for M1 = 10 we have\n",
    "v1 = 102.3*pi/180.;\n",
    "# in region 2\n",
    "v2 = v1 - theta;\n",
    "# for this value of v2, from appendix C\n",
    "M2 = 6.4;\n",
    "# from Appendix A for M1 = 10 and M2 = 6.4, we have\n",
    "p2 = 1./(2355.)*1.*42440.*p1;\n",
    "print\"M2 =\",M2,\"\\np2 =\",p2,\"atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E10 : Pg 315"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M2 = 5.22283426943 \n",
      "p2 = 13.32 atm \n",
      "p0,2 = 9.854568 x 10**3 atm\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "M1 = 10;                        # upstream mach number\n",
    "theta = 15*math.pi/180;              # deflection angle\n",
    "p1 = 1;                          # ambient pressure in atm\n",
    "\n",
    "# from fig 9.9, for M1 = 10 and theta = 15 we have\n",
    "b = 20*math.pi/180;\n",
    "Mn_1 = M1*math.sin(b);\n",
    "\n",
    "# from Appendix B, for Mn,1 = 3.42\n",
    "Mn_2 = 0.4552;\n",
    "M2 = Mn_2/math.sin(b-theta);\n",
    "p2 = 13.32*p1;\n",
    "\n",
    "# from Appendix A, for M1 = 10\n",
    "p0_2 = 0.2322*42440*p1;\n",
    "\n",
    "print\"M2 =\",M2,\"\\np2 =\",p2,\"atm\",\"\\np0,2 =\",p0_2/1e3,\"x 10**3 atm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example E11 : Pg 316"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The lift and drag coefficients are given by:\n",
      "cl = 0.124948402826 \n",
      "cd = 0.0109315687729\n"
     ]
    }
   ],
   "source": [
    "# All the quantities are expressed in SI units\n",
    "import math \n",
    "M1 = 3.;                        # upstream mach number\n",
    "theta = 5.*math.pi/180.;             # deflection angle\n",
    "alpha = theta;                 # angle of attack\n",
    "gam = 1.4;\n",
    "\n",
    "# from appendix C, for M1 = 3 we have\n",
    "v1 = 49.76*math.pi/180.;\n",
    "\n",
    "# from eq.(9.43)\n",
    "v2 = v1 + theta;\n",
    "\n",
    "# for this value of v2, from appendix C\n",
    "M2 = 3.27;\n",
    "\n",
    "# from Appendix A for M1 = 3 and M2 = 3.27, we have\n",
    "p_ratio1 = 36.73/55.;\n",
    "\n",
    "# from fig. 9.9, for M1 = 3 and theta = 5\n",
    "b = 23.1*math.pi/180.;\n",
    "Mn_1 = M1*math.sin(b);\n",
    "\n",
    "# from Appendix B\n",
    "p_ratio2 = 1.458;\n",
    "\n",
    "# thus\n",
    "c_l = 2./gam/(M1**2.)*(p_ratio2-p_ratio1)*math.cos(alpha);\n",
    "\n",
    "c_d = 2./gam/(M1**2.)*(p_ratio2-p_ratio1)*math.sin(alpha);\n",
    "\n",
    "print\"The lift and drag coefficients are given by:\\ncl =\",c_l,\"\\ncd =\",c_d"
   ]
  }
 ],
 "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
}
