Skip to content

Commit

Permalink
Merge branch 'develop' into i2643-banded
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Feb 17, 2023
2 parents 5faa557 + c9e2a45 commit 664a024
Show file tree
Hide file tree
Showing 119 changed files with 1,026 additions and 783 deletions.
13 changes: 12 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,18 @@
"avatar_url": "https://avatars.githubusercontent.com/u/112731474?v=4",
"profile": "https://github.com/iatzak",
"contributions": [
"doc"
"doc",
"bug",
"code"
]
},
{
"login": "ayeankit",
"name": "Ankit Kumar",
"avatar_url": "https://avatars.githubusercontent.com/u/72691866?v=4",
"profile": "https://github.com/ayeankit",
"contributions": [
"code"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/url_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: URLs-checker
uses: urlstechie/urlchecker-action@0.0.31
uses: urlstechie/urlchecker-action@master
with:
# A comma-separated list of file types to cover in the URL checks
file_types: .rst,.md,.py,.ipynb
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.DS_Store
*.mat
*.csv
*.hidden

# don't ignore important .txt and .csv files
!requirements*
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ repos:
exclude: assets/js/webapp\.js

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.237"
rev: "v0.0.246"
hooks:
- id: ruff
args: [--ignore=E741, --exclude=__init__.py]
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Features

- Added temperature control to experiment class. ([#2518])(https://github.com/pybamm-team/PyBaMM/pull/2518)
- The "particle size" option can now be a tuple to allow different behaviour in each electrode([#2672](https://github.com/pybamm-team/PyBaMM/pull/2672)).

## Bug fixes

- Fixed the length scaling for the first dimension of r-R plots ([#2663](https://github.com/pybamm-team/PyBaMM/pull/2663)).

# [v23.1](https://github.com/pybamm-team/PyBaMM/tree/v23.1) - 2023-01-31

## Features
Expand Down
103 changes: 53 additions & 50 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion benchmarks/different_model_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class TimeBuildModelLossActiveMaterial:
)

def time_setup_model(self, model, params):

build_model("Ai2020", model, "loss of active material", params)


Expand Down
4 changes: 0 additions & 4 deletions benchmarks/work_precision_sets/time_vs_abstols.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
itertools.product(solvers.values(), models.values()),
itertools.product(solvers, models),
):

for params in parameters:

time_points = []
solver = i[0]

Expand Down Expand Up @@ -70,13 +68,11 @@
disc.process_model(model)

for tol in abstols:

solver.atol = tol
solver.solve(model, t_eval=t_eval)
time = 0
runs = 20
for k in range(0, runs):

solution = solver.solve(model, t_eval=t_eval)
time += solution.solve_time.value
time = time / runs
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/work_precision_sets/time_vs_dt_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
models.values(),
models,
):

for params in parameters:

time_points = []
# solver = pybamm.CasadiSolver()

Expand Down Expand Up @@ -74,14 +72,12 @@
disc.process_model(model)

for t in dt_max:

solver = pybamm.CasadiSolver(dt_max=t)

solver.solve(model, t_eval=t_eval)
time = 0
runs = 20
for k in range(0, runs):

solution = solver.solve(model, t_eval=t_eval)
time += solution.solve_time.value
time = time / runs
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/work_precision_sets/time_vs_mesh_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
itertools.product(solvers.values(), models.values()),
itertools.product(solvers, models),
):

for params in parameters:
time_points = []
solver = i[0]
Expand All @@ -42,7 +41,6 @@
i = list(i)

for N in npts:

var_pts = {
"x_n": N, # negative electrode
"x_s": N, # separator
Expand All @@ -57,7 +55,6 @@
time = 0
runs = 20
for k in range(0, runs):

solution = sim.solve([0, 3500])
time += solution.solve_time.value
time = time / runs
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/work_precision_sets/time_vs_no_of_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
itertools.product(solvers.values(), models.values()),
itertools.product(solvers, models),
):

for params in parameters:
time_points = []
ns = []
Expand All @@ -42,7 +41,6 @@
i = list(i)

for N in npts:

var_pts = {
"x_n": N, # negative electrode
"x_s": N, # separator
Expand All @@ -57,7 +55,6 @@
time = 0
runs = 20
for k in range(0, runs):

solution = sim.solve([0, 3500])
time += solution.solve_time.value
time = time / runs
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/work_precision_sets/time_vs_reltols.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
itertools.product(solvers.values(), models.values()),
itertools.product(solvers, models),
):

for params in parameters:

time_points = []
solver = i[0]

Expand Down Expand Up @@ -76,13 +74,11 @@
disc.process_model(model)

for tol in reltols:

solver.rtol = tol
solver.solve(model, t_eval=t_eval)
time = 0
runs = 20
for k in range(0, runs):

solution = solver.solve(model, t_eval=t_eval)
time += solution.solve_time.value
time = time / runs
Expand Down
2 changes: 2 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"sphinx.ext.napoleon",
"sphinx_design",
"sphinx_copybutton",
"myst_parser",
]


Expand Down Expand Up @@ -99,6 +100,7 @@
# https://pydata-sphinx-theme.readthedocs.io/en/latest/index.html# for more information)
# mostly copied from numpy, scipy, pandas
html_logo = "source/_static/pybamm_logo.png"
html_favicon = "source/_static/favicon/favicon.png"

html_theme_options = {
"logo": {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PyBaMM documentation
:maxdepth: 1
:hidden:

source/user_guide/index
User Guide <source/user_guide/index>
source/api/index

**Version**: |version|
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ sphinx>4.0
pydata-sphinx-theme
sphinx_design
sphinx-copybutton
myst-parser
Binary file added docs/source/_static/favicon/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,85 +1,82 @@
Fundamentals
============
# Fundamentals

PyBaMM (Python Battery Mathematical Modelling) is an open-source battery simulation package
written in Python. Our mission is to accelerate battery modelling research by
providing open-source tools for multi-institutional, interdisciplinary collaboration.
providing open-source tools for multi-institutional, interdisciplinary collaboration.
Broadly, PyBaMM consists of

#. a framework for writing and solving systems of differential equations,
#. a library of battery models and parameters, and
#. specialized tools for simulating battery-specific experiments and visualizing the results.
1. a framework for writing and solving systems of differential equations,
2. a library of battery models and parameters, and
3. specialized tools for simulating battery-specific experiments and visualizing the results.

Together, these enable flexible model definitions and fast battery simulations, allowing users to
explore the effect of different battery designs and modeling assumptions under a variety of operating scenarios.

.. note::
> **NOTE**: This user-guide is a work-in-progress, we hope that this brief but incomplete overview will be useful to you.
This user-guide is a work-in-progress, we hope that this brief but incomplete overview will be useful to you.
## Core framework

Core framework
~~~~~~~~~~~~~~
The core of the framework is a custom computer algebra system to define mathematical equations,
and a domain specific modeling language to combine these equations into systems of differential equations
(usually partial differential equations for variables depending on space and time).
The `expression tree <https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/expression_tree/expression-tree.ipynb>`_ example gives an introduction to the computer algebra system, and the `Getting Started <https://github.com/pybamm-team/PyBaMM/tree/develop/examples/notebooks/Getting%20Started>`_ tutorials
The [expression tree](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/expression_tree/expression-tree.ipynb) example gives an introduction to the computer algebra system, and the [Getting Started](https://github.com/pybamm-team/PyBaMM/tree/develop/examples/notebooks/Getting%20Started) tutorials
walk through creating models of increasing complexity.

Once a model has been defined symbolically, PyBaMM solves it using the Method of Lines. First, the equations are discretised in the spatial dimension, using the finite volume method. Then, the resulting system is solved using third-party numerical solvers. Depending on the form of the model, the system can be ordinary differential equations (ODEs) (if only `model.rhs` is defined), or algebraic equations (if only `model.algebraic` is defined), or differential-algebraic equations (DAEs) (if both `model.rhs` and `model.algebraic` are defined). Jupyter notebooks explaining the solvers can be found `here <https://github.com/pybamm-team/PyBaMM/tree/develop/examples/notebooks/solvers>`_.
Once a model has been defined symbolically, PyBaMM solves it using the Method of Lines. First, the equations are discretised in the spatial dimension, using the finite volume method. Then, the resulting system is solved using third-party numerical solvers. Depending on the form of the model, the system can be ordinary differential equations (ODEs) (if only `model.rhs` is defined), or algebraic equations (if only `model.algebraic` is defined), or differential-algebraic equations (DAEs) (if both `model.rhs` and `model.algebraic` are defined). Jupyter notebooks explaining the solvers can be found [here](https://github.com/pybamm-team/PyBaMM/tree/develop/examples/notebooks/solvers).

## Model and Parameter Library

Model and Parameter Library
~~~~~~~~~~~~~~~~~~~~~~~~~~~
PyBaMM contains an extensive library of battery models and parameters.
The bulk of the library consists of models for lithium-ion, but there are also some other chemistries (lead-acid, lithium metal).
Models are first divided broadly into common named models of varying complexity, such as the single particle model` (SPM) or Doyle-Fuller-Newman model (DFN).
Models are first divided broadly into common named models of varying complexity, such as the single particle model (SPM) or Doyle-Fuller-Newman model (DFN).
Most options can be applied to any model, but some are model-specific (an error will be raised if you attempt to set an option is not compatible with a model).
See :ref:`base_battery_model` for a list of options.
See [](base_battery_model) for a list of options.

The parameter library is simply a collection of python files each defining a complete set of parameters
for a particular battery chemistry, covering all major lithium-ion chemistries (NMC, LFP, NCA, ...).
External parameter sets can be linked using entry points (see :ref:`parameter_sets`).

Battery-specific tools
~~~~~~~~~~~~~~~~~~~~~~
One of PyBaMM's unique features is the ``Experiment`` class, which allows users to define synthetic experiments using simple instructions in English
External parameter sets can be linked using entry points (see [](parameter_sets)).

.. code-block:: python
## Battery-specific tools

pybamm.Experiment(
[
("Discharge at C/10 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 50 mA",
"Rest for 1 hour")
]
* 3,
)
One of PyBaMM's unique features is the `Experiment` class, which allows users to define synthetic experiments using simple instructions in English

The above instruction will conduct a standard discharge / rest / charge / rest cycle three times, with a 10 hour discharge and 1 hour rest at the end of each cycle.
```python
pybamm.Experiment(
[
("Discharge at C/10 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 50 mA",
"Rest for 1 hour")
]
* 3,
)
```

The ``Simulation`` class handles simulating an ``Experiment``, as well as calculating additional outputs such as capacity as a function of cycle number. For example, the following code will simulate the experiment above and plot the standard output variables:
The above instruction will conduct a standard discharge / rest / charge / rest cycle three times, with a 10 hour discharge and 1 hour rest at the end of each cycle.

.. code-block:: python
The `Simulation` class handles simulating an `Experiment`, as well as calculating additional outputs such as capacity as a function of cycle number. For example, the following code will simulate the experiment above and plot the standard output variables:

import pybamm
import matplotlib.pyplot as plt
```python
import pybamm
import matplotlib.pyplot as plt

# load model and parameter values
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment)
solution = sim.solve()
solution.plot()
# load model and parameter values
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment)
solution = sim.solve()
solution.plot()
```

Finally, PyBaMM provides cusotm visualization tools:

* :ref:`quick_plot`: for easily plotting simulation outputs in a grid, including comparing multiple simulations
* :ref:`plot_voltage_components`: for plotting the component overpotentials that make up a voltage curve
- [](quick_plot): for easily plotting simulation outputs in a grid, including comparing multiple simulations
- [](plot_voltage_components): for plotting the component overpotentials that make up a voltage curve

Users are not limited to these tools and can plot the output of a simulation solution by accessing the underlying numpy array for the solution variables as

.. code-block:: python
solution["variable name"].data
```python
solution["variable name"].data
```

and using the plotting library of their choice.
and using the plotting library of their choice.
40 changes: 40 additions & 0 deletions docs/source/user_guide/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Getting Started

The easiest way to use PyBaMM is to run a 1C constant-current discharge with a model of your choice with all the default settings:

```python
import pybamm
model = pybamm.lithium_ion.DFN() # Doyle-Fuller-Newman model
sim = pybamm.Simulation(model)
sim.solve([0, 3600]) # solve for 1 hour
sim.plot()
```

or simulate an experiment such as a constant-current discharge followed by a constant-current-constant-voltage charge:

```python
import pybamm
experiment = pybamm.Experiment(
[
("Discharge at C/10 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 50 mA",
"Rest for 1 hour")
]
* 3,
)
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
sim.solve()
sim.plot()
```

However, much greater customisation is available. It is possible to change the physics, parameter values, geometry, submesh type, number of submesh points, methods for spatial discretisation and solver for integration (see DFN [script](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/scripts/DFN.py) or [notebook](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/models/DFN.ipynb)).

For new users we recommend the [Getting Started](https://github.com/pybamm-team/PyBaMM/tree/develop/examples/notebooks/Getting%20Started) guides. These are intended to be very simple step-by-step guides to show the basic functionality of PyBaMM, and can either be downloaded and used locally, or used online through [Google Colab](https://colab.research.google.com/github/pybamm-team/PyBaMM/blob/develop).

Further details can be found in a number of [detailed examples](https://github.com/pybamm-team/PyBaMM/blob/develop/examples/notebooks/README.md), hosted on
GitHub. In addition, full details of classes and methods can be found in the [](api_docs).
Additional supporting material can be found
[here](https://github.com/pybamm-team/pybamm-supporting-material/).
Loading

0 comments on commit 664a024

Please sign in to comment.