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

Improve presentation of Introduction in PDF. #76

Merged
merged 2 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"\n",
"If the water to the left of the dam is deeper than the water to the right (i.e. $h_l > h_r$) then we expect water to flow from left to right in some manner. In reality we might expect the flow to be somewhat turbulent and multidimensional, but suppose that we could idealize this with a one-dimensional model in which the velocity is purely horizontal and is constant throughout the depth of the fluid, so for $t>0$ the velocity varies only with $x$ and $t$, given by some function $u(x,t)$, and the depth is given by $h(x,t)$. \n",
"\n",
"In the notebook [Shallow_water.ipynb](Shallow_water.ipynb) we will discuss the one-dimensional **shallow water equations** that can be used to model this idealized situation. \n",
"In [Shallow_water.ipynb](Shallow_water.ipynb) we will discuss the one-dimensional **shallow water equations** that can be used to model this idealized situation. \n",
"\n",
"The animation below shows the solution to the shallow water equations in the situation just described. The water is colored red for water that is initially to the left of the dam and blue for water that is initially to the right. The stripes with different shading are to help you visualize the flow. Think of the color as a dye that is simply carried along with the water as it flows. In the notebook [Shallow_water_tracer.ipynb](Shallow_water_tracer.ipynb) we will see that we can in fact model this by adding another equation to the shallow water equations."
"The animation below shows the solution to the shallow water equations in the situation just described. The water is colored red for water that is initially to the left of the dam and blue for water that is initially to the right. The stripes with different shading are to help you visualize the flow. Think of the color as a dye that is simply carried along with the water as it flows. In [Shallow_water_tracer.ipynb](Shallow_water_tracer.ipynb) we will see that we can in fact model this by adding another equation to the shallow water equations."
]
},
{
Expand All @@ -36,20 +36,20 @@
"source": [
"%matplotlib inline\n",
"from exact_solvers import shallow_water\n",
"demo_plot = shallow_water.make_demo_plot_function\n",
"from ipywidgets import widgets, fixed\n",
"from ipywidgets import interact"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"interact(shallow_water.make_demo_plot_function(h_l=3., h_r=1., u_l=0., u_r=0),\n",
" t=widgets.FloatSlider(min=0.001,max=0.6,step=0.1,value=0.), fig=fixed(0))"
"interact(demo_plot(h_l=3., h_r=1., u_l=0., u_r=0),\n",
" t=widgets.FloatSlider(min=0., max=0.6, step=0.1,\n",
" value=0.), fig=fixed(0));"
]
},
{
Expand Down Expand Up @@ -114,8 +114,9 @@
"metadata": {},
"outputs": [],
"source": [
"interact(shallow_water.make_demo_plot_function(h_l=1., h_r=3., u_l=0., u_r=0),\n",
" t=widgets.FloatSlider(min=0.001,max=0.6,step=0.1,value=0.), fig=fixed(0));"
"interact(demo_plot(h_l=1., h_r=3., u_l=0., u_r=0),\n",
" t=widgets.FloatSlider(min=0.0, max=0.6, step=0.1,\n",
" value=0.), fig=fixed(0));"
]
},
{
Expand All @@ -131,8 +132,9 @@
"metadata": {},
"outputs": [],
"source": [
"interact(shallow_water.make_demo_plot_function(h_l=1., h_r=1., u_l=0.8, u_r=-0.8),\n",
" t=widgets.FloatSlider(min=0.001,max=0.6,step=0.1,value=0.), fig=fixed(0));"
"interact(demo_plot(h_l=1., h_r=1., u_l=0.8, u_r=-0.8),\n",
" t=widgets.FloatSlider(min=0., max=0.6, step=0.1,\n",
" value=0.), fig=fixed(0));"
]
},
{
Expand All @@ -148,15 +150,16 @@
"metadata": {},
"outputs": [],
"source": [
"interact(shallow_water.make_demo_plot_function(h_l=1., h_r=1., u_l=-0.8, u_r=0.8),\n",
" t=widgets.FloatSlider(min=0.001,max=0.6,step=0.1,value=0.), fig=fixed(0));"
"interact(demo_plot(h_l=1., h_r=1., u_l=-0.8, u_r=0.8),\n",
" t=widgets.FloatSlider(min=0.0, max=0.6, step=0.1,\n",
" value=0.), fig=fixed(0));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the notebook [Shallow_water.ipynb](Shallow_water.ipynb) we will show how to solve the Riemann problem for arbitrary left and right states and in particular how to determine whether each wave is a shock or rarefaction wave."
"In [Shallow_water.ipynb](Shallow_water.ipynb) we will show how to solve the Riemann problem for arbitrary left and right states and in particular how to determine whether each wave is a shock or rarefaction wave."
]
},
{
Expand Down Expand Up @@ -218,7 +221,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# A linear example: acoustic waves\n",
"## A linear example: acoustic waves\n",
"\n",
"We end this introduction with a sample linear system. Acoustic waves in one dimension can be modeled by the system of PDEs\n",
"\n",
Expand Down Expand Up @@ -261,7 +264,11 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"hide"
]
},
"outputs": [],
"source": [
"from IPython.core.display import display, HTML\n",
Expand All @@ -275,28 +282,23 @@
"source": [
"## Phase plane plot for the shallow water equations\n",
"\n",
"The phase plane plot for the nonlinear shallow water equations is more interesting. Since the eigenvectors of the Jacobian matrix vary with $q$, the curves connecting states separated by a single wave are not straight lines. There is also a distinction between the curves connecting states by a shock wave and those connecting states by a rarefaction wave. This is discussed in much more detail in the notebook [Shallow_water.ipynb](Shallow_water.ipynb), but here is an interactive view that allows you to see how the solution changes as you move the left and right states around in the phase plane:"
"The phase plane plot for the nonlinear shallow water equations is more interesting. Since the eigenvectors of the Jacobian matrix vary with $q$, the curves connecting states separated by a single wave are not straight lines. There is also a distinction between the curves connecting states by a shock wave and those connecting states by a rarefaction wave. This is discussed in much more detail in [Shallow_water.ipynb](Shallow_water.ipynb), but here is an interactive view that allows you to see how the solution changes as you move the left and right states around in the phase plane:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"tags": [
"hide"
]
},
"outputs": [],
"source": [
"from IPython.core.display import display, HTML\n",
"app = open('phase_plane_shallow_water_verysmall.html','r').read()\n",
"display(HTML(app))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -315,7 +317,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"version": "2.7.13"
}
},
"nbformat": 4,
Expand Down
8 changes: 7 additions & 1 deletion exact_solvers/shallow_water.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,13 @@ def reval_rho_u(x):
num_vars = len(primitive_variables)

def plot_shallow_water_demo(t=0.5, fig=0):
q = np.array(reval(x/t))
if t == 0:
q = np.zeros((2,len(x)))
q[0,:] = q_l[0]*(x<=0) + q_r[0]*(x>0)
q[1,:] = q_l[1]*(x<=0) + q_r[1]*(x>0)
else:
q = np.array(reval(x/t))

if t<0.02:
q[1] = np.where(x<0, q_l[1], q_r[1])

Expand Down
18 changes: 17 additions & 1 deletion riemann.tplx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

((* block title *))
\title{The Riemann Problem for Hyperbolic PDEs: Theory and Approximate Solvers}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\},fontsize=\small}
((* endblock title *))

((* block maketitle *))
Expand All @@ -47,3 +46,20 @@
((( super() )))
((*- endif -*))
((*- endblock any_cell -*))

((* block input scoped *))
((( add_my_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor') )))
((* endblock input *))

% Purpose: Renders an output/input prompt
((* macro add_my_prompt(text, cell, prompt, prompt_color) -*))
((*- if cell.execution_count is defined -*))
((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
((*- else -*))
((*- set execution_count = " " -*))
((*- endif -*))
((*- set indention = " " * (execution_count | length + 7) -*))
\begin{Verbatim}[fontsize=\small,commandchars=\\\{\}]
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))