Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
PerezHz committed Apr 10, 2024
1 parent 7b4082a commit 92d1ee4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
27 changes: 24 additions & 3 deletions ext/TaylorIntegrationDiffEq.jl
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions test/common.jl
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions 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
Expand Down

0 comments on commit 92d1ee4

Please sign in to comment.