Skip to content

Commit

Permalink
#759 merge in master
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Feb 11, 2020
2 parents 684a814 + 6c1fd4f commit 36b676c
Show file tree
Hide file tree
Showing 51 changed files with 1,247 additions and 259 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## Features

- Added discontinuity event and ability for solvers to integrate over discontinuities. For models using heavyside functions in certain patterns, the discretisation class automatically adds in discontinuity events required ([#759](https://github.com/pybamm-team/PyBaMM/issues/759)

- Added functionality to solve DAE models with non-smooth current inputs ([#808](https://github.com/pybamm-team/PyBaMM/pull/808))
- Added functionality to simulate experiments and testing protocols ([#807](https://github.com/pybamm-team/PyBaMM/pull/807))
- Added fuzzy string matching for parameters and variables ([#796](https://github.com/pybamm-team/PyBaMM/pull/796))
- 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))
- 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))
- Allow initial conditions in the particle to depend on x ([#786](https://github.com/pybamm-team/PyBaMM/pull/786))
- 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))
- 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))
- Added notebook to explain broadcasts ([#776](https://github.com/pybamm-team/PyBaMM/pull/776))
Expand Down Expand Up @@ -65,6 +68,7 @@
## Breaking changes

- Model events are now represented as a list of `pybamm.Event` ([#759](https://github.com/pybamm-team/PyBaMM/issues/759)
- Removed `ParameterValues.update_model`, whose functionality is now replaced by `InputParameter` ([#801](https://github.com/pybamm-team/PyBaMM/pull/801))
- Removed `Outer` and `Kron` nodes as no longer used ([#777](https://github.com/pybamm-team/PyBaMM/pull/777))
- Moved `results` to separate repositories ([#761](https://github.com/pybamm-team/PyBaMM/pull/761))
- The parameters "Bruggeman coefficient" must now be specified separately as "Bruggeman coefficient (electrolyte)" and "Bruggeman coefficient (electrode)"
Expand Down
34 changes: 10 additions & 24 deletions INSTALL-LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,14 @@ PyBaMM can be installed via pip:
pip install pybamm
```

PyBaMM's dependencies (such as `numpy`, `scipy`, etc) will be installed automatically when you install PyBaMM using `pip`.

PyBaMM has the following python libraries as dependencies: `numpy`, `scipy`, `pandas`,
`matplotlib`. These will be installed automatically when you install PyBaMM using `pip`,
following the instructions below. First, make sure you have activated your virtual
environment as above, and that you have the latest version of pip installed:

Then navigate to the path where you downloaded PyBaMM to (you will already be in the
correct location if you followed the instructions above), and install both PyBaMM and
its dependencies by typing:

```bash
pip install pybamm
```
For an introduction to virtual environments, see (https://realpython.com/python-virtual-environments-a-primer/).

### developer install
### Developer install

If you wish to contribute to PyBaMM, you should get the latest version from the GitHub repository.
To do so, you must have Git installed.
For instance run
To do so, you must have Git installed. For instance run
```bash
sudo apt install git
```
Expand All @@ -70,7 +58,7 @@ To install PyBaMM, the first step is to get the code by cloning this repository
git clone https://github.com/pybamm-team/PyBaMM.git
cd PyBaMM
```
Then, install PyBaMM as a develop per with [developer](CONTRIBUTING.md), use
Then, to install PyBaMM as a [developer](CONTRIBUTING.md), type

```bash
pip install -e .[dev,docs]
Expand Down Expand Up @@ -100,10 +88,10 @@ This can be done using `git`, running
git clone https://github.com/pybamm-team/PyBaMM.git
cd PyBaMM
```
Alternatively, you can dowload the source code archive from [the PyBaMM GitHub repo](https://github.com/pybamm-team/PyBaMM.git) and extract it the location of your choice.
Alternatively, you can download the source code archive from [the PyBaMM GitHub repo](https://github.com/pybamm-team/PyBaMM.git) and extract it to the location of your choice.

Ideally you should have the python package `wget` installed.
This allows for the automatic download of some of the dependencies has part of the installation process.
This allows for the automatic download of some of the dependencies that are part of the installation process.
You can install it using (within your virtual environment)
```bash
pip install wget
Expand All @@ -113,7 +101,6 @@ pip install wget
Users can install [scikits.odes](https://github.com/bmcage/odes) in order to use the
wrapped SUNDIALS ODE and DAE
[solvers](https://pybamm.readthedocs.io/en/latest/source/solvers/scikits_solvers.html).
The Sundials DAE solver is required to solve the DFN battery model in PyBaMM.

Before installing scikits.odes, you need to have installed:

Expand All @@ -139,15 +126,15 @@ Alternatively, you can specify a directory containing the source code of the Sun
```bash
python setup.py install_odes --sundials-src=<path/to/sundials/source>
```
By default, the sundials are installed in a `sundials` directory located at the root of the PyBaMM package.
By default, sundials is installed in a `sundials` directory located at the root of the PyBaMM package.
You can provide another location by using the `--sundials-inst=<path/to/other/location>` option.

If you are installing `scikits.odes` within a virtual environment, the `activate` script will be automatically
updated to add the sundials installation directory to your `LD_LIBRARY_PATH`.
This is required in order to use `scikits.odes`.
As a consequence, after installation you should restart your virtual environment.

If you wish to install the scikits.odes outside of a virtual environment, your `.bashrc` will be modified instead.
If you wish to install `scikits.odes` outside of a virtual environment, your `.bashrc` will be modified instead.
After installation you should therefore run
```bash
source ~/.bashrc
Expand All @@ -166,7 +153,7 @@ sparse solver.
PyBaMM currently offers a direct interface to the sparse KLU solver within Sundials.
#### Prerequisites
The requirements are the same than for the installation of `scikits.odes` (see previous section).
The requirements are the same as for the installation of `scikits.odes` (see previous section).
Additionally, the [pybind11 GitHub repository](https://github.com/pybind/pybind11.git) should be located in `PyBaMM/third-party/`.
First create a directory `third-party` and clone the repository:
```bash
Expand Down Expand Up @@ -198,14 +185,13 @@ python -c "import pybamm; print(pybamm.have_idaklu())
```
### Install everything
It is possible to install both `scikits.odes` and KLU solver using the command
It is possible to install both `scikits.odes` and the KLU solver using the command
```bash
python setup.py install_all
```
Note that options `--sundials-src`, `--sundials-inst` and `suitesparse-src` are still usable
here.
You can make sure the install was successful by runing
Finally, you can check your install by running
```bash
python -c "import pybamm; print(pybamm.have_scikits_odes())
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Contents
source/meshes/index
source/spatial_methods/index
source/solvers/index
source/experiments/index
source/processed_variable
source/util
source/simulation
Expand Down
5 changes: 5 additions & 0 deletions docs/source/experiments/experiment.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Base Experiment Class
=====================

.. autoclass:: pybamm.Experiment
:members:
8 changes: 8 additions & 0 deletions docs/source/experiments/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Experiments
===========

Classes to help set operating conditions for some standard battery modelling experiments

.. toctree::

experiment
3 changes: 3 additions & 0 deletions docs/source/solvers/solution.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Solution
========

.. autoclass:: pybamm._BaseSolution
:members:

.. autoclass:: pybamm.Solution
:members:
4 changes: 2 additions & 2 deletions examples/scripts/DFN.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

pybamm.set_logging_level("INFO")


# load model
model = pybamm.lithium_ion.DFN({"operating mode": "voltage"})
model = pybamm.lithium_ion.DFN()

# create geometry
geometry = model.default_geometry

# load parameter values and process model and geometry
param = model.default_parameter_values
param.update({"Voltage function [V]": 4.1}, check_already_exists=False)
param.process_model(model)
param.process_geometry(geometry)

Expand Down
39 changes: 39 additions & 0 deletions examples/scripts/experimental_protocols/cccv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Constant-current constant-voltage charge
#
import pybamm
import matplotlib.pyplot as plt

pybamm.set_logging_level("INFO")
experiment = pybamm.Experiment(
[
"Discharge at C/10 for 13 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,
period="2 minutes",
)
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
sim.solve()

# Plot voltages from the discharge segments only
fig, ax = plt.subplots()
for i in range(3):
# Extract sub solutions
sol = sim.solution.sub_solutions[i * 5]
# Extract variables
t = sol["Time [h]"].entries
V = sol["Terminal voltage [V]"].entries
# Plot
ax.plot(t - t[0], V, label="Discharge {}".format(i + 1))
ax.set_xlabel("Time [h]")
ax.set_ylabel("Voltage [V]")
ax.set_xlim([0, 13])
ax.legend()

# Show all plots
sim.plot()
19 changes: 19 additions & 0 deletions examples/scripts/experimental_protocols/cccv_lead_acid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Constant-current constant-voltage charge
#
import pybamm

pybamm.set_logging_level("INFO")
experiment = pybamm.Experiment(
[
"Discharge at C/2 until 11 V",
"Rest for 1 hour",
"Charge at C/2 until 14.5 V",
"Hold at 14.5 V until 200 mA",
"Rest for 1 hour",
]
)
model = pybamm.lead_acid.Full()
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
sim.solve()
sim.plot()
13 changes: 13 additions & 0 deletions examples/scripts/experimental_protocols/gitt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# GITT discharge
#
import pybamm

pybamm.set_logging_level("INFO")
experiment = pybamm.Experiment(
["Discharge at C/20 for 1 hour", "Rest for 1 hour"] * 20,
)
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
sim.solve()
sim.plot()
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Negative electrode Bruggeman coefficient (electrode),1.5,Scott Moura FastDFN,
# Interfacial reactions,,,
Negative electrode cation signed stoichiometry,-1,,
Negative electrode electrons in reaction,1,,
Negative electrode reference exchange-current density [A.m-2(m3.mol)1.5],2E-05,Scott Moura FastDFN,Be careful how we implement BV
Reference OCP vs SHE in the negative electrode [V],,,
Negative electrode charge transfer coefficient,0.5,Scott Moura FastDFN,
Negative electrode double-layer capacity [F.m-2],0.2,,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Positive electrode Bruggeman coefficient (electrode),1.5,Scott Moura FastDFN,
# Interfacial reactions,,,
Positive electrode cation signed stoichiometry,-1,,
Positive electrode electrons in reaction,1,,
Positive electrode reference exchange-current density [A.m-2(m3.mol)1.5],6E-07,Scott Moura FastDFN,Be careful how we implement BV
Reference OCP vs SHE in the positive electrode [V],,,
Positive electrode charge transfer coefficient,0.5,Scott Moura FastDFN,
Positive electrode double-layer capacity [F.m-2],0.2,,
Expand Down
8 changes: 7 additions & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def version(formatted=False):
#
# Solver classes
#
from .solvers.solution import Solution
from .solvers.solution import Solution, _BaseSolution
from .solvers.base_solver import BaseSolver
from .solvers.algebraic_solver import AlgebraicSolver
from .solvers.casadi_solver import CasadiSolver
Expand All @@ -246,6 +246,12 @@ def version(formatted=False):
from .solvers.scipy_solver import ScipySolver
from .solvers.idaklu_solver import IDAKLUSolver, have_idaklu

#
# Experiments
#
from .experiments.experiment import Experiment
from . import experiments

#
# other
#
Expand Down
Empty file added pybamm/experiments/__init__.py
Empty file.
Loading

0 comments on commit 36b676c

Please sign in to comment.