Skip to content

Commit 4724540

Browse files
test: test Issue#3342
1 parent c73b0a2 commit 4724540

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/initializationsystem.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,3 +1331,26 @@ end
13311331
@test integ[x] 0.5
13321332
@test integ[y][0.5, sqrt(3.5)] atol=1e-6
13331333
end
1334+
1335+
@testset "Issue#3342" begin
1336+
@variables x(t) y(t)
1337+
stop!(integrator, _, _, _) = terminate!(integrator)
1338+
@named sys = ODESystem([D(x) ~ 1.0
1339+
D(y) ~ 1.0], t; initialization_eqs = [
1340+
y ~ 0.0
1341+
],
1342+
continuous_events = [
1343+
[y ~ 0.5] => (stop!, [y], [], [], nothing)
1344+
])
1345+
sys = structural_simplify(sys)
1346+
prob0 = ODEProblem(sys, [x => NaN], (0.0, 1.0), [])
1347+
1348+
# final_x(x0) is equivalent to x0 + 0.5
1349+
function final_x(x0)
1350+
prob = remake(prob0; u0 = [x => x0])
1351+
sol = solve(prob)
1352+
return sol[x][end]
1353+
end
1354+
@test final_x(0.3) 0.8 # should be 0.8
1355+
@test ForwardDiff.derivative(final_x, 0.3) 1.0
1356+
end

0 commit comments

Comments
 (0)