Skip to content

Commit

Permalink
Apply SIAM book formatting to pdf.
Browse files Browse the repository at this point in the history
Include preface in pdf.
Use \small for code in pdf.
Use SVG backend so that graphics are in vector format.
Adjust figure and font sizes to work with SVG backend.
Plot Riemann solution and phase plane together for nonlinear elasticity.
Fix numerous minor issues in notebooks.
  • Loading branch information
ketch committed Apr 30, 2017
1 parent b7ea741 commit 0d30c94
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 202 deletions.
25 changes: 21 additions & 4 deletions Euler_approximate_solvers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
"# Approximate solvers for the Euler equations of gas dynamics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*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": {},
Expand All @@ -17,10 +24,21 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"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",
Expand All @@ -30,7 +48,6 @@
"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 Down Expand Up @@ -66,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 Down Expand Up @@ -110,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 Down
147 changes: 94 additions & 53 deletions Nonlinear_elasticity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,58 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Nonlinear elasticity\n",
"# Nonlinear elasticity"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"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 scipy.optimize import fsolve\n",
"import matplotlib.pyplot as plt\n",
"from utils import riemann_tools\n",
"from ipywidgets import interact\n",
"from ipywidgets import widgets\n",
"from clawpack import riemann\n",
"from exact_solvers import nonlinear_elasticity"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this chapter we investigate a nonlinear model of elastic strain in heterogeneous materials. This system is equivalent to the $p$-system of gas dynamics, although the stress-strain relation we will use here is very different from the pressure-density relation typically used in gas dynamics. The equations we consider have been investigated numerically in [<cite data-cite=\"leveque2002\"><a href=\"riemann.html#leveque2002\">(LeVeque, 2002)<a></cite>,<cite data-cite=\"leveque2003\"><a href=\"riemann.html#leveque2003\">(LeVeque & Yong, 2003)<a></cite>,<cite data-cite=\"2012_ketchesonleveque_periodic\"><a href=\"riemann.html#2012_ketchesonleveque_periodic\">(Ketcheson & LeVeque, 2012)<a></cite>].\n",
"\n",
"The equations are\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",
"\\end{align} \n",
"Here $\\epsilon$ is the strain, $u$ is the velocity, $\\rho$ is the material density, $\\sigma$ is the stress,\n",
"and ${\\mathcal M}=\\rho u$ is the momentum. \n",
"The first equation is a kinematic relation, while the second represents Newton's second law. This is a nonlinear \n",
"conservation law with spatially varying flux function, in which\n",
"\n",
"The first equation is a kinematic relation, while the second represents Newton's second law. This is a nonlinear conservation law with spatially varying flux function, in which\n",
"\\begin{align}\n",
"q & = \\begin{bmatrix} \\epsilon \\\\ \\rho u \\end{bmatrix}, & f(q,x) & = \\begin{bmatrix} -{\\mathcal M}/\\rho(x) \\\\ -\\sigma(\\epsilon,x) \\end{bmatrix}\n",
"\\end{align}\n",
"\n",
"Here $\\epsilon$ is the strain, $u$ is the velocity, $\\rho$ is the material density, $\\sigma$ is the stress,\n",
"and ${\\mathcal M}=\\rho u$ is the momentum. If we take a linear stress strain relationship $\\sigma(\\epsilon,x)=K(x)\\epsilon$, then this system is equivalent to the acoustics equations that we have\n",
"studied previously. Here we consider instead a quadratic stress:\n",
"\\end{align} \n",
"If we take a linear stress strain relationship $\\sigma(\\epsilon,x)=K(x)\\epsilon$, then this system is equivalent to the acoustics equations that we have\n",
"studied previously. Here we consider instead a quadratic stress response:\n",
"\n",
"\\begin{align}\n",
"\\sigma(\\epsilon,x) = K_1(x) \\epsilon + K_2(x) \\epsilon^2.\n",
Expand All @@ -38,17 +73,16 @@
"The flux jacobian is\n",
"\\begin{align}\n",
"f'(q) = \\begin{bmatrix} 0 & -1/\\rho(x) \\\\ -\\sigma_\\epsilon(\\epsilon,x) & 0 \\end{bmatrix},\n",
"\\end{align}\n",
"with eigenvalues (characteristic sound speeds)\n",
"\\end{align} \n",
"with eigenvalues (characteristic speeds)\n",
"\\begin{align}\n",
"\\lambda^\\pm(x) = \\pm \\sqrt{\\frac{\\sigma_\\epsilon(\\epsilon,x)}{\\rho(x)}} = \\pm c(\\epsilon, x).\n",
"\\end{align}\n",
"\n",
"\\end{align} \n",
"Here for the stress-strain relation we have chosen, $\\sigma_\\epsilon = K_1(x) + 2 K_2(x)\\epsilon$.\n",
"\n",
"It's also convenient to define the nonlinear impedance $Z(\\epsilon, x) = \\rho(x) c(\\epsilon,x)$. Then the eigenvectors of the flux Jacobian are\n",
"\\begin{align}\n",
"R & = \\begin{bmatrix} 1 & 1 \\\\ Z & -Z \\end{bmatrix}.\n",
"R & = \\begin{bmatrix} 1 & 1 \\\\ Z(\\epsilon,x) & -Z(\\epsilon,x) \\end{bmatrix}.\n",
"\\end{align}\n",
"Both characteristic fields are genuinely nonlinear. Furthermore, since the characteristic speeds each have a definite sign, this system does not admit transonic rarefactions."
]
Expand All @@ -58,9 +92,9 @@
"metadata": {},
"source": [
"### Structure of the Riemann solution\n",
"Based on the eigenstructure of the flux jacobian above, the Riemann solution will always include a left-going and a right-going wave, each of which may be a shock or rarefaction. Furthermore, we will see that the jump in $\\rho$ and $K$ at $x=0$ induces a stationary wave there. Thus the overall structure of the Riemann solution is:\n",
"Based on the eigenstructure of the flux jacobian above, the Riemann solution will always include a left-going and a right-going wave, each of which may be a shock or rarefaction. We will see -- similarly to our analysis in [the chapter on variable-speed-limit traffic](Traffic_variable_speed.ipynb) that the jump in $\\rho$ and $K$ at $x=0$ induces a stationary wave there. Thus the overall structure of the Riemann solution is:\n",
"\n",
"![](./figures/nonlinear_elasticity_riemann.png)"
"![Structure of the Riemann solution for variable-coefficient nonlinear elasticity](./figures/nonlinear_elasticity_riemann.png)"
]
},
{
Expand All @@ -86,8 +120,8 @@
"### Integral curves\n",
"The integral curves can be found by writing $\\tilde{q}'(\\xi) = r^{1,2}(\\tilde{q}(\\xi))$ and integrating. This leads to\n",
"\\begin{align}\n",
"u^*_l & = u_l + \\frac{1}{3 K_{2l} \\sqrt{\\rho_l}} \\left( \\sigma_{l,\\epsilon}(\\epsilon^*_l)^{3/2} - \\sigma_{l,\\epsilon}(\\epsilon)^{3/2} \\right) \\\\\n",
"u^*_r & = u_r - \\frac{1}{3 K_{2r} \\sqrt{\\rho_r}} \\left( \\sigma_{r,\\epsilon}(\\epsilon^*_r)^{3/2} - \\sigma_{r,\\epsilon}(\\epsilon)^{3/2} \\right)\n",
"u^*_l & = u_l + \\frac{1}{3 K_{2l} \\sqrt{\\rho_l}} \\left( \\sigma_{l,\\epsilon}(\\epsilon^*_l)^{3/2} - \\sigma_{l,\\epsilon}(\\epsilon)^{3/2} \\right) \\label{NE:integral-curve-1} \\\\\n",
"u^*_r & = u_r - \\frac{1}{3 K_{2r} \\sqrt{\\rho_r}} \\left( \\sigma_{r,\\epsilon}(\\epsilon^*_r)^{3/2} - \\sigma_{r,\\epsilon}(\\epsilon)^{3/2} \\right)\\label{NE:integral-curve-2}\n",
"\\end{align}\n",
"Here $\\sigma_{l,\\epsilon}$ is the derivative of the stress function w.r.t $\\epsilon$ in the left medium."
]
Expand Down Expand Up @@ -117,30 +151,23 @@
"\\begin{align}\n",
"\\xi^2 = \\frac{K_1 + 2K_2\\epsilon}{\\rho}\n",
"\\end{align}\n",
"which leads to $\\epsilon = (\\rho\\xi^2 - K_1)/(2K_2)$. Once the value of $\\epsilon$ is known, $u$ can be determined using the integral curves above."
"which leads to $\\epsilon = (\\rho\\xi^2 - K_1)/(2K_2)$. Once the value of $\\epsilon$ is known, $u$ can be determined using the integral curves \\eqref{NE:integral-curve-1} or \\eqref{NE:integral-curve-2}."
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"from scipy.optimize import fsolve\n",
"import matplotlib.pyplot as plt\n",
"from utils import riemann_tools\n",
"from ipywidgets import interact\n",
"from ipywidgets import widgets\n",
"from clawpack import riemann\n",
"from exact_solvers import nonlinear_elasticity"
"### Solution of the Riemann problem\n",
"Below we show the solution of the Riemann problem. *To view the code that computes this exact solution, uncomment and execute the next cell.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# %load exact_solvers/nonlinear_elasticity.py"
Expand All @@ -149,7 +176,9 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def dsigma(eps, K1, K2):\n",
Expand All @@ -171,14 +200,28 @@
"metadata": {},
"outputs": [],
"source": [
"def riemann_solution(q_l, q_r, aux_l, aux_r):\n",
" ex_states, ex_speeds, ex_reval, wave_types = nonlinear_elasticity.exact_riemann_solution(q_l,q_r,aux_l,aux_r)\n",
" plot_function = riemann_tools.make_plot_function(ex_states, ex_speeds, ex_reval, wave_types,\n",
" layout='vertical',\n",
" variable_names=('Strain','Momentum'),\n",
" plot_chars=[lambda1,lambda2],aux=(aux_l,aux_r))\n",
" interact(plot_function, t=widgets.FloatSlider(value=0.1,min=0,max=.9),\n",
" which_char=widgets.Dropdown(options=[None,1,2],description='Show characteristics'));"
"def make_plot_function(q_l, q_r, aux_l, aux_r):\n",
" states, speeds, reval, wave_types = \\\n",
" nonlinear_elasticity.exact_riemann_solution(q_l,q_r,aux_l,aux_r)\n",
" \n",
" def plot_function(t,which_char):\n",
" ax = riemann_tools.plot_riemann(states,speeds,reval,wave_types,\n",
" t=t,t_pointer=0,\n",
" extra_axes=True,\n",
" variable_names=['Strain','Momentum'])\n",
" if which_char == 1:\n",
" riemann_tools.plot_characteristics(reval,lambda1,(aux_l,aux_r),ax[0])\n",
" elif which_char == 2:\n",
" riemann_tools.plot_characteristics(reval,lambda2,(aux_l,aux_r),ax[0])\n",
" nonlinear_elasticity.phase_plane_plot(q_l, q_r, aux_l, aux_r, ax[3])\n",
" plt.show()\n",
" return plot_function \n",
" \n",
"def plot_riemann_nonlinear_elasticity(rho_l,rho_r,v_l,v_r):\n",
" plot_function = make_plot_function(rho_l,rho_r,v_l,v_r)\n",
" interact(plot_function, t=widgets.FloatSlider(value=0.,min=0,max=1.,step=0.1),\n",
" which_char=widgets.Dropdown(options=[None,1,2],\n",
" description='Show characteristics'));"
]
},
{
Expand All @@ -192,24 +235,15 @@
"q_l = np.array([2.1, 0.])\n",
"q_r = np.array([0.0, 0.])\n",
"\n",
"riemann_solution(q_l, q_r, aux_l, aux_r)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nonlinear_elasticity.phase_plane_plot(q_l, q_r, aux_l, aux_r)"
"plot_riemann_nonlinear_elasticity(q_l, q_r, aux_l, aux_r)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Approximate solution of the Riemann problem using $f$-waves\n",
"The exact solver above requires a nonlinear iterative solver and is relatively expensive. A very cheap approximate Riemann solver for this system was developed in <cite data-cite=\"leveque2002\"><a href=\"riemann.html#leveque2002\">(LeVeque, 2002)<a></cite> using the $f$-wave approach. One simply assumes that both nonlinear waves are shocks, with speeds equal to the characteristic speeds of the left and right states:\n",
"The exact solver above requires a nonlinear iterative rootfinder and is relatively expensive. A very cheap approximate Riemann solver for this system was developed in <cite data-cite=\"leveque2002\"><a href=\"riemann.html#leveque2002\">(LeVeque, 2002)<a></cite> using the $f$-wave approach. One simply approximates both nonlinear waves as shocks, with speeds equal to the characteristic speeds of the left and right states:\n",
"\\begin{align}\n",
"s^1 & = - \\sqrt{\\frac{\\sigma_{\\epsilon,l}(\\epsilon_l)}{\\rho_l}} \\\\\n",
"s^2 & = + \\sqrt{\\frac{\\sigma_{\\epsilon,r}(\\epsilon_r)}{\\rho_r}}.\n",
Expand Down Expand Up @@ -239,7 +273,7 @@
"source": [
"plot_function = riemann_tools.make_plot_function(fwave_states,fwave_speeds, fwave_reval,\n",
" layout='vertical', variable_names=('Strain','Momentum'))\n",
"interact(plot_function, t=widgets.FloatSlider(value=0.1,min=0,max=.9,step=.1));"
"interact(plot_function, t=widgets.FloatSlider(value=0.4,min=0,max=.9,step=.1));"
]
},
{
Expand All @@ -263,7 +297,14 @@
" [wave_types,['contact']*3],\n",
" ['Exact','$f$-wave'],\n",
" layout='vertical',variable_names=nonlinear_elasticity.conserved_variables)\n",
"interact(plot_function, t=widgets.FloatSlider(value=0.1,min=0, max=0.9, step=0.1));"
"interact(plot_function, t=widgets.FloatSlider(value=0.4,min=0, max=0.9, step=0.1));"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, there are significant discretpancies between the approximate solution and the exact one. But in a full numerical discretization, the left- and right-going waves are averaged over neighboring cells at the next step, and the approximate solver yields an effective result quite close to that of the exact solver."
]
}
],
Expand Down
Loading

0 comments on commit 0d30c94

Please sign in to comment.