Passing along data from one time step to the next using DifferentialEquations.jl

I am using DifferentialEquations.jl to solve an ODE of the form \frac{d\boldsymbol{M}}{dt} = \boldsymbol{f}(\boldsymbol{M}), where \boldsymbol{M} = [M_1, ..., M_k]^T, and \boldsymbol{f} = [f_1(\boldsymbol{M}), ..., f_k(\boldsymbol{M})]^T
Without going into the weeds of how exactly the right-hand side, \boldsymbol{f}(\boldsymbol{M}), is computed, let me just say that it involves solving a nonlinear system of equations. At each time step t, that system of equations uses the current state of the solution \boldsymbol{M} to determine a vector of unknowns \boldsymbol{x}, which in turn is needed to compute \boldsymbol{f}(\boldsymbol{M}).

To solve that system of equations it would be very useful to have access to the unknowns \boldsymbol{x} that were computed in the previous time step - they would be a good initial guess for solving the system of equations at the current time step.

Is there a way to achieve what I want, i.e., to pass \boldsymbol{x} to the next time step for use in the evaluation of \boldsymbol{f}?

If your problem is like Mu’=f(u), then you might want to use a mass matrix instead since that doesn’t require an extra nonlinear solve. Otherwise, you can use the parameters to hold a cache of the values, and then use those the values from in the parameters as the guess.

1 Like

Thanks for your reply, @ChrisRackauckas!
Using the parameters to hold a cache of the value of \boldsymbol{x} and then access it in the next time step sounds like it would solve my problem. Can you elaborate a little on how to implement that?

This tutorial has an example of a compute cache. It always rewrites first though: passing to the next timestep is done by just using the value before writing.

https://tutorials.sciml.ai/html/introduction/03-optimizing_diffeq_code.html

Thank you very much, I will work through that example and report on whether I was able to solve my problem using that approach.

That sounds like it might be some kind of continuation method? If so there are specialized packages for that, like