{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Riemann interactive\n", "\n", "In this notebook, we show interactive solutions of two Riemann problems for shallow water equations and acoustics. The user can interactively modify the phase planes and x-t planes and see its corresponding solutions. The code to produce these apps uses the mpld3 library, and it can be found on the clawpack folder riemann/riemann_interactive.py. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we need to load the mpld3 and numpy libraries as well as the riemann_interactive code." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import mpld3\n", "import numpy as np\n", "from clawpack.riemann import riemann_interactive" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Shallow water equations\n", "In this section we show the interactive riemann solution of the exact solver for the shallow water equations. We first define the initial left and right state, the $g$ paramter and the plot range, then we call our riemann interactive plotting and display it. The commented line \"mpld3.save_html\" can be uncommented to save the output as html. On the app feel free to drag and drop the $q_l$ and $q_r$ states in the phase plane. The time can also be adjusted by dragging up and down the black dot in the horizontal time bar in the $x-t$ plane. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Define left and right state (h,hu)\n", "ql = np.array([3.0, 5.0])\n", "qr = np.array([3.0, -5.0])\n", "# Defineoptional parameters (otherwise chooses default values)\n", "plotopts = {'g':1.0, 'time':2.0, 'tmax':5, 'hmax':10, 'humin':-15, 'humax':15}\n", "# Call interactive function (can be called without any argument)\n", "pt = riemann_interactive.shallow_water(ql,qr,**plotopts)\n", "#mpld3.save_html(pt,\"test2.html\")\n", "mpld3.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Acoustic equations\n", "Here we show the exact solution for the Riemann problem of linear acoustics. We again determine the initial left and right states, and we provide the eigenvectors ($r_1,r_2$) and eigenvalues ($\\lambda_1,\\lambda_2$) of the solution. It is written in this way, so one can easily input the eigenvalues of any other two dimensional linear Riemann problem. Additional optional input can be added to adjust the plotted window. In this case, the time is fixed in \"plotopts\" and only the left and right states ($q_l,q_r$) can be moved interactively." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "
\n", "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Define left and right state \n", "ql = np.array([-2.0, 2.0]) \n", "qr = np.array([0.0, -3.0])\n", "# Define two eigenvectors and eigenvalues (acoustics)\n", "zz = 2.0\n", "rho0 = 1.0\n", "r1 = np.array([zz,1.0])\n", "r2 = np.array([-zz,1.0])\n", "lam1 = zz/rho0\n", "lam2 = -zz/rho0\n", "plotopts={'q1min':-5, 'q1max':5, 'q2min':-5, 'q2max':5, 'domain':5, 'time':1, \n", " 'title1':\"Pressure\", 'title2':\"Velocity\"}\n", "riemann_interactive.linear_phase_plane(ql,qr,r1,r2,lam1,lam2,**plotopts)\n", "mpld3.display()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "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.6" } }, "nbformat": 4, "nbformat_minor": 0 }