Repository navigation
PyBaMM integration in co-simulation #5219
Replies: 1 comment
|
Use
The " Your second loop makes a new import pybamm
model = pybamm.lithium_ion.DFN(options={"thermal": "lumped"})
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values["Ambient temperature [K]"] = "[input]"
sim = pybamm.Simulation(model, parameter_values=parameter_values)
dt = 1.0
t = 0.0
while t < total_time:
env_temp = receive_external_temperature()
sol = sim.step(dt, inputs={"Ambient temperature [K]": env_temp}, save=False)
publish(sol["Volume-averaged cell temperature [K]"].entries[-1])
t += dtSome notes:
I checked this in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone, I would like to run a simple pybamm DFN model coupled with an external simulator.
I am thinking about different solutions (with '.solve()' and with '.step()' methods) :
CASE .solve():
model = pybamm.lithium_ion.DFN()
parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values["Ambient temperature [K]"] = "[input]"
sim = pybamm.Simulation(model, parameter_values=parameter_values)
values to manage the number of simulation cycles I need
total_time = 10
start_time=0
stop_time=1
while stop_time < total_time:
receive External Temperature
solution = sim.solve(t_eval=[stop_time - start_time], inputs={"Ambient temperature [K]" : env_temp})
publish solution["Cell temperature [K]"].entries[-1]
start_time = stop_time
stop_time = stop_time + 1
CASE .step()
model = pybamm.lithium_ion.DFN()
parameter_values = pybamm.ParameterValues("Chen2020")
sim = pybamm.Simulation(model, parameter_values=parameter_values)
values to manage the number of simulation cycles I need
total_time = 10
start_time=0
stop_time=1
while stop_time < total_time:
receive External Temperature
parameter_values["Ambient temperature [K]"] = env_temp
sim = pybamm.Simulation(model, parameter_values=parameter_values)
solution = sim.step(dt=1)
publish solution["Cell temperature [K]"].entries[-1]
start_time = stop_time
stop_time = stop_time + 1
So basically I want to run for a simulation cycle, update a parameter of the model, and restart to run a new cycle.
The solve() function accepts 'inputs' as an argument, but solving for t_eval[0,1], t_eval[1,2] etc. actually solves that time window or they are just 'logical' values? Does the method have any memory of what has been computed during the last cycle?
I saw there's the possibility to use the 'starting_solution' argument with the .step() function, but it is valid if in an experiment only, since I am in a co-simulation I do not know the operating conditions at time t of the battery, which depend on the state of coupled simulators.
Does the step() method retain memory about the last cycle? Can I restart from where I left?
Looking at the source code I saw that the step() method solves starting from self._solution . In case the step() method does not have memory, can I set the simulation object ._solution to be the last solution computed and call the step() method again?
Any clarification or suggestion will be appreciated.
Thanks.
All reactions