we are currently writing a simulation engine which is a massive ODE with >>100k elements and therefore need to be very memory conscious.
We need to pre-allocate the u and du vectors and have DifferentialEquations.jl use them in-place. Currently there seems to be no way to supply u and du, only u0, which is not used internally.
This is how we would like to use it:
du = 10.0(u-u)
du = u*(28.0-u) - u
du = u*u - (8/3)*u
u = [1.0;0.0;0.0]
du = [0.0; 0.0; 0.0]
tspan = (0.0,100.0)
# ODEProblem doesnt accept u and du, only u0
prob = ODEProblem(lorenz!,u, du, tspan)
integrator = init(prob,Tsit5())
Is there a way to make this work?
That allocates all of the necessary vectors. Then
step!(integrator) is non-allocating.
How else would you know what vectors to allocate? Different methods need different vectors of different things, so that’s the general form to figure out what needs to be cached for a method.
I am not sure whether that’s the problem but Tsit5 will probably need to allocate a lot more memory than just u and du since it is a higher Order method right?
So it might be that you have to resort to lower order methods like BS3 or perhaps even Euler?
There are also multistep methods such as VCABM although I don’t know how much they need to allocate maybe someone more knowledgeable will be able to estimate this
Thanks for the quick answer!
I know internally that the lorenz! function needs du and u to be a vector with three elements - those are the elements I use, regardless of the method use.
There should be a way for me to allocate those vectors?
But how many vectors? For Tsit5 you need 7, for Ven7 you need over 20.
init is how you can allocate the cache you find in
yes, I see that. I could still save some allocations when pre-allocating du and u.
Maybe I just don’t fully understand what you are doing there.
we could avoid the allocation of u0.
alias_u0: allows the solver to alias the initial condition array that is contained in the problem struct. Defaults to false.