Skip to content

Commit

Permalink
Merge pull request clawpack#74 from ketch/plot_red_blue_stripes
Browse files Browse the repository at this point in the history
Plot red blue stripes
  • Loading branch information
rjleveque authored May 18, 2017
2 parents 2ab7417 + 38dcf01 commit ac879ad
Show file tree
Hide file tree
Showing 13 changed files with 801 additions and 284 deletions.
181 changes: 54 additions & 127 deletions Acoustics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"\n",
"# Riemann problem for acoustics\n",
Expand All @@ -16,11 +13,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
Expand All @@ -30,22 +23,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"The next cell imports a module containing a function that takes a Riemann problem (left state, right state, and approximate solver), and computes the Riemann solution, as well as functions to plot the solution in various forms. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from utils import riemann_tools"
Expand All @@ -54,11 +40,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from utils import animation_tools\n",
Expand All @@ -69,10 +51,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"# Acoustics: exact solution\n",
"We can use this to examine the exact solution of an acoustics Riemann problem.\n",
Expand All @@ -96,11 +75,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"from clawpack.riemann.acoustics_1D_py import acoustics_1D\n",
Expand All @@ -109,22 +84,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Set some problem data needed by the solver:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"problem_data = {}\n",
Expand All @@ -143,22 +111,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Set the left and right states, and solve the Riemann problem"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"q_l = np.array((1,4)) # Left state\n",
Expand All @@ -170,22 +131,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Plot the states in the phase plane:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize=(4,3))\n",
Expand All @@ -195,56 +149,39 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Plot the waves in the x-t plane, and the solution at one particular time:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"fig = riemann_tools.plot_riemann(states,s,riemann_eval,t=0.5)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Animate the Riemann solution:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"riemann_tools.JSAnimate_plot_riemann(states,s,riemann_eval)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"## Shock tube problem:\n",
"\n",
Expand All @@ -254,11 +191,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"q_l = np.array((5,0)) # Left state\n",
Expand All @@ -275,22 +208,15 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"riemann_tools.JSAnimate_plot_riemann(states,s,riemann_eval)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"### Plot the particle trajectories\n",
"\n",
Expand All @@ -308,22 +234,26 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"riemann_tools.plot_riemann_trajectories(states,s,riemann_eval,i_vel=1)"
"wave_types = ['contact','contact'] # for a linear system of 2 equations\n",
"\n",
"# Specify number of trajectories to left and right:\n",
"num_left = 10\n",
"num_right = 10\n",
"\n",
"# compute trajectories:\n",
"x_traj, t_traj, xmax = riemann_tools.compute_riemann_trajectories(states, s, riemann_eval, wave_types,\n",
" i_vel=1, num_left=num_left, num_right=num_right)\n",
"\n",
"# plot trajectories along with waves in the x-t plane:\n",
"riemann_tools.plot_riemann_trajectories(x_traj, t_traj, s, wave_types)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"## Flow into a wall:\n",
"\n",
Expand All @@ -333,11 +263,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"q_l = np.array((3,2)) # Left state\n",
Expand All @@ -354,35 +280,36 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"riemann_tools.JSAnimate_plot_riemann(states,s,riemann_eval)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Again we can plot particle trajectories:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"riemann_tools.plot_riemann_trajectories(states,s,riemann_eval,i_vel=1)"
"# compute trajectories:\n",
"x_traj, t_traj, xmax = riemann_tools.compute_riemann_trajectories(states, s, riemann_eval, wave_types,\n",
" i_vel=1, num_left=num_left, num_right=num_right)\n",
"\n",
"# plot trajectories along with waves in the x-t plane:\n",
"riemann_tools.plot_riemann_trajectories(x_traj, t_traj, s, wave_types)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"If you discard half the solution (for $x>0$ or for $x<0$) then what you see can be viewed as the solution to a problem with fluid streaming at constant velocity toward a solid wall. The result is an acoustic wave that moves away from the wall, and the fluid behind the shock has been decelerated to velocity 0, i.e. it is stationary at the wall.\n",
"\n",
Expand All @@ -406,9 +333,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
Loading

0 comments on commit ac879ad

Please sign in to comment.