Skip to content

Commit

Permalink
Merge pull request #2777 from abillscmu/batt-carnot
Browse files Browse the repository at this point in the history
Method to calculate theoretical efficiency
  • Loading branch information
valentinsulzer authored Mar 15, 2023
2 parents 124efe5 + 0fa49e2 commit c0d394e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- 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))
- 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)).
- Added temperature control to experiment class. ([#2518](https://github.com/pybamm-team/PyBaMM/pull/2518))
- Added method to calculate maximum theoretical energy. ([#2777](https://github.com/pybamm-team/PyBaMM/pull/2777))

## Bug fixes

Expand Down
44 changes: 44 additions & 0 deletions pybamm/models/full_battery_models/lithium_ion/electrode_soh.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,47 @@ def get_min_max_stoichiometries(
"""
esoh_solver = ElectrodeSOHSolver(parameter_values, param, known_value)
return esoh_solver.get_min_max_stoichiometries()


def calculate_theoretical_energy(
parameter_values, initial_soc=1.0, final_soc=0.0, points=100
):
"""
Calculate maximum energy possible from a cell given OCV, initial soc, and final soc
given voltage limits, open-circuit potentials, etc defined by parameter_values
Parameters
----------
parameter_values : :class:`pybamm.ParameterValues`
The parameter values class that will be used for the simulation.
initial_soc : float
The soc at begining of discharge, default 1.0
final_soc : float
The soc at end of discharge, default 1.0
points : int
The number of points at which to calculate voltage.
Returns
-------
E
The total energy of the cell in Wh
"""
# Get initial and final stoichiometric values.
n_i, p_i = get_initial_stoichiometries(initial_soc, parameter_values)
n_f, p_f = get_initial_stoichiometries(final_soc, parameter_values)
n_vals = np.linspace(n_i, n_f, num=points)
p_vals = np.linspace(p_i, p_f, num=points)
# Calculate OCV at each stoichiometry
param = pybamm.LithiumIonParameters()
T = param.T_amb(0)
Vs = np.empty(n_vals.shape)
for i in range(n_vals.size):
Vs[i] = parameter_values.evaluate(
param.p.prim.U(p_vals[i], T)
) - parameter_values.evaluate(param.n.prim.U(n_vals[i], T))
# Calculate dQ
Q_p = parameter_values.evaluate(param.p.prim.Q_init) * (p_f - p_i)
dQ = Q_p / (points - 1)
# Integrate and convert to W-h
E = np.trapz(Vs, dx=dQ)
return E
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ def test_known_solution(self):
self.assertAlmostEqual(sol["Uw(x_0)"].data[0], V_min, places=5)


class TestCalculateTheoreticalEnergy(unittest.TestCase):
def test_efficiency(self):
model = pybamm.lithium_ion.DFN(options={"calculate discharge energy": "true"})
parameter_values = pybamm.ParameterValues("Chen2020")
sim = pybamm.Simulation(model, parameter_values=parameter_values)
sol = sim.solve([0, 3600], initial_soc=1.0)
discharge_energy = sol["Discharge energy [W.h]"].entries[-1]
theoretical_energy = (
pybamm.lithium_ion.electrode_soh.calculate_theoretical_energy(
parameter_values
)
)
# Real energy should be less than discharge energy,
# and both should be greater than 0
self.assertLess(discharge_energy, theoretical_energy)
self.assertLess(0, discharge_energy)
self.assertLess(0, theoretical_energy)


class TestGetInitialSOC(unittest.TestCase):
def test_initial_soc(self):
param = pybamm.LithiumIonParameters()
Expand Down

0 comments on commit c0d394e

Please sign in to comment.