Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
parkec3 committed Aug 16, 2024
1 parent 1fc5670 commit 758175f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Equivalent Circuit Model with split OCV
#
import pybamm
from .base_lithium_ion_model import BaseModel


class ECMsplitOCV(BaseModel):
class ECMsplitOCV(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 @@ -18,9 +17,9 @@ class ECMsplitOCV(BaseModel):
"""

def __init__(self, name="ECM with split OCV"):
super().__init__({}, name)
super().__init__(name)
# TODO citations
param = self.param
# param = self.param

######################
# Variables
Expand All @@ -34,7 +33,9 @@ def __init__(self, name="ECM with split OCV"):
V = pybamm.Variable("Voltage [V]")

# model is isothermal
I = param.current_with_time
I = pybamm.FunctionParameter(
"Current function [A]", {"Time [s]": pybamm.t}
)

# Capacity equation
self.rhs[Q] = I / 3600
Expand Down Expand Up @@ -66,6 +67,10 @@ def __init__(self, name="ECM with split OCV"):
# Voltage expression
V = Up - Un - I * R

# Parameters for Voltage cutoff
voltage_high_cut = pybamm.Parameter('Upper voltage cut-off [V]')
voltage_low_cut = pybamm.Parameter('Lower voltage cut-off [V]')

self.variables = {
"Negative particle SOC": c_n,
"Positive particle SOC": c_p,
Expand All @@ -80,8 +85,8 @@ def __init__(self, name="ECM with split OCV"):

# Events specify points at which a solution should terminate
self.events += [
pybamm.Event("Minimum voltage [V]", V - param.voltage_low_cut),
pybamm.Event("Maximum voltage [V]", param.voltage_high_cut - V),
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),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Test that the model works should I change the base model to just regular base model from .lihtium_ion_model BaseModel
# does that set parameters that we really don't want, is this really as simple as we want it to be
import pybamm
import numpy as np

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

# example parameters
qp0 = 8.73231852
qn0 = 5.82761507
c0_n = 0.9013973983641687*0.9
c0_p = 0.5142305254580026*0.83

# OCV functions
def Un(theta_n):
Un = 0.1493 + 0.8493*np.exp(-61.79*theta_n) + 0.3824*np.exp(-665.8*theta_n) \
- np.exp(39.42*theta_n-41.92) - 0.03131*np.arctan(25.59*theta_n - 4.099) \
- 0.009434*np.arctan(32.49*theta_n - 15.74)
return Un

def Up(theta_p):
Up = -10.72*theta_p**4 + 23.88*theta_p**3 - 16.77*theta_p**2 + 2.595*theta_p + 4.563
return Up

pars = pybamm.ParameterValues(
{
'Positive electrode capacity [A.h]' : qp0,
'Ohmic resistance [Ohm]' : 0.001,
'Negative electrode initial SOC' : c0_n,
'Lower voltage cut-off [V]' : 2.8,
'Positive electrode initial SOC' : c0_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,
}
)

# solve the model
sim = pybamm.Simulation(model, parameter_values=pars)
t_eval = np.linspace(0, 3600)
sim.solve(t_eval)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Test for the ecm split-OCV model
#
import pybamm

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

0 comments on commit 758175f

Please sign in to comment.