forked from pybamm-team/PyBaMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifferent_model_options.py
302 lines (239 loc) · 9.15 KB
/
different_model_options.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
import pybamm
from benchmarks.benchmark_utils import set_random_seed
import numpy as np
def compute_discretisation(model, param):
var_pts = {
pybamm.standard_spatial_vars.x_n: 20,
pybamm.standard_spatial_vars.x_s: 20,
pybamm.standard_spatial_vars.x_p: 20,
pybamm.standard_spatial_vars.r_n: 30,
pybamm.standard_spatial_vars.r_p: 30,
pybamm.standard_spatial_vars.y: 10,
pybamm.standard_spatial_vars.z: 10,
}
geometry = model.default_geometry
param.process_geometry(geometry)
mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts)
return pybamm.Discretisation(mesh, model.default_spatial_methods)
def solve_model_once(model, solver, t_eval):
solver.solve(model, t_eval=t_eval)
def build_model(parameter, model_, option, value):
param = pybamm.ParameterValues(parameter)
model = model_({option: value})
param.process_model(model)
compute_discretisation(model, param).process_model(model)
class SolveModel:
solver: pybamm.BaseSolver
model: pybamm.BaseModel
t_eval: np.ndarray
def solve_setup(self, parameter, model_, option, value, solver_class):
import importlib
idaklu_spec = importlib.util.find_spec("pybamm.solvers.idaklu")
if idaklu_spec is not None:
try:
idaklu = importlib.util.module_from_spec(idaklu_spec)
idaklu_spec.loader.exec_module(idaklu)
except ImportError as e: # pragma: no cover
print("XXXXX cannot find klu", e)
idaklu_spec = None
self.solver = solver_class()
self.model = model_({option: value})
c_rate = 1
tmax = 4000 / c_rate
nb_points = 500
self.t_eval = np.linspace(0, tmax, nb_points)
geometry = self.model.default_geometry
# load parameter values and process model and geometry
param = pybamm.ParameterValues(parameter)
param.process_model(self.model)
param.process_geometry(geometry)
# set mesh
var_pts = {
"x_n": 20,
"x_s": 20,
"x_p": 20,
"r_n": 30,
"r_p": 30,
"y": 10,
"z": 10,
}
mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts)
# discretise model
disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods)
disc.process_model(self.model)
def solve_model(self, _model, _params):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelLossActiveMaterial:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "stress-driven", "reaction-driven", "stress and reaction-driven"],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("Ai2020", model, "loss of active material", params)
class TimeSolveLossActiveMaterial(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "stress-driven", "reaction-driven", "stress and reaction-driven"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
SolveModel.solve_setup(
self, "Ai2020", model, "loss of active material", params, solver_class
)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelLithiumPlating:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "irreversible", "reversible", "partially reversible"],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("OKane2022", model, "lithium plating", params)
class TimeSolveLithiumPlating(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["none", "irreversible", "reversible", "partially reversible"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
SolveModel.solve_setup(
self, "OKane2022", model, "lithium plating", params, solver_class
)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelSEI:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
"none",
"constant",
"reaction limited",
"solvent-diffusion limited",
"electron-migration limited",
"interstitial-diffusion limited",
"ec reaction limited",
],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("Marquis2019", model, "SEI", params)
class TimeSolveSEI(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
"none",
"constant",
"reaction limited",
"solvent-diffusion limited",
"electron-migration limited",
"interstitial-diffusion limited",
"ec reaction limited",
],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
SolveModel.solve_setup(self, "Marquis2019", model, "SEI", params, solver_class)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelParticle:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
"Fickian diffusion",
"uniform profile",
"quadratic profile",
"quartic profile",
],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("Marquis2019", model, "particle", params)
class TimeSolveParticle(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
[
"Fickian diffusion",
"uniform profile",
"quadratic profile",
"quartic profile",
],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
SolveModel.solve_setup(
self, "Marquis2019", model, "particle", params, solver_class
)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelThermal:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["isothermal", "lumped", "x-full"],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("Marquis2019", model, "thermal", params)
class TimeSolveThermal(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["isothermal", "lumped", "x-full"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
SolveModel.solve_setup(
self, "Marquis2019", model, "thermal", params, solver_class
)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)
class TimeBuildModelSurfaceForm:
param_names = ["model", "model option"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["false", "differential", "algebraic"],
)
def setup(self, _model, _params):
set_random_seed()
def time_setup_model(self, model, params):
build_model("Marquis2019", model, "surface form", params)
class TimeSolveSurfaceForm(SolveModel):
param_names = ["model", "model option", "solver class"]
params = (
[pybamm.lithium_ion.SPM, pybamm.lithium_ion.DFN],
["false", "differential", "algebraic"],
[pybamm.CasadiSolver, pybamm.IDAKLUSolver],
)
def setup(self, model, params, solver_class):
set_random_seed()
if (model, params, solver_class) == (
pybamm.lithium_ion.SPM,
"differential",
pybamm.IDAKLUSolver,
):
raise NotImplementedError
SolveModel.solve_setup(
self, "Marquis2019", model, "surface form", params, solver_class
)
def time_solve_model(self, _model, _params, _solver_class):
self.solver.solve(self.model, t_eval=self.t_eval)