forked from pybop-team/PyBOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d98349a
commit 4cbac89
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import pybop | ||
import pybamm | ||
import numpy as np | ||
import pytest | ||
|
||
|
||
class TestGITT: | ||
""" | ||
A class to test the GITT class. | ||
""" | ||
|
||
@pytest.fixture | ||
def model(self): | ||
return "Weppner & Huggins" | ||
|
||
@pytest.fixture | ||
def parameter_set(self): | ||
original_parameters = pybamm.ParameterValues("Xu2019") | ||
|
||
return pybamm.ParameterValues( | ||
{ | ||
"Reference OCP [V]": 4.1821, | ||
"Derivative of the OCP wrt stoichiometry [V]": -1.38636, | ||
"Current function [A]": original_parameters["Current function [A]"], | ||
"Number of electrodes connected in parallel to make a cell": original_parameters[ | ||
"Number of electrodes connected in parallel to make a cell" | ||
], | ||
"Electrode width [m]": original_parameters["Electrode width [m]"], | ||
"Electrode height [m]": original_parameters["Electrode height [m]"], | ||
"Positive electrode active material volume fraction": original_parameters[ | ||
"Positive electrode active material volume fraction" | ||
], | ||
"Positive electrode porosity": original_parameters[ | ||
"Positive electrode porosity" | ||
], | ||
"Positive particle radius [m]": original_parameters[ | ||
"Positive particle radius [m]" | ||
], | ||
"Positive electrode thickness [m]": original_parameters[ | ||
"Positive electrode thickness [m]" | ||
], | ||
"Positive electrode diffusivity [m2.s-1]": original_parameters[ | ||
"Positive electrode diffusivity [m2.s-1]" | ||
], | ||
"Maximum concentration in positive electrode [mol.m-3]": original_parameters[ | ||
"Maximum concentration in positive electrode [mol.m-3]" | ||
], | ||
} | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def dataset(self): | ||
# Define model | ||
original_parameters = pybamm.ParameterValues("Xu2019") | ||
model = pybop.lithium_ion.SPM( | ||
parameter_set=original_parameters, options={"working electrode": "positive"} | ||
) | ||
|
||
# Generate data | ||
sigma = 0.005 | ||
t_eval = np.arange(0, 150, 2) | ||
values = model.predict(t_eval=t_eval) | ||
corrupt_values = values["Voltage [V]"].data + np.random.normal(0, sigma, len(t_eval)) | ||
|
||
# Return dataset | ||
return pybop.Dataset( | ||
{ | ||
"Time [s]": t_eval, | ||
"Current function [A]": values["Current [A]"].data, | ||
"Voltage [V]": corrupt_values, | ||
} | ||
) | ||
|
||
@pytest.mark.unit | ||
def test_gitt_problem(self, model, parameter_set, dataset): | ||
# Test incorrect model | ||
with pytest.raises(ValueError): | ||
pybop.GITT(model="bad model", parameter_set=parameter_set, dataset=dataset) | ||
|
||
# Construct Problem | ||
problem = pybop.GITT(model, parameter_set, dataset) | ||
|
||
# Test fixed attributes | ||
parameters = [ | ||
pybop.Parameter( | ||
"Positive electrode diffusivity [m2.s-1]", | ||
prior=pybop.Gaussian(5e-14, 1e-13), | ||
bounds=[1e-16, 1e-11], | ||
true_value=parameter_set["Positive electrode diffusivity [m2.s-1]"], | ||
), | ||
] | ||
|
||
assert problem.parameters == parameters | ||
|
||
assert problem.signal == ["Voltage [V]"] | ||
|
||
with pytest.raises(NotImplementedError): | ||
problem.evaluate([1e-5, 1e-5]) | ||
with pytest.raises(NotImplementedError): | ||
problem.evaluateS1([1e-5, 1e-5]) | ||
|
||
with pytest.raises(ValueError): | ||
pybop.BaseProblem(parameters, model=model, signal=[1e-5, 1e-5]) | ||
|
||
# Test without bounds | ||
for param in parameters: | ||
param.bounds = None | ||
problem = pybop.BaseProblem(parameters, model=model) | ||
assert problem.bounds is None |