Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: make plots with red/blue stripes advected with flow #68

Merged
merged 11 commits into from
May 18, 2017
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