Skip to content

Commit

Permalink
update notebooks based on changes in other packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ketch committed Mar 22, 2023
1 parent 457fcab commit 777e578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 63 deletions.
63 changes: 4 additions & 59 deletions notebooks/pyclaw/Quadrants.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"from bokeh.io import output_notebook\n",
"from bokeh.palettes import Greys256\n",
"output_notebook()\n",
"p1 = figure(title=\"Quadrants\",plot_width=400,height=400,x_range=(0,1),y_range=(0,1))\n",
"p1 = figure(title=\"Quadrants\",width=400,height=400,x_range=(0,1),y_range=(0,1))\n",
"frame = claw.frames[40]\n",
"density = frame.q[0,:,:]\n",
"(vx,vy) = np.gradient(density)\n",
Expand All @@ -170,68 +170,13 @@
"metadata": {},
"source": [
"## Plotting with VisClaw\n",
"To plot with VisClaw, we must first define a setplot function:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def setplot(plotdata): \n",
" plotfigure = plotdata.new_plotfigure(name='Density', figno=0)\n",
" plotaxes = plotfigure.new_plotaxes()\n",
" plotaxes.title = 'Density'\n",
" plotaxes.scaled = True # so aspect ratio is 1\n",
" plotitem = plotaxes.new_plotitem(plot_type='2d_schlieren')\n",
" plotitem.plot_var = 0 \n",
" return plotdata"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can plot a single frame as follows (most of this code will be unnecessary in the next version):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from clawpack.visclaw import data\n",
"from clawpack.visclaw import frametools\n",
"plotdata = data.ClawPlotData()\n",
"plotdata.setplot = setplot\n",
"claw.plotdata = frametools.call_setplot(setplot,plotdata)\n",
"\n",
"frame = claw.load_frame(40)\n",
"f=claw.plot_frame(frame)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"VisClaw also has an interactive plotting loop capability. However, that doesn't work well in the notebook, because no plot appears until you exit the loop, and then you only get the last plot. Try this command instead from an IPython prompt."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"claw.plot()"
"Due to changes in VisClaw, it is not recommended for plotting within a Jupyter notebook."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -245,7 +190,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.10.4"
},
"toc": {
"nav_menu": {},
Expand Down
12 changes: 8 additions & 4 deletions notebooks/pyclaw/Stegotons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
"source": [
"# Stegotons: solitary waves arising in non-dispersive periodic media\n",
"A fascinating new class of solitary waves was discovered in [a 2003 paper by R.J. LeVeque and D. Yong](http:https://faculty.washington.edu/rjl/pubs/solitary/40815.pdf). Solitary waves usually appear as solutions of nonlinear dispersive wave equations, like the KdV or NLS equations. But the waves discovered by LeVeque and Yong arise in a system of nonlinear wave equations **with no dispersion!** The nonlinear elasticity equations they investigated are:\n",
"\n",
"\\begin{align}\n",
"\\epsilon_t(x,t) - u_x(x,t) & = 0 \\\\\n",
"(\\rho(x) u(x,t))_t - \\sigma(\\epsilon(x,t),x)_x & = 0.\n",
"\\end{align}\n",
"\n",
"They took the density $\\rho(x)$ and bulk modulus $K(x)$ to be periodic functions and the stress strain relation $\\sigma(\\epsilon,x)$ nonlinear (they used an exponential function, but any nonlinear function will work).\n",
"\n",
"If $\\rho$ and $K$ are chosen so that the impedance $Z = \\sqrt{\\rho K}$ varies in space, then waves undergo reflection on the fine scale. Remarkably, the effect of these reflections is an effective behavior that mimics dispersion -- as [predicted already by Santosa & Symes in 1993](http:https://epubs.siam.org/doi/abs/10.1137/0151049).\n",
Expand Down Expand Up @@ -145,7 +147,7 @@
"from bokeh.plotting import figure, show\n",
"from bokeh.io import output_notebook\n",
"output_notebook()\n",
"p1 = figure(title=\"Stegotons\",plot_width=800,height=400)\n",
"p1 = figure(title=\"Stegotons\",width=800,height=400)\n",
"strain = claw.frames[-1].q[0,:]\n",
"p1.line(xc,strain,line_width=2)\n",
"show(p1)"
Expand Down Expand Up @@ -371,7 +373,9 @@
"ax = plt.axes(xlim=(0, 300), ylim=(0, 0.6))\n",
"line, = ax.plot([], [])\n",
"\n",
"animation.FuncAnimation(fig, fplot, frames=len(claw.frames))"
"anim = animation.FuncAnimation(fig, fplot, frames=len(claw.frames))\n",
"plt.close()\n",
"HTML(anim.to_jshtml())"
]
},
{
Expand All @@ -380,7 +384,7 @@
"metadata": {},
"outputs": [],
"source": [
"p1 = figure(title=\"Stegotons\",plot_width=800,height=400)\n",
"p1 = figure(title=\"Stegotons\",width=800,height=400)\n",
"strain = claw.frames[-20].q[0,:]\n",
"p1.line(xc,strain,line_width=2)\n",
"show(p1)"
Expand Down Expand Up @@ -423,7 +427,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.10.4"
},
"toc": {
"nav_menu": {},
Expand Down

0 comments on commit 777e578

Please sign in to comment.