From f86eea787d9702aa42c093526d4131f3d5694c3d Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Tue, 27 Jun 2023 14:16:09 -0400 Subject: [PATCH] add tests and fixes --- src/common_interface/integrator_utils.jl | 4 ++-- test/interpolation.jl | 25 ++++++++++++++++++++++++ test/runtests.jl | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/interpolation.jl diff --git a/src/common_interface/integrator_utils.jl b/src/common_interface/integrator_utils.jl index c54674f..6c6b0e4 100644 --- a/src/common_interface/integrator_utils.jl +++ b/src/common_interface/integrator_utils.jl @@ -52,12 +52,12 @@ function DiffEqBase.savevalues!(integrator::AbstractSundialsIntegrator, tmp = integrator(curt) save_value!(integrator.sol.u, tmp, uType, - integrator.opts.save_idxs, Val{false}) + integrator.opts.save_idxs, false) push!(integrator.sol.t, curt) if integrator.opts.dense tmp = integrator(curt, Val{1}) save_value!(integrator.sol.interp.du, tmp, uType, - integrator.opts.save_idxs, Val{false}) + integrator.opts.save_idxs, false) end end diff --git a/test/interpolation.jl b/test/interpolation.jl new file mode 100644 index 0000000..7d242f6 --- /dev/null +++ b/test/interpolation.jl @@ -0,0 +1,25 @@ +using Sundials, Test, DiffEqBase +using ForwardDiff +import ODEProblemLibrary: prob_ode_linear, prob_ode_2Dlinear + +function regression_test(alg, tol_ode_linear, tol_ode_2Dlinear) + sol = solve(prob_ode_linear, alg, dense = true, abstol=1e-8, reltol=1e-8) + @inferred sol(.5) + u0 = sol[1] + p = sol.prob.p + for t in 0.0:1/16:1.0 + @test isapprox(u0 * exp(p*t), sol(t), rtol=tol_ode_linear) + end + + sol = solve(prob_ode_2Dlinear, alg, dt = 1 / 2^(2), dense = true) + sol2 = solve(prob_ode_2Dlinear, alg, dense = true, abstol=1e-8, reltol=1e-8) + u0 = sol[1] + p = sol.prob.p + for t in 0.0:1/16:1.0 + @test isapprox(u0 .* exp(p*t), sol(t), rtol=tol_ode_2Dlinear) + end +end + +regression_test(ARKODE(), 1e-5, 1e-4) +regression_test(CVODE_BDF(), 1e-6, 1e-2) +regression_test(CVODE_Adams(), 1e-6, 1e-3) diff --git a/test/runtests.jl b/test/runtests.jl index 3a32188..b876dd4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -41,3 +41,5 @@ end @testset "Mass Matrix" begin include("common_interface/mass_matrix.jl") end @testset "Preconditioners" begin include("common_interface/precs.jl") end end + +@testset "Interpolation" begin include("interpolation.jl") end