{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Convergence of numerical solutions to weak solutions of conservation laws\n", "\n", "This worksheet follows the discussion in [LeVeque, 1992] Chapter 12. Solutions of hyperbolic PDEs develop discontinuities, so we have to consider weak solutions that satisfy an integral conservation law.\n", "We'll consider the inviscid Burgers' equation:\n", "\n", "$$q_t + \\left(\\frac{1}{2} q^2\\right)_x = 0$$\n", "\n", "discretized by two simple finite difference methods. The first is simply the upwind method applied to Burgers' equation:\n", "\n", "$$Q^{n+1}_j = Q^n_j - \\frac{\\Delta t}{2\\Delta x} \\left((Q^n_j)^2 - (Q^n_{j-1})^2\\right)$$\n", "\n", "The second discretization is obtained by writing Burgers' equation in quasilinear form:\n", "\n", "$$u_t + uu_x = 0$$\n", "\n", "and using an upwind difference:\n", "\n", "$$Q^{n+1}_j = Q^n_j - \\frac{\\Delta t}{\\Delta x} Q^n_j\\left(Q^n_j - Q^n_{j-1}\\right)$$\n", "\n", "The first method is conservative, since the fluxes will cancel out if we sum over the whole grid. The second method is not conservative. Let's implement them and see what happens." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import time, sys\n", "import matplotlib\n", "from matplotlib import animation\n", "from JSAnimation import IPython_display" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def take_step(q,dt,dx,method):\n", " if method == 'conservative':\n", " q[1:-1] = q[1:-1] - 0.5*dt/dx * ( q[1:-1]**2 - q[:-2]**2 )\n", " elif method == 'non-conservative':\n", " q[1:-1] = q[1:-1] - dt/dx * q[1:-1] * (q[1:-1] - q_nc[0:-2]) \n", " return q" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "