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] Add IPython notebooks with PyClaw versions of FVM book examples #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
109 changes: 109 additions & 0 deletions fvmbook/chap3/acousimple/acoustics_simple_waves.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"metadata": {
"name": "",
"signature": "sha256:78991e4acc93c32f483391d7a48b3dfe1559a0d2ee23b89d604c56147ff47ace"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Simple waves in the acoustics system"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code in this notebook runs the simulation that produces the output shown in Figures 3.1 and 3.8."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%matplotlib inline\n",
"from clawpack import pyclaw\n",
"from clawpack import riemann\n",
"import numpy as np\n",
"from clawpack.visclaw import ianimate\n",
"\n",
"import matplotlib\n",
"matplotlib.rcParams.update({'font.size': 22})\n",
"import matplotlib.pyplot as plt"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Define the domain, equations, and boundary conditions\n",
"domain = pyclaw.Domain([-1.],[1.],[800])\n",
"solver = pyclaw.ClawSolver1D(riemann.acoustics_1D)\n",
"solver.bc_lower[0] = pyclaw.BC.wall\n",
"solver.bc_upper[0] = pyclaw.BC.extrap\n",
"\n",
"num_eqn = 2\n",
"solution = pyclaw.Solution(num_eqn,domain)\n",
"solver.limiters = pyclaw.limiters.tvd.MC\n",
"\n",
"# Define the material parameters\n",
"rho = 1.0 # Density\n",
"bulk = 0.25 # Bulk modulus\n",
"solution.problem_data['rho']=rho\n",
"solution.problem_data['bulk']=bulk\n",
"solution.problem_data['zz']=np.sqrt(rho*bulk) # Impedance\n",
"solution.problem_data['cc']=np.sqrt(bulk/rho) # Sound speed\n",
"\n",
"# Define the initial condition\n",
"xc=solution.p_centers[0] # Cell centers\n",
"solution.q[0,:] = 0.5*np.exp(-80 * xc**2) + 0.5*(np.abs(xc+0.2)<0.1)\n",
"solution.q[1,:] = 0.\n",
"\n",
"# Set up the simulation and output\n",
"claw = pyclaw.Controller()\n",
"claw.solution = solution\n",
"claw.solver = solver\n",
"claw.output_format = None\n",
"claw.keep_copy = True\n",
"claw.tfinal = 3.0\n",
"claw.num_output_times = 30\n",
"claw.verbosity = 1"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"status = claw.run()"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ianimate.ianimate(claw,varname='Pressure')"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Loading