Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small delay with step errors #544

Open
albheim opened this issue Jun 29, 2021 · 0 comments
Open

Small delay with step errors #544

albheim opened this issue Jun 29, 2021 · 0 comments

Comments

@albheim
Copy link
Member

albheim commented Jun 29, 2021

Was notified that running step on a system with a small delay creates some problem with dt <= dtmin from DifferentialEquations.jl which generates a warning and it seems like it does not create the saved values which errors when we try to index into them.

julia> step(delay(0.01))
t = 0.0:0.07:14.000000000000002
┌ Warning: dt <= dtmin. Aborting. There is either an error in your model specification or the true solution is unstable.
└ @ SciMLBase ~/.julia/packages/SciMLBase/EFFG1/src/integrator_interface.jl:345
ERROR: BoundsError: attempt to access 4-element Vector{Tuple{Vector{Float64}, Vector{Float64}}} at index [5]
Stacktrace:
 [1] getindex
   @ ./array.jl:801 [inlined]
 [2] _lsim(sys::DelayLtiSystem{Float64, Float64}, u!::Any, t::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, x0::Vector{Float64}, alg::DelayDiffEq.MethodOfSteps{OrdinaryDiffEq.Tsit5, DiffEqBase.NLFunctional{Rational{Int64}, Rational{Int64}}, false}; kwargs::Base.Iterators.Pairs{Symbol, Float64, Tuple{Symbol, Symbol}, NamedTuple{(:abstol, :reltol), Tuple{Float64, Float64}}})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/delay_systems.jl:204
 [3] lsim(sys::DelayLtiSystem{Float64, Float64}, u::ControlSystems.var"#299#300", t::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}; x0::Vector{Float64}, alg::DelayDiffEq.MethodOfSteps{OrdinaryDiffEq.Tsit5, DiffEqBase.NLFunctional{Rational{Int64}, Rational{Int64}}, false}, abstol::Float64, reltol::Float64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/delay_systems.jl:99
 [4] step(sys::DelayLtiSystem{Float64, Float64}, t::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/delay_systems.jl:246
 [5] step
   @ ~/.julia/dev/ControlSystems/src/delay_systems.jl:238 [inlined]
 [6] #step#164
   @ ~/.julia/dev/ControlSystems/src/timeresp.jl:33 [inlined]
 [7] step(sys::DelayLtiSystem{Float64, Float64})
   @ ControlSystems ~/.julia/dev/ControlSystems/src/timeresp.jl:33
 [8] top-level scope
   @ REPL[21]:1

Here is a stripped down version of the code causing this problem, not sure if this is something that should be reported to DifferentialEquations or if we should work around it on our side.

using DelayDiffEq, DifferentialEquations
using ControlSystems
using LinearAlgebra

function f(du, u, h, p, t)
    tau = p
    # This is system for delay(tau) using two states based on our partitioned state space
    # y(t) = d(t-tau)
    # d(t) = u(t)
    hout = h(p, t-tau, Val{1}, idxs=2)
    du .+= [hout; 1]
end

t = 0:0.01:10
x0 = [0.0, 0.0]
p = 0.01

h!(p, t, deriv::Type{Val{1}}; idxs=0) = 0

prob = DDEProblem{true}(f, x0, h!,
            (t[1], t[end]),
            p,
            constant_lags=p,# Not sure if sort needed
            neutral=true,           # We have derivatives on RHS (d(t)) 
            )

sol = solve(prob, Tsit5(); tstops=t, saveat=t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant