Skip to content

Commit 5d341ab

Browse files
feat: allow interpolating discretes past the final time point
1 parent 4fd028f commit 5d341ab

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/solutions/ode_solutions.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ function (sol::AbstractODESolution)(t::Number, ::Type{deriv}, idxs,
287287
ps = parameter_values(discs)
288288
for ts_idx in eachindex(discs)
289289
partition = discs[ts_idx]
290-
interp_val = ConstantInterpolation(partition.t, partition.u)(
291-
t, nothing, deriv, nothing, continuity)
290+
interp_val = _hold_discrete(partition.u, partition.t, t)
292291
ps = with_updated_parameter_timeseries_values(sol, ps, ts_idx => interp_val)
293292
end
294293
end
@@ -312,8 +311,7 @@ function (sol::AbstractODESolution)(t::Number, ::Type{deriv}, idxs::AbstractVect
312311
ps = parameter_values(discs)
313312
for ts_idx in eachindex(discs)
314313
partition = discs[ts_idx]
315-
interp_val = ConstantInterpolation(partition.t, partition.u)(
316-
t, nothing, deriv, nothing, continuity)
314+
interp_val = _hold_discrete(partition.u, partition.t, t)
317315
ps = with_updated_parameter_timeseries_values(sol, ps, ts_idx => interp_val)
318316
end
319317
end

test/downstream/solution_interface.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,12 @@ end
341341
@test _ss isa SciMLBase.SavedSubsystem
342342
end
343343
end
344+
345+
@testset "Interpolation after final discrete save" begin
346+
@variables x(t) y(t)
347+
@parameters start
348+
@mtkbuild sys=ODESystem([D(x) ~ y, y ~ ifelse(t < start, 1.0, 2.0)], t) additional_passes=[ModelingToolkit.IfLifting]
349+
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0), [start => 0.5])
350+
sol = solve(prob)
351+
@test sol(0.6, idxs = y) 2.0
352+
end

0 commit comments

Comments
 (0)