# Riemann interactive¶

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.

First we need to load the mpld3 and numpy libraries as well as the riemann_interactive code.

In [4]:
import mpld3
import numpy as np
from clawpack.riemann import riemann_interactive


## Shallow water equations¶

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.

In [5]:
# Define left and right state (h,hu)
ql = np.array([3.0, 5.0])
qr = np.array([3.0, -5.0])
# Defineoptional parameters (otherwise chooses default values)
plotopts = {'g':1.0, 'time':2.0, 'tmax':5, 'hmax':10, 'humin':-15, 'humax':15}
# Call interactive function (can be called without any argument)
pt = riemann_interactive.shallow_water(ql,qr,**plotopts)
#mpld3.save_html(pt,"test2.html")
mpld3.display()

Out[5]:

## Acoustic equations¶

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.

In [6]:
# Define left and right state
ql = np.array([-2.0, 2.0])
qr = np.array([0.0, -3.0])
# Define two eigenvectors and eigenvalues (acoustics)
zz = 2.0
rho0 = 1.0
r1 = np.array([zz,1.0])
r2 = np.array([-zz,1.0])
lam1 = zz/rho0
lam2 = -zz/rho0
plotopts={'q1min':-5, 'q1max':5, 'q2min':-5, 'q2max':5, 'domain':5, 'time':1,
'title1':"Pressure", 'title2':"Velocity"}
riemann_interactive.linear_phase_plane(ql,qr,r1,r2,lam1,lam2,**plotopts)
mpld3.display()

Out[6]: