926926@testset " DDEs" begin
927927 function oscillator (; name, k = 1.0 , τ = 0.01 )
928928 @parameters k= k τ= τ
929- @variables x (.. )= 0.1 y (t)= 0.1 jcn (t)= 0.0 delx (t)
929+ @variables x (.. )= 0.1 + t y (t)= 0.1 + t jcn (t)= 0.0 + t delx (t)
930930 eqs = [D (x (t)) ~ y,
931931 D (y) ~ - k * x (t - τ) + jcn,
932932 delx ~ x (t - τ)]
@@ -942,32 +942,13 @@ end
942942 @named coupledOsc = compose (coupledOsc, systems)
943943 sys = structural_simplify (coupledOsc)
944944 prob = DDEProblem (sys, [], (0.0 , 10.0 ); constant_lags = [sys. osc1. τ, sys. osc2. τ])
945- # TODO : Remove this hack once MTK can generate appropriate observed functions
946- fn = prob. f
947- function fake_observed (_)
948- return function obsfn (u, h, p, t)
949- return u + h (p, t - 0.1 )
950- end
951- end
952-
953- struct NonMarkovianWrapper{S}
954- sys:: S
955- end
956- SymbolicIndexingInterface. symbolic_container (x:: NonMarkovianWrapper ) = x. sys
957- SymbolicIndexingInterface. is_markovian (:: NonMarkovianWrapper ) = false
958- fn = DDEFunction (fn. f; observed = fake_observed, sys = NonMarkovianWrapper (fn. sys))
959- function fake_hist (p, t)
960- return ones (length (prob. u0)) .* t
961- end
962- prob = DDEProblem (
963- fn, prob. u0, fake_hist, prob. tspan, prob. p; constant_lags = prob. constant_lags)
964945 sym = sys. osc1. delx
965- @test prob[sym] ≈ prob. u0 .+ (prob. tspan[1 ] - 0.1 )
946+ delay = sys. osc1. τ
947+ original = sys. osc1. x
948+ @test prob[sym] ≈ prob[original] .+ (prob. tspan[1 ] - prob. ps[delay])
966949 integ = init (prob, MethodOfSteps (Tsit5 ()))
967950 step! (integ, 10.0 , true )
968- # DelayDiffEq wraps `integ.f` and that doesn't contain `.observed`
969- # so the hack above doesn't work. `@reset` also doesn't work.
970- @test_broken integ[sym] ≈ integ. u + SciMLBase. get_sol (integ)(9.9 )
951+ @test integ[sym] ≈ SciMLBase. get_sol (integ)(integ. t - integ. ps[delay]; idxs = original)
971952 sol = solve (prob, MethodOfSteps (Tsit5 ()))
972- @test sol[sym] ≈ sol. u .+ sol (sol. t .- 0.1 ) . u
953+ @test sol[sym] ≈ sol (sol. t .- sol . ps[delay]; idxs = original)
973954end
0 commit comments