Skip to content

Commit

Permalink
Merge pull request #707 from JuliaDiffEq/myb/switching
Browse files Browse the repository at this point in the history
Fix stiff switching algorithm
  • Loading branch information
YingboMa committed Mar 22, 2019
2 parents 98412e9 + a1429ed commit 320cd9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/derivative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions test/stiffness_detection_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 320cd9c

Please sign in to comment.