Skip to content

Commit cbd3565

Browse files
committed
fix test
1 parent 25f2997 commit cbd3565

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

pybamm/models/full_battery_models/lithium_ion/electrode_soh.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ def solve(self, inputs):
244244
raise split_error
245245

246246
sol_dict = {key: sol[key].data[0] for key in sol.all_models[0].variables.keys()}
247+
248+
# Calculate theoretical energy
249+
x_0 = sol_dict["x_0"]
250+
y_0 = sol_dict["y_0"]
251+
x_100 = sol_dict["x_100"]
252+
y_100 = sol_dict["y_100"]
253+
energy = pybamm.lithium_ion.electrode_soh.theoretical_energy_integral(
254+
self.parameter_values, x_100, x_0, y_100, y_0
255+
)
256+
sol_dict.update({"Maximum theoretical energy [W.h]": energy})
247257
return sol_dict
248258

249259
def _set_up_solve(self, inputs):
@@ -622,7 +632,9 @@ def calculate_theoretical_energy(
622632
The total energy of the cell in Wh
623633
"""
624634
# Get initial and final stoichiometric values.
625-
n_i, p_i = get_initial_stoichiometries(initial_soc, parameter_values)
626-
n_f, p_f = get_initial_stoichiometries(final_soc, parameter_values)
627-
E = theoretical_energy_integral(parameter_values, n_i, n_f, p_i, p_f, points=points)
635+
x_100, y_100 = get_initial_stoichiometries(initial_soc, parameter_values)
636+
x_0, y_0 = get_initial_stoichiometries(final_soc, parameter_values)
637+
E = theoretical_energy_integral(
638+
parameter_values, x_100, x_0, y_100, y_0, points=points
639+
)
628640
return E

tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_electrode_soh.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ def test_known_solution(self):
3131
ics = esoh_solver._set_up_solve(inputs)
3232
sol_split = esoh_solver._solve_split(inputs, ics)
3333
for key in sol:
34-
self.assertAlmostEqual(sol[key], sol_split[key].data[0], places=5)
34+
if key != "Maximum theoretical energy [W.h]":
35+
self.assertAlmostEqual(sol[key], sol_split[key].data[0], places=5)
36+
else:
37+
# theoretical_energy is not present in sol_split
38+
x_0 = sol_split["x_0"].data[0]
39+
y_0 = sol_split["y_0"].data[0]
40+
x_100 = sol_split["x_100"].data[0]
41+
y_100 = sol_split["y_100"].data[0]
42+
energy = pybamm.lithium_ion.electrode_soh.theoretical_energy_integral(
43+
parameter_values, x_100, x_0, y_100, y_0
44+
)
45+
self.assertAlmostEqual(sol[key], energy, places=5)
3546

3647
# should still work with old inputs
3748
n_Li = parameter_values.evaluate(param.n_Li_particles_init)

0 commit comments

Comments
 (0)