From 92d1ee4f362f0009f2f9167b1da4281b420f5b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20A=2E=20P=C3=A9rez-Hern=C3=A1ndez?= Date: Wed, 10 Apr 2024 09:37:39 +0200 Subject: [PATCH] wip --- ext/TaylorIntegrationDiffEq.jl | 27 ++++++++++++++++++++++++--- test/common.jl | 13 +++++++++++++ test/runtests.jl | 18 +++++++++--------- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/ext/TaylorIntegrationDiffEq.jl b/ext/TaylorIntegrationDiffEq.jl index f0afddeb..79c1c84a 100644 --- a/ext/TaylorIntegrationDiffEq.jl +++ b/ext/TaylorIntegrationDiffEq.jl @@ -9,19 +9,21 @@ if isdefined(Base, :get_extension) import OrdinaryDiffEq: OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqConstantCache, OrdinaryDiffEqMutableCache, alg_order, alg_cache, initialize!, perform_step!, @unpack, - @cache, stepsize_controller!, step_accept_controller!, _ode_addsteps! + @cache, stepsize_controller!, step_accept_controller!, _ode_addsteps!, + _ode_interpolant!, _ode_interpolant else using ..OrdinaryDiffEq import ..OrdinaryDiffEq: OrdinaryDiffEqAdaptiveAlgorithm, OrdinaryDiffEqConstantCache, OrdinaryDiffEqMutableCache, alg_order, alg_cache, initialize!, perform_step!, @unpack, - @cache, stepsize_controller!, step_accept_controller!, _ode_addsteps! + @cache, stepsize_controller!, step_accept_controller!, _ode_addsteps!, + _ode_interpolant!, _ode_interpolant end using StaticArrays: SVector, SizedArray using RecursiveArrayTools: ArrayPartition -import DiffEqBase: ODEProblem, solve, ODE_DEFAULT_NORM +import DiffEqBase: ODEProblem, solve, ODE_DEFAULT_NORM, interp_summary # TODO: check which keywords work fine const warnkeywords = (:save_idxs, :d_discontinuities, :unstable_check, :save_everystep, @@ -286,6 +288,25 @@ function _ode_addsteps!(k, t, uprev, u, dt, f, p, cache::TaylorMethodCache, nothing end +function interp_summary(::Type{cacheType}, dense::Bool) where {cacheType <: TaylorMethodCache} + dense ? "Taylor series polynomial evaluation" : "1st order linear" +end + +# idxs gives back multiple values +function _ode_interpolant!(out, Θ, dt, y₀, y₁, k, cache::TaylorMethodCache, idxs, T::Type{Val{TI}}) where {TI} + Θm1 = Θ - 1 + @inbounds for i in eachindex(out) + out[i] = cache.uT[i](Θm1*dt) + end + out +end + +# when idxs gives back a single value +function _ode_interpolant(Θ, dt, y₀, y₁, k, cache::TaylorMethodCache, idxs, T::Type{Val{TI}}) where {TI} + Θm1 = Θ - 1 + return cache.uT[idxs](Θm1*dt) +end + @inline TaylorIntegration.__jetcoeffs!(::Val{false}, f::ODEFunction, t, x::Taylor1{U}, params, rv::TaylorIntegration.RetAlloc{Taylor1{U}}) where {U} = TaylorIntegration.__jetcoeffs!(Val(false), f.f, t, x, params) @inline TaylorIntegration.__jetcoeffs!(::Val{true}, f::ODEFunction, t, x::Taylor1{U}, params, diff --git a/test/common.jl b/test/common.jl index 8d3ddcc9..173220b2 100644 --- a/test/common.jl +++ b/test/common.jl @@ -99,6 +99,19 @@ import Logging: Warn harmosc!, u0, tspan[1], tspan[2], order, abstol)) @test sol.t == tv1 @test xv1[end,:] == sol.u[end] + @test DiffEqBase.interp_summary(sol.interp) == "Taylor series polynomial evaluation" + tvsol = range(tspan[1], tspan[2], length=10) + tv2, xv2, psol2 = (@test_logs min_level=Logging.Warn taylorinteg( + harmosc!, u0, tspan[1], tspan[2], order, abstol, Val(true))) + Θ = rand() + dt_test = (tv2[end]-tv2[end-1]) + t_test = tv2[end-1] + Θ*dt_test + @test norm(sol(t_test) .- psol2[end,:]( Θ*dt_test ), Inf) < 1e-14 + Θ = rand() + Θm1 = Θ - 1 + dt_test = (tv2[end-1]-tv2[end-2]) + t_test = tv2[end-2] + Θ*dt_test + @test norm( sol(t_test) .- psol2[end,:]( Θm1*dt_test ) ) < 1e-14 end @testset "Test discrete callback in common interface" begin diff --git a/test/runtests.jl b/test/runtests.jl index 0c2fc5e3..253274de 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,16 +1,16 @@ # This file is part of the TaylorIntegration.jl package; MIT licensed testfiles = ( - "one_ode.jl", - "many_ode.jl", - "complex.jl", - "jettransport.jl", - "lyapunov.jl", - "bigfloats.jl", + # "one_ode.jl", + # "many_ode.jl", + # "complex.jl", + # "jettransport.jl", + # "lyapunov.jl", + # "bigfloats.jl", "common.jl", - "rootfinding.jl", - "taylorize.jl", - "aqua.jl", + # "rootfinding.jl", + # "taylorize.jl", + # "aqua.jl", ) for file in testfiles