PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Pass array of times to `step`

Open rtimms opened this issue 2 years ago • 8 comments

When you call solver.step you pass in dt, the time time increment you want to step forward in. You can also pass npts to get the solution back at a linearly spaced array of times between the initial time, t0, and t0+dt. It would be good to instead be able to pass an array of times, t_eval, like you pass to solve, so you can get step solutions returned at non-linearly spaced times.

The motivation for this is that right now you can't pass a starting_solution to Simualtion.solve if you aren't using an experiment, so if you want to chain solutions together you have to call Simulation.step instead.

An alternative is that we allow starting solutions without experiments in Simulation.solve.

The whole logic for step and solve is pretty clunky both in Simulation and BaseSolver, but that's a separate issue...

rtimms avatar Nov 15 '23 10:11 rtimms

Hey I would like to work on this.

prady0t avatar Nov 22 '23 21:11 prady0t

Can you please give examples of how to use step() function to get solutions which I can use for debugging? I'm quite new here and I cant find it in project doc.

prady0t avatar Nov 25 '23 09:11 prady0t

Sorry for the slow reply. Take a look here.

rtimms avatar Dec 07 '23 14:12 rtimms

Thanks 😄

prady0t avatar Dec 07 '23 16:12 prady0t

Maybe if we change step function to something like:

    def step(
        self,
        old_solution,
        model,
        dt=0,
        non_linear_time=None,
        npts=2,
        inputs=None,
        save=True,
    )

Here non_linear_time is an array of time (example: [0,10,15,17,20]). We can assign dt = non_linear_time[i] - non_linear_time[i-1] inside a loop and make changes to the function accordingly. Is this a correct solution?

prady0t avatar Dec 16 '23 08:12 prady0t

Here non_linear_time is an array of time (example: [0,10,15,17,20]).

Hi @prady0t, theoretically it looks promising, though it would be nicer to open a PR to keep things moving & also would be easier for us to suggest changes there 🙂

arjxn-py avatar Dec 16 '23 15:12 arjxn-py

Sure will do!

prady0t avatar Dec 16 '23 15:12 prady0t

Here non_linear_time is an array of time (example: [0,10,15,17,20]).

Hi @prady0t, theoretically it looks promising, though it would be nicer to open a PR to keep things moving & also would be easier for us to suggest changes there 🙂

Made a PR. Please have a look.

prady0t avatar Dec 17 '23 07:12 prady0t