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

Plot voltage components for composite electrodes #4435

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
141 changes: 123 additions & 18 deletions docs/source/examples/notebooks/plotting/plot-voltage-components.ipynb

Large diffs are not rendered by default.

32 changes: 26 additions & 6 deletions src/pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1333,9 +1333,19 @@ def set_voltage_variables(self):
eta_particle_n = self.variables[
f"Negative {phase_n}particle concentration overpotential [V]"
]
eta_particle_p = self.variables[
f"Positive {phase_p}particle concentration overpotential [V]"
]
if self.options.positive["particle phases"] == "2":
eta_particle_p = (
self.variables[
f"Positive {phase_p}particle concentration overpotential [V]"
]
+ self.variables[
"Positive secondary particle concentration overpotential [V]"
]
) / 2
else:
eta_particle_p = self.variables[
f"Positive {phase_p}particle concentration overpotential [V]"
]

ocv_surf = ocp_surf_p_av - ocp_surf_n_av
ocv_bulk = ocp_p_bulk - ocp_n_bulk
Expand All @@ -1351,9 +1361,19 @@ def set_voltage_variables(self):
eta_r_n_av = self.variables[
f"X-averaged negative electrode {phase_n}reaction overpotential [V]"
]
eta_r_p_av = self.variables[
f"X-averaged positive electrode {phase_p}reaction overpotential [V]"
]
if self.options.positive["particle phases"] == "2":
eta_r_p_av = (
self.variables[
f"X-averaged positive electrode {phase_p}reaction overpotential [V]"
]
+ self.variables[
"X-averaged positive electrode secondary reaction overpotential [V]"
]
) / 2
else:
eta_r_p_av = self.variables[
f"X-averaged positive electrode {phase_p}reaction overpotential [V]"
]
eta_r_av = eta_r_p_av - eta_r_n_av

delta_phi_s_n_av = self.variables[
Expand Down
121 changes: 85 additions & 36 deletions src/pybamm/plotting/plot_voltage_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pybamm.util import import_optional_dependency
from pybamm.simulation import Simulation
from pybamm.solvers.solution import Solution
from pybamm.parameters.base_parameters import NullParameters


def plot_voltage_components(
Expand Down Expand Up @@ -39,8 +40,12 @@ def plot_voltage_components(
# Check if the input is a Simulation and extract Solution
if isinstance(input_data, Simulation):
solution = input_data.solution
working_electrode = input_data.options["working electrode"]
model_param = input_data.model.param
elif isinstance(input_data, Solution):
solution = input_data
working_electrode = input_data.all_models[0].options["working electrode"]
model_param = input_data.all_models[0].param
plt = import_optional_dependency("matplotlib.pyplot")

# Set a default value for alpha, the opacity
Expand All @@ -52,42 +57,82 @@ def plot_voltage_components(
else:
fig, ax = plt.subplots(figsize=(8, 4))

if split_by_electrode is False:
overpotentials = [
"Battery particle concentration overpotential [V]",
"X-averaged battery reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery solid phase ohmic losses [V]",
]
labels = [
"Particle concentration overpotential",
"Reaction overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
]
else:
overpotentials = [
"Battery negative particle concentration overpotential [V]",
"Battery positive particle concentration overpotential [V]",
"X-averaged battery negative reaction overpotential [V]",
"X-averaged battery positive reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery negative solid phase ohmic losses [V]",
"X-averaged battery positive solid phase ohmic losses [V]",
]
labels = [
"Negative particle concentration overpotential",
"Positive particle concentration overpotential",
"Negative reaction overpotential",
"Positive reaction overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic negative electrode overpotential",
"Ohmic positive electrode overpotential",
]
if working_electrode == "both":
if split_by_electrode is False:
overpotentials = [
"Battery particle concentration overpotential [V]",
"X-averaged battery reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery solid phase ohmic losses [V]",
]
labels = [
"Particle concentration overpotential",
"Reaction overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
]
else:
overpotentials = [
"Battery negative particle concentration overpotential [V]",
"Battery positive particle concentration overpotential [V]",
"X-averaged battery negative reaction overpotential [V]",
"X-averaged battery positive reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery negative solid phase ohmic losses [V]",
"X-averaged battery positive solid phase ohmic losses [V]",
]
labels = [
"Negative particle concentration overpotential",
"Positive particle concentration overpotential",
"Negative reaction overpotential",
"Positive reaction overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic negative electrode overpotential",
"Ohmic positive electrode overpotential",
]
elif working_electrode == "positive":
if isinstance(model_param.p.sec, NullParameters):
overpotentials = [
"Positive particle concentration overpotential [V]",
"X-averaged positive electrode reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery solid phase ohmic losses [V]",
]
labels = [
"Particle concentration overpotential",
"Reaction overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
]
else:
overpotentials = [
"Positive primary particle concentration overpotential [V]",
"Positive secondary particle concentration overpotential [V]",
"Battery negative particle concentration overpotential [V]",
"X-averaged positive electrode primary reaction overpotential [V]",
"X-averaged positive electrode secondary reaction overpotential [V]",
"X-averaged battery negative reaction overpotential [V]",
"X-averaged battery concentration overpotential [V]",
"X-averaged battery electrolyte ohmic losses [V]",
"X-averaged battery solid phase ohmic losses [V]",
]
labels = [
"Primary particle concentration overpotential",
"Secondary particle concentration overpotential",
"Negative particle concentration overpotential",
"Primary reaction overpotential",
"Secondary reaction overpotential",
"Negative interface overpotential",
"Electrolyte concentration overpotential",
"Ohmic electrolyte overpotential",
"Ohmic electrode overpotential",
]

# Plot
# Initialise
Expand Down Expand Up @@ -128,6 +173,10 @@ def plot_voltage_components(
# negative overpotentials are positive for a discharge and negative for a charge
# so we have to multiply by -1 to show them correctly
sgn = -1 if "negative" in overpotential else 1
sgn = -1 if "Lithium metal" in overpotential else 1
for phase in ["primary", "secondary"]:
for type in ["reaction", "particle concentration"]:
sgn *= 0.5 if f"{phase} {type}" in overpotential else 1
bottom = top + sgn * solution[overpotential].entries
ax.fill_between(time, bottom, top, **kwargs_fill, label=label)
top = bottom
Expand Down