Initial temperature input does not work

Hi, I have seen this entry on GitHub where PyBamm is used to solve the electrical problem, while the thermal problem is handled in Simulink (GitHub - FaradayInstitution/pybamm_simulink_example: An example of how to run pybamm in simulink)

I am having a problem in understanding how PyBamm should be setup for this. I want to solve the electrical problem in PyBamm at a given “isothermal” condition, the heat generated in a solution step will then be handled by a external thermal model, that will then loop back the temperature as an input for the next step in PyBamm.

I have tried a minimal example. Where I setup two “Initial temperature [K]” values using the ORegan2022 parameter set (which includes temperature dependencies on transport). But there is no differences in the voltage response. Am I doing something wrong?

import pybamm
import matplotlib.pyplot as plt

model = pybamm.lithium_ion.DFN()
parameters = pybamm.ParameterValues(“ORegan2022”)

parameters[“Initial temperature [K]”] = “[input]”

solver = pybamm.IDAKLUSolver()

sim = pybamm.Simulation(model=model, solver=solver, parameter_values=parameters)

solamb = sim.solve([0, 2000], inputs={“Initial temperature [K]”: 298.0})
solamb1 = sim.solve([0, 2000], inputs={“Initial temperature [K]”: 215.0})

time = solamb[“Time [s]”].entries
time1 = solamb1[“Time [s]”].entries
voltage = solamb[‘Voltage [V]’]
voltage1 = solamb1[‘Voltage [V]’]

y_model = voltage(time)
y_model1 = voltage1(time1)

fig = plt.figure()
plt.plot(time, y_model, label=“pSOC”)
plt.plot(time1, y_model1, label=“pSOC”)
plt.show()

Hi Oarcelus,

You can do it this way:

import pybamm

import matplotlib.pyplot as plt

# Model and parameters

model = pybamm.lithium_ion.DFN()

parameter_values= pybamm.ParameterValues(“ORegan2022”)

parameter_values[“Initial temperature [K]”] = pybamm.InputParameter(“Temperature [K]”)

parameter_values[“Ambient temperature [K]”] = pybamm.InputParameter(“Temperature [K]”)

import pybamm

import matplotlib.pyplot as plt

sim = pybamm.Simulation(model, parameter_values=parameter_values)

plt.figure()

for T0 in [280, 298, 320]:
soln = sim.solve(
[0, 3600], inputs={“Temperature [K]”: T0}
)

plt.plot(

    soln\["Time \[s\]"\].entries,

    soln\["Voltage \[V\]"\].entries,

    label=f"{T0} K"

)

plt.xlabel(“Time [s]”)

plt.ylabel(“Terminal voltage [V]”)

plt.legend()

plt.show()

Here, T0 can also come from an external function if needed.
Note that both the ambient and initial temperatures must be overridden, otherwise the isothermal model will not show any temperature effect — the ambient temperature is what effectively controls the isothermal behaviour.

Regards,

Sunil

1 Like