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

Issue 983 half cell #1121

Merged
merged 46 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f35712b
#983 started implementing half cell
brosaplanella Jun 27, 2020
7ff2bd6
#983 continued implementation, still not working
brosaplanella Jun 27, 2020
3ca7689
#983 half cell running need debugging
brosaplanella Jul 20, 2020
db733bc
#893 removed lithium parameter set
brosaplanella Jul 20, 2020
4e31bf4
#983 debug and flake8
brosaplanella Jul 20, 2020
e12a2b6
#983 started implementing half cell
brosaplanella Jun 27, 2020
e3ca575
#983 continued implementation, still not working
brosaplanella Jun 27, 2020
e028d6b
#983 half cell running need debugging
brosaplanella Jul 20, 2020
18f1376
#893 removed lithium parameter set
brosaplanella Jul 20, 2020
01c9ad4
#983 debug and flake8
brosaplanella Jul 20, 2020
450632f
#983 running half cell model
brosaplanella Jul 21, 2020
73b8e26
#983 started example running half cell experiment
brosaplanella Jul 21, 2020
f584712
#983 working example one GITT pulse
brosaplanella Jul 27, 2020
6969f2f
#983 flake8
brosaplanella Jul 27, 2020
75cd138
#983 remove old half cell model
brosaplanella Jul 27, 2020
29c21c4
Merge branch 'issue-983-half-cell' of https://github.com/ferranbrosa/…
brosaplanella Jul 27, 2020
12f049e
983 added discharge capacity
brosaplanella Jul 27, 2020
de9c69d
#983 added Modulo operator
brosaplanella Jul 27, 2020
ce5be6d
#983 use % symbol
brosaplanella Jul 27, 2020
fab44a5
#983 flake8
brosaplanella Jul 27, 2020
6a5221c
#983 added multiple GITT pulses
brosaplanella Jul 28, 2020
02a22cd
#983 implement modulo events
brosaplanella Jul 28, 2020
82967e4
flake8
brosaplanella Jul 28, 2020
0e2a9b2
#983 started half cell test but needs debugging
brosaplanella Jul 29, 2020
8247ba3
#983 changed notation to positive and negative electrodes
brosaplanella Aug 3, 2020
6c9ccd6
flake8
brosaplanella Aug 3, 2020
40d49d6
#983 fix test
brosaplanella Aug 3, 2020
b40c266
#983 added copy and fixed tests
brosaplanella Aug 3, 2020
344c2fc
#983 added error if BasicDFNHalfCell ran with Simulations
brosaplanella Aug 3, 2020
aea3fec
#983 update example
brosaplanella Aug 3, 2020
e2e6f55
#983 update CHANGELOG
brosaplanella Aug 3, 2020
c9d63da
Merge branch 'develop' into issue-983-half-cell
brosaplanella Aug 3, 2020
b55a0fa
flake8
brosaplanella Aug 3, 2020
b44d9cb
#983 add tests modulo
brosaplanella Aug 4, 2020
3ca2d60
#983 added floor and ceil operators
brosaplanella Aug 8, 2020
fdd0bb3
flake8
brosaplanella Aug 8, 2020
08884a0
#983 Tino's PR comments
brosaplanella Aug 8, 2020
16b4ee8
Merge branch 'develop' into issue-983-half-cell
brosaplanella Aug 10, 2020
61afe34
#983 improve coverage
brosaplanella Aug 10, 2020
6ea7f0a
#983 add more Modulo tests to improve coverage
brosaplanella Aug 10, 2020
65d7b59
flake8
brosaplanella Aug 10, 2020
b4ecfbc
#983 added test events Modulo
brosaplanella Aug 11, 2020
a3e9f39
#983 change default options to improve codacy
brosaplanella Aug 11, 2020
9912c7a
#983 undo previous change as it doesn't fix codacy
brosaplanella Aug 11, 2020
85a2e83
#983 added new test
brosaplanella Aug 11, 2020
e296965
#983 Tino's second round of comments
brosaplanella Aug 11, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Added DFN model for a half cell ([#1121](https://github.com/pybamm-team/PyBaMM/pull/1121))
- Added "R-averaged particle concentration" variables` ([#1118](https://github.com/pybamm-team/PyBaMM/pull/1118))
- Added support for sensitivity calculations to the casadi solver ([#1109](https://github.com/pybamm-team/PyBaMM/pull/1109))
- Added support for index 1 semi-explicit dae equations and sensitivity calculations to JAX BDF solver ([#1107](https://github.com/pybamm-team/PyBaMM/pull/1107))
Expand Down
65 changes: 65 additions & 0 deletions examples/scripts/DFN_half_cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#
# Example showing how to load and solve the DFN for the half cell
#

import pybamm
import numpy as np

pybamm.set_logging_level("INFO")

# load model
options = {"working electrode": "positive"}
model = pybamm.lithium_ion.BasicDFNHalfCell(options=options)

# create geometry
geometry = model.default_geometry

# load parameter values
chemistry = pybamm.parameter_sets.Chen2020
param = pybamm.ParameterValues(chemistry=chemistry)

# add lithium counter electrode parameter values
param.update(
{
"Lithium counter electrode exchange-current density [A.m-2]": 12.6,
"Lithium counter electrode conductivity [S.m-1]": 1.0776e7,
"Lithium counter electrode thickness [m]": 250e-6,
},
check_already_exists=False,
)

# process model and geometry
param.process_model(model)
param.process_geometry(geometry)

# set mesh
var = pybamm.standard_spatial_vars
var_pts = {var.x_n: 30, var.x_s: 30, var.x_p: 30, var.r_n: 10, var.r_p: 10}
mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)

# discretise model
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model)

# solve model
t_eval = np.linspace(0, 3800, 1000)
solver = pybamm.CasadiSolver(mode="fast", atol=1e-6, rtol=1e-3)
solution = solver.solve(model, t_eval)

# plot
plot = pybamm.QuickPlot(
solution,
[
"Negative particle surface concentration [mol.m-3]",
"Electrolyte concentration [mol.m-3]",
"Positive particle surface concentration [mol.m-3]",
"Current [A]",
"Negative electrode potential [V]",
"Electrolyte potential [V]",
"Positive electrode potential [V]",
"Terminal voltage [V]",
],
time_unit="seconds",
spatial_unit="um",
)
plot.dynamic_plot()
15 changes: 15 additions & 0 deletions pybamm/expression_tree/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,21 @@ def _binary_evaluate(self, left, right):
return left < right


class Modulo(BinaryOperator):
"Calculates the remainder of an integer division"

def __init__(self, left, right):
super().__init__("%", left, right)

def __str__(self):
""" See :meth:`pybamm.Symbol.__str__()`. """
return "{!s} mod {!s}".format(self.left, self.right)

def _binary_evaluate(self, left, right):
""" See :meth:`pybamm.BinaryOperator._binary_evaluate()`. """
return left % right


brosaplanella marked this conversation as resolved.
Show resolved Hide resolved
class Minimum(BinaryOperator):
" Returns the smaller of two objects "

Expand Down
2 changes: 2 additions & 0 deletions pybamm/expression_tree/operations/convert_to_casadi.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def _convert(self, symbol, t, y, y_dot, inputs):
converted_left = self.convert(left, t, y, y_dot, inputs)
converted_right = self.convert(right, t, y, y_dot, inputs)

if isinstance(symbol, pybamm.Modulo):
return casadi.fmod(converted_left, converted_right)
if isinstance(symbol, pybamm.Minimum):
return casadi.fmin(converted_left, converted_right)
if isinstance(symbol, pybamm.Maximum):
Expand Down
6 changes: 6 additions & 0 deletions pybamm/expression_tree/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ def __abs__(self):
pybamm.AbsoluteValue(self), keep_domains=True
)

def __mod__(self, other):
"""return an :class:`Modulo` object"""
return pybamm.simplify_if_constant(
pybamm.Modulo(self, other), keep_domains=True
)

def diff(self, variable):
"""
Differentiate a symbol with respect to a variable. For any symbol that can be
Expand Down
1 change: 1 addition & 0 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def options(self, extra_options):
"external submodels": [],
"sei": None,
"sei porosity change": False,
"working electrode": "negative"
brosaplanella marked this conversation as resolved.
Show resolved Hide resolved
}
# Change the default for cell geometry based on which thermal option is provided
extra_options = extra_options or {}
Expand Down
1 change: 1 addition & 0 deletions pybamm/models/full_battery_models/lithium_ion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .dfn import DFN
from .basic_dfn import BasicDFN
from .basic_spm import BasicSPM
from .basic_dfn_half_cell import BasicDFNHalfCell
Loading