From cf7dcd144f9396cc6b348e8804d9ffc3de164a80 Mon Sep 17 00:00:00 2001 From: oscarddssmith Date: Wed, 6 Nov 2024 13:24:01 -0500 Subject: [PATCH] prepare to remove OrdinaryDiffEq dependency --- Project.toml | 8 ++++ src/DelayDiffEq.jl | 14 ++----- src/alg_utils.jl | 60 +++++++++++++-------------- src/fpsolve/fpsolve.jl | 8 ++-- src/fpsolve/functional.jl | 18 ++++---- src/fpsolve/type.jl | 4 +- src/integrators/interface.jl | 80 ++++++++++++++++++------------------ src/integrators/utils.jl | 36 ++++++++-------- src/solve.jl | 64 ++++++++++++++--------------- 9 files changed, 147 insertions(+), 145 deletions(-) diff --git a/Project.toml b/Project.toml index db1e51e8..726b1cb3 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,10 @@ DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8" +OrdinaryDiffEqDefault = "50262376-6c5a-4cf5-baba-aaf4f84d72d7" +OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8" +OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" @@ -22,6 +26,10 @@ ArrayInterface = "7" DataStructures = "0.18" DiffEqBase = "6.122" OrdinaryDiffEq = "6.69" +OrdinaryDiffEqCore = "1.9.0" +OrdinaryDiffEqDefault = "1.1.0" +OrdinaryDiffEqNonlinearSolve = "1.2.2" +OrdinaryDiffEqRosenbrock = "1.2.0" RecursiveArrayTools = "2, 3" Reexport = "0.2, 1.0" SciMLBase = "1.90, 2" diff --git a/src/DelayDiffEq.jl b/src/DelayDiffEq.jl index f4f99c30..114e6844 100644 --- a/src/DelayDiffEq.jl +++ b/src/DelayDiffEq.jl @@ -1,6 +1,7 @@ module DelayDiffEq using Reexport +import OrdinaryDiffEqCore, OrdinaryDiffEqNonlinearSolve, OrdinaryDiffEqRosenbrock @reexport using OrdinaryDiffEq using DataStructures @@ -18,16 +19,9 @@ using DiffEqBase: AbstractDDEAlgorithm, AbstractDDEIntegrator, AbstractODEIntegr using DiffEqBase: @.. -if isdefined(OrdinaryDiffEq, :FastConvergence) - using OrdinaryDiffEq: FastConvergence, Convergence, SlowConvergence, - VerySlowConvergence, - Divergence, AbstractNLSolverCache, NLNewton, - NLAnderson, NLFunctional -else - using DiffEqBase: FastConvergence, Convergence, SlowConvergence, VerySlowConvergence, - Divergence, AbstractNLSolverCache -end -using OrdinaryDiffEq: RosenbrockMutableCache +using OrdinaryDiffEqNonlinearSolve: NLNewton, NLAnderson, NLFunctional, AbstractNLSolverCache, + FastConvergence, Convergence, SlowConvergence, VerySlowConvergence, Divergence +using OrdinaryDiffEqRosenbrock: RosenbrockMutableCache import SciMLBase diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 10da692a..2ae8199f 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -17,49 +17,49 @@ SciMLBase.isadaptive(alg::AbstractMethodOfStepsAlgorithm) = SciMLBase.isadaptive function isconstrained(alg::AbstractMethodOfStepsAlgorithm{constrained}) where {constrained} constrained end -OrdinaryDiffEq.uses_uprev(alg::AbstractMethodOfStepsAlgorithm, adaptive) = true +OrdinaryDiffEqCore.uses_uprev(alg::AbstractMethodOfStepsAlgorithm, adaptive) = true -function OrdinaryDiffEq.isimplicit(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.isimplicit(alg.alg) +function OrdinaryDiffEqCore.isimplicit(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.isimplicit(alg.alg) end -function OrdinaryDiffEq.isdtchangeable(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.isdtchangeable(alg.alg) +function OrdinaryDiffEqCore.isdtchangeable(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.isdtchangeable(alg.alg) end -function OrdinaryDiffEq.ismultistep(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.ismultistep(alg.alg) +function OrdinaryDiffEqCore.ismultistep(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.ismultistep(alg.alg) end -function OrdinaryDiffEq.isautoswitch(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.isautoswitch(alg.alg) +function OrdinaryDiffEqCore.isautoswitch(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.isautoswitch(alg.alg) end -function OrdinaryDiffEq.get_chunksize(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.get_chunksize(alg.alg) +function OrdinaryDiffEqCore.get_chunksize(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.get_chunksize(alg.alg) end -function OrdinaryDiffEq.get_chunksize_int(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.get_chunksize_int(alg.alg) +function OrdinaryDiffEqCore.get_chunksize_int(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.get_chunksize_int(alg.alg) end -function OrdinaryDiffEq.alg_autodiff(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_autodiff(alg.alg) +function OrdinaryDiffEqCore.alg_autodiff(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_autodiff(alg.alg) end -function OrdinaryDiffEq.alg_difftype(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_difftype(alg.alg) +function OrdinaryDiffEqCore.alg_difftype(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_difftype(alg.alg) end -function OrdinaryDiffEq.standardtag(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.standardtag(alg.alg) +function OrdinaryDiffEqCore.standardtag(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.standardtag(alg.alg) end -function OrdinaryDiffEq.concrete_jac(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.concrete_jac(alg.alg) +function OrdinaryDiffEqCore.concrete_jac(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.concrete_jac(alg.alg) end -function OrdinaryDiffEq.alg_extrapolates(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_extrapolates(alg.alg) +function OrdinaryDiffEqCore.alg_extrapolates(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_extrapolates(alg.alg) end -function OrdinaryDiffEq.alg_order(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_order(alg.alg) +function OrdinaryDiffEqCore.alg_order(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_order(alg.alg) end -function OrdinaryDiffEq.alg_maximum_order(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_maximum_order(alg.alg) +function OrdinaryDiffEqCore.alg_maximum_order(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_maximum_order(alg.alg) end -function OrdinaryDiffEq.alg_adaptive_order(alg::AbstractMethodOfStepsAlgorithm) - OrdinaryDiffEq.alg_adaptive_order(alg.alg) +function OrdinaryDiffEqCore.alg_adaptive_order(alg::AbstractMethodOfStepsAlgorithm) + OrdinaryDiffEqCore.alg_adaptive_order(alg.alg) end """ @@ -68,7 +68,7 @@ end Return if algorithm `alg` is a composite algorithm. """ iscomposite(alg) = false -iscomposite(::OrdinaryDiffEq.OrdinaryDiffEqCompositeAlgorithm) = true +iscomposite(::OrdinaryDiffEqCore.OrdinaryDiffEqCompositeAlgorithm) = true iscomposite(alg::AbstractMethodOfStepsAlgorithm) = iscomposite(alg.alg) function DiffEqBase.prepare_alg(alg::MethodOfSteps, u0, p, prob) diff --git a/src/fpsolve/fpsolve.jl b/src/fpsolve/fpsolve.jl index 9ef9790b..5f38f846 100644 --- a/src/fpsolve/fpsolve.jl +++ b/src/fpsolve/fpsolve.jl @@ -1,14 +1,14 @@ -OrdinaryDiffEq.initial_η(fpsolver::FPSolver, integrator::DDEIntegrator) = fpsolver.ηold +OrdinaryDiffEqNonlinearSolve.initial_η(fpsolver::FPSolver, integrator::DDEIntegrator) = fpsolver.ηold -OrdinaryDiffEq.apply_step!(fpsolver::FPSolver, integrator::DDEIntegrator) = nothing +OrdinaryDiffEqNonlinearSolve.apply_step!(fpsolver::FPSolver, integrator::DDEIntegrator) = nothing function DiffEqBase.postamble!(fpsolver::FPSolver, integrator::DDEIntegrator) integrator.stats.nfpiter += fpsolver.iter - if OrdinaryDiffEq.nlsolvefail(fpsolver) + if OrdinaryDiffEqNonlinearSolve.nlsolvefail(fpsolver) integrator.stats.nfpconvfail += 1 end - integrator.force_stepfail = OrdinaryDiffEq.nlsolvefail(fpsolver) || + integrator.force_stepfail = OrdinaryDiffEqNonlinearSolve.nlsolvefail(fpsolver) || integrator.force_stepfail nothing diff --git a/src/fpsolve/functional.jl b/src/fpsolve/functional.jl index d5d7b16b..8df23b59 100644 --- a/src/fpsolve/functional.jl +++ b/src/fpsolve/functional.jl @@ -1,4 +1,4 @@ -function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLFunctional}, +function OrdinaryDiffEqNonlinearSolve.compute_step!(fpsolver::FPSolver{<:NLFunctional}, integrator::DDEIntegrator) # update ODE integrator to next time interval together with correct interpolation if fpsolver.iter == 1 @@ -10,7 +10,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLFunctional}, compute_step_fixedpoint!(fpsolver, integrator) end -function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, +function OrdinaryDiffEqNonlinearSolve.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, integrator::DDEIntegrator) @unpack cache, iter = fpsolver @unpack aa_start = cache @@ -23,7 +23,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, cache.z₊old = integrator.u elseif previter > aa_start # actually perform Anderson acceleration - integrator.u = OrdinaryDiffEq.anderson(integrator.u, cache) + integrator.u = OrdinaryDiffEqNonlinearSolve.anderson(integrator.u, cache) integrator.stats.nsolve += 1 end @@ -39,7 +39,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, compute_step_fixedpoint!(fpsolver, integrator) end -function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, true}, +function OrdinaryDiffEqNonlinearSolve.compute_step!(fpsolver::FPSolver{<:NLAnderson, true}, integrator::DDEIntegrator) @unpack cache, iter = fpsolver @unpack aa_start = cache @@ -52,7 +52,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, true}, @.. cache.z₊old = integrator.u elseif previter > aa_start # actually perform Anderson acceleration - OrdinaryDiffEq.anderson!(integrator.u, cache) + OrdinaryDiffEqNonlinearSolve.anderson!(integrator.u, cache) integrator.stats.nsolve += 1 end @@ -77,11 +77,11 @@ function compute_step_fixedpoint!( ode_integrator = integrator.integrator # recompute next integration step - OrdinaryDiffEq.perform_step!(integrator, integrator.cache, true) + OrdinaryDiffEqCore.perform_step!(integrator, integrator.cache, true) # compute residuals dz = integrator.u .- ode_integrator.u - atmp = OrdinaryDiffEq.calculate_residuals(dz, ode_integrator.u, integrator.u, + atmp = OrdinaryDiffEqNonlinearSolve.calculate_residuals(dz, ode_integrator.u, integrator.u, opts.abstol, opts.reltol, opts.internalnorm, t) @@ -103,11 +103,11 @@ function compute_step_fixedpoint!( ode_integrator = integrator.integrator # recompute next integration step - OrdinaryDiffEq.perform_step!(integrator, integrator.cache, true) + OrdinaryDiffEqCore.perform_step!(integrator, integrator.cache, true) # compute residuals @.. dz = integrator.u - ode_integrator.u - OrdinaryDiffEq.calculate_residuals!(atmp, dz, ode_integrator.u, integrator.u, + OrdinaryDiffEqNonlinearSolve.calculate_residuals!(atmp, dz, ode_integrator.u, integrator.u, opts.abstol, opts.reltol, opts.internalnorm, t) opts.internalnorm(atmp, t) diff --git a/src/fpsolve/type.jl b/src/fpsolve/type.jl index f5f0f2ad..6b48d8cf 100644 --- a/src/fpsolve/type.jl +++ b/src/fpsolve/type.jl @@ -1,13 +1,13 @@ # solver mutable struct FPSolver{algType, iip, uTolType, C <: AbstractNLSolverCache} <: - OrdinaryDiffEq.AbstractNLSolver{algType, iip} + OrdinaryDiffEqNonlinearSolve.AbstractNLSolver{algType, iip} alg::algType κ::uTolType fast_convergence_cutoff::uTolType ηold::uTolType iter::Int maxiters::Int - status::OrdinaryDiffEq.NLStatus + status::OrdinaryDiffEqNonlinearSolve.NLStatus cache::C nfails::Int end diff --git a/src/integrators/interface.jl b/src/integrators/interface.jl index 2732e063..a73fed6b 100644 --- a/src/integrators/interface.jl +++ b/src/integrators/interface.jl @@ -1,7 +1,7 @@ # accept/reject computed integration step, propose next step, and apply callbacks -function OrdinaryDiffEq.loopfooter!(integrator::DDEIntegrator) - # apply same logic as in OrdinaryDiffEq - OrdinaryDiffEq._loopfooter!(integrator) +function OrdinaryDiffEqCore.loopfooter!(integrator::DDEIntegrator) + # apply same logic as in OrdinaryDiffEqCore + OrdinaryDiffEqCore._loopfooter!(integrator) if !integrator.accept_step # reset ODE integrator to the cached values if the last step failed @@ -80,7 +80,7 @@ function DiffEqBase.savevalues!(integrator::DDEIntegrator, force_save = false, ode_integrator.dtcache = ode_integrator.dt # update solution - OrdinaryDiffEq._savevalues!(integrator, force_save, reduce_size) + OrdinaryDiffEqCore._savevalues!(integrator, force_save, reduce_size) end # clean up the solution of the integrator @@ -111,11 +111,11 @@ function DiffEqBase.postamble!(integrator::DDEIntegrator) DiffEqBase.postamble!(integrator.integrator) # clean solution of the DDE integrator - OrdinaryDiffEq._postamble!(integrator) + OrdinaryDiffEqCore._postamble!(integrator) end # perform next integration step -function OrdinaryDiffEq.perform_step!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.perform_step!(integrator::DDEIntegrator) @unpack cache, history = integrator # reset boolean which indicates if the history function was evaluated at a time point @@ -123,13 +123,13 @@ function OrdinaryDiffEq.perform_step!(integrator::DDEIntegrator) history.isout = false # perform always at least one calculation of the stages - OrdinaryDiffEq.perform_step!(integrator, cache) + OrdinaryDiffEqCore.perform_step!(integrator, cache) # if the history function was evaluated at time points past the final time point of the # solution, i.e. returned extrapolated values, continue with a fixed-point iteration if history.isout # perform fixed-point iteration - OrdinaryDiffEq.nlsolve!(integrator.fpsolver, integrator) + OrdinaryDiffEqCore.nlsolve!(integrator.fpsolver, integrator) end # update ODE integrator to next time interval together with correct interpolation @@ -139,11 +139,11 @@ function OrdinaryDiffEq.perform_step!(integrator::DDEIntegrator) end # initialize the integrator -function OrdinaryDiffEq.initialize!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.initialize!(integrator::DDEIntegrator) ode_integrator = integrator.integrator # initialize the cache - OrdinaryDiffEq.initialize!(integrator, integrator.cache) + OrdinaryDiffEqCore.initialize!(integrator, integrator.cache) # copy interpolation data to the ODE integrator @inbounds for i in 1:length(integrator.k) @@ -190,8 +190,8 @@ function Base.resize!(integrator::DDEIntegrator, cache, i) for c in full_cache(cache) resize!(c, i) end - OrdinaryDiffEq.resize_nlsolver!(integrator, i) - OrdinaryDiffEq.resize_J_W!(cache, integrator, i) + OrdinaryDiffEqCore.resize_nlsolver!(integrator, i) + OrdinaryDiffEqCore.resize_J_W!(cache, integrator, i) resize_non_user_cache!(integrator, cache, i) resize_fpsolver!(integrator, i) nothing @@ -203,8 +203,8 @@ function DiffEqBase.resize_non_user_cache!(integrator::DDEIntegrator, cache::RosenbrockMutableCache, i) cache.J = similar(cache.J, i, i) cache.W = similar(cache.W, i, i) - OrdinaryDiffEq.resize_jac_config!(cache.jac_config, i) - OrdinaryDiffEq.resize_grad_config!(cache.grad_config, i) + OrdinaryDiffEqCore.resize_jac_config!(cache.jac_config, i) + OrdinaryDiffEqCore.resize_grad_config!(cache.grad_config, i) nothing end @@ -339,7 +339,7 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. integrator.uprev = integrator.u end - if OrdinaryDiffEq.alg_extrapolates(integrator.alg) + if OrdinaryDiffEqCore.alg_extrapolates(integrator.alg) if isinplace(integrator.sol.prob) recursivecopy!(integrator.uprev2, integrator.uprev) else @@ -352,10 +352,10 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. # reinit time stops, time points at which solution is saved, and discontinuities tType = typeof(integrator.t) tspan = (tType(t0), tType(tf)) - integrator.opts.tstops = OrdinaryDiffEq.initialize_tstops(tType, tstops, + integrator.opts.tstops = OrdinaryDiffEqCore.initialize_tstops(tType, tstops, d_discontinuities, tspan) - integrator.opts.saveat = OrdinaryDiffEq.initialize_saveat(tType, saveat, tspan) - integrator.opts.d_discontinuities = OrdinaryDiffEq.initialize_d_discontinuities( + integrator.opts.saveat = OrdinaryDiffEqCore.initialize_saveat(tType, saveat, tspan) + integrator.opts.d_discontinuities = OrdinaryDiffEqCore.initialize_d_discontinuities( Discontinuity{ tType, Int @@ -365,7 +365,7 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. # update order of initial discontinuity and propagated discontinuities integrator.order_discontinuity_t0 = order_discontinuity_t0 - maximum_order = OrdinaryDiffEq.alg_maximum_order(integrator.alg) + maximum_order = OrdinaryDiffEqCore.alg_maximum_order(integrator.alg) tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated( tType, tstops, @@ -406,7 +406,7 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. end # erase array of tracked discontinuities - if order_discontinuity_t0 ≤ OrdinaryDiffEq.alg_maximum_order(integrator.alg) + if order_discontinuity_t0 ≤ OrdinaryDiffEqCore.alg_maximum_order(integrator.alg) resize!(integrator.tracked_discontinuities, 1) integrator.tracked_discontinuities[1] = Discontinuity( integrator.tdir * @@ -437,11 +437,11 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. end if reinit_callbacks - OrdinaryDiffEq.initialize_callbacks!(integrator, initialize_save) + OrdinaryDiffEqCore.initialize_callbacks!(integrator, initialize_save) end if reinit_cache - OrdinaryDiffEq.initialize!(integrator) + OrdinaryDiffEqCore.initialize!(integrator) end nothing @@ -461,7 +461,7 @@ function DiffEqBase.auto_dt_reset!(integrator::DDEIntegrator) # determine initial time step ode_prob = ODEProblem(f, prob.u0, prob.tspan, prob.p) - integrator.dt = OrdinaryDiffEq.ode_determine_initdt(u, t, tdir, dtmax, opts.abstol, + integrator.dt = OrdinaryDiffEqCore.ode_determine_initdt(u, t, tdir, dtmax, opts.abstol, opts.reltol, opts.internalnorm, ode_prob, integrator) @@ -493,14 +493,14 @@ end DiffEqBase.has_stats(::DDEIntegrator) = true -# https://github.com/SciML/OrdinaryDiffEq.jl/pull/1753 +# https://github.com/SciML/OrdinaryDiffEqCore.jl/pull/1753 # Backwards compatability -@static if isdefined(OrdinaryDiffEq, :DEPRECATED_ADDSTEPS) - const _ode_addsteps! = OrdinaryDiffEq._ode_addsteps! - const ode_addsteps! = OrdinaryDiffEq.ode_addsteps! +@static if isdefined(OrdinaryDiffEqCore, :DEPRECATED_ADDSTEPS) + const _ode_addsteps! = OrdinaryDiffEqCore._ode_addsteps! + const ode_addsteps! = OrdinaryDiffEqCore.ode_addsteps! else const _ode_addsteps! = DiffEqBase.addsteps! - const ode_addsteps! = OrdinaryDiffEq._ode_addsteps! + const ode_addsteps! = OrdinaryDiffEqCore._ode_addsteps! end function DiffEqBase.addsteps!(integrator::DDEIntegrator, args...) @@ -514,11 +514,11 @@ function DiffEqBase.change_t_via_interpolation!(integrator::DDEIntegrator, }) where { T } - OrdinaryDiffEq._change_t_via_interpolation!(integrator, t, modify_save_endpoint) + OrdinaryDiffEqCore._change_t_via_interpolation!(integrator, t, modify_save_endpoint) end # update integrator when u is modified by callbacks -function OrdinaryDiffEq.handle_callback_modifiers!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.handle_callback_modifiers!(integrator::DDEIntegrator) integrator.reeval_fsal = true # recalculate fsalfirst after applying step # update heap of discontinuities @@ -563,23 +563,23 @@ function DiffEqBase.step!(integrator::DDEIntegrator) @inbounds begin if integrator.opts.advance_to_tstop while integrator.tdir * integrator.t < first(integrator.opts.tstops) - OrdinaryDiffEq.loopheader!(integrator) + OrdinaryDiffEqCore.loopheader!(integrator) DiffEqBase.check_error!(integrator) == ReturnCode.Success || return - OrdinaryDiffEq.perform_step!(integrator) - OrdinaryDiffEq.loopfooter!(integrator) + OrdinaryDiffEqCore.perform_step!(integrator) + OrdinaryDiffEqCore.loopfooter!(integrator) end else - OrdinaryDiffEq.loopheader!(integrator) + OrdinaryDiffEqCore.loopheader!(integrator) DiffEqBase.check_error!(integrator) == ReturnCode.Success || return - OrdinaryDiffEq.perform_step!(integrator) - OrdinaryDiffEq.loopfooter!(integrator) + OrdinaryDiffEqCore.perform_step!(integrator) + OrdinaryDiffEqCore.loopfooter!(integrator) while !integrator.accept_step - OrdinaryDiffEq.loopheader!(integrator) - OrdinaryDiffEq.perform_step!(integrator) - OrdinaryDiffEq.loopfooter!(integrator) + OrdinaryDiffEqCore.loopheader!(integrator) + OrdinaryDiffEqCore.perform_step!(integrator) + OrdinaryDiffEqCore.loopfooter!(integrator) end end - OrdinaryDiffEq.handle_tstop!(integrator) + OrdinaryDiffEqCore.handle_tstop!(integrator) end end diff --git a/src/integrators/utils.jl b/src/integrators/utils.jl index 324f04c8..faa8e37b 100644 --- a/src/integrators/utils.jl +++ b/src/integrators/utils.jl @@ -156,15 +156,15 @@ discontinuities that are checked by a `DiscontinuityCallback` (if existent). =# # handle discontinuities at the current time point of the `integrator` -function OrdinaryDiffEq.handle_discontinuities!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.handle_discontinuities!(integrator::DDEIntegrator) # remove all discontinuities at current time point and calculate minimal order # of these discontinuities - d = OrdinaryDiffEq.pop_discontinuity!(integrator) + d = OrdinaryDiffEqCore.pop_discontinuity!(integrator) order = d.order tdir_t = integrator.tdir * integrator.t - while OrdinaryDiffEq.has_discontinuity(integrator) && - OrdinaryDiffEq.first_discontinuity(integrator) == tdir_t - d2 = OrdinaryDiffEq.pop_discontinuity!(integrator) + while OrdinaryDiffEqCore.has_discontinuity(integrator) && + OrdinaryDiffEqCore.first_discontinuity(integrator) == tdir_t + d2 = OrdinaryDiffEqCore.pop_discontinuity!(integrator) order = min(order, d2.order) end @@ -174,16 +174,16 @@ function OrdinaryDiffEq.handle_discontinuities!(integrator::DDEIntegrator) if integrator.EEst isa AbstractFloat maxΔt = 10eps(integrator.t) - while OrdinaryDiffEq.has_discontinuity(integrator) && - abs(OrdinaryDiffEq.first_discontinuity(integrator).t - tdir_t) < maxΔt - d2 = OrdinaryDiffEq.pop_discontinuity!(integrator) + while OrdinaryDiffEqCore.has_discontinuity(integrator) && + abs(OrdinaryDiffEqCore.first_discontinuity(integrator).t - tdir_t) < maxΔt + d2 = OrdinaryDiffEqCore.pop_discontinuity!(integrator) order = min(order, d2.order) end # also remove all corresponding time stops - while OrdinaryDiffEq.has_tstop(integrator) && - abs(OrdinaryDiffEq.first_tstop(integrator) - tdir_t) < maxΔt - OrdinaryDiffEq.pop_tstop!(integrator) + while OrdinaryDiffEqCore.has_tstop(integrator) && + abs(OrdinaryDiffEqCore.first_tstop(integrator) - tdir_t) < maxΔt + OrdinaryDiffEqCore.pop_tstop!(integrator) end end @@ -208,7 +208,7 @@ function add_next_discontinuities!(integrator, order, t = integrator.t) next_order = neutral ? order : order + 1 # only track discontinuities up to order of the applied method - alg_maximum_order = OrdinaryDiffEq.alg_maximum_order(integrator.alg) + alg_maximum_order = OrdinaryDiffEqCore.alg_maximum_order(integrator.alg) next_order <= alg_maximum_order + 1 || return # discontinuities caused by constant lags @@ -233,25 +233,25 @@ function add_next_discontinuities!(integrator, order, t = integrator.t) end # Interface for accessing and removing next time stops and discontinuities -function OrdinaryDiffEq.has_tstop(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.has_tstop(integrator::DDEIntegrator) return _has(integrator.opts.tstops, integrator.tstops_propagated) end -function OrdinaryDiffEq.first_tstop(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.first_tstop(integrator::DDEIntegrator) return _first(integrator.opts.tstops, integrator.tstops_propagated) end -function OrdinaryDiffEq.pop_tstop!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.pop_tstop!(integrator::DDEIntegrator) return _pop!(integrator.opts.tstops, integrator.tstops_propagated) end -function OrdinaryDiffEq.has_discontinuity(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.has_discontinuity(integrator::DDEIntegrator) return _has(integrator.opts.d_discontinuities, integrator.d_discontinuities_propagated) end -function OrdinaryDiffEq.first_discontinuity(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.first_discontinuity(integrator::DDEIntegrator) return _first(integrator.opts.d_discontinuities, integrator.d_discontinuities_propagated) end -function OrdinaryDiffEq.pop_discontinuity!(integrator::DDEIntegrator) +function OrdinaryDiffEqCore.pop_discontinuity!(integrator::DDEIntegrator) return _pop!(integrator.opts.d_discontinuities, integrator.d_discontinuities_propagated) end diff --git a/src/solve.jl b/src/solve.jl index 8da07441..6231be2b 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -29,13 +29,13 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, dtmax = eltype(prob.tspan)(prob.tspan[end] - prob.tspan[1]), force_dtmin = false, adaptive = DiffEqBase.isadaptive(alg), - gamma = OrdinaryDiffEq.gamma_default(alg.alg), + gamma = OrdinaryDiffEqCore.gamma_default(alg.alg), abstol = nothing, reltol = nothing, - qmin = OrdinaryDiffEq.qmin_default(alg.alg), - qmax = OrdinaryDiffEq.qmax_default(alg.alg), - qsteady_min = OrdinaryDiffEq.qsteady_min_default(alg.alg), - qsteady_max = OrdinaryDiffEq.qsteady_max_default(alg.alg), + qmin = OrdinaryDiffEqCore.qmin_default(alg.alg), + qmax = OrdinaryDiffEqCore.qmax_default(alg.alg), + qsteady_min = OrdinaryDiffEqCore.qsteady_min_default(alg.alg), + qsteady_max = OrdinaryDiffEqCore.qsteady_max_default(alg.alg), qoldinit = DiffEqBase.isadaptive(alg) ? 1 // 10^4 : 0, controller = nothing, fullnormalize = true, @@ -59,7 +59,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, progress_message = DiffEqBase.ODE_DEFAULT_PROG_MESSAGE, progress_id = :DelayDiffEq, userdata = nothing, - allow_extrapolation = OrdinaryDiffEq.alg_extrapolates(alg), + allow_extrapolation = OrdinaryDiffEqCore.alg_extrapolates(alg), initialize_integrator = true, alias_u0 = false, # keyword arguments for DDEs @@ -77,7 +77,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, if alg.alg isa CompositeAlgorithm && alg.alg.choice_function isa AutoSwitch auto = alg.alg.choice_function alg = MethodOfSteps(CompositeAlgorithm(alg.alg.algs, - OrdinaryDiffEq.AutoSwitchCache(0, 0, + OrdinaryDiffEqCore.AutoSwitchCache(0, 0, auto.nonstiffalg, auto.stiffalg, auto.stiffalgfirst, @@ -139,7 +139,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # get the differential vs algebraic variables differential_vars = prob isa DAEProblem ? prob.differential_vars : - OrdinaryDiffEq.get_differential_vars(f, u) + OrdinaryDiffEqCore.get_differential_vars(f, u) # create a history function history = build_history_function(prob, alg, rate_prototype, reltol_internal, @@ -159,7 +159,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # build cache ode_integrator = history.integrator - cache = OrdinaryDiffEq.alg_cache(alg.alg, u, rate_prototype, uEltypeNoUnits, + cache = OrdinaryDiffEqCore.alg_cache(alg.alg, u, rate_prototype, uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f_with_history, t0, zero(tType), reltol_internal, p, calck, @@ -170,7 +170,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # create solution alg_choice = iscomposite(alg) ? Int[] : nothing - id = OrdinaryDiffEq.InterpolationData(f_with_history, timeseries, ts, ks, + id = OrdinaryDiffEqCore.InterpolationData(f_with_history, timeseries, ts, ks, alg_choice, dense, cache, differential_vars, false) sol = DiffEqBase.build_solution(prob, alg.alg, ts, timeseries; dense = dense, k = ks, interp = id, @@ -178,10 +178,10 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, stats = stats) # retrieve time stops, time points at which solutions is saved, and discontinuities - tstops_internal = OrdinaryDiffEq.initialize_tstops(tType, tstops, d_discontinuities, + tstops_internal = OrdinaryDiffEqCore.initialize_tstops(tType, tstops, d_discontinuities, tspan) - saveat_internal = OrdinaryDiffEq.initialize_saveat(tType, saveat, tspan) - d_discontinuities_internal = OrdinaryDiffEq.initialize_d_discontinuities( + saveat_internal = OrdinaryDiffEqCore.initialize_saveat(tType, saveat, tspan) + d_discontinuities_internal = OrdinaryDiffEqCore.initialize_d_discontinuities( Discontinuity{ tType, Int @@ -189,7 +189,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, d_discontinuities, tspan) - maximum_order = OrdinaryDiffEq.alg_maximum_order(alg) + maximum_order = OrdinaryDiffEqCore.alg_maximum_order(alg) tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated( tType, tstops, @@ -232,7 +232,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, end if controller === nothing - controller = OrdinaryDiffEq.default_controller(alg.alg, cache, + controller = OrdinaryDiffEqCore.default_controller(alg.alg, cache, convert(QT, qoldinit)::QT, beta1, beta2) end @@ -242,9 +242,9 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, save_everystep || isempty(saveat) || saveat isa Number || prob.tspan[2] in saveat : save_end - # added in OrdinaryDiffEq.jl#2032 - if hasfield(OrdinaryDiffEq.DEOptions, :progress_id) - opts = OrdinaryDiffEq.DEOptions{typeof(abstol_internal), typeof(reltol_internal), + # added in OrdinaryDiffEqCore.jl#2032 + if hasfield(OrdinaryDiffEqCore.DEOptions, :progress_id) + opts = OrdinaryDiffEqCore.DEOptions{typeof(abstol_internal), typeof(reltol_internal), QT, tType, typeof(controller), typeof(internalnorm), typeof(internalopnorm), typeof(save_end_user), @@ -301,7 +301,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, advance_to_tstop, stop_at_next_tstop) else - opts = OrdinaryDiffEq.DEOptions{typeof(abstol_internal), typeof(reltol_internal), + opts = OrdinaryDiffEqCore.DEOptions{typeof(abstol_internal), typeof(reltol_internal), QT, tType, typeof(controller), typeof(internalnorm), typeof(internalopnorm), typeof(save_end_user), @@ -390,14 +390,14 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, event_last_time = 0 vector_event_last_time = 1 last_event_error = zero(uBottomEltypeNoUnits) - dtchangeable = OrdinaryDiffEq.isdtchangeable(alg.alg) + dtchangeable = OrdinaryDiffEqCore.isdtchangeable(alg.alg) q11 = QT(1) success_iter = 0 erracc = QT(1) dtacc = tType(1) - if isdefined(OrdinaryDiffEq, :get_fsalfirstlast) - fsalfirst, fsallast = OrdinaryDiffEq.get_fsalfirstlast(cache, rate_prototype) + if isdefined(OrdinaryDiffEqCore, :get_fsalfirstlast) + fsalfirst, fsallast = OrdinaryDiffEqCore.get_fsalfirstlast(cache, rate_prototype) integrator = DDEIntegrator{typeof(alg.alg), isinplace(prob), typeof(u0), tType, typeof(p), typeof(eigen_est), QT, typeof(tdir), typeof(k), typeof(sol), @@ -472,7 +472,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, typeof(discontinuity_reltol), typeof(history), typeof(tstops_propagated), typeof(d_discontinuities_propagated), - OrdinaryDiffEq.fsal_typeof(alg.alg, rate_prototype), + OrdinaryDiffEqCore.fsal_typeof(alg.alg, rate_prototype), typeof(last_event_error), typeof(callback_cache), typeof(differential_vars)}(sol, u, k, t0, @@ -532,12 +532,12 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # initialize DDE integrator if initialize_integrator initialize_solution!(integrator) - OrdinaryDiffEq.initialize_callbacks!(integrator, initialize_save) - OrdinaryDiffEq.initialize!(integrator) + OrdinaryDiffEqCore.initialize_callbacks!(integrator, initialize_save) + OrdinaryDiffEqCore.initialize!(integrator) end # take care of time step dt = 0 and dt with incorrect sign - OrdinaryDiffEq.handle_dt!(integrator) + OrdinaryDiffEqCore.handle_dt!(integrator) integrator end @@ -550,23 +550,23 @@ function DiffEqBase.solve!(integrator::DDEIntegrator) @inbounds while !isempty(tstops) while tdir * integrator.t < first(tstops) # apply step or adapt step size - OrdinaryDiffEq.loopheader!(integrator) + OrdinaryDiffEqCore.loopheader!(integrator) # abort integration following same criteria as for ODEs: # maxiters exceeded, dt <= dtmin, integration unstable DiffEqBase.check_error!(integrator) == ReturnCode.Success || return sol # calculate next step - OrdinaryDiffEq.perform_step!(integrator) + OrdinaryDiffEqCore.perform_step!(integrator) # calculate proposed next step size, handle callbacks, and update solution - OrdinaryDiffEq.loopfooter!(integrator) + OrdinaryDiffEqCore.loopfooter!(integrator) isempty(tstops) && break end # remove hit or passed stopping time points - OrdinaryDiffEq.handle_tstop!(integrator) + OrdinaryDiffEqCore.handle_tstop!(integrator) end # clean up solution @@ -584,7 +584,7 @@ function DiffEqBase.solve!(integrator::DDEIntegrator) integrator.sol = DiffEqBase.solution_new_retcode(sol, ReturnCode.Success) end -function OrdinaryDiffEq.initialize_callbacks!(integrator::DDEIntegrator, +function OrdinaryDiffEqCore.initialize_callbacks!(integrator::DDEIntegrator, initialize_save = true) callbacks = integrator.opts.callback prob = integrator.sol.prob @@ -605,7 +605,7 @@ function OrdinaryDiffEq.initialize_callbacks!(integrator::DDEIntegrator, integrator.uprev = integrator.u end - if OrdinaryDiffEq.alg_extrapolates(integrator.alg) + if OrdinaryDiffEqCore.alg_extrapolates(integrator.alg) if isinplace(prob) recursivecopy!(integrator.uprev2, integrator.uprev) else