Skip to content

Commit

Permalink
Improve presentation of Indtroduction in PDF.
Browse files Browse the repository at this point in the history
- Resolve issues with t=0 (see clawpack#75)
- Make all code fit on page by shortening lines and reducing code font size
- Avoid using top-level header (#) since that gets converted to a new chapter
  • Loading branch information
ketch committed May 22, 2017
1 parent ac879ad commit 20f1224
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 26 deletions.
50 changes: 26 additions & 24 deletions Introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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,8 +150,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.0, max=0.6, step=0.1,\n",
" value=0.), fig=fixed(0));"
]
},
{
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 @@ -281,22 +288,17 @@
{
"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 *))

0 comments on commit 20f1224

Please sign in to comment.