Skip to content

Commit 2291c25

Browse files
authored
Merge pull request #1616 from ValentinKaisermayer/dae-observed
adds observedfun for DAEFunction
2 parents dab34ed + c3b6871 commit 2291c25

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ function DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
509509
_jac = nothing
510510
end
511511

512+
obs = observed(sys)
513+
observedfun = let sys = sys, dict = Dict()
514+
function generated_observed(obsvar, u, p, t)
515+
obs = get!(dict, value(obsvar)) do
516+
build_explicit_observed_function(sys, obsvar; checkbounds = checkbounds)
517+
end
518+
obs(u, p, t)
519+
end
520+
end
521+
512522
jac_prototype = if sparse
513523
uElType = u0 === nothing ? Float64 : eltype(u0)
514524
if jac
@@ -526,11 +536,10 @@ function DiffEqBase.DAEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
526536
DAEFunction{iip}(f,
527537
jac = _jac === nothing ? nothing : _jac,
528538
syms = Symbol.(dvs),
529-
jac_prototype = jac_prototype
539+
jac_prototype = jac_prototype,
530540
# missing fields in `DAEFunction`
531541
#indepsym = Symbol(get_iv(sys)),
532-
#observed = observedfun,
533-
)
542+
observed = observedfun)
534543
end
535544

536545
"""

test/odesystem.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ let
605605
@test prob.du0 du0
606606
@test prob.p [1]
607607
sol = solve(prob, IDA())
608+
@test sol[y] 0.9 * sol[x[1]] + sol[x[2]]
608609
@test isapprox(sol[x[1]][end], 1, atol = 1e-3)
609610

610611
prob = DAEProblem(sys, [D(y) => 0, D(x[1]) => 0, D(x[2]) => 0], Pair[x[1] => 0.5],

0 commit comments

Comments
 (0)