Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ end
end
integrator.u_modified = true
callback.affect!(integrator)
if integrator.sol.prob isa DAEProblem || !(integrator.f.mass_matrix isa UniformScaling)
DiffEqBase.initialize_dae!(integrator)
end
@inbounds if callback.save_positions[2]
savevalues!(integrator, true)
saved_in_cb = true
Expand Down
10 changes: 10 additions & 0 deletions test/downstream/community_callback_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,13 @@ u0 = [0.0, 0.0, 1.0]
prob = ODEProblem(f!, u0, (0.0, 10.0); callback = cb)
soln = solve(prob, Tsit5())
@test soln.t[end] ≈ 4.712347213360699

odefun = ODEFunction((u, p, t) -> [u[2], u[2] - p]; mass_matrix = [1 0; 0 0])
prob = ODEProblem(odefun, [0.0, -1.0], (0., 1), 1, callback=PresetTimeCallback(.5, integ->(integ.p=-integ.p;)))
#test that reinit happens for both FSAL and non FSAL integrators
@testset "dae re-init" for alg in [FBDF(), Rodas5P()]
sol = solve(prob, alg)
Comment on lines +224 to +226
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a DAEProblem case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dae test added. That said, for extra fun, IDA fails to solve this because it does callbacks separately and wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, your code here is bad.

# test that the callback flipping p caused u[2] to get flipped.
first_t = findfirst(isequal(0.5), sol.t)
@test sol.u[first_t][2] == -sol.u[first_t+1][2]
end