From a1429ed498d9eac8f41c3eadba92e4633d884ce3 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Fri, 22 Mar 2019 09:52:34 -0400 Subject: [PATCH] Fix stiff switching algorithm --- src/derivative_wrappers.jl | 2 +- test/stiffness_detection_test.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/derivative_wrappers.jl b/src/derivative_wrappers.jl index 3e713935ba..3443cee56d 100644 --- a/src/derivative_wrappers.jl +++ b/src/derivative_wrappers.jl @@ -70,7 +70,7 @@ function jacobian!(J::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number}, f else isforward = alg.diff_type === Val{:forward} if isforward - forwardcache = get_tmp_cache(integrator)[2] + forwardcache = get_tmp_cache(integrator, alg, unwrap_cache(integrator, true))[2] f(forwardcache, x) integrator.destats.nf += 1 DiffEqDiffTools.finite_difference_jacobian!(J, f, x, jac_config, forwardcache) diff --git a/test/stiffness_detection_test.jl b/test/stiffness_detection_test.jl index 8da469325c..b021386abb 100644 --- a/test/stiffness_detection_test.jl +++ b/test/stiffness_detection_test.jl @@ -15,6 +15,8 @@ probArr = [prob1, prob2, prob3] # Test if switching back and forth is_switching_fb(sol) = maximum(diff(findall(x->x==2, sol.alg_choice))) > 5 for prob in probArr + sol = @test_nowarn solve(prob, AutoTsit5(Rosenbrock23(autodiff=false))) + @test is_switching_fb(sol) alg = AutoTsit5(Rodas5(); maxstiffstep=5, maxnonstiffstep=5, stiffalgfirst=true) sol = solve(prob, alg) @test length(sol.t) < 280 @@ -38,4 +40,7 @@ for prob in probArr sol = solve(prob,AutoVern9(KenCarp3(); maxstiffstep=4, maxnonstiffstep=4)) @test length(sol.t) < 470 @test is_switching_fb(sol) + sol = solve(prob,AutoVern9(KenCarp3(autodiff=false); maxstiffstep=4, maxnonstiffstep=4)) + @test length(sol.t) < 470 + @test is_switching_fb(sol) end