-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
Copy pathcccv.py
78 lines (73 loc) · 1.92 KB
/
cccv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#
# Constant-current constant-voltage charge
#
import pybamm
import matplotlib.pyplot as plt
pybamm.set_logging_level("NOTICE")
experiment = pybamm.Experiment(
[
(
"Discharge at C/5 for 10 hours or until 3.3 V",
"Rest for 1 hour",
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 10 mA",
"Rest for 1 hour",
),
]
* 3
)
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(
model, experiment=experiment, solver=pybamm.CasadiSolver("fast with events")
)
sim.solve()
# Plot voltages from the discharge segments only
fig, ax = plt.subplots()
for i in range(3):
# Extract sub solutions
sol = sim.solution.cycles[i]
# Extract variables
t = sol["Time [h]"].entries
V = sol["Terminal voltage [V]"].entries
# Plot
ax.plot(t - t[0], V, label="Discharge {}".format(i + 1))
ax.set_xlabel("Time [h]")
ax.set_ylabel("Voltage [V]")
ax.set_xlim([0, 10])
ax.legend(loc="lower left")
# Save time, voltage, current, discharge capacity, temperature, and electrolyte
# concentration to csv and matlab formats
sim.solution.save_data(
"output.mat",
[
"Time [h]",
"Current [A]",
"Terminal voltage [V]",
"Discharge capacity [A.h]",
"X-averaged cell temperature [K]",
"Electrolyte concentration [mol.m-3]",
],
to_format="matlab",
short_names={
"Time [h]": "t",
"Current [A]": "I",
"Terminal voltage [V]": "V",
"Discharge capacity [A.h]": "Q",
"X-averaged cell temperature [K]": "T",
"Electrolyte concentration [mol.m-3]": "c_e",
},
)
# We can only save 0D variables to csv
sim.solution.save_data(
"output.csv",
[
"Time [h]",
"Current [A]",
"Terminal voltage [V]",
"Discharge capacity [A.h]",
"X-averaged cell temperature [K]",
],
to_format="csv",
)
# Show all plots
sim.plot()