Skip to content

Commit

Permalink
Merge pull request clawpack#69 from ketch/bookform
Browse files Browse the repository at this point in the history
Initial effort at compiling book.
  • Loading branch information
rjleveque authored May 7, 2017
2 parents 7bf1ed6 + f481629 commit 2ab7417
Show file tree
Hide file tree
Showing 20 changed files with 2,420 additions and 1,120 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
.ipynb_checkpoints
None*.png
f2py_output.txt
_output/
*.bbl
*.blg
*.out
*.toc
??-*.ipynb
combined_files/
html/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
11 changes: 8 additions & 3 deletions Advection.ipynb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Advection"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
Expand Down
98 changes: 35 additions & 63 deletions Euler_approximate_solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,52 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"# Table of contents\n",
"\n",
"- [HLLE Solver](#HLLE-Solver)\n",
"- [Roe Solver](#Roe-Solver)\n",
"- [Comparison of solvers](#Comparison-of-two-approximate-solvers-with-the-exact-solution)"
"# Approximate solvers for the Euler equations of gas dynamics"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"In the [Part I](Euler_equations.ipynb) we studied the Riemann problem for Euler equations of inviscid, compressible fluid flow . As we saw, the exact solution of the Riemann problem is computationally expensive, since it requires solving a set of nonlinear algebraic equations. In the context of finite volume methods, the detailed structure of the Riemann solution is almost immediately discarded -- only its impact on the neighboring cell averages is used. So it makes sense to consider whether we can approximate the solution with less computation. In this chapter, we investigate approximate solvers for the Euler equations."
"*Note: this notebook is currently a placeholder for Part II of the book, in which the concepts behind approximate solvers will be introduced in a methodical way. The present notebook is here simply to show the facility with which different solvers may be compared and understood using the tools available in this book.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In [Part I](Euler_equations.ipynb) we studied the Riemann problem for Euler equations of inviscid, compressible fluid flow . As we saw, the exact solution of the Riemann problem is computationally expensive, since it requires solving a set of nonlinear algebraic equations. In the context of finite volume methods, the detailed structure of the Riemann solution is almost immediately discarded -- only its impact on the neighboring cell averages is used. So it makes sense to consider whether we can approximate the solution with less computation. In this chapter, we investigate approximate solvers for the Euler equations."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
"collapsed": true,
"tags": [
"hide"
]
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"%config InlineBackend.figure_format = 'svg'\n",
"import matplotlib as mpl\n",
"mpl.rcParams['font.size'] = 8\n",
"figsize =(8,4)\n",
"mpl.rcParams['figure.figsize'] = figsize\n",
"\n",
"import numpy as np\n",
"from exact_solvers import Euler\n",
"from clawpack import riemann\n",
"from utils import riemann_tools\n",
"import matplotlib.pyplot as plt\n",
"from collections import namedtuple\n",
"from ipywidgets import interact, widgets\n",
"from ipywidgets import interact\n",
"from ipywidgets import widgets\n",
"import matplotlib\n",
"matplotlib.rcParams.update({'font.size': 12})\n",
"Primitive_State = namedtuple('State', Euler.primitive_variables)\n",
"gamma = 1.4\n",
"problem_data = {}\n",
Expand All @@ -53,10 +57,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"## HLLE Solver\n",
"\n",
Expand All @@ -66,11 +67,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"solver = riemann.euler_1D_py.euler_hll_1D\n",
Expand All @@ -86,7 +83,7 @@
"print(\"HLL solver solution to Euler equations:\")\n",
"states_hll, s_hll, hll_eval = riemann_tools.riemann_solution(solver,left_state,right_state,\n",
" problem_data=problem_data,verbose=True)\n",
"fig, ax = plt.subplots(1,3,figsize=(16,4))\n",
"fig, ax = plt.subplots(1,3,figsize=figsize)\n",
"riemann_tools.plot_phase(states_hll,0,1,ax[0])\n",
"riemann_tools.plot_phase(states_hll,0,2,ax[1])\n",
"riemann_tools.plot_phase(states_hll,1,2,ax[2])\n",
Expand All @@ -96,11 +93,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"plot_function = riemann_tools.make_plot_function(states_hll,s_hll, hll_eval,\n",
Expand All @@ -110,10 +103,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"## Roe solver\n",
"The Roe solver is an example of a linearized Riemann solver. It approximates the Riemann problem by considering an approximation of the flux Jacobian: $\\hat{A} \\approx f'(q)$ and exactly solving the Riemann problem for the linear hyperbolic system\n",
Expand All @@ -126,11 +116,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"solver = riemann.euler_1D_py.euler_roe_1D\n",
Expand All @@ -141,7 +127,7 @@
"print(\"Roe solver solution to Euler equations:\")\n",
"states, s, roe_eval = riemann_tools.riemann_solution(solver,left_state,right_state,\n",
" problem_data=problem_data,verbose=True)\n",
"fig, ax = plt.subplots(1,2,figsize=(10,4))\n",
"fig, ax = plt.subplots(1,2,figsize=figsize)\n",
"riemann_tools.plot_phase(states,0,1,ax[0])\n",
"riemann_tools.plot_phase(states,0,2,ax[1])\n",
"riemann_tools.plot_phase_3d(states)"
Expand All @@ -150,11 +136,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"plot_function = riemann_tools.make_plot_function(states,s,roe_eval,variable_names=Euler.conserved_variables)\n",
Expand All @@ -163,22 +145,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"## Comparison of two approximate solvers with the exact solution\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"metadata": {},
"outputs": [],
"source": [
"ex_states, ex_speeds, reval, ex_wave_types = Euler.exact_riemann_solution(left_state ,right_state, gamma)\n",
Expand All @@ -194,10 +169,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Notice that the Roe solver significantly understimates the shock speed, and even propagates the contact discontinuity in the wrong direction. Nevertheless, when used as an ingredient in a numerical method, it gives good results."
]
Expand All @@ -223,5 +195,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
Loading

0 comments on commit 2ab7417

Please sign in to comment.