Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Jan 24, 2024
1 parent c28bbb0 commit c8264b8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
9 changes: 1 addition & 8 deletions pybamm/parameters/bpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def process_float_function_table(value, name):
Process BPX FloatFunctionTable to a float, python function or data for a pybamm
Interpolant.
"""
if value is None:
pass
elif isinstance(value, Function):
if isinstance(value, Function):
value = value.to_python_function(preamble=preamble)
elif isinstance(value, InterpolatedTable):
# return (name, (x, y)) to match the output of
Expand Down Expand Up @@ -453,11 +451,6 @@ def _bpx_to_domain_param_dict(instance: BPX, pybamm_dict: dict, domain: Domain)
and name == "particle"
):
particle_instance = getattr(instance, "particle")
if len(particle_instance.keys()) > 2:
raise NotImplementedError(
"PyBaMM does not support more than two "
"particle phases in blended electrodes"
)
# Loop over phases
for i, phase_name in enumerate(particle_instance.keys()):
phase_instance = particle_instance[phase_name]
Expand Down
63 changes: 63 additions & 0 deletions tests/unit/test_parameters/test_bpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,69 @@ def test_bpx_blended(self):
sim = pybamm.Simulation(model, parameter_values=pv, experiment=experiment)
sim.solve(calc_esoh=False)

def test_bpx_blended_error(self):
bpx_obj = copy.copy(self.base)
bpx_obj["Parameterisation"]["Positive electrode"] = {
"Thickness [m]": 5.23e-05,
"Conductivity [S.m-1]": 0.789,
"Porosity": 0.277493,
"Transport efficiency": 0.1462,
"Particle": {
"Large Particles": {
"Diffusivity [m2.s-1]": 3.2e-14,
"Particle radius [m]": 8e-06,
"OCP [V]": "-3.04420906 * x + 10.04892207 - 0.65637536 * tanh(-4.02134095 * (x - 0.80063948)) + 4.24678547 * tanh(12.17805062 * (x - 7.57659337)) - 0.3757068 * tanh(59.33067782 * (x - 0.99784492))",
"Entropic change coefficient [V.K-1]": -1e-4,
"Surface area per unit volume [m-1]": 186331,
"Reaction rate constant [mol.m-2.s-1]": 2.305e-05,
"Minimum stoichiometry": 0.42424,
"Maximum stoichiometry": 0.96210,
"Maximum concentration [mol.m-3]": 46200,
"Diffusivity activation energy [J.mol-1]": 15000,
"Reaction rate constant activation energy [J.mol-1]": 3500,
},
"Medium Particles": {
"Diffusivity [m2.s-1]": 3.2e-14,
"Particle radius [m]": 4e-06,
"OCP [V]": "-3.04420906 * x + 10.04892207 - 0.65637536 * tanh(-4.02134095 * (x - 0.80063948)) + 4.24678547 * tanh(12.17805062 * (x - 7.57659337)) - 0.3757068 * tanh(59.33067782 * (x - 0.99784492))",
"Entropic change coefficient [V.K-1]": -1e-4,
"Surface area per unit volume [m-1]": 186331,
"Reaction rate constant [mol.m-2.s-1]": 2.305e-05,
"Minimum stoichiometry": 0.42424,
"Maximum stoichiometry": 0.96210,
"Maximum concentration [mol.m-3]": 46200,
"Diffusivity activation energy [J.mol-1]": 15000,
"Reaction rate constant activation energy [J.mol-1]": 3500,
},
"Small Particles": {
"Diffusivity [m2.s-1]": 3.2e-14,
"Particle radius [m]": 1e-06,
"OCP [V]": "-3.04420906 * x + 10.04892207 - 0.65637536 * tanh(-4.02134095 * (x - 0.80063948)) + 4.24678547 * tanh(12.17805062 * (x - 7.57659337)) - 0.3757068 * tanh(59.33067782 * (x - 0.99784492))",
"Entropic change coefficient [V.K-1]": -1e-4,
"Surface area per unit volume [m-1]": 186331,
"Reaction rate constant [mol.m-2.s-1]": 2.305e-05,
"Minimum stoichiometry": 0.42424,
"Maximum stoichiometry": 0.96210,
"Maximum concentration [mol.m-3]": 46200,
"Diffusivity activation energy [J.mol-1]": 15000,
"Reaction rate constant activation energy [J.mol-1]": 3500,
},
},
}

filename = "tmp.json"
with tempfile.NamedTemporaryFile(
suffix=filename, delete=False, mode="w"
) as tmp:
# write to a tempory file so we can
# get the source later on using inspect.getsource
# (as long as the file still exists)
json.dump(bpx_obj, tmp)
tmp.flush()

with self.assertRaisesRegex(NotImplementedError, "PyBaMM does not support"):
pybamm.ParameterValues.create_from_bpx(tmp.name)

def test_bpx_user_defined(self):
bpx_obj = copy.copy(self.base)
data = {"x": [0, 1], "y": [0, 1]}
Expand Down

0 comments on commit c8264b8

Please sign in to comment.