{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Demo of running AMRClaw Fortran code and plotting results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook can be found in `$CLAW/apps/notebooks/amrclaw_advection_2d_square`\n",
"\n",
"The is adapted from $CLAW/amrclaw/examples/advection_2d_square to illustrate the use of IPython notebooks.\n",
"\n",
"The setrun.py and setplot.py files are taken from that example but some parameters are modified in the notebook below.\n",
"\n",
"The 2-dimensional advection equation $q_t + uq_x + vq_y = 0$ is solved in the unit square with periodic boundary conditions. The constant advection velocities $u$ and $v$ are specified in setrun.py but can be changed below."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Have plots appear inline in notebook:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check that the CLAW environment variable is set. (It must be set in the Unix shell before starting the notebook server)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using Clawpack from /Users/rjl/git/clawpack\n"
]
}
],
"source": [
"import os\n",
"try:\n",
" CLAW = os.environ['CLAW'] \n",
" print \"Using Clawpack from \", CLAW\n",
"except:\n",
" print \"*** Environment variable CLAW must be set to run code\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Module with functions used to execute system commands and capture output:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from clawpack.clawutil import nbtools"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Compile the code:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Executing shell command: make new\n",
"Done... Check this file to see output:\n"
]
},
{
"data": {
"text/html": [
"compile_output.txt
"
],
"text/plain": [
"/Users/rjl/git/clawpack/apps/notebooks/amrclaw/advection_2d_square/compile_output.txt"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"nbtools.make_exe(new=True) # new=True ==> force recompilation of all code"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Make documentation files:"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"See the README.html file for links to input files...\n"
]
},
{
"data": {
"text/html": [
"README.html
"
],
"text/plain": [
"/Users/rjl/git/clawpack/apps/notebooks/amrclaw/advection_2d_square/README.html"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"nbtools.make_htmls()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run the code and plot results using the setrun.py and setplot.py files in this directory:\n",
"\n",
"First create data files needed for the Fortran code, using parameters specified in setrun.py:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"nbtools.make_data(verbose=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now run the code and produce plots. Specifying a label insures the resulting plot directory will persist after later runs are done below."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Executing shell command: make output OUTDIR=_output_1\n",
"Done... Check this file to see output:\n"
]
},
{
"data": {
"text/html": [
"run_output_1.txt
"
],
"text/plain": [
"/Users/rjl/git/clawpack/apps/notebooks/amrclaw/advection_2d_square/run_output_1.txt"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Executing shell command: make plots OUTDIR=_output_1 PLOTDIR=_plots_1\n",
"Done... Check this file to see output:\n"
]
},
{
"data": {
"text/html": [
"plot_output_1.txt
"
],
"text/plain": [
"/Users/rjl/git/clawpack/apps/notebooks/amrclaw/advection_2d_square/plot_output_1.txt"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"View plots created at this link:\n"
]
},
{
"data": {
"text/html": [
"_plots_1/_PlotIndex.html
"
],
"text/plain": [
"/Users/rjl/git/clawpack/apps/notebooks/amrclaw/advection_2d_square/_plots_1/_PlotIndex.html"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"outdir,plotdir = nbtools.make_output_and_plots(label='1')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display the animation inline:\n",
"\n",
"Clicking on the _PlotIndex link above, you can view an animation of the results. \n",
"\n",
"After creating all png files in the _plots directory, these can also be combined in an animation that is displayed inline:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"