diff --git a/lib/OrdinaryDiffEqFIRK/Project.toml b/lib/OrdinaryDiffEqFIRK/Project.toml index dd5beeb6ad5..2d631e65686 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.10" +version = "2.8.11" [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 3f937ed2a08..c496b6dd818 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) @@ -2004,17 +1992,15 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - cmax = tabs[end].c - for j in eachindex(cmax) - weight = _stage_weight(c, 1, cmax[j]) - kj = @.. weight * z[1] - for i in 2:num_stages - weight = _stage_weight(c, i, cmax[j]) - kj = @.. kj + weight * z[i] - end - integrator.k[j + 2] = kj + cmax = tabs[end].c + for j in eachindex(cmax) + weight = _stage_weight(c, 1, cmax[j]) + kj = @.. weight * z[1] + for i in 2:num_stages + weight = _stage_weight(c, i, cmax[j]) + kj = @.. kj + weight * z[i] end + integrator.k[j + 2] = kj end end @@ -2360,15 +2346,13 @@ end if OrdinaryDiffEqCore.get_EEst(integrator) <= oneunit(OrdinaryDiffEqCore.get_EEst(integrator)) cache.dtprev = dt - if alg.extrapolant != :constant - cmax = tabs[end].c - for j in eachindex(cmax) - weight = _stage_weight(c, 1, cmax[j]) - @.. integrator.k[j + 2] = weight * z[1] - for i in 2:num_stages - weight = _stage_weight(c, i, cmax[j]) - @.. integrator.k[j + 2] += weight * z[i] - end + cmax = tabs[end].c + for j in eachindex(cmax) + weight = _stage_weight(c, 1, cmax[j]) + @.. integrator.k[j + 2] = weight * z[1] + for i in 2:num_stages + weight = _stage_weight(c, i, cmax[j]) + @.. integrator.k[j + 2] += weight * z[i] end end end @@ -2610,10 +2594,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 @@ -2798,10 +2780,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 c0a93f3137a..235d3bee54b 100644 --- a/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl +++ b/lib/OrdinaryDiffEqFIRK/test/ode_firk_tests.jl @@ -354,3 +354,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