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

Issue 569 create model notebooks #877

Merged
merged 11 commits into from
Mar 11, 2020
Merged

Conversation

rtimms
Copy link
Contributor

@rtimms rtimms commented Mar 10, 2020

Description

Added some more notebooks covering creating models, and comparing full and reduced-order models. Also fixes some typos in other notebooks

Fixes #569 #672

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Mar 10, 2020

Codecov Report

Merging #877 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #877   +/-   ##
========================================
  Coverage    97.79%   97.79%           
========================================
  Files          210      210           
  Lines        10585    10587    +2     
========================================
+ Hits         10352    10354    +2     
  Misses         233      233           
Impacted Files Coverage Δ
...bamm/models/full_battery_models/lithium_ion/dfn.py 100.00% <ø> (ø)
...bamm/models/full_battery_models/lithium_ion/spm.py 100.00% <ø> (ø)
...amm/models/full_battery_models/lithium_ion/spme.py 100.00% <ø> (ø)
...bamm/parameters/standard_parameters_lithium_ion.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eae19f2...b8ebc9c. Read the comment docs.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks Rob, that's all very clear, just a few comments

"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the keys of this dictionary are strings (i.e. the names of the variables). The model is now completely defined and is ready to be discretised and solved!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could point out the "name" here can be different to the string passed to define the variable

],
"source": [
"disc = pybamm.Discretisation() # use the default discretisation\n",
"disc.process_model(model)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use ; to suppress output

"cell_type": "markdown",
"metadata": {},
"source": [
"We then create a mesh using the `pybamm.MeshGenerator` class. As inputs this class takes the type of mesh and any parameters required by the mesh. In this case we choose a uniform one-dimensional mesh which doesn't require any parameters. Example of meshes that do require parameters include the `pybamm.Exponential1DSubMesh` which clusters points close to one or both boundaries using an exponential rule. It takes a parameter which sets how closely the points are clustered together. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe show an inline example of the exponential 1D submesh?

" \"negative particle\": {\n",
" \"primary\": {r: {\"min\": pybamm.Scalar(0), \"max\": pybamm.Scalar(1)}}\n",
" }\n",
"}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this issue but it feels like there's one too many nested dictionaries in the geometry. I can't think of how to reformat to make it clearer while keeping the existing functionality, but maybe someone else can?

"cell_type": "markdown",
"metadata": {},
"source": [
"In the [next notebook](/5-comparing-full-and-reduced-order-models.ipynb) we consider the limit of fast diffusion in the particle. This leads to a reduced-order model for the particle behaviour, which we compare with the full (Fickian diffusion) model. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this link is broken (should be 4- not 5-)

"source": [
"We can now populate the variables dictionary of both models with any variables of interest. We can compute the average concentration in the full model using the operator `pybamm.r_average`. We may also wish to compare the concentration profile predicted by the full model with the uniform concentration profile predicted by the reduced model. We can use the operator `pybamm.PrimaryBroadcast` to broadcast the scalar valued uniform concentration across the particle domain so that it can be visualised as a function of $r$. \n",
"\n",
"Note: the \"Primary\" refers to the fact the we are broadcasting in only one dimension. For some models, such as the DFN, variables may depend on a \"pseudo-dimension\" (e.g. the position in $x$ across the cell), but spatial operators only act in the \"primary dimension\" (e.g. the position ion $r$ within the particle). If you are unfamiliar with battery models, do not worry, the details of this are not important for this example. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to the broadcasts notebook (in the expression tree folder)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a typo where it says "(e.g. the position ion $r$ ...".

"cell_type": "markdown",
"metadata": {},
"source": [
"In the [next notebook](/5-a-simple-SEI-model.ipynb) we consider a simple model for SEI growth, and show how to correctly pose the model in non-dimensional form and then create and solve it using pybamm."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this link is also broken

"| $c_0$ | mol m$^{-3}$ | $2.5 \\times 10^{4}$ |\n",
"\n"
]
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment on the fact that all battery models in pybamm are dimensionless for better numerical conditioning and that this will be explained further in [link to notebook]

Copy link
Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job Rob!

I encountered some issues when rendering it in GitHub, not sure if this is just me or if I should be doing it in another way. If so, please just ignore those comments.

Apart from that, just a few typos and also the references format are not consistent: the DFN paper appears at the very end of the notebook while the Marquis et al. paper appears right after it has been referenced.

]
},
{
"cell_type": "code",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this final code cell necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed it appears in other notebooks too

"In the [previous notebook](./1-an-ode-model.ipynb) we show how to create, discretise and solve an ODE model in pybamm. In this notebook we show how to create and solve a PDE problem, which will require meshing of the spatial domain.\n",
"\n",
"As an example, we consider the problem of linear diffusion on a unit sphere,\n",
"\\begin{equation*}\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LaTeX equation does not render (at least to me) when I visualise it in GitHub. The one in the ODE example worked fine, it might be a syntax issue...

"metadata": {},
"source": [
"In the [previous notebook](./2-a-pde-model.ipynb) we saw how to solve a PDE model in pybamm. Now it is time to solve a real-life battery problem! We consider the problem of spherical diffusion in the negative electrode particle within the single particle model. That is,\n",
"\\begin{equation*}\n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the previous notebook, they do not render to me.

"source": [
"We can now populate the variables dictionary of both models with any variables of interest. We can compute the average concentration in the full model using the operator `pybamm.r_average`. We may also wish to compare the concentration profile predicted by the full model with the uniform concentration profile predicted by the reduced model. We can use the operator `pybamm.PrimaryBroadcast` to broadcast the scalar valued uniform concentration across the particle domain so that it can be visualised as a function of $r$. \n",
"\n",
"Note: the \"Primary\" refers to the fact the we are broadcasting in only one dimension. For some models, such as the DFN, variables may depend on a \"pseudo-dimension\" (e.g. the position in $x$ across the cell), but spatial operators only act in the \"primary dimension\" (e.g. the position ion $r$ within the particle). If you are unfamiliar with battery models, do not worry, the details of this are not important for this example. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a typo where it says "(e.g. the position ion $r$ ...".

"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"![SEI.png](attachment:SEI.png)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image doesn't render

"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"Once we have stated the equations, we can add them to the `model.rhs` dictionary. This is a dictionary which stores the right had sides of the governing equations. Each key in the dictionary corresponds to the variable which the equation is being solved for."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "right hand side"

"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"We can also output the dimensional versions of these variables by multiplying by the scalings in the Non-dimensionalisation section. By convention, we recommend include in the units in the output variables name so that they do not overwrite the dimensionless output variables. We also `.update` the disctionary so that we add to the previous output variables."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: it should be "dictionary"

"deletable": true,
"editable": true
},
"metadata": {},
"source": [
"And thats it, the model is fully defined and ready to be used. If you plan on reusing the model several times, you can additionally set model defaults which include: a default geometry to run the model on, a default set of parameter values, a default solver, etc."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "that's"

@@ -18,7 +18,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The SPM consists of two spherically symmetric diffusion equations: one within a representative negative particle ($\\text{k}=\\text{n}$) and one within a representative positive particle ($\\text{k}=\\text{p}$). In the centre of the particle the classical no-flux condition is imposed. Since the SPM assumes that all particles in an electrode behave in exactly the same way, the flux on the surface of a particle is simply the current $I$ divided by the thickness of the electrode $L_{\\text{k}}$. The concentration of lithium in electrode $\\text{k}$ is denoted $c_{\\text{k}}$ and the current is denoted by $I$. All parameters in the model stated here are dimensionless and are given in terms of dimensional parameters at the end of this notebook. The model equations for the SPM are then: \n",
"The SPM consists of two spherically symmetric diffusion equations: one within a representative negative particle ($\\text{k}=\\text{n}$) and one within a representative positive particle ($\\text{k}=\\text{p}$). In the centre of the particle the standard no-flux condition is imposed. Since the SPM assumes that all particles in an electrode behave in exactly the same way, the flux on the surface of a particle is simply the current $I$ divided by the thickness of the electrode $L_{\\text{k}}$. The concentration of lithium in electrode $\\text{k}$ is denoted $c_{\\text{k}}$ and the current is denoted by $I$. All parameters in the model stated here are dimensionless and are given in terms of dimensional parameters at the end of this notebook. The model equations for the SPM are then: \n",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one does not render either.

@rtimms
Copy link
Contributor Author

rtimms commented Mar 11, 2020

I encountered some issues when rendering it in GitHub, not sure if this is just me or if I should be doing it in another way. If so, please just ignore those comments.

I always have problems viewing notebooks directly in github. I'm not sure what the fix is for this?

@brosaplanella
Copy link
Member

I encountered some issues when rendering it in GitHub, not sure if this is just me or if I should be doing it in another way. If so, please just ignore those comments.

I always have problems viewing notebooks directly in github. I'm not sure what the fix is for this?

I don't know either. If they look fine locally then it is OK. I guess they will work fine in the JupyterHub (is it up and running already?)

@rtimms
Copy link
Contributor Author

rtimms commented Mar 11, 2020

I don't know either. If they look fine locally then it is OK. I guess they will work fine in the JupyterHub (is it up and running already?)

It is up, but not "live"

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge when ready!

@rtimms rtimms merged commit 14dff27 into develop Mar 11, 2020
@rtimms rtimms deleted the issue-569-create-model-notebooks branch March 11, 2020 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sequence of jupyter notebooks / other types of documentation for model creation
3 participants