-
-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,23 @@ | ||
# | ||
# Compare lithium-ion battery models | ||
# | ||
import argparse | ||
import numpy as np | ||
import pybamm | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--debug", action="store_true", help="Set logging level to 'DEBUG'." | ||
) | ||
args = parser.parse_args() | ||
if args.debug: | ||
pybamm.set_logging_level("DEBUG") | ||
else: | ||
pybamm.set_logging_level("INFO") | ||
pybamm.set_logging_level("INFO") | ||
|
||
# load models | ||
options = {"thermal": "lumped"} | ||
models = [ | ||
pybamm.lithium_ion.SPM(options), | ||
pybamm.lithium_ion.SPMe(options), | ||
pybamm.lithium_ion.DFN(options), | ||
pybamm.lithium_ion.SPM(), | ||
pybamm.lithium_ion.SPMe(), | ||
pybamm.lithium_ion.DFN(), | ||
] | ||
|
||
|
||
# load parameter values and process models and geometry | ||
param = models[0].default_parameter_values | ||
param["Current function [A]"] = 1 | ||
|
||
for model in models: | ||
param.process_model(model) | ||
|
||
# set mesh | ||
var = pybamm.standard_spatial_vars | ||
var_pts = {var.x_n: 10, var.x_s: 10, var.x_p: 10, var.r_n: 10, var.r_p: 10} | ||
|
||
# discretise models | ||
# create and run simulations | ||
sims = [] | ||
for model in models: | ||
# create geometry | ||
geometry = model.default_geometry | ||
param.process_geometry(geometry) | ||
mesh = pybamm.Mesh(geometry, models[-1].default_submesh_types, var_pts) | ||
disc = pybamm.Discretisation(mesh, model.default_spatial_methods) | ||
disc.process_model(model) | ||
|
||
# solve model | ||
solutions = [None] * len(models) | ||
t_eval = np.linspace(0, 3600, 100) | ||
for i, model in enumerate(models): | ||
solutions[i] = model.default_solver.solve(model, t_eval) | ||
sim = pybamm.Simulation(model) | ||
sim.solve() | ||
sims.append(sim) | ||
|
||
# plot | ||
plot = pybamm.QuickPlot(solutions, linestyles=[":", "--", "-"]) | ||
plot.dynamic_plot() | ||
pybamm.dynamic_plot(sims) |