Skip to content

Commit 1b42969

Browse files
committed
#759 merge master
2 parents fba1294 + 93b3b25 commit 1b42969

File tree

65 files changed

+2972
-3182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2972
-3182
lines changed

.requirements-docs.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ scikit-fem>=0.2.0
88
casadi>=3.5.0
99
guzzle-sphinx-theme
1010
sphinx>=1.5
11+
python-Levenshtein>=0.12.0

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ matrix:
7979
env:
8080
- PYBAMM_UNIT=true
8181
- PYBAMM_SCIKITS_ODES=true
82-
# Unit testing on Python3.7 on Ubuntu without scikit odes
82+
- PYBAMM_KLU=true
83+
# Unit and example testing on Python3.7 on Ubuntu without optional dependencies
8384
- python: "3.7"
8485
addons:
8586
apt:
@@ -95,6 +96,7 @@ matrix:
9596
- libsuitesparse-dev
9697
env:
9798
- PYBAMM_UNIT=true
99+
- PYBAMM_EXAMPLES=true
98100
if: type != cron
99101
# Cover, docs and style checking, latest Python version only
100102
- python: "3.7"

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Features
44

5+
- Added fuzzy string matching for parameters and variables ([#796](https://github.com/pybamm-team/PyBaMM/pull/796))
6+
- Changed ParameterValues to raise an error when a parameter that wasn't previously defined is updated ([#796](https://github.com/pybamm-team/PyBaMM/pull/796))
7+
- Added some basic models (BasicSPM and BasicDFN) in order to clearly demonstrate the PyBaMM model structure for battery models ([#795](https://github.com/pybamm-team/PyBaMM/pull/795))
58
- Added the harmonic mean to the Finite Volume method, which is now used when computing fluxes ([#783](https://github.com/pybamm-team/PyBaMM/pull/783))
69
- Refactored `Solution` to make it a dictionary that contains all of the solution variables. This automatically creates `ProcessedVariable` objects when required, so that the solution can be obtained much more easily. ([#781](https://github.com/pybamm-team/PyBaMM/pull/781))
710
- Added notebook to explain broadcasts ([#776](https://github.com/pybamm-team/PyBaMM/pull/776))
@@ -33,6 +36,7 @@
3336

3437
## Optimizations
3538

39+
- Simplified solver interface ([#800](https://github.com/pybamm-team/PyBaMM/pull/800))
3640
- Added caching for shape evaluation, used during discretisation ([#780](https://github.com/pybamm-team/PyBaMM/pull/780))
3741
- Added an option to skip model checks during discretisation, which could be slow for large models ([#739](https://github.com/pybamm-team/PyBaMM/pull/739))
3842
- Use CasADi's automatic differentation algorithms by default when solving a model ([#714](https://github.com/pybamm-team/PyBaMM/pull/714))
@@ -41,6 +45,8 @@
4145

4246
## Bug fixes
4347

48+
- Fixed examples to run with basic pip installation ([#800](https://github.com/pybamm-team/PyBaMM/pull/800))
49+
- Added events for CasADi solver when stepping ([#800](https://github.com/pybamm-team/PyBaMM/pull/800))
4450
- Improved implementation of broadcasts ([#776](https://github.com/pybamm-team/PyBaMM/pull/776))
4551
- Fixed a bug which meant that the Ohmic heating in the current collectors was incorrect if using the Finite Element Method ([#767](https://github.com/pybamm-team/PyBaMM/pull/767))
4652
- Improved automatic broadcasting ([#747](https://github.com/pybamm-team/PyBaMM/pull/747))

docs/source/expression_tree/variable.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Variable
33

44
.. autoclass:: pybamm.Variable
55
:members:
6+
7+
.. autoclass:: pybamm.ExternalVariable
8+
:members:

docs/source/models/lithium_ion/dfn.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Doyle-Fuller-Newman (DFN)
33

44
.. autoclass:: pybamm.lithium_ion.DFN
55
:members:
6+
7+
.. autoclass:: pybamm.lithium_ion.BasicDFN
8+
:members:

docs/source/models/lithium_ion/spm.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Single Particle Model (SPM)
33

44
.. autoclass:: pybamm.lithium_ion.SPM
55
:members:
6+
7+
.. autoclass:: pybamm.lithium_ion.BasicSPM
8+
:members:

docs/source/solvers/base_solvers.rst

-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@ Base Solvers
33

44
.. autoclass:: pybamm.BaseSolver
55
:members:
6-
7-
.. autoclass:: pybamm.OdeSolver
8-
:members:
9-
10-
.. autoclass:: pybamm.DaeSolver
11-
:members:

docs/tutorials/add-solver.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,29 @@ The role of solvers is to solve a model at a given set of time points, returning
2727
Base solver classes vs specific solver classes
2828
----------------------------------------------
2929

30-
There is one general base solver class, :class:`pybamm.BaseSolver`, and two specialised base classes, :class:`pybamm.OdeSolver` and :class:`pybamm.DaeSolver`. The general base class simply sets up some useful solver properties such as tolerances. The specialised base classes implement a method :meth:`self.solve()` that solves a model at a given set of time points.
30+
There is one general base solver class, :class:`pybamm.BaseSolver`, which sets up some useful solver properties such as tolerances and implement a method :meth:`self.solve()` that solves a model at a given set of time points.
3131

3232
The ``solve`` method unpacks the model, simplifies it by removing extraneous operations, (optionally) creates or calls the mass matrix and/or jacobian, and passes the appropriate attributes to another method, called ``integrate``, which does the time-stepping. The role of specific solver classes is simply to implement this ``integrate`` method for an arbitrary set of derivative function, initial conditions etc.
3333

34-
The base DAE solver class also computes a consistent set of initial conditions for the algebraic equations, using ``model.concatenated_initial_conditions`` as an initial guess.
34+
The base solver class also computes a consistent set of initial conditions for the algebraic equations, using ``model.concatenated_initial_conditions`` as an initial guess.
3535

3636
Implementing a new solver
3737
-------------------------
3838

3939
To add a new solver (e.g. My Fast DAE Solver), first create a new file (``my_fast_dae_solver.py``) in ``pybamm/solvers/``,
40-
with a single class that inherits from either :class:`pybamm.OdeSolver` or :class:`pybamm.DaeSolver`, depending on whether the new solver can solve DAE systems. For example:
40+
with a single class that inherits from :class:`pybamm.BaseSolver`. For example:
4141

4242
.. code-block:: python
4343
44-
def MyFastDaeSolver(pybamm.DaeSolver):
44+
def MyFastDaeSolver(pybamm.BaseSolver):
4545
4646
Also add the class to ``pybamm/__init__.py``:
4747

4848
.. code-block:: python
4949
5050
from .solvers.my_fast_dae_solver import MyFastDaeSolver
5151
52-
You can then start implementing the solver by adding the ``integrate`` function to the class (the interfaces are slightly different for an ODE Solver and a DAE Solver, see :meth:`pybamm.OdeSolver.integrate` vs :meth:`pybamm.DaeSolver.integrate`)
52+
You can then start implementing the solver by adding the ``integrate`` function to the class.
5353

5454
For an example of an existing solver implementation, see the Scikits DAE solver
5555
`API docs <https://pybamm.readthedocs.io/en/latest/source/solvers/scikits_solvers.html>`_

examples/notebooks/README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ The following notebooks are specific to different stages of the PyBaMM pipeline,
4848

4949
### Models
5050

51-
The following models are implemented and can easily be used or [compared](./models/lead-acid.ipynb). We always welcome [new models](https://pybamm.readthedocs.io/en/latest/tutorials/add-model.html)!
51+
Several battery models are implemented and can easily be used or [compared](./models/lead-acid.ipynb). The notebooks below show the solution of each individual model. We always welcome [new models](https://pybamm.readthedocs.io/en/latest/tutorials/add-model.html)!
52+
53+
Once you are comfortable with the expression tree structure, a good starting point to understand the models in PyBaMM is to take a look at the [basic SPM](https://github.com/pybamm-team/PyBaMM/blob/master/pybamm/models/full_battery_models/lithium_ion/basic_spm.py) and [basic DFN](https://github.com/pybamm-team/PyBaMM/blob/master/pybamm/models/full_battery_models/lithium_ion/basic_dfn.py), since these define the entire model (variables, equations, initial and boundary conditions, events) in a single class and so are easier to understand. However, we recommend that you subsequently use the full models as they offer much greater flexibility for coupling different physical effects and visualising a greater range of variables.
5254

5355
#### Lithium-ion models
5456

@@ -72,10 +74,9 @@ See [here](https://pybamm.readthedocs.io/en/latest/tutorials/add-spatial-method.
7274

7375
### Solvers
7476

75-
The following solvers are implemented
76-
- Scipy ODE solver
77-
- [Scikits ODE solver](./solvers/scikits-ode-solver.ipynb)
78-
- [Scikits DAE solver](./solvers/scikits-dae-solver.ipynb)
79-
- CasADi DAE solver
77+
The following notebooks show examples for generic ODE and DAE solvers. Several solvers are implemented in PyBaMM and we encourage users to try different ones to find the most appropriate one for their models.
78+
79+
- [ODE solver](./solvers/ode-solver.ipynb)
80+
- [DAE solver](./solvers/dae-solver.ipynb)
8081

8182
See [here](https://pybamm.readthedocs.io/en/latest/tutorials/add-solver.html) for instructions on adding new solvers.

examples/notebooks/change-settings.ipynb

+39-19
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@
123123
"cell_type": "code",
124124
"execution_count": 3,
125125
"metadata": {},
126+
"outputs": [
127+
{
128+
"data": {
129+
"text/plain": [
130+
"<bound method ParameterValues.items of <pybamm.parameters.parameter_values.ParameterValues object at 0x1113519e8>>"
131+
]
132+
},
133+
"execution_count": 3,
134+
"metadata": {},
135+
"output_type": "execute_result"
136+
}
137+
],
138+
"source": [
139+
"model.default_parameter_values.items"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": 4,
145+
"metadata": {},
126146
"outputs": [
127147
{
128148
"name": "stdout",
@@ -155,8 +175,8 @@
155175
"Typical current [A] 0.680616\n",
156176
"Negative electrode conductivity [S.m-1] 100.0\n",
157177
"Maximum concentration in negative electrode [mol.m-3] 24983.2619938437\n",
158-
"Negative electrode diffusivity [m2.s-1] <function graphite_mcmb2528_diffusivity_Dualfoil1998 at 0x13e6f9840>\n",
159-
"Negative electrode OCP [V] <function graphite_mcmb2528_ocp_Dualfoil1998 at 0x13e6f96a8>\n",
178+
"Negative electrode diffusivity [m2.s-1] <function graphite_mcmb2528_diffusivity_Dualfoil1998 at 0x13dad4400>\n",
179+
"Negative electrode OCP [V] <function graphite_mcmb2528_ocp_Dualfoil1998 at 0x13dad4598>\n",
160180
"Negative electrode porosity 0.3\n",
161181
"Negative electrode active material volume fraction 0.7\n",
162182
"Negative particle radius [m] 1e-05\n",
@@ -173,15 +193,15 @@
173193
"Negative electrode density [kg.m-3] 1657.0\n",
174194
"Negative electrode specific heat capacity [J.kg-1.K-1] 700.0\n",
175195
"Negative electrode thermal conductivity [W.m-1.K-1] 1.7\n",
176-
"Negative electrode OCP entropic change [V.K-1] <function graphite_entropic_change_Moura2016 at 0x13e6f9730>\n",
196+
"Negative electrode OCP entropic change [V.K-1] <function graphite_entropic_change_Moura2016 at 0x13dad4488>\n",
177197
"Reference temperature [K] 298.15\n",
178-
"Negative electrode reaction rate <function graphite_electrolyte_reaction_rate_Dualfoil1998 at 0x13e6f98c8>\n",
198+
"Negative electrode reaction rate <function graphite_electrolyte_reaction_rate_Dualfoil1998 at 0x13dad4620>\n",
179199
"Negative reaction rate activation energy [J.mol-1] 37480.0\n",
180200
"Negative solid diffusion activation energy [J.mol-1] 42770.0\n",
181201
"Positive electrode conductivity [S.m-1] 10.0\n",
182202
"Maximum concentration in positive electrode [mol.m-3] 51217.9257309275\n",
183-
"Positive electrode diffusivity [m2.s-1] <function lico2_diffusivity_Dualfoil1998 at 0x13e6f97b8>\n",
184-
"Positive electrode OCP [V] <function lico2_ocp_Dualfoil1998 at 0x13e6f9950>\n",
203+
"Positive electrode diffusivity [m2.s-1] <function lico2_diffusivity_Dualfoil1998 at 0x13dad4510>\n",
204+
"Positive electrode OCP [V] <function lico2_ocp_Dualfoil1998 at 0x13dad46a8>\n",
185205
"Positive electrode porosity 0.3\n",
186206
"Positive electrode active material volume fraction 0.7\n",
187207
"Positive particle radius [m] 1e-05\n",
@@ -198,8 +218,8 @@
198218
"Positive electrode density [kg.m-3] 3262.0\n",
199219
"Positive electrode specific heat capacity [J.kg-1.K-1] 700.0\n",
200220
"Positive electrode thermal conductivity [W.m-1.K-1] 2.1\n",
201-
"Positive electrode OCP entropic change [V.K-1] <function lico2_entropic_change_Moura2016 at 0x13e6f9a60>\n",
202-
"Positive electrode reaction rate <function lico2_electrolyte_reaction_rate_Dualfoil1998 at 0x13e6f9ae8>\n",
221+
"Positive electrode OCP entropic change [V.K-1] <function lico2_entropic_change_Moura2016 at 0x13dad47b8>\n",
222+
"Positive electrode reaction rate <function lico2_electrolyte_reaction_rate_Dualfoil1998 at 0x13dad4840>\n",
203223
"Positive reaction rate activation energy [J.mol-1] 39570.0\n",
204224
"Positive solid diffusion activation energy [J.mol-1] 18550.0\n",
205225
"Separator porosity 1.0\n",
@@ -210,8 +230,8 @@
210230
"Separator thermal conductivity [W.m-1.K-1] 0.16\n",
211231
"Typical electrolyte concentration [mol.m-3] 1000.0\n",
212232
"Cation transference number 0.4\n",
213-
"Electrolyte diffusivity [m2.s-1] <function electrolyte_diffusivity_Capiglia1999 at 0x13e6f9c80>\n",
214-
"Electrolyte conductivity [S.m-1] <function electrolyte_conductivity_Capiglia1999 at 0x13e6f99d8>\n",
233+
"Electrolyte diffusivity [m2.s-1] <function electrolyte_diffusivity_Capiglia1999 at 0x13dad49d8>\n",
234+
"Electrolyte conductivity [S.m-1] <function electrolyte_conductivity_Capiglia1999 at 0x13dad4730>\n",
215235
"Electrolyte diffusion activation energy [J.mol-1] 37040.0\n",
216236
"Electrolyte conductivity activation energy [J.mol-1] 34700.0\n",
217237
"Heat transfer coefficient [W.m-2.K-1] 10.0\n",
@@ -250,7 +270,7 @@
250270
},
251271
{
252272
"cell_type": "code",
253-
"execution_count": 4,
273+
"execution_count": 5,
254274
"metadata": {},
255275
"outputs": [
256276
{
@@ -282,7 +302,7 @@
282302
},
283303
{
284304
"cell_type": "code",
285-
"execution_count": 5,
305+
"execution_count": 6,
286306
"metadata": {},
287307
"outputs": [],
288308
"source": [
@@ -298,7 +318,7 @@
298318
},
299319
{
300320
"cell_type": "code",
301-
"execution_count": 6,
321+
"execution_count": 7,
302322
"metadata": {},
303323
"outputs": [],
304324
"source": [
@@ -314,7 +334,7 @@
314334
},
315335
{
316336
"cell_type": "code",
317-
"execution_count": 7,
337+
"execution_count": 8,
318338
"metadata": {},
319339
"outputs": [
320340
{
@@ -352,7 +372,7 @@
352372
},
353373
{
354374
"cell_type": "code",
355-
"execution_count": 8,
375+
"execution_count": 9,
356376
"metadata": {},
357377
"outputs": [
358378
{
@@ -384,7 +404,7 @@
384404
},
385405
{
386406
"cell_type": "code",
387-
"execution_count": 9,
407+
"execution_count": 10,
388408
"metadata": {},
389409
"outputs": [],
390410
"source": [
@@ -408,7 +428,7 @@
408428
},
409429
{
410430
"cell_type": "code",
411-
"execution_count": 10,
431+
"execution_count": 11,
412432
"metadata": {},
413433
"outputs": [
414434
{
@@ -453,7 +473,7 @@
453473
},
454474
{
455475
"cell_type": "code",
456-
"execution_count": 11,
476+
"execution_count": 12,
457477
"metadata": {},
458478
"outputs": [
459479
{
@@ -477,7 +497,7 @@
477497
},
478498
{
479499
"cell_type": "code",
480-
"execution_count": 12,
500+
"execution_count": 13,
481501
"metadata": {},
482502
"outputs": [
483503
{

examples/notebooks/parameter-values.ipynb

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"name": "stdout",
4848
"output_type": "stream",
4949
"text": [
50-
"parameter values are {'a': 1, 'b': 2, 'c': 3}\n"
50+
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e0f0>\n"
5151
]
5252
}
5353
],
@@ -73,7 +73,7 @@
7373
"name": "stdout",
7474
"output_type": "stream",
7575
"text": [
76-
"parameter values are {'a': 4, 'b': 5, 'c': 6}\n"
76+
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
7777
]
7878
}
7979
],
@@ -126,7 +126,7 @@
126126
"cell_type": "markdown",
127127
"metadata": {},
128128
"source": [
129-
"We can input functions into the parameter values, either directly"
129+
"We can input functions into the parameter values, either directly (note we bypass the check that the parameter already exists)"
130130
]
131131
},
132132
{
@@ -138,14 +138,14 @@
138138
"name": "stdout",
139139
"output_type": "stream",
140140
"text": [
141-
"parameter values are {'a': 4, 'b': 5, 'c': 6, 'cube function': <function cubed at 0x136260a60>}\n"
141+
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
142142
]
143143
}
144144
],
145145
"source": [
146146
"def cubed(x):\n",
147147
" return x ** 3\n",
148-
"parameter_values.update({\"cube function\": cubed})\n",
148+
"parameter_values.update({\"cube function\": cubed}, check_already_exists=False)\n",
149149
"print(\"parameter values are {}\".format(parameter_values))"
150150
]
151151
},
@@ -165,7 +165,7 @@
165165
"name": "stdout",
166166
"output_type": "stream",
167167
"text": [
168-
"parameter values are {'a': 4, 'b': 5, 'c': 6, 'cube function': <function cubed at 0x136260a60>, 'square function': <function squared at 0x136260ae8>}\n"
168+
"parameter values are <pybamm.parameters.parameter_values.ParameterValues object at 0x13dd5e860>\n"
169169
]
170170
}
171171
],
@@ -178,7 +178,7 @@
178178
"\"\"\"\n",
179179
")\n",
180180
"f.close()\n",
181-
"parameter_values.update({\"square function\": pybamm.load_function(\"squared.py\")})\n",
181+
"parameter_values.update({\"square function\": pybamm.load_function(\"squared.py\")}, check_already_exists=False)\n",
182182
"print(\"parameter values are {}\".format(parameter_values))"
183183
]
184184
},
@@ -405,7 +405,7 @@
405405
{
406406
"data": {
407407
"text/plain": [
408-
"{Variable(-0x53753a8d5f6f95de, u, children=[], domain=[], auxiliary_domains={}): Multiplication(0x3e1bde14593f44cc, *, children=['-a', 'y[0:1]'], domain=[], auxiliary_domains={})}"
408+
"{Variable(0x1b4aef6f668c631, u, children=[], domain=[], auxiliary_domains={}): Multiplication(-0x36caade7fdf02dac, *, children=['-a', 'y[0:1]'], domain=[], auxiliary_domains={})}"
409409
]
410410
},
411411
"execution_count": 12,

0 commit comments

Comments
 (0)