Code Monkey home page Code Monkey logo

clawpack / riemann_book Goto Github PK

View Code? Open in Web Editor NEW
246.0 15.0 94.0 62.79 MB

An interactive book about the Riemann problem for hyperbolic PDEs, using Jupyter notebooks.

License: BSD 3-Clause "New" or "Revised" License

Python 1.70% Jupyter Notebook 6.79% TeX 0.39% HTML 91.06% Smarty 0.01% Shell 0.01% CSS 0.01% Fortran 0.03% Dockerfile 0.01%
riemann-solver python jupyter-notebook book hyperbolic-equations partial-differential-equations mathematics numerical-methods

riemann_book's Introduction

PyPI Downloads conda-forge

Please see the documentation for Clawpack at http://www.clawpack.org.

If you are cloning this repository, the following pages may be of particular interest:

riemann_book's People

Contributors

alexfikl avatar breuera avatar katrinleinweber avatar ketch avatar mandli avatar maojrs avatar rjleveque avatar yuvipanda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

riemann_book's Issues

Polishing chapters for the submission

I would like to make sure that some of our eyes go over each chapter before we declare it ready for submission in the proposal. I'm not sure how detailed and critical we need to be at this stage, but this will at least ensure that we smooth out the roughest edges. I'll make a list of the chapters here and we can each initial next to the ones we've read and are happy with. I suggest reading them in PDF form since we've spent most of our time so far looking at them in the notebooks.

  • Preface
  • Introduction
  • Traffic flow DK
  • Shallow water DK
  • Variable-speed traffic flow DK
  • Nonlinear elasticity DK
  • Tammann DK
  • Pressureless flow (shallow water in low gravity) DK
  • Kitchen sink DK

These are the chapters that are in the PDF at the moment. If we plan to include others in the proposal we should add them here.

Misc. problems

Noticed while going through #74...

  • Introduction.ipynb: double rarefaction at earliest t shows artifacts at discontinuity,
  • Introduction.ipynb: The interacts have t = 0.001 to avoid problems at t=0 and these are not reset to t=0.2 by utils.snapshot_widget.
  • Intro and elsewhere: utils.snapshot_widget creates some plots where it's not clear what time the solution is shown at, do we want to include t in titles?
  • Traffic_flow.ipynb: Traffic jam shock leaves the domain: expand xlim?
  • Shallow_water.ipynb: Why do cells show tags (only in this notebook)?
  • Shallow_tracer.ipynb: Redo with the new plotting of stripes rather than using PyClaw? Needs more description too.

Eq. in acoustics NB

I think I found an error in the acoustics NB in the solution by characteristics. The equation $w=\alpha_1 r_1 + \alpha_2 r_2$, should read either $q=\alpha_1 r_1 + \alpha_2 r_2$ or $q=w_1 r_1 + w_2 r_2$. I thought it was just a typo, but in the interactive below is this equation that is represented. David, I think you wrote this part, so I wanted to check with you before correcting anything.

Characteristics incorrectly terminate in SW section 1.4.5

This refers to the example with the entropy-violating rarefaction imposed in the dam-break problem.
The text says that that the 2-characteristics cross within the 2-rarefaction, but something has been changed with the characteristic plotting so that the characteristics coming from the left actually terminate at the left edge of the rarefaction. I don't know when this was changed.

Code lines in the PDF go past the right edge of the page

Much of the code in the book includes lines that are too long to fit in the margins of the PDF version. I've done the following to fix this:

  • Change the code font size to small everywhere (via the template file riemann.tplx)
  • Use shorter names and eliminate some spaces where appropriate
  • Use line breaks to split code onto multiple lines

The last part is work in progress and several chapters still need this treatment. It's a bit ugly but I don't see any way around it. Suggestions welcome.

make_pdf.py cannot find riemann.tex

Hi, when I try to generate a PDF, it runs almost until the end but I get the error below,

...
[NbConvertApp] Writing 777704 bytes to build_pdf/13-Euler_approximate.ipynb
[NbConvertApp] Converting notebook build_pdf/14-FV_compare.ipynb to notebook
[NbConvertApp] Executing notebook with kernel: python
[NbConvertApp] Writing 497763 bytes to build_pdf/14-FV_compare.ipynb
INFO:__main__:Combined 15 files
INFO:__main__:Converting to latex
    value = self._validate(obj, dynamic_default())
  File "/home/user/Documents/env3/lib/python3.6/site-packages/nbconvert/preprocessors/svg2pdf.py", line 59, in _inkscape_version_default
    stderr=subprocess.PIPE)
  File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'inkscape': 'inkscape'
Traceback (most recent call last):
  File "../files_for_latex_pdf/fix_latex_file.py", line 8, in <module>
    lines = open(fname,'r').read()
FileNotFoundError: [Errno 2] No such file or directory: 'riemann.tex'
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
! I can't find file `riemann'.

If I'm not mistaken the code is supposed to create a riemann.tex but it is also trying to read it before it creates it? Is there a bootstrap riemann.tex file that I need?

Apart from this error, I am able to run the notebooks on their own without any problems (except, partially, the claw code, it generates the graph but doesn't animate)

Thanks,

Try out `nbinteract`

I just became aware of the nbinteract project by @SamLau95 that can turn notebooks into interactive webpages. Might be an interesting way to put this book up in more places.

Tamman EOS notebook generates errors

@maojrs I thought I successfully ran this notebook back when it was added, but I must be wrong since it doesn't work for me now and it hasn't been changed.

The second code cell gives me an error about passing 5 arguments to phi_exact. I was able to fix that, but then I get an error about ul being undefined. Does the notebook run for you?

Some tips from Fernando

Some notes from discussion with @fperez yesterday...

  1. We should take a look at https://github.com/takluyver/bookbook regarding cross referencing between notebooks.

  2. Regarding jupyter-widgets/ipywidgets#1085, this seems to be fixed in the latest master branch... But: it only shows the widgets and lets you move them, it doesn't embed the results in the notebook like the old StaticWidgets, so you won't see the plots change. So not really what we want.

  3. If we use widgets and want the pdf version to show the plots with a specific setting, we could initialize them using value = in creating the widgets. For more control, e.g. to set different values for the pdf than what we want to initialize them to in the notebook, we could add info to the cell metadata and then modify nbconvert to parse this.

  4. Several examples of notebooks in journal publications can be found at:

  5. Perhaps not relevant for this book project, but some interesting new projects for rendering and manipulating 3d plots in a notebook:

nbconvert --to html doesn't handle equation numbers

The equation numbers come out as (???) when a notebook is converted via e.g.

jupyter nbconvert --to html Introduction.ipynb 

I tried installing latex_envs and then tried:

jupyter nbconvert --to html_with_lenvs Introduction.ipynb 

but that didn't work, and then equation numbers were also broken in the notebooks themselves, so I disabled it.

Other ideas on how to do this?

Create pdf in build_pdf directory?

@ketch: I suggest we

  • consolidate make_chapters.py and make_book.sh into make_pdf.py similar to make_html.py so it's less confusing where things are done and where the specify the desired chapters.

  • Build the pdf file in a new directory build_pdf so that all the files generated 0*.ipynb, riemann.aux, etc. don't end up cluttering up the main directory. Then move the pdf file out of this directory so it can be safely deleted to clean up. This would be similar to what's done in #83 for html files.

Burgers chapter

I just went over the Burgers' equation chapter again and made many corrections (see 204d29c). There were some issues I didn't solve:

  1. The explanation in “Rarefaction wave” section doesn’t seem to make sense without talking about smoothing out the IC. Since no initial point takes values between q_l and q_r, where do those values in the later solution come from?
  2. In the section "Weak solutions": I don't understand what is meant by saying "We can generalize this result." What result?
  3. In the same section: without saying more about the support of \phi, I don’t think the integration by parts makes sense. Why do we get a boundary term at t=0 and not at the other boundaries?
  4. What does “any form of the integral conservation law” mean?
  5. The sentence starting “Note this rules out the interval…” doesn’t make sense to me.
  6. Figure captions should say “x-t plane” rather than “xt-plane”. But maybe it would be better to change them simply to “characteristics”.

Overall, the writing in this chapter feels to me like it assumes the reader already knows this material. Is that the intent?

plot_chars in make_plot_function (riemann_utils.py)

I am trying to set plot_chars = True while calling make_plot_function, but I keep getting an error. I think there might be a bug since this is called:
plot_characteristics(states,speeds,plot_chars,ax[0])

and the function actually takes:
plot_characteristics(reval, char_speed, axes=None, extra_lines=None).

Azure Notebooks issues

I'm trying to get everything working on the Azure notebook server.

You should be able to try it out from this link:
https://notebooks.azure.com/anon-gmbcuq/libraries/riemann_book
https://notebooks.azure.com/rjleveque/libraries/riemann-book

Some issues:

Linking to figures using this markdown:

![Velocity as a function of density in the LWR traffic model.](./figures/LWR-Velocity.png)

as done in Traffic_flow.ipynb, for example, doesn't seem to work. But this does:

from IPython.display import Image
Image('./figures/LWR-Velocity.png')

Links to citations give a "page not found" error even though riemann.html exists.

Probably other issues I haven't run into yet...

riemann_tools.make_plot_function for primitive variables

@ketch I am trying to use riemann_tools.make_plot_function to plot the primitive variables for the Euler Tammann, but it does not scale the ranges properly since it does the scaling for the conserved variables.
In the example I am showing, the primitive variables are much more relevant than the conserved ones. It would be nice if we can add this functionality or at least some added parameter to force which plotting range is used. I have a couple of ideas on how to do this but thought to check with you in case I am missing something that is already there. Maybe forcing the plotting range could be a better choice, so we can also zoom in into very small waves.

Euler compare suggestions

@ketch I took a look at Euler compare suggestions. I think the plots look really nice, and they show what we want to show. However, I think it would benefit from a bit more text and explanations.

  • In the intro we should maybe add a brief intro to the shocktube problem and the blastwave problem since these are the examples we will use to compare the solutions.
  • I am not really sure what you mean by fine solution in the plots. Is that the exact solution from the solver, or is it the solution computed with clawpack but with a very fine grid?
  • Do we want to show all the code, or should we wrap it, so the user can only change the parameters that are relevant to them? Is the idea is that they go pyclaw all the way in this NB?
  • An additional cool figure could be an interact that shows the analytic solution of one of the problems at a fixed time, along with the HLL and ROE approximation solutions, where the slider modifies the number of grid points.
  • Maybe explain briefly what are high-order weno or at least add some references. We could also add the blastwave with Weno high-order?

I could help with some of this if you want.

Burgers interact

I took a look at the interact not working in burgers. The problems seems to be this line:

from utils.snapshot_widgets import interact
should be
from ipywidgets import interact

If we use the first one, we get the snapshots as we want right? If we use the second one then we get the interacts. If I remember correctly the script to produce the pdf changed all the from ipywidgets import interact to from utils.snapshot_widgets import interact. Maybe we should add to the script to revert everything once the pdf is generated.

I am happy to do that but just want to check with you guys since I didn't write that part, and I don't want to break anything else.

I also noticed an additional parameter was added to burgers_demos.multivalued_solution and burgers_demos.shock_location To fix the interact. I don't think this was necessary, we just need to change the import statement on the top of the notebook.

Should I just revert these changes to the original or am I missing something?

Use of red and blue colors in shallow water plots

Currently we use red and blue to distinguish water that started to the left/right of x=0. We also use these two colors to distinguish shocks/Hugoniot loci versus rarefactions/integral curves. I wonder if it would be better to change one of these to prevent the reader from thinking that they are somehow related.

For instance, we could just use blue and green in the shallow water plots.

Electronic material that needs to be adapted for the print book

There are a few things that still read funny in the PDF and need to be modified to work there:

  • At the end of the introduction, the interactive phase planes for acoustics and shallow water. Can we host these HTML files somewhere (Github doesn't seem to work for that) and put a hyperlink in?

Error pops up in plot_riemann for Traffic

Error comes up when plotting Riemann problem. For instance, when plotting the last example in traffic_flow notebook, if densities are chosen to zero, an error pops up. I think this has to do with how the axes-ranges are chosen. I also think it might be more educational if the x-axis range doesn't change when modifying the Riemann's problem initial condition. This way one can observe how the shock/rarefaction changes as function of the I.C. This concerns also the Burgers' equation notebook that I am working on.

mpl_toolkits?

The function util/riemann_tools.plot_phase_3d uses:

    from mpl_toolkits.mplot3d import Axes3D

This broke for a 574 student when trying to execute Euler_approximate_solvers.ipynb

mpl_toolkits apparently needs to be installed separately from matplotlib, although I think it is in the Anaconda distribution, for example.

Prepare book proposal

Electronic version:

  • Get electronic version working with Docker
  • Issue a new release of Clawpack to include new Riemann solvers and Python-3 compatible visclaw
  • Optional: Get electronic version working with Azure

Print version:

  • Decide what chapters to include in PDF proposal
  • Generate static plots for PDF version (probably using #64)
  • Generate PDF
  • correct any issues with PDF

Other necessary steps:

  • Finish writing Introduction
  • Choose title
  • Deal with any notational issues
  • Complete proposal form
  • submit to publisher

Plot styling

Following up on our discussion about font sizes and such in plots: matplotlib supports custom styles, and we can define our own. It's a bit unclear how to distribute a style in a way that is easy for the user to automatically load, so it may be better to try one of the built-in styles. I have provided a few examples here:

https://gist.github.com/ketch/c9286ed82a016ae6e371ee6afae5d918

I think the plots with darker backgrounds and grids might be nice in some situations, but for now maybe 'seaborn-talk' is a nice minimal modification; it just makes the fonts larger.

If you try checking styles yourself, please note that you shouldn't run different cells in succession; the style changes are cumulative.

Spacing before equations

In order to make the PDF look right (without unwanted paragraph breaks), many equations should be inserted without a blank line before or after them. But in the notebook this is problematic because the notebook's default MathJax configuration doesn't put any space above display math. See jupyter/notebook#392

Euler notebook revisions

We should:

  • Use 3D plots in the Euler equations notebook and discuss why we can just use the 2D projection
  • Use a different example in the approximate solvers notebook, so that the Roe speed doesn't 'happen' to be equal to the rarefaction speed.
  • Fix the auto scaling of the axes -- in at least one case the top of the momentum plot is cut off.

Tammann notebook issues

I noticed a few issues that I wasn't able to deal with myself:

  • It might be convenient to just work out everything for either the 1-wave and then say "similarly, for the 3-wave we obtain..." instead of keeping the parameters $k$ and $n$ everywhere.
  • In 6.1.2: "As the entropy is invariant" -- with respect to what?
  • Also in 6.1.2, there is a sentence "for numerical purposes" that seems a bit out of place since there are no other comments about numerical methods here.
  • Near the end of 6.1.2 instead of saying that the function $\Phi$ "might change in each iteration of the root finder", I think it would be nice (as we do elsewhere) to just define the function piecewise.
  • At the start of 6.1.4, the first equation reference: I'm not sure this is the equation we mean to refer to.
  • There is a reference near the beginning of 6.2.1 that is not defined in our bibliography.
  • The script F notation seems unnecessary -- can we dispense with it?

Things to do in multiple notebooks

A list of some things that we need to do still:

  1. Put github links for all exact_solvers codes in each notebook?
  2. If we put these in, modify fix_latex_file.py so it doesn't generate two footnotes with github links.
  3. Decide whether to use [Shallow_water.ipynb](Shallow_water.ipynb) to refer to other chapters, or [Shallow_water](Shallow_water.ipynb) and make consistent.
  4. We use subscripts q_l some places and q_\ell others. Make consistent.
  5. Add more references to other books or papers?
  6. Improve the looks of riemann.html generated by make_html_bib.sh. Currently the entries are put in the order they appear in riemann.bib, not in alphabetical order. Also some have first names, others not.
  7. Move utility scripts in utils and change links as needed.
  8. Make a set of files documenting how we do things and the tools we use, maybe as .md files in a doc folder? Fix the link to these in Preface.ipynb.
  9. Fix up the Dockerfile if necessary and make sure everything works on binder.

Second equation of subsection 9.1.3

The book "Riemann Problem and Jupyter Solutions" is thought-provoking and eye-opening and I really enjoy reading it. When I was reading subsection 9.1.3, I found that the subscript x for the second term in the second equation was omitted for some reason.

Comments and suggestions for Part II

@rjleveque @ketch I went over the second part, took me a bit longer than expected. I think it is overall in good shape, but of course there are a couple of thinks we could still improve. My comments/suggestions follow:

Chapter 11:

  • Sec 11.1, 4th paragraph: State explicitly what are R and \Lambda. Or at least cite Chapter 4, where we first introduce this diagonalization.
  • Sec 11.1, end: Should we cite notebooks not in printed version of the book like acoustics in heterogeneous media?
  • Before Sec 11.2 and Sec 11.3: maybe add a small paragraph saying that most approximate (if not all) Riemann solvers fall within two categories: linearized Riemann solvers and two (or more) wave solvers.
  • Sec 11.3: Mention that in some special cases additional waves can be added to the two-wave solvers (as is the case with the HLLC)

Chapter 12:

  • General comment: I think this notebook can be improved. It is nice we show the solutions using clawpack, but it will also be nice to show the actual solution of the approximate Riemann solver and maybe compare it with the exact solution. Specially in the case of the HLL, so it is clear it separates into three states. Also, if I am correct the HLL solver doesn't need an entropy fix for the transonic case. If so, maybe organizing the chapter differently could help make this clear. If it is ok with you, I'll give it a shot in improving this Chapter.

Chapter 13:

  • Sec 13.1.1, first paragraph: Maybe say explicitly that the averages must be chose to satisfy Property 3.
  • Sec 13.1.2, after first code section and before examples: Add subsection for Roe solver examples and maybe a brief description before each example.
  • Sec 13.2.2 examples, Same as before, maybe add a brief desription before each example: Dam-break, isolated 2-shock, transonic rarefaction
  • The interact from the last two code cells in the notebook doesn't work.

Chapter 14:

  • Second paragraph: When mentioning the Energy is given by the relation 14.4, maybe also add the ideal gas equation of state for reference.
    Sec 14.1, first paragraph. Reference as in Chapter not working in pdf. Maybe this is already fixed in latest version of make_pdf.
    Sec 14.2 HLLE Solver: Many parts uses HLL instead of HLLE. I know it is basically the same, but maybe somewhat confusing to have the two acronyms. Maybe change all to HLLE since we are using the HLLE choice of wave speed.
    Maybe add the HLLC/HLLEC solver as an example of a three wave HLL solver. I am happy to do this.

Chapter 15:

  • In first part, maybe add a brief description before the large chunk of code of wat this code does.
  • In all the interacts, maybe we can add a tab to choose if we want to plot density, momentum or energy, so the reader can also see how the solvers perform on the other variables. I am happy to implement this.
  • Sec 15.2, High-order WENO, a longer but still brief explanation of how these methods work would be nice to have in the beggining of this Section.

I can contribute by trying improvements on Burgers approximate, adding the HLLC solver to the Euler compare and adding a tab to choose density/momentum or energy in the interacts of Chapter 15. If this is ok with you since you wrote these chapters, I am happy to implement these, so please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.