<commit_before>{
 "metadata": {
  "name": "",
  "signature": "sha256:7525976cba33387a0961753abb1c945b0cd3dcc5c8e05ab16efc9731df3fb992"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 6,
     "metadata": {},
     "source": [
      "Content under Creative Commons Attribution license CC-BY 4.0, code under MIT license (c)2014 <NAME>, <NAME>, <NAME>.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 6,
     "metadata": {},
     "source": [
      "Sod, <NAME>. \"A survey of several finite difference methods for systems of nonlinear hyperbolic conservation laws.\" Journal of computational physics 27.1 (1978): 1-31."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#Sod's Test Problems\n",
      "\n",
      "The shock tube is a common test for computational solvers and it has an analytical solution for comparison of results.  \n",
      "\n",
      "###What's a shock tube?\n",
      "\n",
      "Picture a tube that's sealed on both ends.  In the middle is an infinitely-thin, rigid membrane that separates the left-hand side from the right-hand side.  \n",
      "\n",
      "The left-hand side and right-hand side are filled with a fluid, but the two sides are held at different pressure and density levels.  \n",
      "\n",
      "At time $t = 0.0 s$, the infinitely-thin membrane is removed instantaneously.  \n",
      "\n",
      "What happens?  \n",
      "\n",
      "You get a shock.  The area of higher-pressure, no longer constrained by the wall, rushes into the lower-pressure area as the tube comes to equilibrium.  \n",
      "\n",
      "The shock tube problem is a *Riemann problem* and has an analytical solution, which makes it very useful for comparing the efficacy of different numerical schemes at resolving shocks.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The Euler Equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The Euler Equations govern the motion of fluid that is inviscid (zero viscosity). \n",
      "\n",
      "Written in vector form, you can see that the Euler Equations bear a strong resemblence to the traffic density equation that has been the focus of this module:\n",
      "\n",
      "\\begin{equation}\n",
      "\\frac{\\partial }{\\partial t} \\underline{\\mathbf{u}} + \\frac{\\partial }{\\partial x} \\underline{\\mathbf{f}} = 0\n",
      "\\end{equation}\n",
      "\n",
      "The big difference to note here is that the values $\\underline{\\mathbf{u}}$ and $\\underline{\\mathbf{f}}$ are *vectors*.  If you review the [Phugoid Full Model](http://nbviewer.ipython.org/github/numerical-mooc/numerical-mooc/blob/master/lessons/01_phugoid/01_03_PhugoidFullModel.ipynb) lesson, you will recall that we can solve for several values at once using the vector form of an equation.  In the Phugoid Module, it was an ODE -- now we apply the same procedure to a PDE.  \n",
      "\n",
      "Let's take a look at what $\\underline{\\mathbf{u}}$ and $\\underline{\\mathbf{f}}$ consist of.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The Conservative Euler Equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The conservative formulation of the Euler equations is required when solutions contain shocks.  As you might expect, the Sod's Shock Tube solutions do contain shocks.  \n",
      "\n",
      "The conserved variables $\\underline{\\mathbf{u}}$ are"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "\\begin{equation}\\underline{\\mathbf{u}} = \\left[ \\begin{array}{c}\n",
      "\\rho \\\\\n",
      "\\rho u \\\\\n",
      "\\rho e_T \\\\ \n",
      "\\end{array} \\right]\\end{equation}\n",
      "\n",
      "where $\\rho$ is the density of the fluid, $u$ is the velocity of the fluid and $e_T = e + \\frac{u^2}{2}$ is the specific total energy.\n",
      "\n",
      "\n",
      "\n",
      "$\\underline{\\mathbf{f}}$ is the flux vector:\n",
      "\n",
      "\\begin{equation}\\underline{\\mathbf{f}} = \\left[ \\begin{array}{c}\n",
      "\\rho u \\\\\n",
      "\\rho u^2 + p \\\\\n",
      "(\\rho e_T + p) u \\\\ \\end{array} \\right]\n",
      "\\end{equation}\n",
      "\n",
      "where $p$ is the pressure of the fluid."
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The three equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "If we put together the conserved variables and the flux vector into our PDE, we get the following set of equations:\n",
      "\n",
      "\\begin{equation}\n",
      "\\frac{\\partial}{\\partial t}\n",
      "\\left[ \\begin{array}{c}\n",
      "\\rho \\\\\n",
      "\\rho u \\\\\n",
      "\\rho e_T \\\\ \n",
      "\\end{array} \\right]\n",
      "+ \\frac{\\partial}{\\partial x}\n",
      "\\left[ \\begin{array}{c}\n",
      "\\rho u \\\\\n",
      "\\rho u^2 + p \\\\\n",
      "(\\rho e_T + p) u\\\\ \\end{array}\n",
      "\\right]\n",
      "=0\n",
      "\\end{equation}"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "There's one pretty major problem there.  We have 3 equations and 4 unknowns.  But there is a solution!  We can use an equation of state to calculate the pressure -- in this case, we'll use the ideal gas law."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "###Calculate the pressure\n",
      "\n",
      "For an ideal gas, the equation of state is\n",
      "\n",
      "$$e = e(\\rho, p) = \\frac{p}{(\\gamma -1) \\rho} \\text{ where } \\gamma=1.4$$\n",
      "\n",
      "$$\\therefore p = (\\gamma -1)\\rho e $$ \n",
      "\n",
      "Recall from above that\n",
      "\n",
      "$$e_T = e+\\frac{1}{2} u^2$$\n",
      "\n",
      "$$\\therefore e = e_T - \\frac{1}{2}u^2$$\n",
      "\n",
      "Putting it all together, we arrive at an equation for the pressure\n",
      "\n",
      "$$p = (\\gamma -1)\\left(\\rho e_T - \\frac{\\rho u^2}{2}\\right)$$"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Flux in terms of $\\underline{\\mathbf{u}}$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "With our traffic model, the flux was a function of traffic density.  For the Euler equations, the three equations we have are coupled and the flux *vector* is a function of $\\underline{\\mathbf{u}}$\n",
      "\n",
      "$$\\underline{\\mathbf{f}} = f(\\underline{\\mathbf{u}})$$\n",
      "\n",
      "In order to get everything squared away, we need to represent $\\underline{\\mathbf{f}}$ in terms of $\\underline{\\mathbf{u}}$."
     ]<commit_msg>Comment on value of gamma.<commit_after>{
 "metadata": {
  "name": "",
  "signature": "sha256:7525976cba33387a0961753abb1c945b0cd3dcc5c8e05ab16efc9731df3fb992"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 6,
     "metadata": {},
     "source": [
      "Content under Creative Commons Attribution license CC-BY 4.0, code under MIT license (c)2014 <NAME>, <NAME>, <NAME>.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 6,
     "metadata": {},
     "source": [
      "Sod, <NAME>. \"A survey of several finite difference methods for systems of nonlinear hyperbolic conservation laws.\" Journal of computational physics 27.1 (1978): 1-31."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "#Sod's Test Problems\n",
      "\n",
      "The shock tube is a common test for computational solvers and it has an analytical solution for comparison of results.  \n",
      "\n",
      "###What's a shock tube?\n",
      "\n",
      "Picture a tube that's sealed on both ends.  In the middle is an infinitely-thin, rigid membrane that separates the left-hand side from the right-hand side.  \n",
      "\n",
      "The left-hand side and right-hand side are filled with a fluid, but the two sides are held at different pressure and density levels.  \n",
      "\n",
      "At time $t = 0.0 s$, the infinitely-thin membrane is removed instantaneously.  \n",
      "\n",
      "What happens?  \n",
      "\n",
      "You get a shock.  The area of higher-pressure, no longer constrained by the wall, rushes into the lower-pressure area as the tube comes to equilibrium.  \n",
      "\n",
      "The shock tube problem is a *Riemann problem* and has an analytical solution, which makes it very useful for comparing the efficacy of different numerical schemes at resolving shocks.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The Euler Equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The Euler Equations govern the motion of fluid that is inviscid (zero viscosity). \n",
      "\n",
      "Written in vector form, you can see that the Euler Equations bear a strong resemblence to the traffic density equation that has been the focus of this module:\n",
      "\n",
      "\\begin{equation}\n",
      "\\frac{\\partial }{\\partial t} \\underline{\\mathbf{u}} + \\frac{\\partial }{\\partial x} \\underline{\\mathbf{f}} = 0\n",
      "\\end{equation}\n",
      "\n",
      "The big difference to note here is that the values $\\underline{\\mathbf{u}}$ and $\\underline{\\mathbf{f}}$ are *vectors*.  If you review the [Phugoid Full Model](http://nbviewer.ipython.org/github/numerical-mooc/numerical-mooc/blob/master/lessons/01_phugoid/01_03_PhugoidFullModel.ipynb) lesson, you will recall that we can solve for several values at once using the vector form of an equation.  In the Phugoid Module, it was an ODE -- now we apply the same procedure to a PDE.  \n",
      "\n",
      "Let's take a look at what $\\underline{\\mathbf{u}}$ and $\\underline{\\mathbf{f}}$ consist of.  "
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The Conservative Euler Equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The conservative formulation of the Euler equations is required when solutions contain shocks.  As you might expect, the Sod's Shock Tube solutions do contain shocks.  \n",
      "\n",
      "The conserved variables $\\underline{\\mathbf{u}}$ are"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "\\begin{equation}\\underline{\\mathbf{u}} = \\left[ \\begin{array}{c}\n",
      "\\rho \\\\\n",
      "\\rho u \\\\\n",
      "\\rho e_T \\\\ \n",
      "\\end{array} \\right]\\end{equation}\n",
      "\n",
      "where $\\rho$ is the density of the fluid, $u$ is the velocity of the fluid and $e_T = e + \\frac{u^2}{2}$ is the specific total energy.\n",
      "\n",
      "\n",
      "\n",
      "$\\underline{\\mathbf{f}}$ is the flux vector:\n",
      "\n",
      "\\begin{equation}\\underline{\\mathbf{f}} = \\left[ \\begin{array}{c}\n",
      "\\rho u \\\\\n",
      "\\rho u^2 + p \\\\\n",
      "(\\rho e_T + p) u \\\\ \\end{array} \\right]\n",
      "\\end{equation}\n",
      "\n",
      "where $p$ is the pressure of the fluid."
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "The three equations"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "If we put together the conserved variables and the flux vector into our PDE, we get the following set of equations:\n",
      "\n",
      "\\begin{equation}\n",
      "\\frac{\\partial}{\\partial t}\n",
      "\\left[ \\begin{array}{c}\n",
      "\\rho \\\\\n",
      "\\rho u \\\\\n",
      "\\rho e_T \\\\ \n",
      "\\end{array} \\right]\n",
      "+ \\frac{\\partial}{\\partial x}\n",
      "\\left[ \\begin{array}{c}\n",
      "\\rho u \\\\\n",
      "\\rho u^2 + p \\\\\n",
      "(\\rho e_T + p) u\\\\ \\end{array}\n",
      "\\right]\n",
      "=0\n",
      "\\end{equation}"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "There's one pretty major problem there.  We have 3 equations and 4 unknowns.  But there is a solution!  We can use an equation of state to calculate the pressure -- in this case, we'll use the ideal gas law."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "###Calculate the pressure\n",
      "\n",
      "For an ideal gas, the equation of state is\n",
      "\n",
      "$$e = e(\\rho, p) = \\frac{p}{(\\gamma -1) \\rho},$$\n",
      "\n",
      "where $\\gamma = 1.4$ is a reasonable value to model air, \n",
      "\n",
      "$$\\therefore p = (\\gamma -1)\\rho e. $$ \n",
      "\n",
      "Recall from above that\n",
      "\n",
      "$$e_T = e+\\frac{1}{2} u^2$$\n",
      "\n",
      "$$\\therefore e = e_T - \\frac{1}{2}u^2.$$\n",
      "\n",
      "Putting it all together, we arrive at an equation for the pressure\n",
      "\n",
      "$$p = (\\gamma -1)\\left(\\rho e_T - \\frac{\\rho u^2}{2}\\right).$$"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Flux in terms of $\\underline{\\mathbf{u}}$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "With our traffic model, the flux was a function of traffic density.  For the Euler equations, the three equations we have are coupled and the flux *vector* is a function of $\\underline{\\mathbf{u}}$\n",
      "\n",
      "$$\\underline{\\mathbf{f}} = f(\\underline{\\mathbf{u}})$$\n",
      "\n",
      "In order to get everything squared away, we need to represent $\\underline{\\mathbf{f}}$ in terms of $\\underline{\\mathbf{u}}$."
     ]
{'fraction_non_alphanumeric': 0.18866059450681352, 'fraction_numerical': 0.013415236884840783, 'mean_word_length': 2.1115992970123023, 'pattern_counts': {'":': 110, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1550345', 'n_tokens_mistral': 4859, 'n_tokens_neox': 4582, 'n_words': 1477}