Skip to content

VectorOfArray with adaptive time steps in OrdinaryDiffEq  #243

Description

@aluque

Perhaps I am doing something wrong but combining VectorOfArray with adaptive stepsize control in OrdinarryDiffEq doesn't seem to work:

using OrdinaryDiffEq
using RecursiveArrayTools

u0 = VectorOfArray([ones(4, 4) for _ in 1:4])

# With this, error control works and the time steps are shorter:
# u0 = ones(4, 4, 4)

function dudt!(du, u, p, t)
    @. du = -u
end

tspan = (0.0, 100.0)
prob = ODEProblem(dudt!, u0, tspan)
integrator = init(prob, Midpoint(), dtmax=10.0)

for i in 1:10
    step!(integrator)
    @info "" integrator.EEst integrator.dt (integrator.cache.fsalfirst[1] === integrator.cache.k[1])
end            

println("Final time t = $(integrator.t)")
println("Solution u = $(integrator.sol.u[end][1, 1, 1])")
println("Exact u = $(exp(-integrator.t))")

This chooses the maximum allowed dt=10.0 and produces an inaccurate integration. To me its seems related to the use of recursivecopy! in apply_step! of OrdinaryDiffEq. It copies references to the underlying arrays instead of contents.
After that the error estimates are zero.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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