Skip to content

Commit

Permalink
#632 merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Jun 15, 2020
2 parents 6a0376c + e354928 commit 873c943
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 90 deletions.
55 changes: 7 additions & 48 deletions examples/scripts/compare_lead_acid.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
#
# Compare lead-acid 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
models = [
Expand All @@ -23,43 +13,12 @@
# pybamm.lead_acid.Full(),
]

# load parameter values and process models and geometry
param = models[0].default_parameter_values
param.update({"Current function [A]": "[input]", "Initial State of Charge": 1})
# create and run simulations
sims = []
for model in models:
param.process_model(model)

# discretise models
var = pybamm.standard_spatial_vars
var_pts = {var.x_n: 25, var.x_s: 41, var.x_p: 34, var.y: 10, var.z: 10}
for model in models:
geometry = model.default_geometry
param.process_geometry(geometry)
mesh = pybamm.Mesh(geometry, model.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 * 2, 1000)
for i, model in enumerate(models):
solution = model.default_solver.solve(
model, t_eval, inputs={"Current function [A]": 1}
)
solutions[i] = solution
sim = pybamm.Simulation(model)
sim.solve()
sims.append(sim)

# plot
output_variables = [
"Interfacial current density [A.m-2]",
"Electrolyte concentration [mol.m-3]",
"Current [A]",
"Porosity",
"Electrolyte potential [V]",
"Terminal voltage [V]",
"Negative electrode reaction overpotential",
"Positive electrode reaction overpotential",
"Sum of interfacial current densities",
"Sum of electrolyte reaction source terms",
]
plot = pybamm.QuickPlot(solutions, output_variables, linestyles=[":", "--", "-"])
plot.dynamic_plot()
pybamm.dynamic_plot(sims)
52 changes: 10 additions & 42 deletions examples/scripts/compare_lithium_ion.py
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)

0 comments on commit 873c943

Please sign in to comment.