Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type instability when iterating over callbacks in simple integrators #1684

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/callbacks_step/save_solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@ end
get_element_variables!(element_variables, u_ode, semi)
callbacks = integrator.opts.callback
if callbacks isa CallbackSet
for cb in callbacks.continuous_callbacks
foreach(callbacks.continuous_callbacks) do cb
get_element_variables!(element_variables, u_ode, semi, cb;
t = integrator.t, iter = iter)
end
for cb in callbacks.discrete_callbacks
foreach(callbacks.discrete_callbacks) do cb
get_element_variables!(element_variables, u_ode, semi, cb;
t = integrator.t, iter = iter)
end
Expand Down
7 changes: 4 additions & 3 deletions src/callbacks_step/summary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,17 @@ function initialize_summary_callback(cb::DiscreteCallback, u, t, integrator;

callbacks = integrator.opts.callback
if callbacks isa CallbackSet
for cb in callbacks.continuous_callbacks
foreach(callbacks.continuous_callbacks) do cb
show(io_context, MIME"text/plain"(), cb)
println(io, "\n")
end
for cb in callbacks.discrete_callbacks
foreach(callbacks.discrete_callbacks) do cb
# Do not show ourselves
cb.affect! === summary_callback && continue
cb.affect! === summary_callback && return nothing

show(io_context, MIME"text/plain"(), cb)
println(io, "\n")
return nothing
end
else
show(io_context, MIME"text/plain"(), callbacks)
Expand Down
7 changes: 4 additions & 3 deletions src/time_integration/methods_2N.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ function solve(ode::ODEProblem, alg::T;

# initialize callbacks
if callback isa CallbackSet
for cb in callback.continuous_callbacks
foreach(callback.continuous_callbacks) do cb
error("unsupported")
end
for cb in callback.discrete_callbacks
foreach(callback.discrete_callbacks) do cb
cb.initialize(cb, integrator.u, integrator.t, integrator)
end
elseif !isnothing(callback)
Expand Down Expand Up @@ -172,10 +172,11 @@ function solve!(integrator::SimpleIntegrator2N)

# handle callbacks
if callbacks isa CallbackSet
for cb in callbacks.discrete_callbacks
foreach(callbacks.discrete_callbacks) do cb
if cb.condition(integrator.u, integrator.t, integrator)
cb.affect!(integrator)
end
return nothing
end
end

Expand Down
7 changes: 4 additions & 3 deletions src/time_integration/methods_3Sstar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ function solve(ode::ODEProblem, alg::T;

# initialize callbacks
if callback isa CallbackSet
for cb in callback.continuous_callbacks
foreach(callback.continuous_callbacks) do cb
error("unsupported")
end
for cb in callback.discrete_callbacks
foreach(callback.discrete_callbacks) do cb
cb.initialize(cb, integrator.u, integrator.t, integrator)
end
elseif !isnothing(callback)
Expand Down Expand Up @@ -248,10 +248,11 @@ function solve!(integrator::SimpleIntegrator3Sstar)

# handle callbacks
if callbacks isa CallbackSet
for cb in callbacks.discrete_callbacks
foreach(callbacks.discrete_callbacks) do cb
if cb.condition(integrator.u, integrator.t, integrator)
cb.affect!(integrator)
end
return nothing
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/time_integration/methods_SSP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ function solve(ode::ODEProblem, alg = SimpleSSPRK33()::SimpleAlgorithmSSP;

# initialize callbacks
if callback isa CallbackSet
for cb in callback.continuous_callbacks
foreach(callback.continuous_callbacks) do cb
error("unsupported")
end
for cb in callback.discrete_callbacks
foreach(callback.discrete_callbacks) do cb
cb.initialize(cb, integrator.u, integrator.t, integrator)
end
elseif !isnothing(callback)
Expand Down Expand Up @@ -184,7 +184,7 @@ function solve!(integrator::SimpleIntegratorSSP)

# handle callbacks
if callbacks isa CallbackSet
for cb in callbacks.discrete_callbacks
foreach(callbacks.discrete_callbacks) do cb
if cb.condition(integrator.u, integrator.t, integrator)
cb.affect!(integrator)
end
Expand Down
Loading