Skip to content

Commit 9aa93b8

Browse files
Merge pull request #1186 from brosaplanella/issue-1185-example-conservation
Added example conservation
2 parents fdeaa94 + 461438d commit 9aa93b8

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Features
44

5+
- Added an example script to check conservation of lithium ([#1186](https://github.com/pybamm-team/PyBaMM/pull/1186))
56

67
## Optimizations
78

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Check conservation of lithium
3+
#
4+
5+
import pybamm
6+
import matplotlib.pyplot as plt
7+
8+
pybamm.set_logging_level("INFO")
9+
10+
model = pybamm.lithium_ion.DFN()
11+
12+
experiment = pybamm.Experiment(
13+
[
14+
"Discharge at 1C until 3.2 V",
15+
"Rest for 2 hours",
16+
"Charge at C/3 until 4 V",
17+
"Charge at 4 V until 5 mA",
18+
"Rest for 2 hours",
19+
]
20+
* 3
21+
)
22+
23+
sim = pybamm.Simulation(model, experiment=experiment)
24+
sim.solve()
25+
solution = sim.solution
26+
27+
t = solution["Time [s]"].entries
28+
Ne = solution["Total concentration in electrolyte [mol]"].entries
29+
Np = solution["Total lithium in positive electrode [mol]"].entries
30+
Nn = solution["Total lithium in negative electrode [mol]"].entries
31+
Ntot = Np + Nn + Ne
32+
33+
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
34+
35+
ax[0].plot(t, Ntot / Ntot[0] - 1)
36+
ax[0].set_xlabel("Time (s)")
37+
ax[0].set_ylabel("Variation of total lithium as fraction of initial value")
38+
39+
ax[1].plot(t, Np + Nn, label="total")
40+
ax[1].plot(t, Np, label="positive")
41+
ax[1].plot(t, Nn, label="negative")
42+
ax[1].set_xlabel("Time (s)")
43+
ax[1].set_ylabel("Total lithium in electrode (mol)")
44+
ax[1].legend()
45+
46+
fig.tight_layout()
47+
48+
plt.show()

0 commit comments

Comments
 (0)