Skip to content

Commit

Permalink
Merge pull request #1083 from ferranbrosa/issue-1079-update-getting-s…
Browse files Browse the repository at this point in the history
…tarted-notebooks

Issue 1079 update getting started notebooks
  • Loading branch information
valentinsulzer authored Jun 30, 2020
2 parents cc5d9f1 + 3d9390e commit 7f35218
Show file tree
Hide file tree
Showing 12 changed files with 2,018 additions and 660 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Reformatted Getting Starte notebooks ([#1083](https://github.com/pybamm-team/PyBaMM/pull/1083))
- Reformatted Landesfeind electrolytes ([#1064](https://github.com/pybamm-team/PyBaMM/pull/1064))
- Adapted examples to be run in Google Colab ([#1061](https://github.com/pybamm-team/PyBaMM/pull/1061))
- Added some new solvers for algebraic models ([#1059](https://github.com/pybamm-team/PyBaMM/pull/1059))
Expand All @@ -17,7 +18,7 @@
- Fix `QuickPlot` to display variables discretised by FEM (in y-z) properly ([#1078](https://github.com/pybamm-team/PyBaMM/pull/1078))
- Add length scales to `EffectiveResistance` models ([#1071](https://github.com/pybamm-team/PyBaMM/pull/1071))
- Allowed for pybamm functions exp, sin, cos, sqrt to be used in expression trees that
are converted to casadi format ([#1067](https://github.com/pybamm-team/PyBaMM/pull/1067)
are converted to casadi format ([#1067](https://github.com/pybamm-team/PyBaMM/pull/1067))
- Fix a bug where variables that depend on y and z were transposed in `QuickPlot` ([#1055](https://github.com/pybamm-team/PyBaMM/pull/1055))

## Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install pybamm -q # install PyBaMM if it is not installed\n",
"import pybamm"
Expand All @@ -32,7 +40,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We now load the model that we wish to run. For this notebook, we choose the single particle model with electrolyte (SPMe):"
"We now load the model that we wish to run. For this notebook, we choose the Doyle-Fuller-Newman (DFN) model:"
]
},
{
Expand All @@ -41,7 +49,7 @@
"metadata": {},
"outputs": [],
"source": [
"model = pybamm.lithium_ion.SPMe()"
"model = pybamm.lithium_ion.DFN()"
]
},
{
Expand Down Expand Up @@ -71,7 +79,18 @@
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"<pybamm.solvers.solution.Solution at 0x7fa3273a5a90>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sim.solve()"
]
Expand All @@ -91,12 +110,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "089df7a7f1f24690b734df6cf83bd550",
"model_id": "1c41a48411a94ff9a6fc19096bb4a0f5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.9999999999999999, step=0.05), Output()), _"
"interactive(children=(FloatSlider(value=0.0, description='t', max=3599.9999999999995, step=35.99999999999999),"
]
},
"metadata": {},
Expand All @@ -113,22 +132,15 @@
"source": [
"In this tutorial, we have solved a model with the inbuilt default settings. However, PyBaMM is designed to be highly customisable. Over the course of the getting started tutorials, we will see how various settings can be changed so that the model is appropriate for your situation. \n",
"\n",
"In [Tutorial 2](./Tutorial%202%20-%20Setting%20Parameter%20Values.ipynb) we cover setting and changing parameter values."
"In [Tutorial 2](./Tutorial%202%20-%20Compare%20models.ipynb) we cover how to simulate and compare different models."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "PyBaMM development (env)",
"language": "python",
"name": "python3"
"name": "pybamm-dev"
},
"language_info": {
"codemirror_mode": {
Expand Down
147 changes: 147 additions & 0 deletions examples/notebooks/Getting Started/Tutorial 2 - Compare models.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Tutorial 2 - Compare models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In [Tutorial 1](./Tutorial%201%20-%20How%20to%20run%20a%20model.ipynb), we saw how to run a PyBaMM simulation of the DFN model. However, PyBaMM includes other standard electrochemical models such as the Single Particle Model (SPM) and the Single Particle Model with electrolyte (SPMe). In this tutorial, we will see how to simulate and compare these three models. \n",
"\n",
"Again, the first step is to import the pybamm library into the notebook:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install pybamm -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We start creating a list of all the models we wish to solve"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"models = [\n",
" pybamm.lithium_ion.SPM(),\n",
" pybamm.lithium_ion.SPMe(),\n",
" pybamm.lithium_ion.DFN(),\n",
"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and now we can loop over the list, creating and solving simulations as we go. The solved simulations are stored in the list `sims`"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"sims = []\n",
"for model in models:\n",
" sim = pybamm.Simulation(model)\n",
" sim.solve()\n",
" sims.append(sim)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now pass our list of simulations to the dynamic plot method, which will plot the different outputs in the same figure"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "63e7fa6511714626abc1173c35aad054",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=3599.9999999999995, step=35.99999999999999),…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f089bff9518>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pybamm.dynamic_plot(sims, time_unit=\"seconds\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this tutorial we have seen how easy it is to run and compare different electrochemical models. In [Tutorial 3](./Tutorial%203%20-%20Basic%20plotting.ipynb) we cover how to simulate and compare different models."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "PyBaMM development (env)",
"language": "python",
"name": "pybamm-dev"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 7f35218

Please sign in to comment.