Skip to content

Commit

Permalink
updated tests and naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
parkec3 committed Sep 3, 2024
1 parent b820e59 commit f23ac77
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
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 a lithium ion equivalent circuit model with split open circuit voltages for each electrode. ([#4330](https://github.com/pybamm-team/PyBaMM/pull/4330))
- Added additional user-configurable options to the (`IDAKLUSolver`) and adjusted the default values to improve performance. ([#4282](https://github.com/pybamm-team/PyBaMM/pull/4282))
- Added the diffusion element to be used in the Thevenin model. ([#4254](https://github.com/pybamm-team/PyBaMM/pull/4254))

Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/models/lithium_ion/ecm_split_ocv.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Equivalent Circuit Model with Split OCV (ECMsplitOCV)
Equivalent Circuit Model with Split OCV (SplitOCVR)
=====================================================

.. autoclass:: pybamm.lithium_ion.ECMsplitOCV
.. autoclass:: pybamm.lithium_ion.SplitOCVR
:members:

.. footbibliography::
4 changes: 2 additions & 2 deletions src/pybamm/models/full_battery_models/lithium_ion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
from .Yang2017 import Yang2017
from .mpm import MPM
from .msmr import MSMR
from .basic_ecm_split_OCV import ECMsplitOCV
from .basic_splitOCVR import SplitOCVR

__all__ = ['Yang2017', 'base_lithium_ion_model', 'basic_dfn',
'basic_dfn_composite', 'basic_dfn_half_cell', 'basic_spm', 'dfn',
'electrode_soh', 'electrode_soh_half_cell', 'mpm', 'msmr',
'newman_tobias', 'spm', 'spme', 'ecm_split_ocv']
'newman_tobias', 'spm', 'spme', 'basic_splitOCVR']
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pybamm


class ECMsplitOCV(pybamm.BaseModel):
class SplitOCVR(pybamm.BaseModel):
"""Basic Equivalent Circuit Model that uses two OCV functions
for each electrode. This model is easily parameterizable with minimal parameters.
This class differs from the :class: pybamm.equivalent_circuit.Thevenin() due
Expand All @@ -25,8 +25,8 @@ def __init__(self, name="ECM with split OCV"):
# All variables are only time-dependent
# No domain definition needed

c_n = pybamm.Variable("Negative particle SOC")
c_p = pybamm.Variable("Positive particle SOC")
theta_n = pybamm.Variable("Negative particle stoichiometry")
theta_p = pybamm.Variable("Positive particle stoichiometry")
Q = pybamm.Variable("Discharge capacity [A.h]")
V = pybamm.Variable("Voltage [V]")

Expand All @@ -42,22 +42,22 @@ def __init__(self, name="ECM with split OCV"):
Q_p = pybamm.Parameter("Positive electrode capacity [A.h]")

# State of charge electrode equations
c_n_0 = pybamm.Parameter("Negative electrode initial SOC")
c_p_0 = pybamm.Parameter("Positive electrode initial SOC")
self.rhs[c_n] = -I / Q_n / 3600
self.rhs[c_p] = I / Q_p / 3600
self.initial_conditions[c_n] = c_n_0
self.initial_conditions[c_p] = c_p_0
theta_n_0 = pybamm.Parameter("Negative electrode initial stoichiometry")
theta_p_0 = pybamm.Parameter("Positive electrode initial stoichiometry")
self.rhs[theta_n] = -I / Q_n / 3600
self.rhs[theta_p] = I / Q_p / 3600
self.initial_conditions[theta_n] = theta_n_0
self.initial_conditions[theta_p] = theta_p_0

# Resistance for IR expression
R = pybamm.Parameter("Ohmic resistance [Ohm]")

# Open-circuit potential for each electrode
Un = pybamm.FunctionParameter(
"Negative electrode OCP [V]", {"Negative particle SOC": c_n}
"Negative electrode OCP [V]", {"Negative particle stoichiometry": theta_n}
)
Up = pybamm.FunctionParameter(
"Positive electrode OCP [V]", {"Positive particle SOC": c_p}
"Positive electrode OCP [V]", {"Positive particle stoichiometry": theta_p}
)

# Voltage expression
Expand All @@ -68,8 +68,8 @@ def __init__(self, name="ECM with split OCV"):
voltage_low_cut = pybamm.Parameter("Lower voltage cut-off [V]")

self.variables = {
"Negative particle SOC": c_n,
"Positive particle SOC": c_p,
"Negative particle stoichiometry": theta_n,
"Positive particle stoichiometry": theta_p,
"Current [A]": I,
"Discharge capacity [A.h]": Q,
"Voltage [V]": V,
Expand All @@ -83,17 +83,17 @@ def __init__(self, name="ECM with split OCV"):
self.events += [
pybamm.Event("Minimum voltage [V]", V - voltage_low_cut),
pybamm.Event("Maximum voltage [V]", voltage_high_cut - V),
pybamm.Event("Maximum Negative Electrode SOC", 0.999 - c_n),
pybamm.Event("Maximum Positive Electrode SOC", 0.999 - c_p),
pybamm.Event("Minimum Negative Electrode SOC", c_n - 0.0001),
pybamm.Event("Minimum Positive Electrode SOC", c_p - 0.0001),
pybamm.Event("Maximum Negative Electrode stoichiometry", 0.999 - theta_n),
pybamm.Event("Maximum Positive Electrode stoichiometry", 0.999 - theta_p),
pybamm.Event("Minimum Negative Electrode stoichiometry", theta_n - 0.0001),
pybamm.Event("Minimum Positive Electrode stoichiometry", theta_p - 0.0001),
]

@property
def default_quick_plot_variables(self):
return [
"Voltage [V]",
["Negative particle SOC", "Positive particle SOC"],
["Negative particle stoichiometry", "Positive particle stoichiometry"],
"Negative electrode OCP [V]",
"Positive electrode OCP [V]",
"Current [A]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
#
import pybamm
import numpy as np
import tests


class TestECMSplitOCVModel:
def test_run_model_with_parameters(self):
model = pybamm.lithium_ion.ECMsplitOCV()

class TestSplitOCVR:
def test_basic_processing(self):
# example parameters
qp0 = 8.73231852
qn0 = 5.82761507
c0_n = 0.9013973983641687 * 0.9
c0_p = 0.5142305254580026 * 0.83
theta0_n = 0.9013973983641687 * 0.9
theta0_p = 0.5142305254580026 * 0.83

# OCV functions
def Un(theta_n):
Expand Down Expand Up @@ -41,18 +40,17 @@ def Up(theta_p):
{
"Positive electrode capacity [A.h]": qp0,
"Ohmic resistance [Ohm]": 0.001,
"Negative electrode initial SOC": c0_n,
"Negative electrode initial stoichiometry": theta0_n,
"Lower voltage cut-off [V]": 2.8,
"Positive electrode initial SOC": c0_p,
"Positive electrode initial stoichiometry": theta0_p,
"Upper voltage cut-off [V]": 4.2,
"Negative electrode capacity [A.h]": qn0,
"Current function [A]": 5,
"Positive electrode OCP [V]": Up,
"Negative electrode OCP [V]": Un,
"Nominal cell capacity [A.h]": 5,
}
)

# solve the model
sim = pybamm.Simulation(model, parameter_values=pars)
t_eval = np.linspace(0, 3600)
sim.solve(t_eval)
model = pybamm.lithium_ion.SplitOCVR()
modeltest = tests.StandardModelTest(model)
modeltest.test_all(param=pars)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import pybamm


class TestECMSplitOCV:
class TestSplitOCVR:
def test_ecmsplitocv_well_posed(self):
model = pybamm.lithium_ion.ECMsplitOCV()
model = pybamm.lithium_ion.SplitOCVR()
model.check_well_posedness()

def test_get_default_quick_plot_variables(self):
model = pybamm.lithium_ion.ECMsplitOCV()
model = pybamm.lithium_ion.SplitOCVR()
variables = model.default_quick_plot_variables
assert "Current [A]" in variables

0 comments on commit f23ac77

Please sign in to comment.