Skip to content

PyBamm in co-simulation #5221

@Matia-Torlini

Description

@Matia-Torlini

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions