Skip to content

Commit 7ff45ec

Browse files
Merge pull request #2781 from abillscmu/energy-summary
Add theoretical energy to summary variables
2 parents 5465052 + cbd3565 commit 7ff45ec

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Added "Negative electrode surface potential difference at separator interface [V]", which is the value of the surface potential difference (`phi_s - phi_e`) at the anode/separator interface, commonly controlled in fast-charging algorithms to avoid plating. Also added "Positive electrode surface potential difference at separator interface [V]". ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))
77
- Added "Open-circuit voltage [V]", which is the open-circuit voltage as calculated from the bulk particle concentrations. The old variable "Measured open circuit voltage [V]", which referred to the open-circuit potential as calculated from the surface particle concentrations, has been renamed to "Surface open-circuit voltage [V]". ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))
88
- Added an example for `plot_voltage_components`, explaining what the different voltage components are. ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))
9+
- Added method to calculate maximum theoretical energy. ([#2777](https://github.com/pybamm-team/PyBaMM/pull/2777)) and add to summary variables ([#2781](https://github.com/pybamm-team/PyBaMM/pull/2781))
910

1011
## Bug fixes
1112

@@ -33,7 +34,6 @@
3334
- Added an option for using a banded jacobian and sundials banded solvers for the IDAKLU solve ([#2677](https://github.com/pybamm-team/PyBaMM/pull/2677))
3435
- The "particle size" option can now be a tuple to allow different behaviour in each electrode ([#2672](https://github.com/pybamm-team/PyBaMM/pull/2672)).
3536
- Added temperature control to experiment class. ([#2518](https://github.com/pybamm-team/PyBaMM/pull/2518))
36-
- Added method to calculate maximum theoretical energy. ([#2777](https://github.com/pybamm-team/PyBaMM/pull/2777))
3737

3838
## Bug fixes
3939

pybamm/models/full_battery_models/lithium_ion/electrode_soh.py

Lines changed: 46 additions & 10 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):
@@ -560,9 +570,7 @@ def get_min_max_stoichiometries(
560570
return esoh_solver.get_min_max_stoichiometries()
561571

562572

563-
def calculate_theoretical_energy(
564-
parameter_values, initial_soc=1.0, final_soc=0.0, points=100
565-
):
573+
def theoretical_energy_integral(parameter_values, n_i, n_f, p_i, p_f, points=100):
566574
"""
567575
Calculate maximum energy possible from a cell given OCV, initial soc, and final soc
568576
given voltage limits, open-circuit potentials, etc defined by parameter_values
@@ -571,10 +579,9 @@ def calculate_theoretical_energy(
571579
----------
572580
parameter_values : :class:`pybamm.ParameterValues`
573581
The parameter values class that will be used for the simulation.
574-
initial_soc : float
575-
The soc at begining of discharge, default 1.0
576-
final_soc : float
577-
The soc at end of discharge, default 1.0
582+
n_i, n_f, p_i, p_f : float
583+
initial and final stoichiometries for the positive and negative
584+
electrodes, respectively
578585
points : int
579586
The number of points at which to calculate voltage.
580587
@@ -583,9 +590,6 @@ def calculate_theoretical_energy(
583590
E
584591
The total energy of the cell in Wh
585592
"""
586-
# Get initial and final stoichiometric values.
587-
n_i, p_i = get_initial_stoichiometries(initial_soc, parameter_values)
588-
n_f, p_f = get_initial_stoichiometries(final_soc, parameter_values)
589593
n_vals = np.linspace(n_i, n_f, num=points)
590594
p_vals = np.linspace(p_i, p_f, num=points)
591595
# Calculate OCV at each stoichiometry
@@ -602,3 +606,35 @@ def calculate_theoretical_energy(
602606
# Integrate and convert to W-h
603607
E = np.trapz(Vs, dx=dQ)
604608
return E
609+
610+
611+
def calculate_theoretical_energy(
612+
parameter_values, initial_soc=1.0, final_soc=0.0, points=100
613+
):
614+
"""
615+
Calculate maximum energy possible from a cell given OCV, initial soc, and final soc
616+
given voltage limits, open-circuit potentials, etc defined by parameter_values
617+
618+
Parameters
619+
----------
620+
parameter_values : :class:`pybamm.ParameterValues`
621+
The parameter values class that will be used for the simulation.
622+
initial_soc : float
623+
The soc at begining of discharge, default 1.0
624+
final_soc : float
625+
The soc at end of discharge, default 0.0
626+
points : int
627+
The number of points at which to calculate voltage.
628+
629+
Returns
630+
-------
631+
E
632+
The total energy of the cell in Wh
633+
"""
634+
# Get initial and final stoichiometric values.
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+
)
640+
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)