diff --git a/lib/OrdinaryDiffEqCore/Project.toml b/lib/OrdinaryDiffEqCore/Project.toml index 332809f7c33..c431792646c 100644 --- a/lib/OrdinaryDiffEqCore/Project.toml +++ b/lib/OrdinaryDiffEqCore/Project.toml @@ -1,7 +1,7 @@ name = "OrdinaryDiffEqCore" uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" authors = ["ParamThakkar123 "] -version = "4.12.0" +version = "4.12.1" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/lib/OrdinaryDiffEqCore/src/alg_utils.jl b/lib/OrdinaryDiffEqCore/src/alg_utils.jl index 82a77ec84b5..d0bb5f3b358 100644 --- a/lib/OrdinaryDiffEqCore/src/alg_utils.jl +++ b/lib/OrdinaryDiffEqCore/src/alg_utils.jl @@ -126,6 +126,15 @@ Return whether `alg` provides a special interpolant for its stiff branch """ has_stiff_interpolation(alg) = false +""" + get_current_has_stiff_interpolation(alg, cache) -> Bool + +`has_stiff_interpolation` for the algorithm that is currently active, which for a +`CompositeAlgorithm` is the sub-algorithm selected by `cache.current` rather than +the wrapper itself. +""" +get_current_has_stiff_interpolation(alg, cache) = has_stiff_interpolation(alg) + """ OrdinaryDiffEqCore.has_stage_limiter(alg) @@ -160,6 +169,10 @@ function get_current_isfsal(alg::CompositeAlgorithm, cache) return _eval_index(isfsal, alg.algs, cache.current)::Bool end +function get_current_has_stiff_interpolation(alg::CompositeAlgorithm, cache) + return _eval_index(has_stiff_interpolation, alg.algs, cache.current)::Bool +end + all_fsal(alg, cache) = isfsal(alg) all_fsal(alg::CompositeAlgorithm, cache) = _all_fsal(alg.algs) diff --git a/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl b/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl index 09fd8590e64..37490335e96 100644 --- a/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl +++ b/lib/OrdinaryDiffEqCore/src/integrators/integrator_interface.jl @@ -81,8 +81,8 @@ end @inline function SciMLBase.get_du(integrator::ODEIntegrator) isdiscretecache(integrator.cache) && error("Derivatives are not defined for this stepper.") - return if isfsal(integrator.alg) && - !has_stiff_interpolation(integrator.alg) + return if get_current_isfsal(integrator.alg, integrator.cache) && + !get_current_has_stiff_interpolation(integrator.alg, integrator.cache) # Special stiff interpolations do not store the # right value in fsallast integrator.fsallast @@ -116,8 +116,8 @@ end if isdiscretecache(integrator.cache) out .= integrator.cache.tmp else - return if isfsal(integrator.alg) && - !has_stiff_interpolation(integrator.alg) + return if get_current_isfsal(integrator.alg, integrator.cache) && + !get_current_has_stiff_interpolation(integrator.alg, integrator.cache) # Special stiff interpolations do not store the # right value in fsallast out .= integrator.fsallast diff --git a/test/InterfaceII/get_du.jl b/test/InterfaceII/get_du.jl index 099038f8b68..264ef26ef0c 100644 --- a/test/InterfaceII/get_du.jl +++ b/test/InterfaceII/get_du.jl @@ -23,6 +23,10 @@ res = copy(cache) for alg in [ Vern6(), Vern7(), Vern8(), Vern9(), Rodas4(), Rodas4P(), Rodas5(), Rodas5P(), TRBDF2(), KenCarp4(), FBDF(), QNDF(), + # A CompositeAlgorithm must report the derivative of whichever + # sub-algorithm is currently active, not of the wrapper. + AutoTsit5(Rosenbrock23()), AutoTsit5(Rodas5P()), + AutoVern7(Rodas4()), AutoVern9(Rodas4()), AutoVern9(Rodas5P()), ] sol = solve( prob, alg, tstops = [0.2], callback = dusave, abstol = 1.0e-12, reltol = 1.0e-12