19
19
else :
20
20
pybamm .set_logging_level ("INFO" )
21
21
22
+
23
+ class CCCV :
24
+ num_switches = 1
25
+
26
+ def __call__ (self , variables ):
27
+ # switch controls 1A charge vs 4.2V charge
28
+ # charging current is negative
29
+ a = variables ["Switch 1" ]
30
+ I = variables ["Current [A]" ]
31
+ V = variables ["Terminal voltage [V]" ]
32
+ return (a < 0.5 ) * (I + 1 ) + (a > 0.5 ) * (I )
33
+
34
+
35
+ class CCCP :
36
+ num_switches = 1
37
+
38
+ def __call__ (self , variables ):
39
+ # switch controls 4W charge vs 4.2V charge
40
+ # charging current (and hence power) is negative
41
+ a = variables ["Switch 1" ]
42
+ I = variables ["Current [A]" ]
43
+ V = variables ["Terminal voltage [V]" ]
44
+ return (a * (V > 0 ) <= 0 ) * (I * V + 4 ) + (a * (V > 0 ) > 0 ) * (V - 4.2 )
45
+
46
+
22
47
# load models
23
48
models = [
24
- pybamm .lithium_ion .DFN ({"operating mode" : "custom" } ),
25
- pybamm .lithium_ion .DFN ({"operating mode" : "voltage" }),
26
- pybamm .lithium_ion .DFN ({"operating mode" : "custom" } ),
49
+ pybamm .lithium_ion .SPM ({"operating mode" : CCCV }, name = "CCCV SPM" ),
50
+ # pybamm.lithium_ion.DFN({"operating mode": "voltage"}, name="CV DFN" ),
51
+ # pybamm.lithium_ion.DFN({"operating mode": CCCP}, name="CCCP DFN" ),
27
52
]
28
53
29
54
30
55
# load parameter values and process models and geometry
31
- params = [models [ 0 ] .default_parameter_values ] * 3
56
+ params = [model .default_parameter_values for model in models ]
32
57
33
58
# 1. CC-CV: Charge at 1C ( A) to 4.2V then 4.2V hold
34
- a = pybamm .Parameter ("CCCV switch" )
59
+ params [0 ]["Switch 1" ] = 0
60
+ params [0 ]["Upper voltage cut-off [V]" ] = 4.15
35
61
62
+ # # 2. CV: Charge at 4.1V
63
+ # params[1]["Voltage function"] = 4.1
36
64
37
- def cccv (I , V ):
38
- # switch a controls 1A charge vs 4.2V charge
39
- # charging current is negative
40
- return a * (I + 1 ) + (1 - a ) * (V - 4.2 )
65
+ # # 3. CP-CV: Charge at 4W to 4.2V then 4.2V hold
66
+ # b = pybamm.Parameter("CCCP switch")
41
67
42
68
43
- params [0 ]["CCCV switch" ] = 1 # start with CC
44
- params [0 ]["External circuit function" ] = cccv
69
+ # params[2 ]["CCCP switch"] = 1 # start with CP
70
+ # params[2 ]["External circuit function"] = cccp
45
71
46
- # 2. CV: Charge at 4.1V
47
- params [1 ]["Voltage function" ] = 4.1
48
72
for model , param in zip (models , params ):
49
73
param .process_model (model )
50
74
51
- # 3. CP-CV: Charge at 4W to 4.2V then 4.2V hold
52
- b = pybamm .Parameter ("CCCP switch" )
53
-
54
-
55
- def cccp (I , V ):
56
- # switch a controls 1A charge vs 4.2V charge
57
- # charging current is negative
58
- return b * (I * V + 4 ) + (1 - b ) * (V - 4.2 )
59
-
60
-
61
- params [0 ]["CCCP switch" ] = 1 # start with CP
62
- params [0 ]["External circuit function" ] = cccp
63
-
64
75
# set mesh
65
76
var = pybamm .standard_spatial_vars
66
77
var_pts = {var .x_n : 10 , var .x_s : 10 , var .x_p : 10 , var .r_n : 5 , var .r_p : 5 }
67
78
68
79
# discretise models
80
+ discs = {}
69
81
for model in models :
70
82
# create geometry
83
+ model .convert_to_format = "python"
71
84
geometry = model .default_geometry
72
85
param .process_geometry (geometry )
73
86
mesh = pybamm .Mesh (geometry , models [- 1 ].default_submesh_types , var_pts )
74
87
disc = pybamm .Discretisation (mesh , model .default_spatial_methods )
75
88
disc .process_model (model )
76
-
77
- # solve model
78
- solutions = [None ] * len (models )
79
- t_eval = np .linspace (0 , 0.3 , 100 )
80
- for i , model in enumerate (models ):
81
- solutions [i ] = model .default_solver .solve (model , t_eval )
82
-
89
+ discs [model ] = disc
90
+
91
+ # solve models
92
+ solver0 = model .default_solver
93
+ solution0 = solver0 .step (model , 1 , npts = 1000 )
94
+ params [0 ]["Switch 1" ] = 1
95
+ params [0 ]["Upper voltage cut-off [V]" ] = 4.16
96
+ params [0 ].update_model (models [0 ], discs [models [0 ]])
97
+ solution0 .append (solver0 .step (model , 1 - solution0 .t [- 1 ], npts = 1000 ))
98
+ solutions = [solution0 ]
99
+ # # Step
100
+ # solution0 = models[0].default_solver.step(models[0], t_eval)
101
+ # # Switch to CV
102
+ # params[0].update({"CCCV switch": 0})
103
+ # params[0].update_model(models[0], discs[models[0]])
104
+ # # Step
105
+ # solution0.append(models[0].default_solver.step(models[0], t_eval))
106
+
107
+ # solution1 = models[1].default_solver.solve(models[1], t_eval)
108
+
109
+ # solutions = [solution0, solution1]
83
110
# plot
84
111
output_variables = [
85
112
"Negative particle surface concentration" ,
@@ -88,7 +115,7 @@ def cccp(I, V):
88
115
"Current [A]" ,
89
116
"Negative electrode potential [V]" ,
90
117
"Electrolyte potential [V]" ,
91
- "Terminal power [W] " ,
118
+ "Switch 1 " ,
92
119
"Terminal voltage [V]" ,
93
120
]
94
121
plot = pybamm .QuickPlot (models , mesh , solutions , output_variables )
0 commit comments