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

Fix half cell bug #1133

Merged
merged 3 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -14,6 +14,7 @@

## Bug fixes

- 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))
- `t_eval` now gets changed to a `linspace` if a list of length 2 is passed ([#1113](https://github.com/pybamm-team/PyBaMM/pull/1113))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class BasicDFNHalfCell(BaseModel):
"""

def __init__(
self,
name="Doyle-Fuller-Newman half cell model",
options=None,
self, name="Doyle-Fuller-Newman half cell model", options=None,
):
super().__init__({}, name)
pybamm.citations.register("marquis2019asymptotic")
Expand All @@ -48,7 +46,7 @@ def __init__(
if options["working electrode"] not in ["negative", "positive"]:
raise ValueError(
"The option 'working electrode' should be either 'positive'"
"or 'negative'"
" or 'negative'"
)

self.options.update(options)
Expand All @@ -59,6 +57,11 @@ def __init__(
######################
# Variables that depend on time only are created without a domain
Q = pybamm.Variable("Discharge capacity [A.h]")

# Define some useful scalings
pot = param.potential_scale
i_typ = param.current_scale

# Variables that vary spatially are created with a domain. Depending on
# which is the working electrode we need to define a set variables or another
if working_electrode == "negative":
Expand Down Expand Up @@ -134,7 +137,7 @@ def __init__(
# Set concentration in negative particle to be equal to the initial
# concentration as it is not the working electrode
x_n = pybamm.PrimaryBroadcast(
pybamm.standard_spatial_vars.x_n, "positive particle"
pybamm.standard_spatial_vars.x_n, "negative particle"
)
c_s_n = param.c_n_init(x_n)

Expand Down Expand Up @@ -297,9 +300,11 @@ def __init__(
######################
# Current in the solid
######################
eps_s_n = pybamm.Parameter("Negative electrode active material volume fraction")
eps_s_p = pybamm.Parameter("Positive electrode active material volume fraction")

if working_electrode == "negative":
sigma_eff_n = param.sigma_n * (1 - eps_n) ** param.b_s_n
sigma_eff_n = param.sigma_n * eps_s_n ** param.b_s_n
i_s_n = -sigma_eff_n * pybamm.grad(phi_s_n)
self.boundary_conditions[phi_s_n] = {
"left": (
Expand All @@ -319,7 +324,7 @@ def __init__(
param.c_n_init(0), param.T_init
)
else:
sigma_eff_p = param.sigma_p * (1 - eps_p) ** param.b_s_p
sigma_eff_p = param.sigma_p * eps_s_p ** param.b_s_p
i_s_p = -sigma_eff_p * pybamm.grad(phi_s_p)
self.boundary_conditions[phi_s_p] = {
"left": (pybamm.Scalar(0), "Neumann"),
Expand Down Expand Up @@ -376,19 +381,20 @@ def __init__(
)
self.algebraic[phi_e] = pybamm.div(i_e) - j

ref_potential = param.U_n_ref / pot

if working_electrode == "negative":
self.boundary_conditions[phi_e] = {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (pybamm.Scalar(0), "Dirichlet"),
"right": (ref_potential, "Dirichlet"),
}
else:
self.boundary_conditions[phi_e] = {
"left": (pybamm.Scalar(0), "Dirichlet"),
"left": (ref_potential, "Dirichlet"),
"right": (pybamm.Scalar(0), "Neumann"),
}

self.initial_conditions[phi_e] = pybamm.Scalar(0)

self.initial_conditions[phi_e] = ref_potential
######################
# (Some) variables
######################
Expand All @@ -398,12 +404,9 @@ def __init__(
"Lithium counter electrode exchange-current density [A.m-2]"
)

pot = param.potential_scale
i_typ = param.current_scale

if working_electrode == "negative":
voltage = pybamm.boundary_value(phi_s_n, "left")
voltage_dim = param.U_n_ref + pot * voltage
voltage = pybamm.boundary_value(phi_s_n, "left") - ref_potential
voltage_dim = pot * pybamm.boundary_value(phi_s_n, "left")
vdrop_Li = 2 * pybamm.arcsinh(
i_cell * i_typ / j_Li
) + L_Li * i_typ * i_cell / (sigma_Li * pot)
Expand All @@ -412,7 +415,7 @@ def __init__(
+ L_Li * i_typ * i_cell / sigma_Li
)
else:
voltage = pybamm.boundary_value(phi_s_p, "right")
voltage = pybamm.boundary_value(phi_s_p, "right") - ref_potential
voltage_dim = param.U_p_ref + pot * voltage
vdrop_Li = -(
2 * pybamm.arcsinh(i_cell * i_typ / j_Li)
Expand All @@ -436,8 +439,7 @@ def __init__(
"Negative particle surface concentration [mol.m-3]": param.c_n_max
* c_s_surf_n,
"X-averaged negative particle surface concentration [mol.m-3]":
param.c_n_max
* c_s_surf_n_av,
param.c_n_max * c_s_surf_n_av,
"Negative particle concentration [mol.m-3]": param.c_n_max * c_s_n,
"Electrolyte concentration": c_e,
"Electrolyte concentration [mol.m-3]": param.c_e_typ * c_e,
Expand All @@ -447,17 +449,17 @@ def __init__(
"Positive particle surface concentration [mol.m-3]": param.c_p_max
* c_s_surf_p,
"X-averaged positive particle surface concentration [mol.m-3]":
param.c_p_max
* c_s_surf_p_av,
param.c_p_max * c_s_surf_p_av,
"Positive particle concentration [mol.m-3]": param.c_p_max * c_s_p,
"Current [A]": I,
"Negative electrode potential": phi_s_n,
"Negative electrode potential [V]": param.U_n_ref + pot * phi_s_n,
"Negative electrode potential [V]": pot * phi_s_n,
"Negative electrode open circuit potential": param.U_n(c_s_surf_n, T),
"Electrolyte potential": phi_e,
"Electrolyte potential [V]": pot * phi_e,
"Electrolyte potential [V]": -param.U_n_ref + pot * phi_e,
"Positive electrode potential": phi_s_p,
"Positive electrode potential [V]": param.U_p_ref + pot * phi_s_p,
"Positive electrode potential [V]": (param.U_p_ref - param.U_n_ref)
+ pot * phi_s_p,
"Positive electrode open circuit potential": param.U_p(c_s_surf_p, T),
"Voltage drop": voltage,
"Voltage drop [V]": voltage_dim,
Expand Down