Skip to content

Commit

Permalink
Merge branch 'pybamm-team:develop' into issue_3392_improve_API_docume…
Browse files Browse the repository at this point in the history
…ntation
  • Loading branch information
AbhishekChaudharii authored Dec 8, 2023
2 parents d5106c7 + 32fad00 commit f87ba02
Show file tree
Hide file tree
Showing 26 changed files with 608 additions and 21 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,24 @@
"bug",
"code"
]
},
{
"login": "AbhishekChaudharii",
"name": "Abhishek Chaudhari",
"avatar_url": "https://avatars.githubusercontent.com/u/91185083?v=4",
"profile": "https://github.com/AbhishekChaudharii",
"contributions": [
"doc"
]
},
{
"login": "shubhambhar007",
"name": "Shubham Bhardwaj",
"avatar_url": "https://avatars.githubusercontent.com/u/32607282?v=4",
"profile": "https://github.com/shubhambhar007",
"contributions": [
"infra"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/run_periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- name: Check style
run: |
python -m pip install pre-commit
git add .
pre-commit run ruff
build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: Check style
run: |
python -m pip install pre-commit
git add .
pre-commit run ruff
run_unit_tests:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Features

- Added a new unary operator, `EvaluateAt`, that evaluates a spatial variable at a given position ([#3573](https://github.com/pybamm-team/PyBaMM/pull/3573))
- Added a method, `insert_reference_electrode`, to `pybamm.lithium_ion.BaseModel` that insert a reference electrode to measure the electrolyte potential at a given position in space and adds new variables that mimic a 3E cell setup. ([#3573](https://github.com/pybamm-team/PyBaMM/pull/3573))
- Serialisation added so models can be written to/read from JSON ([#3397](https://github.com/pybamm-team/PyBaMM/pull/3397))
- Mechanical parameters are now a function of stoichiometry and temperature ([#3576](https://github.com/pybamm-team/PyBaMM/pull/3576))

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![code style](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-67-orange.svg)](#-contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg)](#-contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

</div>
Expand Down Expand Up @@ -271,6 +271,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Agnik7"><img src="https://avatars.githubusercontent.com/u/77234005?v=4?s=100" width="100px;" alt="Agnik Bakshi"/><br /><sub><b>Agnik Bakshi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=Agnik7" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RuiheLi"><img src="https://avatars.githubusercontent.com/u/84007676?v=4?s=100" width="100px;" alt="RuiheLi"/><br /><sub><b>RuiheLi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=RuiheLi" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chmabaur"><img src="https://avatars.githubusercontent.com/u/127507466?v=4?s=100" width="100px;" alt="chmabaur"/><br /><sub><b>chmabaur</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Achmabaur" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=chmabaur" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AbhishekChaudharii"><img src="https://avatars.githubusercontent.com/u/91185083?v=4?s=100" width="100px;" alt="Abhishek Chaudhari"/><br /><sub><b>Abhishek Chaudhari</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=AbhishekChaudharii" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/shubhambhar007"><img src="https://avatars.githubusercontent.com/u/32607282?v=4?s=100" width="100px;" alt="Shubham Bhardwaj"/><br /><sub><b>Shubham Bhardwaj</b></sub></a><br /><a href="#infra-shubhambhar007" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
</tbody>
</table>
Expand Down
6 changes: 6 additions & 0 deletions docs/source/api/expression_tree/unary_operator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Unary Operators
.. autoclass:: pybamm.Mass
:members:

.. autoclass:: pybamm.BoundaryMass
:members:

.. autoclass:: pybamm.Integral
:members:

Expand All @@ -58,6 +61,9 @@ Unary Operators
.. autoclass:: pybamm.BoundaryGradient
:members:

.. autoclass:: pybamm.EvaluateAt
:members:

.. autoclass:: pybamm.UpwindDownwind
:members:

Expand Down
1 change: 1 addition & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The notebooks are organised into subfolders, and can be viewed in the galleries
notebooks/models/rate-capability.ipynb
notebooks/models/saving_models.ipynb
notebooks/models/SEI-on-cracks.ipynb
notebooks/models/simulate-3E-cell.ipynb
notebooks/models/simulating-ORegan-2022-parameter-set.ipynb
notebooks/models/SPM.ipynb
notebooks/models/SPMe.ipynb
Expand Down
210 changes: 210 additions & 0 deletions docs/source/examples/notebooks/models/simulate-3E-cell.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Simulating a 3E cell\n",
"\n",
"In this notebook we show how to insert a reference electrode to mimic a 3E cell."
]
},
{
"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[plot,cite]\" -q # install PyBaMM if it is not installed\n",
"import pybamm"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"We first load a model"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"model = pybamm.lithium_ion.DFN()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we use the helper function `insert_reference_electrode` to insert a reference electrode into the model. This function takes the position of the reference electrode as an optional argument. If no position is given, the reference electrode is inserted at the midpoint of the separator. The helper function adds the new variables \"Reference electrode potential [V]\", \"Negative electrode 3E potential [V]\" and \"Positive electrode 3E potential [V]\" to the model.\n",
"\n",
"In this example we will explicitly pass a position to show how it is done"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"L_n = model.param.n.L # Negative electrode thickness [m]\n",
"L_s = model.param.s.L # Separator thickness [m]\n",
"L_ref = L_n + L_s / 2 # Reference electrode position [m]\n",
"\n",
"model.insert_reference_electrode(L_ref)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we can set up a simulation and solve the model as usual"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<pybamm.solvers.solution.Solution at 0x169dc5950>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sim = pybamm.Simulation(model)\n",
"sim.solve([0, 3600])"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's plot a comparison of the 3E potentials and the potential difference between the solid and electrolyte phases at the electrode/separator interfaces"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d1f4e1ed03764660b87ee56b135b24a7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x169816a90>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sim.plot(\n",
" [\n",
" [\n",
" \"Negative electrode surface potential difference at separator interface [V]\",\n",
" \"Negative electrode 3E potential [V]\",\n",
" ],\n",
" [\n",
" \"Positive electrode surface potential difference at separator interface [V]\",\n",
" \"Positive electrode 3E potential [V]\",\n",
" ],\n",
" \"Voltage [V]\",\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1] Joel A. E. Andersson, Joris Gillis, Greg Horn, James B. Rawlings, and Moritz Diehl. CasADi – A software framework for nonlinear optimization and optimal control. Mathematical Programming Computation, 11(1):1–36, 2019. doi:10.1007/s12532-018-0139-4.\n",
"[2] Marc Doyle, Thomas F. Fuller, and John Newman. Modeling of galvanostatic charge and discharge of the lithium/polymer/insertion cell. Journal of the Electrochemical society, 140(6):1526–1533, 1993. doi:10.1149/1.2221597.\n",
"[3] Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, and others. Array programming with NumPy. Nature, 585(7825):357–362, 2020. doi:10.1038/s41586-020-2649-2.\n",
"[4] Scott G. Marquis, Valentin Sulzer, Robert Timms, Colin P. Please, and S. Jon Chapman. An asymptotic derivation of a single particle model with electrolyte. Journal of The Electrochemical Society, 166(15):A3693–A3706, 2019. doi:10.1149/2.0341915jes.\n",
"[5] Valentin Sulzer, Scott G. Marquis, Robert Timms, Martin Robinson, and S. Jon Chapman. Python Battery Mathematical Modelling (PyBaMM). Journal of Open Research Software, 9(1):14, 2021. doi:10.5334/jors.309.\n",
"\n"
]
}
],
"source": [
"pybamm.print_citations()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"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.11.6"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "9ff3d0c7e37de5f5aa47f4f719e4c84fc6cba7b39c571a05173422444e82fa58"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.4 ('dev': venv)",
"display_name": "dev",
"language": "python",
"name": "python3"
},
Expand All @@ -177,7 +177,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.9.16"
},
"toc": {
"base_numbering": 1,
Expand All @@ -194,7 +194,7 @@
},
"vscode": {
"interpreter": {
"hash": "0f0e5a277ebcf03e91e138edc3d4774b5dee64e7d6640c0d876f99a9f6b2a4dc"
"hash": "bca2b99bfac80e18288b793d52fa0653ab9b5fe5d22e7b211c44eb982a41c00c"
}
}
},
Expand Down
51 changes: 51 additions & 0 deletions examples/scripts/minimal_example_of_lookup_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pybamm
import pandas as pd
import numpy as np


def process_2D(name, data):
data = data.to_numpy()
x1 = np.unique(data[:, 0])
x2 = np.unique(data[:, 1])

value = data[:, 2]

x = (x1, x2)

value_data = value.reshape(len(x1), len(x2), order="C")

formatted_data = (name, (x, value_data))

return formatted_data


parameter_values = pybamm.ParameterValues(pybamm.parameter_sets.Chen2020)

# overwrite the diffusion coefficient with a 2D lookup table
D_s_n = parameter_values["Negative electrode diffusivity [m2.s-1]"]
df = pd.DataFrame(
{
"T": [0, 0, 25, 25, 45, 45],
"sto": [0, 1, 0, 1, 0, 1],
"D_s_n": [D_s_n, D_s_n, D_s_n, D_s_n, D_s_n, D_s_n],
}
)
df["T"] = df["T"] + 273.15
D_s_n_data = process_2D("Negative electrode diffusivity [m2.s-1]", df)


def D_s_n(sto, T):
name, (x, y) = D_s_n_data
return pybamm.Interpolant(x, y, [T, sto], name)


parameter_values["Negative electrode diffusivity [m2.s-1]"] = D_s_n

k_n = parameter_values["Negative electrode exchange-current density [A.m-2]"]

model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, parameter_values=parameter_values)

sim.solve([0, 30])

sim.plot(["Negative particle surface concentration [mol.m-3]"])
1 change: 1 addition & 0 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
from .logger import logger, set_logging_level, get_new_logger
from .settings import settings
from .citations import Citations, citations, print_citations

#
# Classes for the Expression Tree
#
Expand Down
Loading

0 comments on commit f87ba02

Please sign in to comment.