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

Add GroupedSPMe model #584

Merged
merged 63 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
963b550
Add first go at grouped SPMe
NicolaCourtier Oct 20, 2024
fdabd64
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Oct 24, 2024
e059cb9
Update thicknesses
NicolaCourtier Oct 24, 2024
d1375f0
Pre-commit styling
NicolaCourtier Oct 24, 2024
0fd41e2
Update overpotentials
NicolaCourtier Oct 24, 2024
5a4b77b
Add double-layer
NicolaCourtier Oct 24, 2024
bfe24c4
Update example
NicolaCourtier Oct 24, 2024
fdb5fc1
Add missing line
NicolaCourtier Oct 25, 2024
6022ab6
Remove factors of length
NicolaCourtier Oct 25, 2024
46dd920
Fix domain parameters
NicolaCourtier Oct 25, 2024
738150f
Update series resistance and etas
NicolaCourtier Oct 28, 2024
3a9d6bf
Set constant conductivity
NicolaCourtier Oct 28, 2024
9923d39
Remove factor of 3
NicolaCourtier Oct 28, 2024
6663892
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Oct 31, 2024
5f2e92b
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 1, 2024
4b828ea
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 1, 2024
d78e495
Add parameter conversion function
NicolaCourtier Nov 3, 2024
c1bde00
Combine plots
NicolaCourtier Nov 3, 2024
2c364a9
Update model options
NicolaCourtier Nov 3, 2024
5cb497d
Rename variables
NicolaCourtier Nov 3, 2024
2808721
Add conductivities and init_soc
NicolaCourtier Nov 4, 2024
24e10a2
Update averaging
NicolaCourtier Nov 4, 2024
dc88e85
Move timescales
NicolaCourtier Nov 4, 2024
c758689
Rescale electrolyte source
NicolaCourtier Nov 4, 2024
b89ad94
Assume high conductivities
NicolaCourtier Nov 4, 2024
3036431
Add electrolyte flux
NicolaCourtier Nov 4, 2024
dd24448
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 8, 2024
965175e
Fix typo
NicolaCourtier Nov 8, 2024
5eb8ff3
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 13, 2024
cad0a03
Add transfer coefficient
NicolaCourtier Nov 14, 2024
f116d15
Update grouped_SPMe
NicolaCourtier Nov 15, 2024
82f0bfb
Revert to sto_e, make double layer optional
NicolaCourtier Nov 18, 2024
1579f8b
Add target continuity conditions
NicolaCourtier Nov 18, 2024
80c6bcc
Simplify ocv_init setting
NicolaCourtier Nov 20, 2024
acf95bd
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 21, 2024
6ccfd63
Remove concatenations
NicolaCourtier Nov 21, 2024
1ed841c
Switch from theoretical to measured capacity
NicolaCourtier Nov 23, 2024
601c92a
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Nov 26, 2024
808b32c
Move example into subfolder
NicolaCourtier Nov 26, 2024
1a578f8
Fix electrolyte scaling
NicolaCourtier Nov 29, 2024
f1e96f4
Add potentials to quick plot
NicolaCourtier Dec 2, 2024
d566801
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 3, 2024
2e46801
Update option setting
NicolaCourtier Dec 4, 2024
ff0422c
Grouped SPMe edit (#577)
noelhallemans Dec 4, 2024
8b822ce
Create grouped_SPMe_experiment.py
NicolaCourtier Dec 4, 2024
aa29725
Move set_initial_state to base models
NicolaCourtier Dec 6, 2024
bb887b2
Remove testing script
NicolaCourtier Dec 6, 2024
8ba44ec
Pre-commit
NicolaCourtier Dec 6, 2024
93ee714
Add tests on GroupedSPMe
NicolaCourtier Dec 6, 2024
20c8809
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 6, 2024
7272454
Test differential surface form
NicolaCourtier Dec 6, 2024
ffdd56b
Fix option setting
NicolaCourtier Dec 6, 2024
3273fa3
Update README.md
NicolaCourtier Dec 6, 2024
8b819db
Add test_grouped_SPMe
NicolaCourtier Dec 6, 2024
e5ad2b3
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 6, 2024
8ccc856
Increase coverage
NicolaCourtier Dec 6, 2024
5b3a6cd
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 6, 2024
c02fda8
Update name and option setting
NicolaCourtier Dec 6, 2024
8603405
Remove comments
NicolaCourtier Dec 11, 2024
cfd8f76
Combine if statements
NicolaCourtier Dec 11, 2024
cee4cfe
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 11, 2024
3646f81
Merge branch 'develop' into grouped-SPMe
NicolaCourtier Dec 11, 2024
87abcc3
Update CHANGELOG.md
NicolaCourtier Dec 11, 2024
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
Prev Previous commit
Next Next commit
Pre-commit styling
NicolaCourtier committed Oct 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d1375f0cacc41e65fc6a22f5fbc2d4f70c47778f
25 changes: 16 additions & 9 deletions examples/scripts/grouped_SPMe.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import matplotlib.pyplot as plt
import numpy as np
import pybop
from pybamm.input.parameters.lithium_ion.Chen2020 import (
graphite_LGM50_ocp_Chen2020,
nmc_LGM50_ocp_Chen2020,
)
from pybamm.models.full_battery_models.lithium_ion.electrode_soh import get_min_max_stoichiometries
from scipy.io import savemat
from pybamm.models.full_battery_models.lithium_ion.electrode_soh import (
get_min_max_stoichiometries,
)

import pybop

# Unpack parameter values from Chen2020
parameter_set = pybop.ParameterSet.pybamm("Chen2020")
@@ -82,7 +83,7 @@
"Upper voltage cut-off [V]": parameter_set["Upper voltage cut-off [V]"],
"Positive electrode thickness [m]": l_p, # normalised
"Negative electrode thickness [m]": l_n, # normalised
"Separator thickness [m]": 1-l_p-l_n, # normalised
"Separator thickness [m]": 1 - l_p - l_n, # normalised
"Positive particle radius [m]": 1, # normalised
"Negative particle radius [m]": 1, # normalised
"Positive electrode OCP [V]": nmc_LGM50_ocp_Chen2020,
@@ -108,11 +109,13 @@

# Test model in the time domain
model_options = {"contact resistance": "true"}
time_domain_SPMe = pybop.lithium_ion.SPMe(parameter_set=parameter_set, options=model_options)
time_domain_SPMe = pybop.lithium_ion.SPMe(
parameter_set=parameter_set, options=model_options
)
time_domain_grouped = pybop.lithium_ion.GroupedSPMe(parameter_set=grouped_parameter_set)
for model in [time_domain_SPMe, time_domain_grouped]:
model.build(initial_state={"Initial SoC": 0.9})
simulation = model.predict(t_eval=np.linspace(0,3600,100))
simulation = model.predict(t_eval=np.linspace(0, 3600, 100))
dataset = pybop.Dataset(
{
"Time [s]": simulation["Time [s]"].data,
@@ -123,8 +126,12 @@
pybop.plot.dataset(dataset)

# Continue with frequency domain model
freq_domain_SPMe = pybop.lithium_ion.SPMe(parameter_set=parameter_set, options=model_options, eis=True)
freq_domain_grouped = pybop.lithium_ion.GroupedSPMe(parameter_set=grouped_parameter_set, eis=True)
freq_domain_SPMe = pybop.lithium_ion.SPMe(
parameter_set=parameter_set, options=model_options, eis=True
)
freq_domain_grouped = pybop.lithium_ion.GroupedSPMe(
parameter_set=grouped_parameter_set, eis=True
)

for model in [freq_domain_SPMe, freq_domain_grouped]:
NSOC = 11
@@ -143,7 +150,7 @@
fig, ax = plt.subplots()
for ii in range(len(SOCs)):
ax.plot(np.real(impedances[:, ii]), -np.imag(impedances[:, ii]))
ax.set(xlabel="$Z_r(\omega)$ [$\Omega$]", ylabel="$-Z_j(\omega)$ [$\Omega$]")
ax.set(xlabel=r"$Z_r(\omega)$ [$\Omega$]", ylabel=r"$-Z_j(\omega)$ [$\Omega$]")
ax.grid()
ax.set_aspect("equal", "box")
plt.show()
42 changes: 26 additions & 16 deletions pybop/models/lithium_ion/basic_SPMe.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import pybamm
import warnings
from pybamm import Event, FunctionParameter, Parameter, ParameterValues, PrimaryBroadcast, Scalar, Variable

import pybamm
from pybamm import (
Event,
FunctionParameter,
Parameter,
ParameterValues,
PrimaryBroadcast,
Scalar,
Variable,
)
from pybamm import lithium_ion as pybamm_lithium_ion
from pybamm import t as pybamm_t
from pybamm.input.parameters.lithium_ion.Chen2020 import (
graphite_LGM50_ocp_Chen2020,
nmc_LGM50_ocp_Chen2020,
)
from pybamm import t as pybamm_t


class BaseGroupedSPMe(pybamm_lithium_ion.BaseModel):
@@ -21,9 +30,7 @@ class BaseGroupedSPMe(pybamm_lithium_ion.BaseModel):

def __init__(self, name="Single particle model with electrolyte", **model_kwargs):
if model_kwargs is not dict(build=True):
unused_kwargs_warning = (
f"The input model_kwargs {list(model_kwargs.keys())} are not currently used by the SPMe."
)
unused_kwargs_warning = f"The input model_kwargs {list(model_kwargs.keys())} are not currently used by the SPMe."
warnings.warn(unused_kwargs_warning, UserWarning, stacklevel=2)

super().__init__({}, name=name)
@@ -127,15 +134,15 @@ def __init__(self, name="Single particle model with electrolyte", **model_kwargs
)
tau_e = pybamm.concatenation(tau_e_n, tau_e_sep, tau_e_p)

beta_n = PrimaryBroadcast(
beta_n = PrimaryBroadcast(
Parameter("Negative relative concentration"),
"negative electrode",
)
beta_sep = PrimaryBroadcast(
Scalar(0),
"separator",
)
beta_p = PrimaryBroadcast(
beta_p = PrimaryBroadcast(
Parameter("Positive relative concentration"),
"positive electrode",
)
@@ -172,10 +179,14 @@ def __init__(self, name="Single particle model with electrolyte", **model_kwargs

j0_n = pybamm.sqrt(sto_n_surf * (1 - sto_n_surf)) # Lacking integral ce!!!!
j0_p = pybamm.sqrt(sto_p_surf * (1 - sto_p_surf)) # Lacking integral ce!!!!

eta_n = (2 * Rg * T / F) * pybamm.arcsinh(tau_r_n * j_n / (2 * j0_n))
eta_p = -(2 * Rg * T / F) * pybamm.arcsinh(tau_r_p * j_p / (2 * j0_p))
eta_e = (2 * Rg * T / F) * (1-t_plus) * (pybamm.log(l_n) - pybamm.log(l_p) + pybamm.log(1))
eta_e = (
(2 * Rg * T / F)
* (1 - t_plus)
* (pybamm.log(l_n) - pybamm.log(l_p) + pybamm.log(1))
)

v_n = self.U(sto_n_surf, "negative") + eta_n
v_p = self.U(sto_p_surf, "positive") + eta_p
@@ -191,15 +202,15 @@ def __init__(self, name="Single particle model with electrolyte", **model_kwargs
# Boundary conditions must be provided for equations with spatial derivatives
self.boundary_conditions[sto_n] = {
"left": (Scalar(0), "Neumann"),
"right": (- tau_d_n * j_n, "Neumann"),
"right": (-tau_d_n * j_n, "Neumann"),
}
self.boundary_conditions[sto_p] = {
"left": (Scalar(0), "Neumann"),
"right": (- tau_d_p * j_p, "Neumann"),
"right": (-tau_d_p * j_p, "Neumann"),
}

sto_n_init = x_0 + (x_100-x_0) * soc_init
sto_p_init = y_0 + (y_100-y_0) * soc_init
sto_n_init = x_0 + (x_100 - x_0) * soc_init
sto_p_init = y_0 + (y_100 - y_0) * soc_init
self.initial_conditions[sto_n] = sto_n_init
self.initial_conditions[sto_p] = sto_p_init

@@ -285,7 +296,6 @@ def __init__(self, name="Single particle model with electrolyte", **model_kwargs
"Voltage [V]": V,
}


@property
def default_parameter_values(self):
parameter_dictionary = {
@@ -325,7 +335,7 @@ def default_parameter_values(self):
"Series resistance [Ohm]": 0.01,
}
return ParameterValues(values=parameter_dictionary)

def build_model(self):
# Build model variables and equations
self._build_model()