Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSMR model #3116

Merged
merged 53 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e60ec43
basic MSMR model with fast diffusion
rtimms May 26, 2023
094f2b6
run test simulation
rtimms May 26, 2023
6387858
particle problem in basic SP MSMR
rtimms May 31, 2023
d1b20a7
update example
rtimms Jun 13, 2023
318f6d3
merge develop
rtimms Jun 13, 2023
e0e42d1
MSMR submodels for diffusion and ocp
rtimms Jun 14, 2023
c644be8
MSMR model options + example
rtimms Jun 14, 2023
e7f9c18
fix options test
rtimms Jun 15, 2023
8d92c18
merge develop
rtimms Jun 20, 2023
dbf2018
esoh for msmr mostly working
rtimms Jun 21, 2023
3a7c39f
start cleaning up esoh
rtimms Jun 21, 2023
ac821e8
fix eSOH
rtimms Jun 23, 2023
0c61222
improve esoh
rtimms Jun 23, 2023
f9a92be
Use .diff to get dx/dU
rtimms Jun 23, 2023
86c4184
esoh tests
rtimms Jun 23, 2023
c49e36f
merge develop
rtimms Jul 4, 2023
42c7438
fix diff for broadcasts
rtimms Jul 4, 2023
4c0758d
start msmr notebook
rtimms Jul 6, 2023
c94d842
improve coverage
rtimms Jul 9, 2023
75835b5
update esoh
rtimms Jul 9, 2023
0f7c2ab
clean up notebook
rtimms Jul 10, 2023
51702ca
merge develop
rtimms Jul 10, 2023
ab61213
add helper function for msmr reactions
rtimms Jul 10, 2023
7b12a61
docs and notebook
rtimms Jul 11, 2023
a33c3af
fix initial soc at solve
rtimms Jul 12, 2023
d88dfb8
merge develop
rtimms Jul 12, 2023
8396295
update notebook
rtimms Jul 12, 2023
917a53b
fix test
rtimms Jul 12, 2023
9af984d
merge develop
rtimms Jul 18, 2023
8c95a6d
add individual reaction params
rtimms Jul 18, 2023
085543f
fix setting by reaction index
rtimms Jul 18, 2023
899067f
add MSMR model class
rtimms Jul 18, 2023
e9148ae
add paramaters by reaction index
rtimms Jul 19, 2023
986d171
debugging current density
rtimms Jul 19, 2023
10bec45
fix exchange current parameters
rtimms Jul 20, 2023
e549a4e
fix PSD
rtimms Jul 21, 2023
f7f8741
merge develop
rtimms Jul 21, 2023
78d2776
esoh coverage
rtimms Jul 21, 2023
925a04e
merge develop
rtimms Jul 21, 2023
fc0d71e
update notebook
rtimms Jul 28, 2023
c4953df
merge 'develop' into 'msmr'
rtimms Aug 10, 2023
d73a1eb
style: pre-commit fixes
pre-commit-ci[bot] Aug 10, 2023
32b73e5
fix tests
rtimms Aug 10, 2023
54a06e0
merge conflicts
rtimms Aug 10, 2023
d8dace3
debug half cell
rtimms Aug 11, 2023
9e513bf
merge develop
rtimms Aug 31, 2023
d1cd977
relax option check
rtimms Aug 31, 2023
d3d921d
merge develop
rtimms Sep 11, 2023
c030b88
ferran msmr comments
rtimms Sep 11, 2023
f8a0fbc
update docs
rtimms Sep 11, 2023
c330ffa
fix example notebooks
rtimms Sep 13, 2023
cb36b35
merge develop
rtimms Sep 13, 2023
77a62c1
update bib in docs
rtimms Sep 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Features

- The parameter "Ambient temperature [K]" can now be given as a function of position `(y,z)` and time `t`. The "edge" and "current collector" heat transfer coefficient parameters can also depend on `(y,z)` ([#3257](https://github.com/pybamm-team/PyBaMM/pull/3257))
- Spherical and cylindrical shell domains can now be solved with any boundary conditions ([#3237](https://github.com/pybamm-team/PyBaMM/pull/3237))
- Processed variables now get the spatial variables automatically, allowing plotting of more generic models ([#3234](https://github.com/pybamm-team/PyBaMM/pull/3234))
- Numpy functions now work with PyBaMM symbols (e.g. `np.exp(pybamm.Symbol("a"))` returns `pybamm.Exp(pybamm.Symbol("a"))`). This means that parameter functions can be specified using numpy functions instead of pybamm functions. Additionally, combining numpy arrays with pybamm objects now works (the numpy array is converted to a pybamm array) ([#3205](https://github.com/pybamm-team/PyBaMM/pull/3205))
- Implement the MSMR model ([#3116](https://github.com/pybamm-team/PyBaMM/pull/3116))

## Bug fixes

Expand Down
4 changes: 4 additions & 0 deletions docs/source/api/models/lithium_ion/electrode_soh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ Electrode SOH models

.. autofunction:: pybamm.lithium_ion.get_min_max_stoichiometries

.. autofunction:: pybamm.lithium_ion.get_initial_ocps

.. autofunction:: pybamm.lithium_ion.get_min_max_ocps

.. footbibliography::
7 changes: 7 additions & 0 deletions docs/source/api/models/lithium_ion/msmr.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Multi-Species Multi-Reaction (MSMR) Model
=========================================

.. autoclass:: pybamm.lithium_ion.MSMR
:members:

.. footbibliography::
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MSMR Open Circuit Potential
===========================


.. autoclass:: pybamm.open_circuit_potential.MSMROpenCircuitPotential
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MSMR Diffusion
==============

.. autoclass:: pybamm.particle.MSMRDiffusion
:members:
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
"V_hat = pybamm.Parameter(\"Partial molar volume [m3.mol-1]\")\n",
"c_inf = pybamm.Parameter(\"Bulk electrolyte solvent concentration [mol.m-3]\")\n",
"\n",
"\n",
"def D(cc):\n",
" return pybamm.FunctionParameter(\"Diffusivity [m2.s-1]\", {\"Solvent concentration [mol.m-3]\": cc})"
]
Expand Down Expand Up @@ -485,9 +486,11 @@
" {\"SEI layer\": {xi: {\"min\": pybamm.Scalar(0), \"max\": pybamm.Scalar(1)}}}\n",
")\n",
"\n",
"\n",
"def Diffusivity(cc):\n",
" return cc * 10**(-12)\n",
"\n",
"\n",
"# parameter values (not physically based, for example only!)\n",
"param = pybamm.ParameterValues(\n",
" {\n",
Expand Down Expand Up @@ -565,6 +568,7 @@
"L_0_eval = param.evaluate(L_0)\n",
"xi = np.linspace(0, 1, 100) # dimensionless space\n",
"\n",
"\n",
"def plot(t):\n",
" _, (ax1, ax2) = plt.subplots(1, 2 ,figsize=(10,5))\n",
" ax1.plot(solution.t, L_out(solution.t) * 1e6)\n",
Expand All @@ -581,6 +585,7 @@
" plt.tight_layout()\n",
" plt.show()\n",
" \n",
"\n",
"import ipywidgets as widgets\n",
"widgets.interact(plot, t=widgets.FloatSlider(min=0,max=solution.t[-1],step=0.1,value=0));"
]
Expand Down
20 changes: 10 additions & 10 deletions docs/source/examples/notebooks/models/DFN.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@
"\n",
"#### Current:\n",
"$$\n",
"i_{\\text{e,n}}\\big|_{x=0} = 0, \\quad i_{\\text{e,p}}\\big|_{x=1}=0, \\\\\n",
"i_{\\text{e,n}}\\big|_{x=0} = 0, \\quad i_{\\text{e,p}}\\big|_{x=L}=0, \\\\\n",
"\\phi_{\\text{e,n}}\\big|_{x=L_{\\text{n}}} = \\phi_{\\text{e,s}}\\big|_{x=L_{\\text{n}}}, \\quad i_{\\text{e,n}}\\big|_{x=L_{\\text{n}}} = i_{\\text{e,s}}\\big\\vert_{x=L_{\\text{n}}} = I, \\\\ \n",
"\\phi_{\\text{e,s}}\\big|_{x=1-L_{\\text{p}}} = \\phi_{\\text{e,p}}\\big|_{x=1-L_{\\text{p}}}, \\quad \n",
" i_{\\text{e,s}}\\big|_{x=1-L_{\\text{p}}} = i_{\\text{e,p}}\\big|_{x=1-L_{\\text{p}}} = I.\n",
"\\phi_{\\text{e,s}}\\big|_{x=L-L_{\\text{p}}} = \\phi_{\\text{e,p}}\\big|_{x=L-L_{\\text{p}}}, \\quad \n",
" i_{\\text{e,s}}\\big|_{x=L-L_{\\text{p}}} = i_{\\text{e,p}}\\big|_{x=L-L_{\\text{p}}} = I.\n",
"$$\n",
"\n",
"#### Concentration in the electrolyte:\n",
"$$\n",
"N_{\\text{e,n}}\\big|_{x=0} = 0, \\quad N_{\\text{e,p}}\\big|_{x=1}=0,\\\\ \n",
"N_{\\text{e,n}}\\big|_{x=0} = 0, \\quad N_{\\text{e,p}}\\big|_{x=L}=0,\\\\ \n",
"c_{\\text{e,n}}\\big|_{x=L_{\\text{n}}} = c_{\\text{e,s}}|_{x=L_{\\text{n}}}, \\quad N_{\\text{e,n}}\\big|_{x=L_{\\text{n}}}=N_{\\text{e,s}}\\big|_{x=L_{\\text{n}}}, \\\\\n",
"c_{\\text{e,s}}|_{x=1-L_{\\text{p}}}=c_{\\text{e,p}}|_{x=1-L_{\\text{p}}}, \\quad N_{\\text{e,s}}\\big|_{x=1-L_{\\text{p}}}=N_{\\text{e,p}}\\big|_{x=1-L_{\\text{p}}}.\n",
"c_{\\text{e,s}}|_{x=L-L_{\\text{p}}}=c_{\\text{e,p}}|_{x=L-L_{\\text{p}}}, \\quad N_{\\text{e,s}}\\big|_{x=L-L_{\\text{p}}}=N_{\\text{e,p}}\\big|_{x=L-L_{\\text{p}}}.\n",
"$$\n",
"\n",
"#### Concentration in the electrode active material:\n",
"$$\n",
"N_{\\text{s,k}}\\big|_{r_{\\text{k}}=0} = 0, \\quad \\text{k} \\in \\text{n, p}, \\quad \\ \\ - N_{\\text{s,k}}\\big|_{r_{\\text{k}}=1} = \\frac{j_{\\text{k}}}{F}, \\quad \\text{k} \\in \\text{n, p}.\n",
"N_{\\text{s,k}}\\big|_{r_{\\text{k}}=0} = 0, \\quad \\text{k} \\in \\text{n, p}, \\quad \\ \\ N_{\\text{s,k}}\\big|_{r_{\\text{k}}=R_{\\text{k}}} = \\frac{j_{\\text{k}}}{F}, \\quad \\text{k} \\in \\text{n, p}.\n",
"$$\n",
"\n",
"#### Reference potential:\n",
Expand All @@ -87,8 +87,8 @@
"#### And the initial conditions:\n",
"\n",
"$$\n",
"c_{\\text{s,k}}(x,r,0) = c_{\\text{s,k,0}}, \\quad \\phi_{\\text{s,n}}(x,0) = 0, \\quad \\phi_{\\text{s,p}}(x,0) = \\phi_{\\text{s,p,0}}, \\\\ \\text{k} \\in \\text{n, p},\\\\\n",
"\\phi_{\\text{e,k}}(x,0) = \\phi_{\\text{e,0}}, \\quad c_{\\text{e,k}}(x,0) = 1, \\\\ \\text{k} \\in \\text{n, s, p}. \n",
"c_{\\text{s,k}}(x,r,0) = c_{\\text{s,k,0}}, \\quad \\text{k} \\in \\text{n, p},\\\\\n",
"c_{\\text{e,k}}(x,0) = c_{\\text{e,0}}, \\quad \\text{k} \\in \\text{n, s, p}. \n",
"$$\n"
]
},
Expand Down Expand Up @@ -269,7 +269,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pybamm",
"display_name": "dev",
"language": "python",
"name": "python3"
},
Expand All @@ -287,7 +287,7 @@
},
"vscode": {
"interpreter": {
"hash": "187972e187ab8dfbecfab9e8e194ae6d08262b2d51a54fa40644e3ddb6b5f74c"
"hash": "bca2b99bfac80e18288b793d52fa0653ab9b5fe5d22e7b211c44eb982a41c00c"
}
}
},
Expand Down
582 changes: 582 additions & 0 deletions docs/source/examples/notebooks/models/MSMR.ipynb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picky comment, can you delete the empty cells at the end of the notebook?

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions docs/source/examples/notebooks/models/SPMe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,26 @@
"\n",
"ii) At the centre of each particle the standard no-flux condition is imposed, and the flux on the surface of the particle is simply the current $I$ divided by the thickness of the electrode $L_{\\text{k}}$, as in the SPM. Since lithium is transferred between the electrolyte and particles, the flux through the particle surface also enters the electrolyte diffusion equation as a source/sink term. There is no transfer of lithium between the electrolyte and current collectors, which leads to no flux boundary conditions on the lithium concentration in the electrolyte $c_{\\text{e,k}}$ at either end of the cell. \n",
"\n",
"iii) We must also impose initial conditions which correspond to setting an initial concentration in each particle $c_{\\text{s,k}}(t=0) = c_{\\text{s,k,0}}$, and to having no deviation from the initial (uniform) lithium concentration in the electrolyte $c_{\\text{e,k}}(t=0) = 0$. \n",
"iii) We must also impose initial conditions which correspond to setting an initial concentration in each particle $c_{\\text{s,k}}(t=0) = c_{\\text{s,k,0}}$, and to having no deviation from the initial (uniform) lithium concentration in the electrolyte $c_{\\text{e,k}}(t=0) = c_{\\text{e,0}}$. \n",
"\n",
"\n",
"The model equations for the SPMe read: \n",
"\n",
"\n",
"#### Particles: \n",
"$$\n",
"\\mathcal{C}_{\\text{k}} \\frac{\\partial c_{\\text{s,k}}}{\\partial t} = -\\frac{1}{r_{\\text{k}}^2} \\frac{\\partial}{\\partial r_{\\text{k}}} \\left(r_{\\text{k}}^2 N_{\\text{s,k}}\\right), \\\\\n",
"\\frac{\\partial c_{\\text{s,k}}}{\\partial t} = -\\frac{1}{r_{\\text{k}}^2} \\frac{\\partial}{\\partial r_{\\text{k}}} \\left(r_{\\text{k}}^2 N_{\\text{s,k}}\\right), \\\\\n",
"N_{\\text{s,k}} = -D_{\\text{s,k}}(c_{\\text{s,k}}) \\frac{\\partial c_{\\text{s,k}}}{\\partial r_{\\text{k}}}, \\quad \\text{k} \\in \\text{n, p},\n",
"$$\n",
"\n",
"$$\n",
"N_{\\text{s,k}}\\big|_{r_{\\text{k}}=0} = 0, \\quad \\text{k} \\in \\text{n, p}, \\quad \\ \\ - \\frac{a_{R, \\text{k}}\\gamma_{\\text{k}}}{\\mathcal{C}_{\\text{k}}} N_{\\text{s,k}}\\big|_{r_{\\text{k}}=1} = \n",
"N_{\\text{s,k}}\\big|_{r_{\\text{k}}=0} = 0, \\quad \\text{k} \\in \\text{n, p}, \\quad \\ \\ N_{\\text{s,k}}\\big|_{r_{\\text{k}}=R_{\\text{k}}} = \n",
"\\begin{cases}\n",
"\t\t \\frac{I}{L_{\\text{n}}}, \\quad &\\text{k}=\\text{n}, \\\\ \n",
"\t\t -\\frac{I}{L_{\\text{p}}}, \\quad &\\text{k}=\\text{p}, \n",
"\t\t \\frac{I}{Fa_{\\text{n}}L_{\\text{n}}}, \\quad &\\text{k}=\\text{n}, \\\\ \n",
"\t\t -\\frac{I}{Fa_{\\text{p}}L_{\\text{p}}}, \\quad &\\text{k}=\\text{p}, \n",
"\\end{cases} \\\\\n",
"c_{\\text{s,k}}(r_{\\text{k}},0) = c_{\\text{s,k,0}}, \\quad \\text{k} \\in \\text{n, p},\n",
"$$\n",
"\n",
"where $D_{\\text{s,k}}$ is the diffusion coefficient in the solid, $N_{\\text{s,k}}$ denotes the flux of lithium ions in the solid particle within the region $\\text{k}$, and $r_{\\text{k}} \\in[0,1]$ is the radial coordinate of the particle in electrode $\\text{k}$. All other relevant parameters are given in the table at the end of this notebook.\n",
"where $D_{\\text{s,k}}$ is the diffusion coefficient in the solid, $N_{\\text{s,k}}$ denotes the flux of lithium ions in the solid particle within the region $\\text{k}$, and $r_{\\text{k}} \\in[0,R_{\\text{k}}]$ is the radial coordinate of the particle in electrode $\\text{k}$. All other relevant parameters are given in the table at the end of this notebook.\n",
"\n",
"\n",
"#### Electrolyte: \n",
Expand All @@ -66,10 +64,10 @@
"$$\n",
"\n",
"$$\n",
"N_{\\text{e,n}}\\big|_{x=0} = 0, \\quad N_{\\text{e,p}}\\big|_{x=1}=0, \\\\\n",
"N_{\\text{e,n}}\\big|_{x=0} = 0, \\quad N_{\\text{e,p}}\\big|_{x=L}=0, \\\\\n",
"c_{\\text{e,k}}(x,0) = 0, \\quad \\text{k} \\in \\text{n, s, p},\n",
"$$\n",
"where $D_{\\text{e}}$ is the diffusion coefficient in the solid, $N_{\\text{e,k}}$ denotes the flux of lithium ions in the electrolyte within the region $\\text{k}$, and $x\\in[0,1]$ is the macroscopic through-cell distance. This equation is also solved subject to continuity of concentration and flux at the electrode/separator interfaces.\n",
"where $D_{\\text{e}}$ is the diffusion coefficient in the solid, $N_{\\text{e,k}}$ denotes the flux of lithium ions in the electrolyte within the region $\\text{k}$, and $x\\in[0,L]$ is the macroscopic through-cell distance. This equation is also solved subject to continuity of concentration and flux at the electrode/separator interfaces.\n",
"\n",
"### Voltage Expression\n",
"The voltage is obtained from the expression: \n",
Expand All @@ -90,7 +88,7 @@
"where\n",
"$$\n",
"\\bar{c}_{\\text{e,n}} = \\frac{1}{L_{\\text{n}}}\\int_0^{L_{\\text{n}}} c_{\\text{e,n}} \\, \\text{d}x, \\quad\n",
"\\bar{c}_{\\text{e,p}} = \\frac{1}{L_{\\text{p}}}\\int_{1-L_{\\text{p}}}^{1} c_{\\text{e,p}} \\, \\text{d}x.\n",
"\\bar{c}_{\\text{e,p}} = \\frac{1}{L_{\\text{p}}}\\int_{L-L_{\\text{p}}}^{L} c_{\\text{e,p}} \\, \\text{d}x.\n",
"$$\n",
"\n",
"More details can be found in [[3]](#References)."
Expand Down Expand Up @@ -248,7 +246,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "pybamm",
"display_name": "dev",
"language": "python",
"name": "python3"
},
Expand All @@ -266,7 +264,7 @@
},
"vscode": {
"interpreter": {
"hash": "187972e187ab8dfbecfab9e8e194ae6d08262b2d51a54fa40644e3ddb6b5f74c"
"hash": "bca2b99bfac80e18288b793d52fa0653ab9b5fe5d22e7b211c44eb982a41c00c"
}
}
},
Expand Down
13 changes: 13 additions & 0 deletions docs/source/examples/notebooks/models/jelly-roll-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,36 @@
"outputs": [],
"source": [
"# define spiral \n",
"\n",
"\n",
"def spiral_pos_inner(t):\n",
" return r0 - eps * delta + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_pos_outer(t):\n",
" return r0 + eps * delta + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_neg_inner(t):\n",
" return r0 - eps * delta + eps / 2 + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_neg_outer(t):\n",
" return r0 + eps * delta + eps / 2 + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_am1_inner(t):\n",
" return r0 + eps * delta + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_am1_outer(t):\n",
" return r0 - eps * delta + eps / 2 + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_am2_inner(t):\n",
" return r0 + eps * delta + eps / 2 + eps * t / (2 * pi)\n",
"\n",
"\n",
"def spiral_am2_outer(t):\n",
" return r0 - eps * delta + eps + eps * t / (2 * pi)"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
"def current_LAM(i, T):\n",
" return -1e-10 * (abs(i) + 1e3 * abs(i) ** 0.5)\n",
"\n",
"\n",
"model = pybamm.lithium_ion.DFN(\n",
" options=\n",
" {\n",
Expand Down
Loading
Loading