Dear PyBaMM team,
To simulate anomalies on pack level, we have been using liionpack with the PyBaMM ECM cell model due to its simplicity and interpretability.
While our simulations work well for cases such as varying internal resistances, we encounter crashes when simulating cells with different capacities. I have created an issue on the liionpack Github:
opened 12:11PM - 18 Mar 25 UTC
bug
### liionpack Version
0.4.1.dev2
### Python Version
3.11.11
### Describe the… bug
I would like to simulate a pack that consists of cells with different capacities.
I'm using the ECM Thévenin model.
As I understood from the provided examples, cell-specific parameters can be set via input parameters.
However, as soon as I define "Cell capacity [A.h]" as an input parameter, the simulation crashes.
Questions:
- Is this a known problem?
- Is there a known solution?
- What are your recommendations?
### Steps to Reproduce
---------------------------------------------------------------------
Variant 1: works for me (capacity defined as general parameter)
---------------------------------------------------------------------
```
import liionpack as lp
import pybamm
import numpy as np
import matplotlib.pyplot as plt
I_mag = 5.0
OCV_init = 4.0 # used for intial guess
Ri_init = 1e-6 # used for intial guess
R_busbar = 1e-6
R_connection = 1e-6
Np = 1
Ns = 4
Nbatt = Np * Ns
netlist = lp.setup_circuit(
Np=Np, Ns=Ns, Rb=R_busbar, Rc=R_connection, Ri=Ri_init, V=OCV_init, I=I_mag
)
def ecm_model(parameter_values = None):
# Create the pybamm model
model = pybamm.equivalent_circuit.Thevenin(options = {"number of rc elements":0, "calculate discharge energy":"true"})
# Add events to the model
model = lp.add_events_to_model(model)
# Set up parameter value
if parameter_values is None:
parameter_values = pybamm.ParameterValues("ECM_Example")
# Change parameter to be an input controlled by the external circuit
#parameter_values.update({"Cell capacity [A.h]": "[input]"})
# Set up solver and simulation
solver = pybamm.CasadiSolver(mode="safe")
sim = pybamm.Simulation(
model=model,
parameter_values=parameter_values,
solver=solver,
)
return sim
# Define parameters
parameter_values = pybamm.ParameterValues("ECM_Example")
inputs={
"Cell capacity [A.h]": (100*np.ones(Np * Ns)),
}
# Define experiment
I_pack = "100 A"
experiment = pybamm.Experiment(
[
f"Charge at {I_pack} for 30 minutes",
"Rest for 15 minutes",
F"Discharge at {I_pack} for 30 minutes",
"Rest for 15 minutes",
],
period= "10 seconds",
)
# Simulate pack
output = lp.solve(
netlist=netlist,
sim_func=ecm_model,
parameter_values=parameter_values,
experiment=experiment,
#inputs=inputs,
)
# Plot output
lp.plot_output(output)
```
Note: In liionpack.solvers.py, I had to make the following small modification to make the ECM within Liiionpack work:
Original:
self.variable_names = [
"Terminal voltage [V]",
"Surface open-circuit voltage [V]",
]
Modified:
self.variable_names = [
"Battery voltage [V]",
"Open-circuit voltage [V]",
]
---------------------------------------------------------------------
Variant 2: does not work for me (capacity defined as input parameter)
---------------------------------------------------------------------
```
import liionpack as lp
import pybamm
import numpy as np
import matplotlib.pyplot as plt
I_mag = 5.0
OCV_init = 4.0 # used for intial guess
Ri_init = 1e-6 # used for intial guess
R_busbar = 1e-6
R_connection = 1e-6
Np = 1
Ns = 4
Nbatt = Np * Ns
netlist = lp.setup_circuit(
Np=Np, Ns=Ns, Rb=R_busbar, Rc=R_connection, Ri=Ri_init, V=OCV_init, I=I_mag
)
def ecm_model(parameter_values = None):
# Create the pybamm model
model = pybamm.equivalent_circuit.Thevenin(options = {"number of rc elements":0, "calculate discharge energy":"true"})
# Add events to the model
model = lp.add_events_to_model(model)
# Set up parameter value
if parameter_values is None:
parameter_values = pybamm.ParameterValues("ECM_Example")
# Change parameter to be an input controlled by the external circuit
parameter_values.update({"Cell capacity [A.h]": "[input]"})
# Set up solver and simulation
solver = pybamm.CasadiSolver(mode="safe")
sim = pybamm.Simulation(
model=model,
parameter_values=parameter_values,
solver=solver,
)
return sim
# Define parameters
parameter_values = pybamm.ParameterValues("ECM_Example")
inputs={
"Cell capacity [A.h]": (100*np.ones(Np * Ns)),
}
# Define experiment
I_pack = "100 A"
experiment = pybamm.Experiment(
[
f"Charge at {I_pack} for 30 minutes",
"Rest for 15 minutes",
F"Discharge at {I_pack} for 30 minutes",
"Rest for 15 minutes",
],
period= "10 seconds",
)
# Simulate pack
output = lp.solve(
netlist=netlist,
sim_func=ecm_model,
parameter_values=parameter_values,
experiment=experiment,
inputs=inputs,
)
# Plot output
lp.plot_output(output)
```
### Expected behaviour
_No response_
### Relevant log output
```shell
```
### Additional context
_No response_
Since the liionpack package appears to be in maintenance mode, I’m unsure how frequently issues on GitHub are addressed. I got in touch with Tom Tranter who recommended to get in contact with you over this channel.
Is our issue known to you? Do you have any recommendations on how to approach this?
I would greatly appreciate any insights you can share.
Thank you so much and best regards,
Matthias