|
| 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