-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
4 changed files
with
299 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,94 @@ | ||
import pybamm | ||
# | ||
# Compare different discretisations in the particle | ||
# | ||
import argparse | ||
import numpy as np | ||
import pybamm | ||
import matplotlib.pyplot as plt | ||
|
||
pybamm.set_logging_level("INFO") | ||
|
||
# load model | ||
model = pybamm.lithium_ion.SPM() | ||
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") | ||
|
||
# create geometry | ||
geometry = model.default_geometry | ||
# load models | ||
models = [ | ||
pybamm.lithium_ion.SPM(name="Uniform mesh"), | ||
pybamm.lithium_ion.SPM(name="Chebyshev mesh"), | ||
pybamm.lithium_ion.SPM(name="Exponential mesh"), | ||
] | ||
|
||
# load parameter values and process model and geometry | ||
param = model.default_parameter_values | ||
param.process_model(model) | ||
param.process_geometry(geometry) | ||
# load parameter values and process models and geometry | ||
param = models[0].default_parameter_values | ||
param["Typical current [A]"] = 1.0 | ||
for model in models: | ||
param.process_model(model) | ||
|
||
# set mesh | ||
submesh_types = { | ||
"negative electrode": pybamm.Uniform1DSubMesh, | ||
"separator": pybamm.Uniform1DSubMesh, | ||
"positive electrode": pybamm.Uniform1DSubMesh, | ||
"negative particle": pybamm.Chebyshev1DSubMesh, | ||
"positive particle": pybamm.Chebyshev1DSubMesh, | ||
"current collector": pybamm.SubMesh0D, | ||
} | ||
var = pybamm.standard_spatial_vars | ||
var_pts = {var.x_n: 10, var.x_s: 10, var.x_p: 10, var.r_n: 9, var.r_p: 9} | ||
mesh = pybamm.Mesh(geometry, submesh_types, var_pts) | ||
|
||
# discretise model | ||
disc = pybamm.Discretisation(mesh, model.default_spatial_methods) | ||
disc.process_model(model) | ||
submesh_types = models[0].default_submesh_types | ||
particle_meshes = [ | ||
pybamm.Uniform1DSubMesh, | ||
pybamm.Chebyshev1DSubMesh, | ||
pybamm.RightExponential1DSubMesh, | ||
] | ||
meshes = [None] * len(models) | ||
# discretise models | ||
for i, model in enumerate(models): | ||
# create geometry | ||
geometry = model.default_geometry | ||
param.process_geometry(geometry) | ||
submesh_types["negative particle"] = particle_meshes[i] | ||
submesh_types["positive particle"] = particle_meshes[i] | ||
meshes[i] = pybamm.Mesh(geometry, submesh_types, model.default_var_pts) | ||
disc = pybamm.Discretisation(meshes[i], model.default_spatial_methods) | ||
disc.process_model(model) | ||
|
||
# solve model | ||
t_eval = np.linspace(0, 0.2, 100) | ||
solution = model.default_solver.solve(model, t_eval) | ||
solutions = [None] * len(models) | ||
t_eval = np.linspace(0, 0.17, 100) | ||
for i, model in enumerate(models): | ||
solutions[i] = model.default_solver.solve(model, t_eval) | ||
|
||
# process particle concentration variables | ||
processed_variables = [None] * len(models) | ||
for i, solution in enumerate(solutions): | ||
c_n = pybamm.ProcessedVariable( | ||
models[i].variables["X-average negative particle concentration [mol.m-3]"], | ||
solution.t, | ||
solution.y, | ||
mesh=meshes[i], | ||
) | ||
c_p = pybamm.ProcessedVariable( | ||
models[i].variables["X-average positive particle concentration [mol.m-3]"], | ||
solution.t, | ||
solution.y, | ||
mesh=meshes[i], | ||
) | ||
processed_variables[i] = {"c_n": c_n, "c_p": c_p} | ||
|
||
|
||
# plot | ||
r_n = mesh["negative particle"][0].edges | ||
c_n = pybamm.ProcessedVariable( | ||
model.variables["X-average negative particle concentration [mol.m-3]"], | ||
solution.t, | ||
solution.y, | ||
mesh=mesh, | ||
) | ||
r_p = mesh["positive particle"][0].edges | ||
c_p = pybamm.ProcessedVariable( | ||
model.variables["X-average positive particle concentration [mol.m-3]"], | ||
solution.t, | ||
solution.y, | ||
mesh=mesh, | ||
) | ||
import ipdb; ipdb.set_trace() | ||
fig, ax = plt.subplots(figsize=(15, 8)) | ||
plt.tight_layout() | ||
plt.subplot(121) | ||
plt.plot( | ||
r_n, | ||
np.zeros_like(r_n), | ||
"ro", | ||
mesh["negative particle"][0].nodes, | ||
c_n(t=0.1, r=mesh["negative particle"][0].nodes), | ||
"b-", | ||
) | ||
plt.subplot(122) | ||
plt.plot( | ||
r_p, | ||
np.zeros_like(r_p), | ||
"ro", | ||
mesh["positive particle"][0].nodes, | ||
c_p(t=0.1, r=mesh["positive particle"][0].nodes), | ||
"b-", | ||
) | ||
plt.show() | ||
def plot(t): | ||
fig, ax = plt.subplots(figsize=(15, 8)) | ||
plt.subplot(121) | ||
plt.xlabel(r"$r_n$") | ||
plt.ylabel("Negative particle concentration [mol.m-3]") | ||
for i, vars in enumerate(processed_variables): | ||
r_n = meshes[i]["negative particle"][0].nodes | ||
neg_plot, = plt.plot(r_n, vars["c_n"](r=r_n, t=t), '-o', label=models[i].name) | ||
plt.subplot(122) | ||
plt.xlabel(r"$r_p$") | ||
plt.ylabel("Positive particle concentration [mol.m-3]") | ||
for i, vars in enumerate(processed_variables): | ||
r_p = meshes[i]["positive particle"][0].nodes | ||
pos_plot, = plt.plot(r_p, vars["c_p"](r=r_p, t=t), '-o', label=models[i].name) | ||
plt.legend() | ||
plt.show() | ||
|
||
|
||
plot(0.1) |
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
Oops, something went wrong.