02 Using Inputs¶
This notebook demonstrates how to change a parameter value across the battery pack by using inputs
In [1]:
Copied!
try:
import liionpack as lp
except:
!pip install -q git+https://github.com/pybamm-team/liionpack.git@main
import liionpack as lp
import pybamm
import numpy as np
try:
import liionpack as lp
except:
!pip install -q git+https://github.com/pybamm-team/liionpack.git@main
import liionpack as lp
import pybamm
import numpy as np
In [2]:
Copied!
I_mag = 5.0
OCV_init = 4.0 # used for intial guess
Ri_init = 5e-2 # used for intial guess
R_busbar = 1.5e-6 # very small to simulate evenly distributed currents
R_connection = 1e-2
Np = 4
Ns = 1
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
)
I_mag = 5.0
OCV_init = 4.0 # used for intial guess
Ri_init = 5e-2 # used for intial guess
R_busbar = 1.5e-6 # very small to simulate evenly distributed currents
R_connection = 1e-2
Np = 4
Ns = 1
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
)
In [3]:
Copied!
experiment = pybamm.Experiment(
["Discharge at 5 A for 30 minutes", "Rest for 15 minutes"],
period="10 seconds",
)
experiment = pybamm.Experiment(
["Discharge at 5 A for 30 minutes", "Rest for 15 minutes"],
period="10 seconds",
)
In [4]:
Copied!
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values = pybamm.ParameterValues("Chen2020")
Everything up to now has been standard but if we want to change a parameter we need to update the parameter_values dictionary. Let's use porosity as an example:
In [5]:
Copied!
parameter_values.search("porosity")
parameter_values.search("porosity")
Negative electrode porosity 0.25 Positive electrode porosity 0.335 Separator porosity 0.47
Change the parameter in the same way as you would with PyBaMM
In [6]:
Copied!
parameter_values.update({"Positive electrode porosity": "[input]"})
parameter_values.update({"Positive electrode porosity": "[input]"})
In [7]:
Copied!
parameter_values["Positive electrode porosity"]
parameter_values["Positive electrode porosity"]
Out[7]:
InputParameter(-0x544c29f591fa6a7d, Positive electrode porosity, children=[], domains={})
With very small busbar resistance all the cells should experience very similar currents and with the same input the solutions should all look very similar too.
Define the input as a dictionary to pass to the solver with a value that is an array with the an element for each battery
In [8]:
Copied!
inputs = {"Positive electrode porosity": np.ones(4) * 0.335}
inputs = {"Positive electrode porosity": np.ones(4) * 0.335}
In [9]:
Copied!
output = lp.solve(
netlist=netlist,
parameter_values=parameter_values,
experiment=experiment,
inputs=inputs,
)
lp.plot_output(output)
output = lp.solve(
netlist=netlist,
parameter_values=parameter_values,
experiment=experiment,
inputs=inputs,
)
lp.plot_output(output)
Stepping simulation: 100%|███████████████████████████████████████████████████████████| 271/271 [00:03<00:00, 82.13it/s]
Now if we change the input let's see what happens
In [10]:
Copied!
inputs = {"Positive electrode porosity": np.linspace(0.5, 1.5, 4) * 0.335}
inputs = {"Positive electrode porosity": np.linspace(0.5, 1.5, 4) * 0.335}
In [11]:
Copied!
output = lp.solve(
netlist=netlist,
parameter_values=parameter_values,
experiment=experiment,
inputs=inputs,
)
lp.plot_output(output)
output = lp.solve(
netlist=netlist,
parameter_values=parameter_values,
experiment=experiment,
inputs=inputs,
)
lp.plot_output(output)
Stepping simulation: 100%|███████████████████████████████████████████████████████████| 271/271 [00:03<00:00, 79.93it/s]
In [ ]:
Copied!