Rate capability design sweep
Map 2C discharge capacity over 256 electrode designs in one batch request.
Make both electrodes' porosities "[input]" and solve a 16 × 16 grid of designs at
2C. The 256 runs share a model and protocol, so they go to Ionworks as one batch
request. Less porous electrodes hold more active material but starve the
electrolyte, so the map shows a best design and a sharp cliff below it. Pass 32
points to np.linspace for a finer, 1024-design map.
This example uses a published PyBaMM parameter set, so you can
copy it and run it as-is on Ionworks. Set IONWORKS_PYBAMM_LOCAL=1 to run the same script with
PyBaMM on your own machine.
Each simulation holds 0.025 of
the credit left after what its running simulations have used if that is fewer, so solve
sends a larger batch in groups of that size, each once the group before it has finished.
If your credit runs out while simulations are running, they are all canceled and charged
for the time they ran.
import ionworks.pybamm as pybamm
import matplotlib.pyplot as plt
import numpy as np
electrodes = ("Negative", "Positive")
parameter_values = pybamm.ParameterValues("Chen2020")
for electrode in electrodes:
parameter_values[f"{electrode} electrode porosity"] = "[input]"
parameter_values[f"{electrode} electrode active material volume fraction"] = (
"[input]"
)
sim = pybamm.Simulation(
pybamm.lithium_ion.SPMe(),
parameter_values=parameter_values,
experiment=pybamm.Experiment(["Discharge at 2C until 2.5 V"]),
)
# All solid is active material, as in Chen2020.
porosities = np.linspace(0.15, 0.45, 16)
designs = [(neg, pos) for neg in porosities for pos in porosities]
def inputs(neg, pos):
values = {}
for electrode, porosity in zip(electrodes, (neg, pos), strict=True):
values[f"{electrode} electrode porosity"] = porosity
values[f"{electrode} electrode active material volume fraction"] = (
1 - porosity
)
return values
solutions = sim.solve(initial_soc=1, inputs=[inputs(*d) for d in designs])
capacity = np.reshape(
[sol["Discharge capacity [A.h]"].entries[-1] for sol in solutions],
(len(porosities), len(porosities)),
)
best = np.unravel_index(capacity.argmax(), capacity.shape)
fig, ax = plt.subplots()
extent = [porosities[0], porosities[-1], porosities[0], porosities[-1]]
image = ax.imshow(capacity, origin="lower", extent=extent, cmap="viridis")
ax.plot(porosities[best[1]], porosities[best[0]], "w*", markersize=12)
ax.set_xlabel("Positive electrode porosity")
ax.set_ylabel("Negative electrode porosity")
fig.colorbar(image, label="2C discharge capacity [A.h]")
plt.show()
print(
f"Best of {len(designs)} designs: {capacity[best]:.2f} A.h at porosities "
f"{porosities[best[0]]:.2f} (negative), {porosities[best[1]]:.2f} (positive)"
)