Hi,
I am currently using pybamm.Simulation.step()
to run a DFN model step-by-step with current as an input. Here’s my minimal working example:
import pybamm
options = {"thermal": "lumped"}
model = pybamm.lithium_ion.DFN(options=options)
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update({"Current function [A]": pybamm.InputParameter("Current [A]")})
parameter_values.set_initial_stoichiometries(0.03)
solver = pybamm.IDAKLUSolver()
sim = pybamm.Simulation(model, parameter_values=parameter_values, solver=solver)
sol = sim.step(dt=1, starting_solution=None, inputs={"Current [A]": -1})
Now my question is:
Can I modify this to use voltage instead of current as the input to sim.step()
?
If yes, how should I change the model and parameters?
Thanks!
derek
22 April 2025 21:35
2
From my understanding of trying something similar, No this is not possible currently. To discharge or charge with a Voltage input requires calling pybamm.experiment()
, which is not an accepted build method in the step solving function currently:
if self.operating_mode in ["without experiment", "drive cycle"]:
self.build()
means that trying to call experiment will result in a Nonetype error because the model is not built
Marc
23 April 2025 14:38
3
Hi @ErfanSamadi1998 , yes, you can do this by setting the operating mode to voltage and by adding a Voltage function [V]
input parameter. For example,
import pybamm
options = {"thermal": "lumped", "operating mode": "voltage"}
model = pybamm.lithium_ion.DFN(options=options)
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update({"Voltage function [V]": pybamm.InputParameter("Voltage [V]")}, check_already_exists=False)
parameter_values.set_initial_stoichiometries(0.03)
solver = pybamm.IDAKLUSolver()
sim = pybamm.Simulation(model, parameter_values=parameter_values, solver=solver)
sol = sim.step(dt=1, starting_solution=None, inputs={"Voltage [V]": 3.5})
sol = sim.step(dt=1, starting_solution=sol, inputs={"Voltage [V]": 3.4})
sol.plot()
Thank you so much for your help, @Marc , Really appreciate it.