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 1112 ec sei params #1136

Merged
merged 27 commits into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c0256cd
#1117 add total lithium variables
brosaplanella Jul 29, 2020
39166c8
#1056 needs further debugging
brosaplanella Jul 29, 2020
1849f63
#1117 check where do errors come from
brosaplanella Jul 30, 2020
7567a25
#1117 still needs debugging
brosaplanella Jul 30, 2020
c886a70
Merge branch 'develop' into issue-1117-total-lithium
brosaplanella Jul 30, 2020
0c15c50
#1117 tidied up
brosaplanella Jul 30, 2020
689091f
#1117 added total concentration in electrolyte
brosaplanella Jul 30, 2020
151588a
#1117 fixed bugs
brosaplanella Jul 30, 2020
0d38535
#1117 added test electrolyte but not working yet
brosaplanella Jul 30, 2020
691a9b0
#1117 fixed bug with extent of lithiation
brosaplanella Jul 30, 2020
1e9be08
flake8
brosaplanella Jul 30, 2020
d600ebe
#1117 fixed conservation electrolyte test
brosaplanella Jul 30, 2020
7779c4a
1117 started particle conservation test
brosaplanella Jul 31, 2020
f034db7
Merge branch 'develop' into issue-1117-total-lithium
brosaplanella Aug 6, 2020
eac9b6c
flake8
brosaplanella Aug 7, 2020
bd96d17
#1117 added test for conservation in particle
brosaplanella Aug 7, 2020
cc9a385
flake8
brosaplanella Aug 7, 2020
81ea029
#1117 fixed added lithium loss variable to ec_reaction_limited
brosaplanella Aug 11, 2020
26279d5
Merge branch 'develop' into issue-1117-total-lithium
brosaplanella Aug 27, 2020
372639f
flake8
brosaplanella Aug 27, 2020
7e9b58e
remove pkl files from examples folder
rtimms Sep 1, 2020
208c010
Merge branch 'develop' of https://github.com/pybamm-team/PyBaMM into …
rtimms Sep 4, 2020
71444db
Merge branch 'develop' into issue-1112-EC-sei-params
rtimms Sep 4, 2020
ebcbafd
#1112 reformat EC sei model
rtimms Sep 4, 2020
fec561f
#1112 Tino comments
rtimms Sep 4, 2020
6d5ede2
#1112 fix examples
rtimms Sep 4, 2020
e5fd81a
#1112 fix examples
rtimms Sep 4, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Added variables which track the total amount of lithium in the system ([#1136](https://github.com/pybamm-team/PyBaMM/pull/1136))
- Added `Upwind` and `Downwind` operators for convection ([#1134](https://github.com/pybamm-team/PyBaMM/pull/1134))
- Added Getting Started notebook on solver options and changing the mesh. Also added a notebook detailing the different thermal options, and a notebook explaining the steps that occur behind the scenes in the `Simulation` class ([#1131](https://github.com/pybamm-team/PyBaMM/pull/1131))
- Added particle submodel that use a polynomial approximation to the concentration within the electrode particles ([#1130](https://github.com/pybamm-team/PyBaMM/pull/1130))
Expand All @@ -18,6 +19,7 @@

## Bug fixes

- Fixed bug where some parameters were not being set by the `EcRectionLimited` SEI model ([#1136](https://github.com/pybamm-team/PyBaMM/pull/1136))
- Fixed bug on electrolyte potential for `BasicDFNHalfCell` ([#1133](https://github.com/pybamm-team/PyBaMM/pull/1133))
- Fixed `r_average` to work with `SecondaryBroadcast` ([#1118](https://github.com/pybamm-team/PyBaMM/pull/1118))
- Fixed finite volume discretisation of spherical integrals ([#1118](https://github.com/pybamm-team/PyBaMM/pull/1118))
Expand Down
Binary file removed examples/notebooks/Getting Started/SPMe.pkl
Binary file not shown.
Binary file removed examples/notebooks/Getting Started/SPMe_sol.pkl
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{
"data": {
"text/plain": [
"<pybamm.solvers.solution.Solution at 0x7f33921f46d8>"
"<pybamm.solvers.solution.Solution at 0x7f39e107d1d0>"
]
},
"execution_count": 1,
Expand Down Expand Up @@ -265,7 +265,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dc5c33b364df4561acc98455a6ec6d9c",
"model_id": "7e116fdff90e40b28b3f13b79f3e7347",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -313,7 +313,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c3c3296fe37e4bffba0dada58dc06afa",
"model_id": "cb9640519af3475b9b921b8523c01020",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -327,7 +327,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f338e87b2b0>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f39dc81a0b8>"
]
},
"execution_count": 11,
Expand Down Expand Up @@ -380,6 +380,27 @@
"In this notebook we have shown how to extract and store the outputs of PyBaMM's simulations. Next, in [Tutorial 7](./Tutorial%207%20-%20Model%20options.ipynb) we will show how to change the model options."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before finishing we will remove the data files we saved so that we leave the directory as we found it"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.remove(\"SPMe.pkl\")\n",
"os.remove(\"SPMe_sol.pkl\")\n",
"os.remove(\"sol_data.pkl\")\n",
"os.remove(\"sol_data.csv\")\n",
"os.remove(\"sol_data.mat\")"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
Binary file removed examples/notebooks/Getting Started/sol_data.pkl
Binary file not shown.
103 changes: 52 additions & 51 deletions examples/notebooks/using-submodels.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/scripts/SPMe_SOC.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
# solve model
t_eval = np.linspace(0, 3600, 100)
sol = model.default_solver.solve(model, t_eval)
xpext = sol["Positive electrode average extent of lithiation"]
xnext = sol["Negative electrode average extent of lithiation"]
xpext = sol["X-averaged positive electrode extent of lithiation"]
xnext = sol["X-averaged negative electrode extent of lithiation"]
xpsurf = sol["X-averaged positive particle surface concentration"]
xnsurf = sol["X-averaged negative particle surface concentration"]
time = sol["Time [h]"]
Expand Down
1 change: 1 addition & 0 deletions examples/scripts/custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
model.submodels["current collector"] = pybamm.current_collector.Uniform(model.param)
model.submodels["thermal"] = pybamm.thermal.isothermal.Isothermal(model.param)
model.submodels["porosity"] = pybamm.porosity.Constant(model.param)
model.submodels["negative electrode"] = pybamm.electrode.ohm.LeadingOrder(
model.param, "Negative"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ def _get_standard_flux_variables(self, N_e):

return variables

def _get_total_concentration_electrolyte(self, c_e, epsilon):
"""
A private function to obtain the total ion concentration in the electrolyte.

Parameters
----------
c_e : :class:`pybamm.Symbol`
The electrolyte concentration
epsilon : :class:`pybamm.Symbol`
The porosity

Returns
-------
variables : dict
The "Total concentration in electrolyte [mol]" variable.
"""

c_e_typ = self.param.c_e_typ
L_x = self.param.L_x
A = self.param.A_cc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should this be epsilon * c_e here?

Copy link
Member

Choose a reason for hiding this comment

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

Yep

c_e_total = pybamm.x_average(epsilon * c_e)

variables = {
"Total concentration in electrolyte [mol]": c_e_typ * L_x * A * c_e_total
}

return variables

def set_events(self, variables):
c_e = variables["Electrolyte concentration"]
self.events.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_fundamental_variables(self):
def get_coupled_variables(self, variables):

tor_0 = variables["Leading-order electrolyte tortuosity"]
eps = variables["Leading-order porosity"]
c_e_0_av = variables["Leading-order x-averaged electrolyte concentration"]
c_e = variables["Electrolyte concentration"]
i_e = variables["Electrolyte current density"]
Expand All @@ -51,6 +52,7 @@ def get_coupled_variables(self, variables):
N_e = N_e_diffusion + N_e_migration + N_e_convection

variables.update(self._get_standard_flux_variables(N_e))
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ def get_fundamental_variables(self):

return variables

def get_coupled_variables(self, variables):
c_e = variables["Electrolyte concentration"]
eps = variables["Porosity"]

variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,13 @@ def get_coupled_variables(self, variables):
)
variables.update(self._get_standard_flux_variables(N_e))

c_e = pybamm.Concatenation(c_e_n, c_e_s, c_e_p)
eps = pybamm.Concatenation(
pybamm.PrimaryBroadcast(eps_n_0, "negative electrode"),
pybamm.PrimaryBroadcast(eps_s_0, "separator"),
pybamm.PrimaryBroadcast(eps_p_0, "positive electrode"),
)

variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_fundamental_variables(self):
def get_coupled_variables(self, variables):

tor = variables["Electrolyte tortuosity"]
eps = variables["Porosity"]
c_e = variables["Electrolyte concentration"]
i_e = variables["Electrolyte current density"]
v_box = variables["Volume-averaged velocity"]
Expand All @@ -48,6 +49,7 @@ def get_coupled_variables(self, variables):
N_e = N_e_diffusion + N_e_migration + N_e_convection

variables.update(self._get_standard_flux_variables(N_e))
variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def get_coupled_variables(self, variables):

variables.update(self._get_standard_flux_variables(N_e))

c_e_av = pybamm.standard_variables.c_e_av
c_e = pybamm.Concatenation(
pybamm.PrimaryBroadcast(c_e_av, ["negative electrode"]),
pybamm.PrimaryBroadcast(c_e_av, ["separator"]),
pybamm.PrimaryBroadcast(c_e_av, ["positive electrode"]),
)
eps = variables["Porosity"]

variables.update(self._get_total_concentration_electrolyte(c_e, eps))

return variables

def set_rhs(self, variables):
Expand Down
130 changes: 96 additions & 34 deletions pybamm/models/submodels/interface/sei/base_sei.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,18 @@ def _get_standard_thickness_variables(self, L_inner, L_outer):
The variables which can be derived from the SEI thicknesses.
"""
param = self.param
domain = self.domain.lower() + " electrode"

# Set scales to one for the "no SEI" model so that they are not required
# by parameter values in general
# Set length scale to one for the "no SEI" model so that it is not
# required by parameter values in general
if isinstance(self, pybamm.sei.NoSEI):
L_scale = 1
n_scale = 1
n_outer_scale = 1
v_bar = 1
else:
L_scale = param.L_sei_0_dim
n_scale = param.L_sei_0_dim * param.a_n_dim / param.V_bar_inner_dimensional
n_outer_scale = (
param.L_sei_0_dim * param.a_n_dim / param.V_bar_outer_dimensional
)
v_bar = param.v_bar

L_inner_av = pybamm.x_average(L_inner)
L_outer_av = pybamm.x_average(L_outer)

n_inner = L_inner # inner SEI concentration
n_outer = L_outer # outer SEI concentration
n_inner_av = pybamm.x_average(L_inner)
n_outer_av = pybamm.x_average(L_outer)

n_SEI = n_inner + n_outer / v_bar # SEI concentration
n_SEI_av = pybamm.x_average(n_SEI)

Q_sei = n_SEI_av * self.param.L_n * self.param.L_y * self.param.L_z

domain = self.domain.lower() + " electrode"

variables = {
"Inner " + domain + " sei thickness": L_inner,
"Inner " + domain + " sei thickness [m]": L_inner * L_scale,
Expand All @@ -84,21 +65,10 @@ def _get_standard_thickness_variables(self, L_inner, L_outer):
"Outer " + domain + " sei thickness [m]": L_outer * L_scale,
"X-averaged outer " + domain + " sei thickness": L_outer_av,
"X-averaged outer " + domain + " sei thickness [m]": L_outer_av * L_scale,
"Inner " + domain + " sei concentration [mol.m-3]": n_inner * n_scale,
"X-averaged inner "
+ domain
+ " sei concentration [mol.m-3]": n_inner_av * n_scale,
"Outer " + domain + " sei concentration [mol.m-3]": n_outer * n_outer_scale,
"X-averaged outer "
+ domain
+ " sei concentration [mol.m-3]": n_outer_av * n_outer_scale,
self.domain + " sei concentration [mol.m-3]": n_SEI * n_scale,
"X-averaged " + domain + " sei concentration [mol.m-3]": n_SEI_av * n_scale,
"Loss of lithium to " + domain + " sei [mol]": Q_sei * n_scale,
}

# Get variables related to the total thickness
L_sei = L_inner + L_outer

variables.update(self._get_standard_total_thickness_variables(L_sei))

return variables
Expand All @@ -125,6 +95,98 @@ def _get_standard_total_thickness_variables(self, L_sei):
}
return variables

def _get_standard_concentraion_variables(self, variables):
"Update variables related to the SEI concentration"
param = self.param
domain = self.domain.lower() + " electrode"

# Set scales to one for the "no SEI" model so that they are not required
# by parameter values in general
if isinstance(self, pybamm.sei.NoSEI):
n_scale = 1
n_outer_scale = 1
v_bar = 1
# Set scales for the "EC Reaction Limited" model
elif isinstance(self, pybamm.sei.EcReactionLimited):
n_scale = 1
n_outer_scale = self.param.c_ec_0_dim
v_bar = 1
else:
n_scale = param.L_sei_0_dim * param.a_n_dim / param.V_bar_inner_dimensional
n_outer_scale = (
param.L_sei_0_dim * param.a_n_dim / param.V_bar_outer_dimensional
)
v_bar = param.v_bar

L_inner = variables["Inner " + domain + " sei thickness"]
L_outer = variables["Outer " + domain + " sei thickness"]

# Set SEI concentration variables. Note these are defined differently for
# the "EC Reaction Limited" model
if isinstance(self, pybamm.sei.EcReactionLimited):
j_outer = variables["Outer " + domain + " sei interfacial current density"]
# concentration of EC on graphite surface, base case = 1
if self.domain == "Negative":
C_ec = self.param.C_ec_n

c_ec = pybamm.Scalar(1) + j_outer * L_outer * C_ec
c_ec_av = pybamm.x_average(c_ec)

n_inner = pybamm.FullBroadcast(
0, self.domain.lower() + " electrode", "current collector"
) # inner SEI concentration
n_outer = j_outer * L_outer * C_ec # outer SEI concentration
else:
n_inner = L_inner # inner SEI concentration
n_outer = L_outer # outer SEI concentration

n_inner_av = pybamm.x_average(L_inner)
n_outer_av = pybamm.x_average(L_outer)

n_SEI = n_inner + n_outer / v_bar # SEI concentration
n_SEI_av = pybamm.x_average(n_SEI)

Q_sei = n_SEI_av * self.param.L_n * self.param.L_y * self.param.L_z

variables.update(
{
"Inner " + domain + " sei concentration [mol.m-3]": n_inner * n_scale,
"X-averaged inner "
+ domain
+ " sei concentration [mol.m-3]": n_inner_av * n_scale,
"Outer "
+ domain
+ " sei concentration [mol.m-3]": n_outer * n_outer_scale,
"X-averaged outer "
+ domain
+ " sei concentration [mol.m-3]": n_outer_av * n_outer_scale,
self.domain + " sei concentration [mol.m-3]": n_SEI * n_scale,
"X-averaged "
+ domain
+ " sei concentration [mol.m-3]": n_SEI_av * n_scale,
"Loss of lithium to " + domain + " sei [mol]": Q_sei * n_scale,
}
)

# Also set variables for EC surface concentration
if isinstance(self, pybamm.sei.EcReactionLimited):
variables.update(
{
self.domain + " electrode EC surface concentration": c_ec,
self.domain
+ " electrode EC surface concentration [mol.m-3]": c_ec
* n_outer_scale,
"X-averaged "
+ self.domain.lower()
+ " electrode EC surface concentration": c_ec_av,
"X-averaged "
+ self.domain.lower()
+ " electrode EC surface concentration": c_ec_av * n_outer_scale,
}
)

return variables

def _get_standard_reaction_variables(self, j_inner, j_outer):
"""
A private function to obtain the standard variables which
Expand Down
6 changes: 5 additions & 1 deletion pybamm/models/submodels/interface/sei/constant_sei.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@


class ConstantSEI(BaseModel):
"""Base class for SEI with constant thickness.
"""
Class for SEI with constant thickness.

Note that there is no SEI current, so we don't need to update the "sum of
interfacial current densities" variables from
Expand All @@ -31,6 +32,9 @@ def get_fundamental_variables(self):
L_outer = self.param.L_outer_0
variables = self._get_standard_thickness_variables(L_inner, L_outer)

# Concentrations (derived from thicknesses)
variables.update(self._get_standard_concentraion_variables(variables))

# Reactions
zero = pybamm.FullBroadcast(
pybamm.Scalar(0), self.domain.lower() + " electrode", "current collector"
Expand Down
Loading