From fe0328d3004c34016a3ac529a2e8203b6a6138e7 Mon Sep 17 00:00:00 2001 From: singhharsh1708 Date: Tue, 27 Oct 2026 06:11:33 +0530 Subject: [PATCH] Store FIRK stages for dense output with extrapolant = :constant --- lib/OrdinaryDiffEqFIRK/Project.toml | 2 +- .../src/firk_perform_step.jl | 76 +++++++------------ lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl | 12 +++ 3 files changed, 41 insertions(+), 49 deletions(-) diff --git a/lib/OrdinaryDiffEqFIRK/Project.toml b/lib/OrdinaryDiffEqFIRK/Project.toml index 01e0399e546..dd5beeb6ad5 100644 --- a/lib/OrdinaryDiffEqFIRK/Project.toml +++ b/lib/OrdinaryDiffEqFIRK/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqFIRK" uuid = "5960d6e9-dd7a-4743-88e7-cf307b64f125" authors = ["ParamThakkar123 "] -version = "2.8.9" +version = "2.8.10" [deps] FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898" diff --git a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl index 3ccc3865f5a..c50237e9aa9 100644 --- a/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl +++ b/lib/OrdinaryDiffEqFIRK/src/firk_perform_step.jl @@ -419,10 +419,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] = z1 - integrator.k[4] = z2 - end + integrator.k[3] = z1 + integrator.k[4] = z2 end integrator.fsallast = f(u, p, t + dt) @@ -589,10 +587,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] .= z1 - integrator.k[4] .= z2 - end + integrator.k[3] .= z1 + integrator.k[4] .= z2 end f(fsallast, u, p, t + dt) @@ -787,11 +783,9 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] = z1 - integrator.k[4] = z2 - integrator.k[5] = z3 - end + integrator.k[3] = z1 + integrator.k[4] = z2 + integrator.k[5] = z3 end integrator.fsallast = f(u, p, t + dt) @@ -1055,11 +1049,9 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] .= z1 - integrator.k[4] .= z2 - integrator.k[5] .= z3 - end + integrator.k[3] .= z1 + integrator.k[4] .= z2 + integrator.k[5] .= z3 end f(fsallast, u, p, t + dt) @@ -1346,13 +1338,11 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] = z1 - integrator.k[4] = z2 - integrator.k[5] = z3 - integrator.k[6] = z4 - integrator.k[7] = z5 - end + integrator.k[3] = z1 + integrator.k[4] = z2 + integrator.k[5] = z3 + integrator.k[6] = z4 + integrator.k[7] = z5 end integrator.fsallast = f(u, p, t + dt) @@ -1739,13 +1729,11 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - integrator.k[3] .= z1 - integrator.k[4] .= z2 - integrator.k[5] .= z3 - integrator.k[6] .= z4 - integrator.k[7] .= z5 - end + integrator.k[3] .= z1 + integrator.k[4] .= z2 + integrator.k[5] .= z3 + integrator.k[6] .= z4 + integrator.k[7] .= z5 end f(fsallast, u, p, t + dt) @@ -1998,10 +1986,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - for i in 1:num_stages - integrator.k[i + 2] = @.. z[i] - end + for i in 1:num_stages + integrator.k[i + 2] = @.. z[i] end end @@ -2340,10 +2326,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - for i in 1:num_stages - integrator.k[i + 2] .= z[i] - end + for i in 1:num_stages + integrator.k[i + 2] .= z[i] end end @@ -2584,10 +2568,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - for i in 1:num_stages - integrator.k[i + 2] = z[i] - end + for i in 1:num_stages + integrator.k[i + 2] = z[i] end end @@ -2772,10 +2754,8 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - for i in 1:num_stages - integrator.k[i + 2] .= z[i] - end + for i in 1:num_stages + integrator.k[i + 2] .= z[i] end end diff --git a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl index 0c186fc70bf..da8d47364ba 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl @@ -339,3 +339,15 @@ end ) @test @inferred(OrdinaryDiffEqCore.get_current_adaptive_order(integ.alg.algs[2], integ.cache)) isa Int end + +@testset "Dense output with extrapolant = :constant" begin + f!(du, u, p, t) = (du .= cos(t) .* u; nothing) + f(u, p, t) = cos(t) .* u + exact(t) = exp(sin(t)) .* [1.0, 2.0] + for prob in (ODEProblem(f!, [1.0, 2.0], (0.0, 4.0)), ODEProblem(f, [1.0, 2.0], (0.0, 4.0))), + alg in (RadauIIA3, RadauIIA5, RadauIIA9, AdaptiveRadau, GaussLegendre) + + sol = solve(prob, alg(extrapolant = :constant); reltol = 1.0e-8, abstol = 1.0e-10, saveat = 0.01) + @test maximum(maximum(abs.(u .- exact(t))) for (t, u) in zip(sol.t, sol.u)) < 1.0e-5 + end +end