Skip to content

Commit

Permalink
Merge branch 'develop' into issue-1594-add-ORegan-2021
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Aug 19, 2021
2 parents 6e72c7d + 15a71cc commit 4f51ac6
Show file tree
Hide file tree
Showing 68 changed files with 3,034 additions and 515 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Install Linux system dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt install gfortran gcc libopenblas-dev graphviz
sudo apt install texlive-full
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added capability for `quaternary` domains (in addition to `primary`, `secondary` and `tertiary`), increasing the maximum number of domains that a `Symbol` can have to 4. ([#1580](https://github.com/pybamm-team/PyBaMM/pull/1580))
- Tabs can now be placed at the bottom of the cell in 1+1D thermal models ([#1581](https://github.com/pybamm-team/PyBaMM/pull/1581))
- Added temperature dependence on electrode electronic conductivity ([#1570](https://github.com/pybamm-team/PyBaMM/pull/1570))
- `pybamm.base_solver.solve` function can take a list of input parameters to calculate the sensitivities of the solution with respect to. Alternatively, it can be set to `True` to calculate the sensitivities for all input parameters ([#1552](https://github.com/pybamm-team/PyBaMM/pull/1552))
- Added a new lithium-ion model `MPM` or Many-Particle Model, with a distribution of particle sizes in each electrode. ([#1529](https://github.com/pybamm-team/PyBaMM/pull/1529))
- Added 2 new submodels for lithium transport in a size distribution of electrode particles: Fickian diffusion (`FickianSingleSizeDistribution`) and uniform concentration profile (`FastSingleSizeDistribution`). ([#1529](https://github.com/pybamm-team/PyBaMM/pull/1529))
- Added a "particle size" domain to the default lithium-ion geometry, including plotting capabilities (`QuickPlot`) and processing of variables (`ProcessedVariable`). ([#1529](https://github.com/pybamm-team/PyBaMM/pull/1529))
Expand Down Expand Up @@ -43,6 +44,7 @@

## Breaking changes

- Changed sensitivity API. Removed `ProcessedSymbolicVariable`, all sensitivity now handled within the solvers and `ProcessedVariable` () ([#1552](https://github.com/pybamm-team/PyBaMM/pull/1552))
- The `Yang2017` parameter set has been removed as the complete parameter set is not publicly available in the literature ([#1577](https://github.com/pybamm-team/PyBaMM/pull/1577))
- Changed how options are specified for the "loss of active material" and "particle cracking" submodels. "loss of active material" can now be one of "none", "stress-driven", or "reaction-driven", or a 2-tuple for different options in negative and positive electrode. Similarly "particle cracking" (now called "particle mechanics") can now be "none", "swelling only", "swelling and cracking", or a 2-tuple ([#1490](https://github.com/pybamm-team/PyBaMM/pull/1490))
- Changed the variable in the full diffusion model from "Electrolyte concentration" to "Porosity times concentration" ([#1476](https://github.com/pybamm-team/PyBaMM/pull/1476))
Expand Down Expand Up @@ -190,7 +192,6 @@ This release adds new operators for more complex models, some basic sensitivity
(e.g. `standard_parameters_lithium_ion` is now `LithiumIonParameters`) ([#1120](https://github.com/pybamm-team/PyBaMM/pull/1120))
- Renamed `quick_plot_vars` to `output_variables` in `Simulation` to be consistent with `QuickPlot`. Passing `quick_plot_vars` to `Simulation.plot()` has been deprecated and `output_variables` should be passed instead ([#1099](https://github.com/pybamm-team/PyBaMM/pull/1099))


# [v0.2.3](https://github.com/pybamm-team/PyBaMM/tree/v0.2.3) - 2020-07-01

This release enables the use of [Google Colab](https://colab.research.google.com/github/pybamm-team/PyBaMM/blob/main/) for running example notebooks, and adds some small new features and bug fixes.
Expand Down
58 changes: 1 addition & 57 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ We use [GIT](https://en.wikipedia.org/wiki/Git) and [GitHub](https://en.wikipedi
1. Create an [issue](https://guides.github.com/features/issues/) where new proposals can be discussed before any coding is done.
2. Create a [branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/) of this repo (ideally on your own [fork](https://help.github.com/articles/fork-a-repo/)), where all changes will be made
3. Download the source code onto your local system, by [cloning](https://help.github.com/articles/cloning-a-repository/) the repository (or your fork of the repository).
4. [Install](#installation) PyBaMM with the developer options.
4. [Install](https://pybamm.readthedocs.io/en/latest/install/install-from-source.html) PyBaMM with the developer options.
5. [Test](#testing) if your installation worked, using the test script: `$ python run-tests.py --unit`.

You now have everything you need to start making changes!
Expand All @@ -44,62 +44,6 @@ You now have everything you need to start making changes!
Finally, if you really, really, _really_ love developing PyBaMM, have a look at the current [project infrastructure](#infrastructure).


## Installation

To install PyBaMM with all developer options follow the steps below:


1. Install tox using the commands below:
```bash
pip install tox # (Using this, you will need to additionally install tox in your virtual environment as decribed below)
# or
pip install pipx # (For installing pipx)
pipx install tox # (Using this, tox can automatically be accessed in your virtual environment)
```
You can also explore and install pipx from their [GitHub repository](https://github.com/pipxproject/pipx)

2. Install sundials using the command below:
```bash
# (Skip this step for Windows installation)
brew install sundials # (MacOS)
#
tox -e pybamm-requires # (GNU/Linux)
```
3. Installing PyBaMM

This can be achieved by forking the repository and cloning it in your machine.

4. Navigate to the cloned repository and create a virtual environment using the commands below:
```bash
tox -e dev # (GNU/Linux and MacOS)
#
python -m tox -e windows-dev # (Windows)
```

This will

a. Create a virtual environment located at `.tox/dev`.

b. Install all the dependencies for PyBaMM, including the ones for documentation and development.

c. Tell Python to use your local pybamm files when you use `import pybamm` anywhere on your system.

5. Finally, activate your environment.


```bash
source .tox/dev/bin/activate # (GNU/Linux and MacOS)
#
.tox\windows-dev\Scripts\activate.bat # (Windows)
```
6. Inside the virtual environment, type:
```bash
pip install tox # (Skip this step if you used pipx above)
```


Full documentation with an installation guide can be found [here](https://pybamm.readthedocs.io/en/latest/install/install-from-source.html)

## Coding style guidelines

PyBaMM follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-0008/) for coding style. These are very common guidelines, and community tools have been developed to check how well projects implement them.
Expand Down
4 changes: 2 additions & 2 deletions FindSUNDIALS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# find the SUNDIALS include directories
find_path(SUNDIALS_INCLUDE_DIR
NAMES
ida/ida.h
idas/idas.h
sundials/sundials_math.h
sundials/sundials_types.h
sunlinsol/sunlinsol_klu.h
Expand All @@ -39,7 +39,7 @@ find_path(SUNDIALS_INCLUDE_DIR
)

set(SUNDIALS_WANT_COMPONENTS
sundials_ida
sundials_idas
sundials_sunlinsolklu
sundials_sunmatrixsparse
sundials_nvecserial
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ hosted on [Read The Docs](https://readthedocs.org/).
Additional supporting material can be found
[here](https://github.com/pybamm-team/pybamm-supporting-material/).

For further examples, see the list of repositories that use PyBaMM [here](https://github.com/pybamm-team/pybamm-example-results).
Note that the examples on the default `develop` branch are tested on the latest `develop` commit. This may sometimes cause errors when running the examples on the pybamm pip package, which is synced to the `main` branch. You can switch to the `main` branch on github to see the version of the examples that is compatible with the latest pip release.

<!-- For further examples, see the list of repositories that use PyBaMM [here](https://github.com/pybamm-team/pybamm-example-results). -->

## 🚀 Installing PyBaMM

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Function control external circuit
:members:

.. autoclass:: pybamm.external_circuit.PowerFunctionControl
:members:

.. autoclass:: pybamm.external_circuit.CCCVFunctionControl
:members:
3 changes: 0 additions & 3 deletions docs/source/solvers/processed_variable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ Post-Process Variables

.. autoclass:: pybamm.ProcessedVariable
:members:

.. autoclass:: pybamm.ProcessedSymbolicVariable
:members:
554 changes: 554 additions & 0 deletions examples/notebooks/models/latexify.ipynb

Large diffs are not rendered by default.

Binary file added examples/notebooks/models/spm_equations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def process_model(self, model, inplace=True, check_model=True):
model_disc.rhs, model_disc.concatenated_rhs = rhs, concat_rhs
model_disc.algebraic, model_disc.concatenated_algebraic = alg, concat_alg

# Save length of rhs and algebraic
model_disc.len_rhs = model_disc.concatenated_rhs.size
model_disc.len_alg = model_disc.concatenated_algebraic.size
model_disc.len_rhs_and_alg = model_disc.len_rhs + model_disc.len_alg

# Process events
processed_events = []
pybamm.logger.verbose("Discretise events for {}".format(model.name))
Expand Down
89 changes: 72 additions & 17 deletions pybamm/experiments/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class Experiment:
faster at simulating individual steps but has higher set-up overhead
drive_cycles : dict
Dictionary of drive cycles to use for this experiment.
cccv_handling : str, optional
How to handle CCCV. If "two-step" (default), then the experiment is run in
two steps (CC then CV). If "ode", then the experiment is run in a single step
using an ODE for current: see
:class:`pybamm.external_circuit.CCCVFunctionControl` for details.
"""

def __init__(
Expand All @@ -66,7 +70,11 @@ def __init__(
termination=None,
use_simulation_setup_type="new",
drive_cycles={},
cccv_handling="two-step",
):
if cccv_handling not in ["two-step", "ode"]:
raise ValueError("cccv_handling should be either 'two-step' or 'ode'")
self.cccv_handling = cccv_handling

self.period = self.convert_time_to_seconds(period.split())
operating_conditions_cycles = []
Expand All @@ -75,9 +83,28 @@ def __init__(
if (isinstance(cycle, tuple) or isinstance(cycle, str)) and all(
[isinstance(cond, str) for cond in cycle]
):
operating_conditions_cycles.append(
cycle if isinstance(cycle, tuple) else (cycle,)
)
if isinstance(cycle, str):
processed_cycle = (cycle,)
else:
processed_cycle = []
idx = 0
finished = False
while not finished:
step = cycle[idx]
if idx < len(cycle) - 1:
next_step = cycle[idx + 1]
else:
next_step = None
finished = True
if self.is_cccv(step, next_step):
processed_cycle.append(step + " then " + next_step)
idx += 2
else:
processed_cycle.append(step)
idx += 1
if idx >= len(cycle):
finished = True
operating_conditions_cycles.append(tuple(processed_cycle))
else:
try:
# Condition is not a string
Expand Down Expand Up @@ -153,7 +180,20 @@ def read_string(self, cond, drive_cycles):
must be numbers, 'C' denotes the unit of the external circuit (can be A for
current, C for C-rate, V for voltage or W for power), and 'hours' denotes
the unit of time (can be second(s), minute(s) or hour(s))
drive_cycles: dict
A map specifying the drive cycles
"""
if " then " in cond:
# If the string contains " then ", then this is a two-step CCCV experiment
# and we need to split it into two strings
cond_CC, cond_CV = cond.split(" then ")
op_CC, _ = self.read_string(cond_CC, drive_cycles)
op_CV, event_CV = self.read_string(cond_CV, drive_cycles)
return {
"electric": op_CC["electric"] + op_CV["electric"],
"time": op_CV["time"],
"period": op_CV["period"],
}, event_CV
# Read period
if " period)" in cond:
cond, time_period = cond.split("(")
Expand All @@ -165,20 +205,12 @@ def read_string(self, cond, drive_cycles):
if "Run" in cond:
cond_list = cond.split()
if "at" in cond:
raise ValueError(
"""Instruction must be
For example: {}""".format(
examples
)
)
raise ValueError(f"Instruction must be of the form: {examples}")
dc_types = ["(A)", "(V)", "(W)"]
if all(x not in cond for x in dc_types):
raise ValueError(
"""Type of drive cycle must be
specified using '(A)', '(V)' or '(W)'.
For example: {}""".format(
examples
)
"Type of drive cycle must be specified using '(A)', '(V)' or '(W)'."
f" For example: {examples}"
)
# Check for Events
elif "for" in cond:
Expand Down Expand Up @@ -208,7 +240,7 @@ def read_string(self, cond, drive_cycles):
time = drive_cycles[cond_list[1]][:, 0][-1]
period = np.min(np.diff(drive_cycles[cond_list[1]][:, 0]))
events = None
elif "Run" not in cond:
else:
if "for" in cond and "or until" in cond:
# e.g. for 3 hours or until 4.2 V
cond_list = cond.split()
Expand Down Expand Up @@ -238,7 +270,8 @@ def read_string(self, cond, drive_cycles):
examples
)
)
return electric + (time,) + (period,), events

return {"electric": electric, "time": time, "period": period}, events

def extend_drive_cycle(self, drive_cycle, end_time):
"Extends the drive cycle to enable for event"
Expand Down Expand Up @@ -404,3 +437,25 @@ def read_termination(self, termination):
"e.g. '80% capacity' or '4 Ah capacity'"
)
return termination_dict

def is_cccv(self, step, next_step):
"""
Check whether a step and the next step indicate a CCCV charge
"""
if self.cccv_handling == "two-step" or next_step is None:
return False
# e.g. step="Charge at 2.0 A until 4.2V"
# next_step="Hold at 4.2V until C/50"
if (
step.startswith("Charge")
and "until" in step
and "V" in step
and "Hold at " in next_step
and "V until" in next_step
):
_, events = self.read_string(step, None)
next_op, _ = self.read_string(next_step, None)
# Check that the event conditions are the same as the hold conditions
if events == next_op["electric"]:
return True
return False
2 changes: 1 addition & 1 deletion pybamm/expression_tree/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _sympy_operator(self, left, right):
def to_equation(self):
"""Convert the node and its subtree into a SymPy equation."""
if self.print_name is not None:
return sympy.symbols(self.print_name)
return sympy.Symbol(self.print_name)
else:
child1, child2 = self.children
eq1 = child1.to_equation()
Expand Down
14 changes: 13 additions & 1 deletion pybamm/expression_tree/concatenations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def __str__(self):
out = out[:-2] + ")"
return out

def _diff(self, variable):
""" See :meth:`pybamm.Symbol._diff()`. """
children_diffs = [
child.diff(variable) for child in self.cached_children
]
if len(children_diffs) == 1:
diff = children_diffs[0]
else:
diff = self.__class__(*children_diffs)

return diff

def get_children_domains(self, children):
# combine domains from children
domain = []
Expand Down Expand Up @@ -120,7 +132,7 @@ def _sympy_operator(self, *children):
self.concat_latex = tuple(map(sympy.latex, children))

if self.print_name is not None:
return sympy.symbols(self.print_name)
return sympy.Symbol(self.print_name)
else:
concat_str = r"\\".join(self.concat_latex)
concat_sym = sympy.Symbol(r"\begin{cases}" + concat_str + r"\end{cases}")
Expand Down
2 changes: 1 addition & 1 deletion pybamm/expression_tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _sympy_operator(self, child):
def to_equation(self):
"""Convert the node and its subtree into a SymPy equation."""
if self.print_name is not None:
return sympy.symbols(self.print_name)
return sympy.Symbol(self.print_name)
else:
eq_list = []
for child in self.children:
Expand Down
8 changes: 6 additions & 2 deletions pybamm/expression_tree/independent_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def _jac(self, variable):
def to_equation(self):
"""Convert the node and its subtree into a SymPy equation."""
if self.print_name is not None:
return sympy.symbols(self.print_name)
return sympy.Symbol(self.print_name)
else:
return sympy.symbols(self.name)
return sympy.Symbol(self.name)


class Time(IndependentVariable):
Expand Down Expand Up @@ -72,6 +72,10 @@ def _evaluate_for_shape(self):
"""
return 0

def to_equation(self):
"""Convert the node and its subtree into a SymPy equation."""
return sympy.Symbol("t")


class SpatialVariable(IndependentVariable):
"""
Expand Down
Loading

0 comments on commit 4f51ac6

Please sign in to comment.