diff --git a/Project.toml b/Project.toml index 351b620..8aceab1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Sundials" uuid = "c3572dad-4567-51f8-b174-8c6c989267f4" authors = ["Chris Rackauckas "] -version = "4.22.0" +version = "4.22.1" [deps] CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" diff --git a/src/common_interface/solve.jl b/src/common_interface/solve.jl index 5ddc13b..b00eb70 100644 --- a/src/common_interface/solve.jl +++ b/src/common_interface/solve.jl @@ -29,6 +29,7 @@ function DiffEqBase.__solve(prob::Union{ ts = [], ks = [], recompile::Type{Val{recompile_flag}} = Val{true}; + abstol = 1e-6, kwargs...) where {algType <: SundialsNonlinearSolveAlgorithm, recompile_flag, uType, isinplace} if prob.u0 isa Number @@ -68,7 +69,8 @@ function DiffEqBase.__solve(prob::Union{ userdata = userdata, linear_solver = linsolve, jac_upper = jac_upper, - jac_lower = jac_lower) + jac_lower = jac_lower, + abstol) f!(resid, u) retcode = interpret_sundials_retcode(flag) diff --git a/src/simple.jl b/src/simple.jl index f4f3b77..baa8397 100644 --- a/src/simple.jl +++ b/src/simple.jl @@ -49,7 +49,8 @@ function ___kinsol(f, userdata::Any = nothing, linear_solver = :Dense, jac_upper = 0, - jac_lower = 0) + jac_lower = 0, + abstol::Float64 = 1e-6) # f, Function to be optimized of the form f(y::Vector{Float64}, fy::Vector{Float64}) # where `y` is the input vector, and `fy` is the result of the function # y0, Vector of initial values @@ -74,6 +75,7 @@ function ___kinsol(f, A = Sundials.SUNBandMatrix(length(y0), jac_upper, jac_lower) LS = Sundials.SUNLinSol_Band(y0, A) end + flag = @checkflag KINSetFuncNormTol(kmem, abstol) true flag = @checkflag Sundials.KINDlsSetLinearSolver(kmem, LS, A) true flag = @checkflag KINSetUserData(kmem, userfun) true ## Solve problem diff --git a/test/kinsol_banded.jl b/test/kinsol_banded.jl index 255fd24..a1dd9dd 100644 --- a/test/kinsol_banded.jl +++ b/test/kinsol_banded.jl @@ -24,10 +24,19 @@ end u0 = ones(5) prob_iip = SteadyStateProblem(f_iip, u0) prob_oop = SteadyStateProblem(f_oop, u0) + +@test maximum(solve(prob_iip, KINSOL(); abstol = 1e-6).u) ≥ 1e-10 +@test maximum(solve(prob_iip, KINSOL(); abstol = 1e-12).u) ≤ 1e-10 + @test solve(prob_iip, KINSOL()) == solve(prob_iip, KINSOL(; linear_solver = :Band, jac_upper = 0, jac_lower = 0)) @test solve(prob_oop, KINSOL()) == solve(prob_oop, KINSOL(; linear_solver = :Band, jac_upper = 0, jac_lower = 0)) +@test solve(prob_iip, KINSOL(); abstol = 1e-12) == + solve(prob_iip, KINSOL(; linear_solver = :Band, jac_upper = 0, jac_lower = 0); + abstol = 1e-12) +@test solve(prob_oop, KINSOL()) == + solve(prob_oop, KINSOL(; linear_solver = :Band, jac_upper = 0, jac_lower = 0)) prob_iip = NonlinearProblem(f_iip, u0) prob_oop = NonlinearProblem(f_oop, u0) @test solve(prob_iip, KINSOL()) ==