Skip to content

Commit

Permalink
fix default solver for non-diagonal mass matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
oscardssmith committed May 28, 2024
1 parent 2029463 commit 1d8ad85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/composite_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ function nonstiffchoice(reltol)
Int(x)
end

function stiffchoice(reltol, len)
function stiffchoice(reltol, len, mass_matrix)
x = if len > MEDIUMSIZE
DefaultSolverChoice.KrylovFBDF
elseif len > SMALLSIZE
DefaultSolverChoice.FBDF
else
if reltol < LOW_TOL
if reltol < LOW_TOL || !isdiag(mass_matrix)
DefaultSolverChoice.Rodas5P
else
DefaultSolverChoice.Rosenbrock23
Expand All @@ -166,7 +166,7 @@ function default_autoswitch(AS::AutoSwitchCache, integrator)
# Chooose the starting method
if AS.current == 0
choice = if AS.stiffalgfirst || integrator.f.mass_matrix != I
stiffchoice(reltol, len)
stiffchoice(reltol, len, integrator.f.mass_matrix)
else
nonstiffchoice(reltol)
end
Expand All @@ -184,7 +184,7 @@ function default_autoswitch(AS::AutoSwitchCache, integrator)
if integrator.f.mass_matrix != I || (!AS.is_stiffalg && AS.count > AS.maxstiffstep)
integrator.dt = dt * AS.dtfac
AS.is_stiffalg = true
AS.current = stiffchoice(reltol, len)
AS.current = stiffchoice(reltol, len, integrator.f.mass_matrix)
elseif (AS.is_stiffalg && AS.count < -AS.maxnonstiffstep)
integrator.dt = dt / AS.dtfac
AS.is_stiffalg = false
Expand Down
2 changes: 1 addition & 1 deletion test/interface/default_solver_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ function swaplinear(u, p, t)
end
swaplinearf = ODEFunction(swaplinear, mass_matrix = ones(2, 2) - I(2))
prob_swaplinear = ODEProblem(swaplinearf, rand(2), (0.0, 1.0), 1.01)
sol = solve(prob_swaplinear, reltol = 1e-7) # reltol must be set to avoid running into a bug with Rosenbrock23
sol = solve(prob_swaplinear)
@test all(isequal(4), sol.alg_choice)
# for some reason the timestepping here is different from regular Rodas5P (including the initial timestep)

0 comments on commit 1d8ad85

Please sign in to comment.