From 2694bedf2cd1619c4a57fdcd27afb71760a289aa Mon Sep 17 00:00:00 2001 From: Lilith Orion Hafner Date: Wed, 14 Feb 2024 11:39:58 -0600 Subject: [PATCH] Run JuliaFormatter.format() Using JuliaFormatter v1.0.47 --- src/alg_utils.jl | 4 +- src/fpsolve/functional.jl | 28 +- src/fpsolve/utils.jl | 29 +- src/functionwrapper.jl | 28 +- src/history_function.jl | 4 +- src/integrators/interface.jl | 111 ++--- src/integrators/type.jl | 148 +++---- src/integrators/utils.jl | 14 +- src/interpolants.jl | 4 +- src/solve.jl | 595 ++++++++++++++------------- src/track.jl | 13 +- src/utils.jl | 89 ++-- test/integrators/cache.jl | 2 +- test/integrators/events.jl | 4 +- test/integrators/iterator.jl | 10 +- test/integrators/residual_control.jl | 2 +- test/integrators/retcode.jl | 2 +- test/integrators/verner.jl | 8 +- test/interface/ad.jl | 12 +- test/interface/composite_solution.jl | 4 +- test/interface/discontinuities.jl | 14 +- test/interface/fpsolve.jl | 2 +- test/interface/history_function.jl | 6 +- test/interface/mass_matrix.jl | 23 +- test/interface/parameters.jl | 8 +- test/interface/save_idxs.jl | 4 +- test/interface/saveat.jl | 15 +- test/interface/unconstrained.jl | 8 +- test/interface/units.jl | 21 +- test/regression/waltman.jl | 9 +- test/runtests.jl | 112 +++-- 31 files changed, 703 insertions(+), 630 deletions(-) diff --git a/src/alg_utils.jl b/src/alg_utils.jl index 2ab8e18d..10da692a 100644 --- a/src/alg_utils.jl +++ b/src/alg_utils.jl @@ -73,6 +73,6 @@ iscomposite(alg::AbstractMethodOfStepsAlgorithm) = iscomposite(alg.alg) function DiffEqBase.prepare_alg(alg::MethodOfSteps, u0, p, prob) MethodOfSteps(DiffEqBase.prepare_alg(alg.alg, u0, p, prob); - constrained = isconstrained(alg), - fpsolve = alg.fpsolve) + constrained = isconstrained(alg), + fpsolve = alg.fpsolve) end diff --git a/src/fpsolve/functional.jl b/src/fpsolve/functional.jl index 0454922a..d5d7b16b 100644 --- a/src/fpsolve/functional.jl +++ b/src/fpsolve/functional.jl @@ -1,5 +1,5 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLFunctional}, - integrator::DDEIntegrator) + integrator::DDEIntegrator) # update ODE integrator to next time interval together with correct interpolation if fpsolver.iter == 1 advance_ode_integrator!(integrator) @@ -11,7 +11,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLFunctional}, end function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, - integrator::DDEIntegrator) + integrator::DDEIntegrator) @unpack cache, iter = fpsolver @unpack aa_start = cache @@ -40,7 +40,7 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, false}, end function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, true}, - integrator::DDEIntegrator) + integrator::DDEIntegrator) @unpack cache, iter = fpsolver @unpack aa_start = cache @@ -68,9 +68,10 @@ function OrdinaryDiffEq.compute_step!(fpsolver::FPSolver{<:NLAnderson, true}, compute_step_fixedpoint!(fpsolver, integrator) end -function compute_step_fixedpoint!(fpsolver::FPSolver{<:Union{NLFunctional, NLAnderson}, - false}, - integrator::DDEIntegrator) +function compute_step_fixedpoint!( + fpsolver::FPSolver{<:Union{NLFunctional, NLAnderson}, + false}, + integrator::DDEIntegrator) @unpack t, opts = integrator @unpack cache = fpsolver ode_integrator = integrator.integrator @@ -81,8 +82,8 @@ function compute_step_fixedpoint!(fpsolver::FPSolver{<:Union{NLFunctional, NLAnd # compute residuals dz = integrator.u .- ode_integrator.u atmp = OrdinaryDiffEq.calculate_residuals(dz, ode_integrator.u, integrator.u, - opts.abstol, opts.reltol, opts.internalnorm, - t) + opts.abstol, opts.reltol, opts.internalnorm, + t) # cache results if isdefined(cache, :dz) @@ -92,9 +93,10 @@ function compute_step_fixedpoint!(fpsolver::FPSolver{<:Union{NLFunctional, NLAnd opts.internalnorm(atmp, t) end -function compute_step_fixedpoint!(fpsolver::FPSolver{<:Union{NLFunctional, NLAnderson}, - true}, - integrator::DDEIntegrator) +function compute_step_fixedpoint!( + fpsolver::FPSolver{<:Union{NLFunctional, NLAnderson}, + true}, + integrator::DDEIntegrator) @unpack t, opts = integrator @unpack cache = fpsolver @unpack dz, atmp = cache @@ -106,7 +108,7 @@ function compute_step_fixedpoint!(fpsolver::FPSolver{<:Union{NLFunctional, NLAnd # compute residuals @.. dz = integrator.u - ode_integrator.u OrdinaryDiffEq.calculate_residuals!(atmp, dz, ode_integrator.u, integrator.u, - opts.abstol, opts.reltol, opts.internalnorm, t) + opts.abstol, opts.reltol, opts.internalnorm, t) opts.internalnorm(atmp, t) end @@ -120,7 +122,7 @@ function Base.resize!(fpcache::FPFunctionalCache, i::Int) end function Base.resize!(fpcache::FPAndersonCache, fpsolver::FPSolver{<:NLAnderson}, - integrator::DDEIntegrator, i::Int) + integrator::DDEIntegrator, i::Int) resize!(fpcache, fpsolver.alg, i) end diff --git a/src/fpsolve/utils.jl b/src/fpsolve/utils.jl index 1b2660f3..da4519f2 100644 --- a/src/fpsolve/utils.jl +++ b/src/fpsolve/utils.jl @@ -1,6 +1,6 @@ # construct solver for fixed-point iterations function build_fpsolver(alg, fpalg::Union{NLFunctional, NLAnderson}, u, uEltypeNoUnits, - uBottomEltypeNoUnits, ::Val{true}) + uBottomEltypeNoUnits, ::Val{true}) # no fixed-point iterations if the algorithm is constrained isconstrained(alg) && return @@ -24,22 +24,23 @@ function build_fpsolver(alg, fpalg::Union{NLFunctional, NLAnderson}, u, uEltypeN dzold = zero(u) z₊old = zero(u) - fpcache = FPAndersonCache(atmp, dz, dzold, z₊old, Δz₊s, Q, R, γs, 0, fpalg.aa_start, - fpalg.droptol) + fpcache = FPAndersonCache( + atmp, dz, dzold, z₊old, Δz₊s, Q, R, γs, 0, fpalg.aa_start, + fpalg.droptol) end # build solver ηold = one(uTolType) FPSolver{typeof(fpalg), true, uTolType, typeof(fpcache)}(fpalg, uTolType(fpalg.κ), - uTolType(fpalg.fast_convergence_cutoff), - ηold, 10000, - fpalg.max_iter, - SlowConvergence, fpcache, 0) + uTolType(fpalg.fast_convergence_cutoff), + ηold, 10000, + fpalg.max_iter, + SlowConvergence, fpcache, 0) end function build_fpsolver(alg, fpalg::Union{NLFunctional, NLAnderson}, u, uEltypeNoUnits, - uBottomEltypeNoUnits, ::Val{false}) + uBottomEltypeNoUnits, ::Val{false}) # no fixed-point iterations if the algorithm is constrained isconstrained(alg) && return @@ -61,18 +62,18 @@ function build_fpsolver(alg, fpalg::Union{NLFunctional, NLAnderson}, u, uEltypeN z₊old = u fpcache = FPAndersonConstantCache(dz, dzold, z₊old, Δz₊s, Q, R, γs, 0, - fpalg.aa_start, - fpalg.droptol) + fpalg.aa_start, + fpalg.droptol) end # build solver ηold = one(uTolType) FPSolver{typeof(fpalg), false, uTolType, typeof(fpcache)}(fpalg, uTolType(fpalg.κ), - uTolType(fpalg.fast_convergence_cutoff), - ηold, 10_000, - fpalg.max_iter, - SlowConvergence, fpcache, 0) + uTolType(fpalg.fast_convergence_cutoff), + ηold, 10_000, + fpalg.max_iter, + SlowConvergence, fpcache, 0) end ## resize diff --git a/src/functionwrapper.jl b/src/functionwrapper.jl index cb84c521..0e97e120 100644 --- a/src/functionwrapper.jl +++ b/src/functionwrapper.jl @@ -48,20 +48,20 @@ function ODEFunctionWrapper(f::DiffEqBase.AbstractDDEFunction, h) Wfact_t = @wrap_h Wfact_t(W, u, h, p, dtgamma, t) ODEFunctionWrapper{isinplace(f), typeof(f.f), typeof(h), typeof(f.mass_matrix), - typeof(f.analytic), typeof(f.tgrad), typeof(jac), - typeof(f.jac_prototype), typeof(f.sparsity), - typeof(Wfact), typeof(Wfact_t), - typeof(f.paramjac), typeof(f.sys), typeof(f.colorvec)}(f.f, h, - f.mass_matrix, - f.analytic, - f.tgrad, jac, - f.jac_prototype, - f.sparsity, - Wfact, - Wfact_t, - f.paramjac, - f.sys, - f.colorvec) + typeof(f.analytic), typeof(f.tgrad), typeof(jac), + typeof(f.jac_prototype), typeof(f.sparsity), + typeof(Wfact), typeof(Wfact_t), + typeof(f.paramjac), typeof(f.sys), typeof(f.colorvec)}(f.f, h, + f.mass_matrix, + f.analytic, + f.tgrad, jac, + f.jac_prototype, + f.sparsity, + Wfact, + Wfact_t, + f.paramjac, + f.sys, + f.colorvec) end (f::ODEFunctionWrapper{true})(du, u, p, t) = f.f(du, u, f.h, p, t) diff --git a/src/history_function.jl b/src/history_function.jl index fc528772..8a7ed24c 100644 --- a/src/history_function.jl +++ b/src/history_function.jl @@ -18,7 +18,7 @@ end HistoryFunction(h, integrator) = HistoryFunction(h, integrator, false) function (f::HistoryFunction)(p, t, ::Type{Val{deriv}} = Val{0}; - idxs = nothing) where {deriv} + idxs = nothing) where {deriv} @unpack integrator = f @unpack tdir, sol = integrator @@ -56,7 +56,7 @@ function (f::HistoryFunction)(p, t, ::Type{Val{deriv}} = Val{0}; end function (f::HistoryFunction)(val, p, t, ::Type{Val{deriv}} = Val{0}; - idxs = nothing) where {deriv} + idxs = nothing) where {deriv} @unpack integrator = f @unpack tdir, sol = integrator diff --git a/src/integrators/interface.jl b/src/integrators/interface.jl index b451149f..edd016f5 100644 --- a/src/integrators/interface.jl +++ b/src/integrators/interface.jl @@ -18,7 +18,7 @@ end # save current state of the integrator function DiffEqBase.savevalues!(integrator::HistoryODEIntegrator, force_save = false, - reduce_size = false)::Tuple{Bool, Bool} + reduce_size = false)::Tuple{Bool, Bool} integrator.saveiter += 1 # TODO: save history only for a subset of components copyat_or_push!(integrator.sol.t, integrator.saveiter, integrator.t) @@ -29,14 +29,14 @@ function DiffEqBase.savevalues!(integrator::HistoryODEIntegrator, force_save = f if iscomposite(integrator.alg) copyat_or_push!(integrator.sol.alg_choice, integrator.saveiter, - integrator.cache.current) + integrator.cache.current) end true, true end function DiffEqBase.savevalues!(integrator::DDEIntegrator, force_save = false, - reduce_size = false)::Tuple{Bool, Bool} + reduce_size = false)::Tuple{Bool, Bool} ode_integrator = integrator.integrator # update time of ODE integrator (can be slightly modified (< 10ϵ) because of time stops) @@ -62,7 +62,7 @@ function DiffEqBase.savevalues!(integrator::DDEIntegrator, force_save = false, # update history saved, savedexactly = DiffEqBase.savevalues!(ode_integrator, force_save, - false) # reduce_size = false + false) # reduce_size = false # check that history was actually updated saved || error("dense history could not be updated") @@ -95,7 +95,7 @@ function DiffEqBase.postamble!(integrator::HistoryODEIntegrator) if iscomposite(integrator.alg) copyat_or_push!(integrator.sol.alg_choice, integrator.saveiter, - integrator.cache.current) + integrator.cache.current) end end @@ -200,7 +200,7 @@ end DiffEqBase.resize_non_user_cache!(integrator::DDEIntegrator, cache, i) = nothing function DiffEqBase.resize_non_user_cache!(integrator::DDEIntegrator, - cache::RosenbrockMutableCache, i) + 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) @@ -267,9 +267,9 @@ DiffEqBase.has_reinit(::HistoryODEIntegrator) = true DiffEqBase.has_reinit(integrator::DDEIntegrator) = true function DiffEqBase.reinit!(integrator::HistoryODEIntegrator, u0 = integrator.sol.prob.u0; - t0 = integrator.sol.prob.tspan[1], - tf = integrator.sol.prob.tspan[end], - erase_sol = true) + t0 = integrator.sol.prob.tspan[1], + tf = integrator.sol.prob.tspan[end], + erase_sol = true) # reinit initial values of the integrator if isinplace(integrator.sol.prob) recursivecopy!(integrator.u, u0) @@ -314,19 +314,19 @@ Reinitialize `integrator` with (optionally) different initial state `u0`, differ integration interval from `t0` to `tf`, and erased solution if `erase_sol = true`. """ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob.u0; - t0 = integrator.sol.prob.tspan[1], - tf = integrator.sol.prob.tspan[end], - erase_sol = true, - tstops = integrator.opts.tstops_cache, - saveat = integrator.opts.saveat_cache, - d_discontinuities = integrator.opts.d_discontinuities_cache, - order_discontinuity_t0 = t0 == integrator.sol.prob.tspan[1] && - u0 == integrator.sol.prob.u0 ? - integrator.order_discontinuity_t0 : 0, - reset_dt = iszero(integrator.dtcache) && - integrator.opts.adaptive, - reinit_callbacks = true, initialize_save = true, - reinit_cache = true) + t0 = integrator.sol.prob.tspan[1], + tf = integrator.sol.prob.tspan[end], + erase_sol = true, + tstops = integrator.opts.tstops_cache, + saveat = integrator.opts.saveat_cache, + d_discontinuities = integrator.opts.d_discontinuities_cache, + order_discontinuity_t0 = t0 == integrator.sol.prob.tspan[1] && + u0 == integrator.sol.prob.u0 ? + integrator.order_discontinuity_t0 : 0, + reset_dt = iszero(integrator.dtcache) && + integrator.opts.adaptive, + reinit_callbacks = true, initialize_save = true, + reinit_cache = true) # reinit history reinit!(integrator.integrator, u0; t0 = t0, tf = tf, erase_sol = true) @@ -353,26 +353,28 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. tType = typeof(integrator.t) tspan = (tType(t0), tType(tf)) integrator.opts.tstops = OrdinaryDiffEq.initialize_tstops(tType, tstops, - d_discontinuities, tspan) + d_discontinuities, tspan) integrator.opts.saveat = OrdinaryDiffEq.initialize_saveat(tType, saveat, tspan) - integrator.opts.d_discontinuities = OrdinaryDiffEq.initialize_d_discontinuities(Discontinuity{ - tType, - Int - }, - d_discontinuities, - tspan) + integrator.opts.d_discontinuities = OrdinaryDiffEq.initialize_d_discontinuities( + Discontinuity{ + tType, + Int + }, + d_discontinuities, + tspan) # update order of initial discontinuity and propagated discontinuities integrator.order_discontinuity_t0 = order_discontinuity_t0 maximum_order = OrdinaryDiffEq.alg_maximum_order(integrator.alg) - tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated(tType, - tstops, - d_discontinuities, - tspan, - order_discontinuity_t0, - maximum_order, - integrator.sol.prob.constant_lags, - integrator.sol.prob.neutral) + tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated( + tType, + tstops, + d_discontinuities, + tspan, + order_discontinuity_t0, + maximum_order, + integrator.sol.prob.constant_lags, + integrator.sol.prob.neutral) integrator.tstops_propagated = tstops_propagated integrator.d_discontinuities_propagated = d_discontinuities_propagated @@ -406,9 +408,10 @@ function DiffEqBase.reinit!(integrator::DDEIntegrator, u0 = integrator.sol.prob. # erase array of tracked discontinuities if order_discontinuity_t0 ≤ OrdinaryDiffEq.alg_maximum_order(integrator.alg) resize!(integrator.tracked_discontinuities, 1) - integrator.tracked_discontinuities[1] = Discontinuity(integrator.tdir * - integrator.t, - order_discontinuity_t0) + integrator.tracked_discontinuities[1] = Discontinuity( + integrator.tdir * + integrator.t, + order_discontinuity_t0) else resize!(integrator.tracked_discontinuities, 0) end @@ -459,8 +462,8 @@ 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, - opts.reltol, opts.internalnorm, - ode_prob, integrator) + opts.reltol, opts.internalnorm, + ode_prob, integrator) # update statistics stats.nf += 2 @@ -505,12 +508,12 @@ function DiffEqBase.addsteps!(integrator::DDEIntegrator, args...) end function DiffEqBase.change_t_via_interpolation!(integrator::DDEIntegrator, - t, - modify_save_endpoint::Type{Val{T}} = Val{ - false - }) where { - T - } + t, + modify_save_endpoint::Type{Val{T}} = Val{ + false + }) where { + T +} OrdinaryDiffEq._change_t_via_interpolation!(integrator, t, modify_save_endpoint) end @@ -521,16 +524,16 @@ function OrdinaryDiffEq.handle_callback_modifiers!(integrator::DDEIntegrator) # update heap of discontinuities # discontinuity is assumed to be of order 0, i.e. solution x is discontinuous push!(integrator.opts.d_discontinuities, - Discontinuity(integrator.tdir * integrator.t, 0)) + Discontinuity(integrator.tdir * integrator.t, 0)) end # recalculate interpolation data and update the ODE integrator function DiffEqBase.reeval_internals_due_to_modification!(integrator::DDEIntegrator, - x::Type{Val{not_initialization}} = Val{ - true - }) where { - not_initialization - } + x::Type{Val{not_initialization}} = Val{ + true + }) where { + not_initialization +} ode_integrator = integrator.integrator if not_initialization diff --git a/src/integrators/type.jl b/src/integrators/type.jl index 35eec41a..c11c6794 100644 --- a/src/integrators/type.jl +++ b/src/integrators/type.jl @@ -1,5 +1,6 @@ -mutable struct HistoryODEIntegrator{algType, IIP, uType, tType, tdirType, ksEltype, SolType, - CacheType, DV} <: +mutable struct HistoryODEIntegrator{ + algType, IIP, uType, tType, tdirType, ksEltype, SolType, + CacheType, DV} <: AbstractODEIntegrator{algType, IIP, uType, tType} sol::SolType u::uType @@ -22,17 +23,17 @@ function (integrator::HistoryODEIntegrator)(t, deriv::Type = Val{0}; idxs = noth end function (integrator::HistoryODEIntegrator)(val::AbstractArray, - t::Union{Number, AbstractArray}, - deriv::Type = Val{0}; idxs = nothing) + t::Union{Number, AbstractArray}, + deriv::Type = Val{0}; idxs = nothing) OrdinaryDiffEq.current_interpolant!(val, t, integrator, idxs, deriv) end mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, - tdirType, - ksEltype, SolType, F, CacheType, IType, FP, O, dAbsType, - dRelType, H, - tstopsType, discType, FSALType, EventErrorType, - CallbackCacheType, DV} <: + tdirType, + ksEltype, SolType, F, CacheType, IType, FP, O, dAbsType, + dRelType, H, + tstopsType, discType, FSALType, EventErrorType, + CallbackCacheType, DV} <: AbstractDDEIntegrator{algType, IIP, uType, tType} sol::SolType u::uType @@ -97,72 +98,73 @@ mutable struct DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUn # incomplete initialization without fsalfirst and fsallast function DDEIntegrator{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, - tdirType, ksEltype, SolType, F, CacheType, IType, FP, - O, dAbsType, dRelType, H, tstopsType, discType, - FSALType, EventErrorType, CallbackCacheType, DV}(sol, u, k, t, dt, f, - p, uprev, uprev2, - tprev, prev_idx, - prev2_idx, - fpsolver, - order_discontinuity_t0, - tracked_discontinuities, - discontinuity_interp_points, - discontinuity_abstol, - discontinuity_reltol, - tstops_propagated, - d_discontinuities_propagated, - alg, dtcache, - dtchangeable, - dtpropose, tdir, - eigen_est, EEst, - qold, - q11, erracc, dtacc, - success_iter, iter, - saveiter, - saveiter_dense, - cache, - callback_cache, - kshortsize, - force_stepfail, - last_stepfail, - just_hit_tstop, - do_error_check, - event_last_time, - vector_event_last_time, - last_event_error, - accept_step, isout, - reeval_fsal, - u_modified, isdae, - opts, stats, - history, - differential_vars, - integrator) where - {algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, tdirType, ksEltype, - SolType, F, - CacheType, IType, FP, O, dAbsType, dRelType, H, tstopsType, discType, - FSALType, EventErrorType, CallbackCacheType, DV} + tdirType, ksEltype, SolType, F, CacheType, IType, FP, + O, dAbsType, dRelType, H, tstopsType, discType, + FSALType, EventErrorType, CallbackCacheType, DV}(sol, u, k, t, dt, f, + p, uprev, uprev2, + tprev, prev_idx, + prev2_idx, + fpsolver, + order_discontinuity_t0, + tracked_discontinuities, + discontinuity_interp_points, + discontinuity_abstol, + discontinuity_reltol, + tstops_propagated, + d_discontinuities_propagated, + alg, dtcache, + dtchangeable, + dtpropose, tdir, + eigen_est, EEst, + qold, + q11, erracc, dtacc, + success_iter, iter, + saveiter, + saveiter_dense, + cache, + callback_cache, + kshortsize, + force_stepfail, + last_stepfail, + just_hit_tstop, + do_error_check, + event_last_time, + vector_event_last_time, + last_event_error, + accept_step, isout, + reeval_fsal, + u_modified, isdae, + opts, stats, + history, + differential_vars, + integrator) where + {algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, tdirType, ksEltype, + SolType, F, + CacheType, IType, FP, O, dAbsType, dRelType, H, tstopsType, discType, + FSALType, EventErrorType, CallbackCacheType, DV} new{algType, IIP, uType, tType, P, eigenType, tTypeNoUnits, tdirType, ksEltype, SolType, F, CacheType, IType, FP, O, dAbsType, dRelType, H, tstopsType, discType, FSALType, - EventErrorType, CallbackCacheType, DV}(sol, u, k, t, dt, f, p, uprev, uprev2, tprev, - prev_idx, prev2_idx, fpsolver, - order_discontinuity_t0, - tracked_discontinuities, - discontinuity_interp_points, - discontinuity_abstol, discontinuity_reltol, - tstops_propagated, - d_discontinuities_propagated, alg, dtcache, - dtchangeable, dtpropose, tdir, - eigen_est, EEst, qold, q11, erracc, dtacc, - success_iter, iter, saveiter, saveiter_dense, - cache, callback_cache, kshortsize, - force_stepfail, last_stepfail, - just_hit_tstop, - do_error_check, event_last_time, - vector_event_last_time, - last_event_error, accept_step, isout, - reeval_fsal, u_modified, isdae, opts, - stats, history, differential_vars, integrator) + EventErrorType, CallbackCacheType, DV}( + sol, u, k, t, dt, f, p, uprev, uprev2, tprev, + prev_idx, prev2_idx, fpsolver, + order_discontinuity_t0, + tracked_discontinuities, + discontinuity_interp_points, + discontinuity_abstol, discontinuity_reltol, + tstops_propagated, + d_discontinuities_propagated, alg, dtcache, + dtchangeable, dtpropose, tdir, + eigen_est, EEst, qold, q11, erracc, dtacc, + success_iter, iter, saveiter, saveiter_dense, + cache, callback_cache, kshortsize, + force_stepfail, last_stepfail, + just_hit_tstop, + do_error_check, event_last_time, + vector_event_last_time, + last_event_error, accept_step, isout, + reeval_fsal, u_modified, isdae, opts, + stats, history, differential_vars, integrator) end end @@ -171,6 +173,6 @@ function (integrator::DDEIntegrator)(t, deriv::Type = Val{0}; idxs = nothing) end function (integrator::DDEIntegrator)(val::AbstractArray, t::Union{Number, AbstractArray}, - deriv::Type = Val{0}; idxs = nothing) + deriv::Type = Val{0}; idxs = nothing) OrdinaryDiffEq.current_interpolant!(val, t, integrator, idxs, deriv) end diff --git a/src/integrators/utils.jl b/src/integrators/utils.jl index f358da63..324f04c8 100644 --- a/src/integrators/utils.jl +++ b/src/integrators/utils.jl @@ -36,10 +36,10 @@ function advance_ode_integrator!(integrator::DDEIntegrator, always_calc_begin = # is incorrect if iscomposite(alg) _ode_addsteps!(k, t, uprev, u, dt, f, p, cache.caches[cache.current], - always_calc_begin, true, true) + always_calc_begin, true, true) else _ode_addsteps!(k, t, uprev, u, dt, f, p, cache, always_calc_begin, - true, true) + true, true) end @inbounds for i in 1:length(k) copyat_or_push!(ode_integrator.k, i, k[i]) @@ -83,10 +83,10 @@ function update_ode_integrator!(integrator::DDEIntegrator, always_calc_begin = f if iscomposite(alg) _ode_addsteps!(k, t, uprev, u, dt, f, p, cache.caches[cache.current], - always_calc_begin, true, true) + always_calc_begin, true, true) else _ode_addsteps!(k, t, uprev, u, dt, f, p, cache, - always_calc_begin, true, true) + always_calc_begin, true, true) end @inbounds for i in 1:length(k) copyat_or_push!(ode_integrator.k, i, k[i]) @@ -245,15 +245,15 @@ end function OrdinaryDiffEq.has_discontinuity(integrator::DDEIntegrator) return _has(integrator.opts.d_discontinuities, - integrator.d_discontinuities_propagated) + integrator.d_discontinuities_propagated) end function OrdinaryDiffEq.first_discontinuity(integrator::DDEIntegrator) return _first(integrator.opts.d_discontinuities, - integrator.d_discontinuities_propagated) + integrator.d_discontinuities_propagated) end function OrdinaryDiffEq.pop_discontinuity!(integrator::DDEIntegrator) return _pop!(integrator.opts.d_discontinuities, - integrator.d_discontinuities_propagated) + integrator.d_discontinuities_propagated) end _has(x, y) = !isempty(x) || !isempty(y) diff --git a/src/interpolants.jl b/src/interpolants.jl index 45c5b43a..deac1c9f 100644 --- a/src/interpolants.jl +++ b/src/interpolants.jl @@ -28,7 +28,7 @@ function constant_extrapolant!(val, t, integrator::DEIntegrator, idxs, deriv) end function constant_extrapolant!(val, t::Number, integrator::DEIntegrator, idxs, - T::Type{Val{0}}) + T::Type{Val{0}}) if val === nothing if idxs === nothing return integrator.u @@ -43,7 +43,7 @@ function constant_extrapolant!(val, t::Number, integrator::DEIntegrator, idxs, end function constant_extrapolant!(val, t::Number, integrator::DEIntegrator, idxs, - T::Type{Val{1}}) + T::Type{Val{1}}) if val === nothing if idxs === nothing return zero(integrator.u) ./ oneunit(t) diff --git a/src/solve.jl b/src/solve.jl index 13785707..319e3528 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -1,72 +1,72 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractDDEProblem, - alg::AbstractMethodOfStepsAlgorithm, args...; - kwargs...) + alg::AbstractMethodOfStepsAlgorithm, args...; + kwargs...) integrator = DiffEqBase.__init(prob, alg, args...; kwargs...) DiffEqBase.solve!(integrator) integrator.sol end function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, - alg::AbstractMethodOfStepsAlgorithm, - timeseries_init = (), - ts_init = (), - ks_init = (); - saveat = (), - tstops = (), - d_discontinuities = (), - save_idxs = nothing, - save_everystep = isempty(saveat), - save_on = true, - save_start = save_everystep || isempty(saveat) || - saveat isa Number || prob.tspan[1] in saveat, - save_end = nothing, - callback = nothing, - dense = save_everystep && isempty(saveat), - calck = (callback !== nothing && callback != CallbackSet()) || # Empty callback - dense, # and no dense output - dt = zero(eltype(prob.tspan)), - dtmin = DiffEqBase.prob2dtmin(prob; use_end_time = false), - dtmax = eltype(prob.tspan)(prob.tspan[end] - prob.tspan[1]), - force_dtmin = false, - adaptive = DiffEqBase.isadaptive(alg), - gamma = OrdinaryDiffEq.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), - qoldinit = DiffEqBase.isadaptive(alg) ? 1 // 10^4 : 0, - controller = nothing, - fullnormalize = true, - failfactor = 2, - beta1 = nothing, - beta2 = nothing, - maxiters = adaptive ? 1000000 : typemax(Int), - internalnorm = DiffEqBase.ODE_DEFAULT_NORM, - internalopnorm = LinearAlgebra.opnorm, - isoutofdomain = DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN, - unstable_check = DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK, - verbose = true, - timeseries_errors = true, - dense_errors = false, - advance_to_tstop = false, - stop_at_next_tstop = false, - initialize_save = true, - progress = false, - progress_steps = 1000, - progress_name = "DDE", - progress_message = DiffEqBase.ODE_DEFAULT_PROG_MESSAGE, - progress_id = gensym("DelayDiffEq"), - userdata = nothing, - allow_extrapolation = OrdinaryDiffEq.alg_extrapolates(alg), - initialize_integrator = true, - alias_u0 = false, - # keyword arguments for DDEs - discontinuity_interp_points::Int = 10, - discontinuity_abstol = eltype(prob.tspan)(1 // Int64(10)^12), - discontinuity_reltol = 0, - kwargs...) + alg::AbstractMethodOfStepsAlgorithm, + timeseries_init = (), + ts_init = (), + ks_init = (); + saveat = (), + tstops = (), + d_discontinuities = (), + save_idxs = nothing, + save_everystep = isempty(saveat), + save_on = true, + save_start = save_everystep || isempty(saveat) || + saveat isa Number || prob.tspan[1] in saveat, + save_end = nothing, + callback = nothing, + dense = save_everystep && isempty(saveat), + calck = (callback !== nothing && callback != CallbackSet()) || # Empty callback + dense, # and no dense output + dt = zero(eltype(prob.tspan)), + dtmin = DiffEqBase.prob2dtmin(prob; use_end_time = false), + dtmax = eltype(prob.tspan)(prob.tspan[end] - prob.tspan[1]), + force_dtmin = false, + adaptive = DiffEqBase.isadaptive(alg), + gamma = OrdinaryDiffEq.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), + qoldinit = DiffEqBase.isadaptive(alg) ? 1 // 10^4 : 0, + controller = nothing, + fullnormalize = true, + failfactor = 2, + beta1 = nothing, + beta2 = nothing, + maxiters = adaptive ? 1000000 : typemax(Int), + internalnorm = DiffEqBase.ODE_DEFAULT_NORM, + internalopnorm = LinearAlgebra.opnorm, + isoutofdomain = DiffEqBase.ODE_DEFAULT_ISOUTOFDOMAIN, + unstable_check = DiffEqBase.ODE_DEFAULT_UNSTABLE_CHECK, + verbose = true, + timeseries_errors = true, + dense_errors = false, + advance_to_tstop = false, + stop_at_next_tstop = false, + initialize_save = true, + progress = false, + progress_steps = 1000, + progress_name = "DDE", + progress_message = DiffEqBase.ODE_DEFAULT_PROG_MESSAGE, + progress_id = gensym("DelayDiffEq"), + userdata = nothing, + allow_extrapolation = OrdinaryDiffEq.alg_extrapolates(alg), + initialize_integrator = true, + alias_u0 = false, + # keyword arguments for DDEs + discontinuity_interp_points::Int = 10, + discontinuity_abstol = eltype(prob.tspan)(1 // Int64(10)^12), + discontinuity_reltol = 0, + kwargs...) if haskey(kwargs, :initial_order) @warn "initial_order has been deprecated. Please specify order_discontinuity_t0 in the DDEProblem instead." order_discontinuity_t0::Int = kwargs[:initial_order] @@ -77,17 +77,17 @@ 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, - auto.nonstiffalg, - auto.stiffalg, - auto.stiffalgfirst, - auto.maxstiffstep, - auto.maxnonstiffstep, - auto.nonstifftol, - auto.stifftol, - auto.dtfac, - auto.stiffalgfirst, - auto.switch_max))) + OrdinaryDiffEq.AutoSwitchCache(0, 0, + auto.nonstiffalg, + auto.stiffalg, + auto.stiffalgfirst, + auto.maxstiffstep, + auto.maxnonstiffstep, + auto.nonstifftol, + auto.stifftol, + auto.dtfac, + auto.stiffalgfirst, + auto.switch_max))) end if haskey(kwargs, :minimal_solution) @@ -98,7 +98,7 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, @warn("Dense output is incompatible with saveat. Please use the SavingCallback from the Callback Library to mix the two behaviors.") end - progress && @logmsg(-1, progress_name, _id=progress_id, progress=0) + progress && @logmsg(-1, progress_name, _id=progress_id,progress=0) isdae = prob.f.mass_matrix !== I && !(prob.f.mass_matrix isa Tuple) && ArrayInterface.issingular(prob.f.mass_matrix) @@ -130,39 +130,40 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # get states (possibly different from the ODE integrator!) u, uprev, uprev2 = u_uprev_uprev2(u0, alg; - alias_u0 = alias_u0, - adaptive = adaptive, - allow_extrapolation = allow_extrapolation, - calck = calck) + alias_u0 = alias_u0, + adaptive = adaptive, + allow_extrapolation = allow_extrapolation, + calck = calck) uEltypeNoUnits = recursive_unitless_eltype(u) uBottomEltypeNoUnits = recursive_unitless_bottom_eltype(u) # get the differential vs algebraic variables - differential_vars = prob isa DAEProblem ? prob.differential_vars : OrdinaryDiffEq.get_differential_vars(f, u) + differential_vars = prob isa DAEProblem ? prob.differential_vars : + OrdinaryDiffEq.get_differential_vars(f, u) # create a history function history = build_history_function(prob, alg, rate_prototype, reltol_internal, - differential_vars; - dt = dt, dtmin = dtmin, calck = false, - adaptive = adaptive, internalnorm = internalnorm) + differential_vars; + dt = dt, dtmin = dtmin, calck = false, + adaptive = adaptive, internalnorm = internalnorm) f_with_history = ODEFunctionWrapper(f, history) # initialize output arrays of the solution k = typeof(rate_prototype)[] ts, timeseries, ks = solution_arrays(u, tspan, rate_prototype; - timeseries_init = timeseries_init, - ts_init = ts_init, - ks_init = ks_init, - save_idxs = save_idxs, - save_start = save_start) + timeseries_init = timeseries_init, + ts_init = ts_init, + ks_init = ks_init, + save_idxs = save_idxs, + save_start = save_start) # build cache ode_integrator = history.integrator cache = OrdinaryDiffEq.alg_cache(alg.alg, u, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, - f_with_history, t0, zero(tType), reltol_internal, p, - calck, - Val(isinplace(prob))) + uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, + f_with_history, t0, zero(tType), reltol_internal, p, + calck, + Val(isinplace(prob))) # separate statistics of the integrator and the history stats = DDEStats(0) @@ -170,37 +171,39 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # create solution alg_choice = iscomposite(alg) ? Int[] : nothing id = OrdinaryDiffEq.InterpolationData(f_with_history, timeseries, ts, ks, - alg_choice, dense, cache, differential_vars, false) + alg_choice, dense, cache, differential_vars, false) sol = DiffEqBase.build_solution(prob, alg.alg, ts, timeseries; - dense = dense, k = ks, interp = id, - alg_choice = id.alg_choice, calculate_error = false, - stats = stats) + dense = dense, k = ks, interp = id, + alg_choice = id.alg_choice, calculate_error = false, + stats = stats) # retrieve time stops, time points at which solutions is saved, and discontinuities tstops_internal = OrdinaryDiffEq.initialize_tstops(tType, tstops, d_discontinuities, - tspan) + tspan) saveat_internal = OrdinaryDiffEq.initialize_saveat(tType, saveat, tspan) - d_discontinuities_internal = OrdinaryDiffEq.initialize_d_discontinuities(Discontinuity{ - tType, - Int - }, - d_discontinuities, - tspan) + d_discontinuities_internal = OrdinaryDiffEq.initialize_d_discontinuities( + Discontinuity{ + tType, + Int + }, + d_discontinuities, + tspan) maximum_order = OrdinaryDiffEq.alg_maximum_order(alg) - tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated(tType, - tstops, - d_discontinuities, - tspan, - order_discontinuity_t0, - maximum_order, - constant_lags, - neutral) + tstops_propagated, d_discontinuities_propagated = initialize_tstops_d_discontinuities_propagated( + tType, + tstops, + d_discontinuities, + tspan, + order_discontinuity_t0, + maximum_order, + constant_lags, + neutral) # reserve capacity for the solution sizehint!(sol, alg, tspan, tstops_internal, saveat_internal; - save_everystep = save_everystep, adaptive = adaptive, dt = tType(dt), - dtmin = dtmin, internalnorm = internalnorm) + save_everystep = save_everystep, adaptive = adaptive, dt = tType(dt), + dtmin = dtmin, internalnorm = internalnorm) # create array of tracked discontinuities # used to find propagated discontinuities with callbacks and to keep track of all @@ -230,8 +233,8 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, if controller === nothing controller = OrdinaryDiffEq.default_controller(alg.alg, cache, - convert(QT, qoldinit)::QT, beta1, - beta2) + convert(QT, qoldinit)::QT, beta1, + beta2) end save_end_user = save_end @@ -242,123 +245,123 @@ function DiffEqBase.__init(prob::DiffEqBase.AbstractDDEProblem, # added in OrdinaryDiffEq.jl#2032 if hasfield(OrdinaryDiffEq.DEOptions, :progress_id) opts = OrdinaryDiffEq.DEOptions{typeof(abstol_internal), typeof(reltol_internal), - QT, tType, typeof(controller), - typeof(internalnorm), typeof(internalopnorm), - typeof(save_end_user), - typeof(callback_set), - typeof(isoutofdomain), - typeof(progress_message), typeof(unstable_check), - typeof(tstops_internal), - typeof(d_discontinuities_internal), typeof(userdata), - typeof(save_idxs), - typeof(maxiters), typeof(tstops), - typeof(saveat), typeof(d_discontinuities)}(maxiters, - save_everystep, - adaptive, - abstol_internal, - reltol_internal, - QT(gamma), - QT(qmax), - QT(qmin), - QT(qsteady_max), - QT(qsteady_min), - QT(qoldinit), - QT(failfactor), - tType(dtmax), - tType(dtmin), - controller, - internalnorm, - internalopnorm, - save_idxs, - tstops_internal, - saveat_internal, - d_discontinuities_internal, - tstops, - saveat, - d_discontinuities, - userdata, - progress, - progress_steps, - progress_name, - progress_message, - progress_id, - timeseries_errors, - dense_errors, - dense, - save_on, - save_start, - save_end, - save_end_user, - callback_set, - isoutofdomain, - unstable_check, - verbose, - calck, - force_dtmin, - advance_to_tstop, - stop_at_next_tstop) + QT, tType, typeof(controller), + typeof(internalnorm), typeof(internalopnorm), + typeof(save_end_user), + typeof(callback_set), + typeof(isoutofdomain), + typeof(progress_message), typeof(unstable_check), + typeof(tstops_internal), + typeof(d_discontinuities_internal), typeof(userdata), + typeof(save_idxs), + typeof(maxiters), typeof(tstops), + typeof(saveat), typeof(d_discontinuities)}(maxiters, + save_everystep, + adaptive, + abstol_internal, + reltol_internal, + QT(gamma), + QT(qmax), + QT(qmin), + QT(qsteady_max), + QT(qsteady_min), + QT(qoldinit), + QT(failfactor), + tType(dtmax), + tType(dtmin), + controller, + internalnorm, + internalopnorm, + save_idxs, + tstops_internal, + saveat_internal, + d_discontinuities_internal, + tstops, + saveat, + d_discontinuities, + userdata, + progress, + progress_steps, + progress_name, + progress_message, + progress_id, + timeseries_errors, + dense_errors, + dense, + save_on, + save_start, + save_end, + save_end_user, + callback_set, + isoutofdomain, + unstable_check, + verbose, + calck, + force_dtmin, + advance_to_tstop, + stop_at_next_tstop) else opts = OrdinaryDiffEq.DEOptions{typeof(abstol_internal), typeof(reltol_internal), - QT, tType, typeof(controller), - typeof(internalnorm), typeof(internalopnorm), - typeof(save_end_user), - typeof(callback_set), - typeof(isoutofdomain), - typeof(progress_message), typeof(unstable_check), - typeof(tstops_internal), - typeof(d_discontinuities_internal), typeof(userdata), - typeof(save_idxs), - typeof(maxiters), typeof(tstops), - typeof(saveat), typeof(d_discontinuities)}(maxiters, - save_everystep, - adaptive, - abstol_internal, - reltol_internal, - QT(gamma), - QT(qmax), - QT(qmin), - QT(qsteady_max), - QT(qsteady_min), - QT(qoldinit), - QT(failfactor), - tType(dtmax), - tType(dtmin), - controller, - internalnorm, - internalopnorm, - save_idxs, - tstops_internal, - saveat_internal, - d_discontinuities_internal, - tstops, - saveat, - d_discontinuities, - userdata, - progress, - progress_steps, - progress_name, - progress_message, - #progress_id, - timeseries_errors, - dense_errors, - dense, - save_on, - save_start, - save_end, - save_end_user, - callback_set, - isoutofdomain, - unstable_check, - verbose, - calck, - force_dtmin, - advance_to_tstop, - stop_at_next_tstop) -end + QT, tType, typeof(controller), + typeof(internalnorm), typeof(internalopnorm), + typeof(save_end_user), + typeof(callback_set), + typeof(isoutofdomain), + typeof(progress_message), typeof(unstable_check), + typeof(tstops_internal), + typeof(d_discontinuities_internal), typeof(userdata), + typeof(save_idxs), + typeof(maxiters), typeof(tstops), + typeof(saveat), typeof(d_discontinuities)}(maxiters, + save_everystep, + adaptive, + abstol_internal, + reltol_internal, + QT(gamma), + QT(qmax), + QT(qmin), + QT(qsteady_max), + QT(qsteady_min), + QT(qoldinit), + QT(failfactor), + tType(dtmax), + tType(dtmin), + controller, + internalnorm, + internalopnorm, + save_idxs, + tstops_internal, + saveat_internal, + d_discontinuities_internal, + tstops, + saveat, + d_discontinuities, + userdata, + progress, + progress_steps, + progress_name, + progress_message, + #progress_id, + timeseries_errors, + dense_errors, + dense, + save_on, + save_start, + save_end, + save_end_user, + callback_set, + isoutofdomain, + unstable_check, + verbose, + calck, + force_dtmin, + advance_to_tstop, + stop_at_next_tstop) + end # create fixed point solver fpsolver = build_fpsolver(alg, alg.fpsolve, u, uEltypeNoUnits, uBottomEltypeNoUnits, - Val(isinplace(prob))) + Val(isinplace(prob))) # initialize indices of u(t) and u(tprev) in the dense history prev_idx = 1 @@ -394,69 +397,69 @@ end dtacc = tType(1) integrator = DDEIntegrator{typeof(alg.alg), isinplace(prob), typeof(u0), tType, - typeof(p), - typeof(eigen_est), QT, typeof(tdir), typeof(k), typeof(sol), - typeof(f_with_history), typeof(cache), - typeof(ode_integrator), typeof(fpsolver), - typeof(opts), typeof(discontinuity_abstol), - typeof(discontinuity_reltol), typeof(history), - typeof(tstops_propagated), - typeof(d_discontinuities_propagated), - OrdinaryDiffEq.fsal_typeof(alg.alg, rate_prototype), - typeof(last_event_error), typeof(callback_cache), - typeof(differential_vars)}(sol, u, k, - t0, - tType(dt), - f_with_history, - p, - uprev, - uprev2, - tprev, - prev_idx, - prev2_idx, - fpsolver, - order_discontinuity_t0, - tracked_discontinuities, - discontinuity_interp_points, - discontinuity_abstol, - discontinuity_reltol, - tstops_propagated, - d_discontinuities_propagated, - alg.alg, - dtcache, - dtchangeable, - dtpropose, - tdir, - eigen_est, - EEst, - QT(qoldinit), - q11, - erracc, - dtacc, - success_iter, - iter, - length(ts), - length(ts), - cache, - callback_cache, - kshortsize, - force_stepfail, - last_stepfail, - just_hit_tstop, - do_error_check, - event_last_time, - vector_event_last_time, - last_event_error, - accept_step, - isout, - reeval_fsal, - u_modified, - isdae, - opts, - stats, - history, - differential_vars, - ode_integrator) + typeof(p), + typeof(eigen_est), QT, typeof(tdir), typeof(k), typeof(sol), + typeof(f_with_history), typeof(cache), + typeof(ode_integrator), typeof(fpsolver), + typeof(opts), typeof(discontinuity_abstol), + typeof(discontinuity_reltol), typeof(history), + typeof(tstops_propagated), + typeof(d_discontinuities_propagated), + OrdinaryDiffEq.fsal_typeof(alg.alg, rate_prototype), + typeof(last_event_error), typeof(callback_cache), + typeof(differential_vars)}(sol, u, k, + t0, + tType(dt), + f_with_history, + p, + uprev, + uprev2, + tprev, + prev_idx, + prev2_idx, + fpsolver, + order_discontinuity_t0, + tracked_discontinuities, + discontinuity_interp_points, + discontinuity_abstol, + discontinuity_reltol, + tstops_propagated, + d_discontinuities_propagated, + alg.alg, + dtcache, + dtchangeable, + dtpropose, + tdir, + eigen_est, + EEst, + QT(qoldinit), + q11, + erracc, + dtacc, + success_iter, + iter, + length(ts), + length(ts), + cache, + callback_cache, + kshortsize, + force_stepfail, + last_stepfail, + just_hit_tstop, + do_error_check, + event_last_time, + vector_event_last_time, + last_event_error, + accept_step, + isout, + reeval_fsal, + u_modified, + isdae, + opts, + stats, + history, + differential_vars, + ode_integrator) # initialize DDE integrator if initialize_integrator @@ -505,8 +508,8 @@ function DiffEqBase.solve!(integrator::DDEIntegrator) if DiffEqBase.has_analytic(f) DiffEqBase.calculate_solution_errors!(sol; - timeseries_errors = opts.timeseries_errors, - dense_errors = opts.dense_errors) + timeseries_errors = opts.timeseries_errors, + dense_errors = opts.dense_errors) end sol.retcode == ReturnCode.Default || return sol @@ -514,7 +517,7 @@ function DiffEqBase.solve!(integrator::DDEIntegrator) end function OrdinaryDiffEq.initialize_callbacks!(integrator::DDEIntegrator, - initialize_save = true) + initialize_save = true) callbacks = integrator.opts.callback prob = integrator.sol.prob @@ -561,10 +564,10 @@ function OrdinaryDiffEq.initialize_callbacks!(integrator::DDEIntegrator, end function initialize_tstops_d_discontinuities_propagated(::Type{T}, tstops, - d_discontinuities, tspan, - order_discontinuity_t0, - alg_maximum_order, - constant_lags, neutral) where {T} + d_discontinuities, tspan, + order_discontinuity_t0, + alg_maximum_order, + constant_lags, neutral) where {T} # create heaps for propagated discontinuities and corresponding time stops tstops_propagated = BinaryMinHeap{T}() d_discontinuities_propagated = BinaryMinHeap{Discontinuity{T, Int}}() diff --git a/src/track.jl b/src/track.jl index 67f26087..24d2711e 100644 --- a/src/track.jl +++ b/src/track.jl @@ -77,8 +77,8 @@ function discontinuity_interval(integrator::DDEIntegrator, lag, T, Θs) # use start and end point of last time interval to check for discontinuities previous_condition = discontinuity_function(integrator, lag, T, integrator.t) if isapprox(previous_condition, 0; - rtol = integrator.discontinuity_reltol, - atol = integrator.discontinuity_abstol) + rtol = integrator.discontinuity_reltol, + atol = integrator.discontinuity_abstol) prev_sign = 0 else prev_sign = cmp(previous_condition, zero(previous_condition)) @@ -135,10 +135,11 @@ function discontinuity_time(integrator::DDEIntegrator, lag, T, (bottom_Θ, top_ (θ, p = nothing) -> discontinuity_function(integrator, lag, T, t + θ * dt) end - Θ = SimpleNonlinearSolve.solve(SimpleNonlinearSolve.IntervalNonlinearProblem{false}(zero_func, - (bottom_Θ, - top_Θ)), - SimpleNonlinearSolve.Falsi()).left + Θ = SimpleNonlinearSolve.solve( + SimpleNonlinearSolve.IntervalNonlinearProblem{false}(zero_func, + (bottom_Θ, + top_Θ)), + SimpleNonlinearSolve.Falsi()).left end integrator.t + Θ * integrator.dt diff --git a/src/utils.jl b/src/utils.jl index 82756bb0..b6f1e1cb 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -37,9 +37,9 @@ Return state vectors `u` and `uprev` (possibly aliased) for solving the differential equation problem for initial state `u0` with algorithm `alg`. """ function u_uprev(u0, alg; - alias_u0 = false, - adaptive = DiffEqBase.isadaptive(alg), - calck = false) + alias_u0 = false, + adaptive = DiffEqBase.isadaptive(alg), + calck = false) if alias_u0 u = u0 else @@ -64,8 +64,8 @@ Return state vectors `u`, `uprev`, and `uprev2` (possibly aliased) for solving t differential equation problem for initial state `u0` with algorithm `alg`. """ function u_uprev_uprev2(u0, alg; - allow_extrapolation = alg_extrapolates(alg), - kwargs...) + allow_extrapolation = alg_extrapolates(alg), + kwargs...) # compute u and uprev first u, uprev = u_uprev(u0, alg; kwargs...) @@ -141,7 +141,7 @@ function callback_set_and_cache(prob, callback) if max_len_cb isa VectorContinuousCallback uBottomEltype = recursive_bottom_eltype(prob.u0) callback_cache = DiffEqBase.CallbackCache(max_len_cb.len, uBottomEltype, - uBottomEltype) + uBottomEltype) else callback_cache = nothing end @@ -164,11 +164,11 @@ Return arrays of saved time points, states, and rates, initialized with the solu first time point if `save_start = true` (the default). """ function solution_arrays(u, tspan, rate_prototype; - timeseries_init, - ts_init, - ks_init, - save_idxs, - save_start) + timeseries_init, + ts_init, + ks_init, + save_idxs, + save_start) # determine types of time and state uType = typeof(u) tType = eltype(tspan) @@ -231,7 +231,7 @@ Suggest that solution `sol` reserves capacity for a number of elements that depends on the parameter settings of the numerical solver. """ function Base.sizehint!(sol::DESolution, alg, tspan, tstops, saveat; - save_everystep, adaptive, internalnorm, dt, dtmin) + save_everystep, adaptive, internalnorm, dt, dtmin) # obtain integration time t0 = first(tspan) integrationtime = last(tspan) - t0 @@ -257,7 +257,7 @@ function Base.sizehint!(sol::DESolution, alg, tspan, tstops, saveat; end function build_history_function(prob, alg, rate_prototype, reltol, differential_vars; - dt, dtmin, adaptive, calck, internalnorm) + dt, dtmin, adaptive, calck, internalnorm) @unpack f, u0, tspan, p = prob t0 = first(tspan) @@ -285,51 +285,52 @@ function build_history_function(prob, alg, rate_prototype, reltol, differential_ # initialize output arrays ode_k = typeof(rate_prototype)[] ode_ts, ode_timeseries, ode_ks = solution_arrays(ode_u, tspan, rate_prototype; - timeseries_init = (), - ts_init = (), - ks_init = (), - save_idxs = nothing, - save_start = true) + timeseries_init = (), + ts_init = (), + ks_init = (), + save_idxs = nothing, + save_start = true) # obtain cache (we alias uprev2 and uprev) ode_cache = OrdinaryDiffEq.alg_cache(alg.alg, ode_u, rate_prototype, uEltypeNoUnits, - uBottomEltypeNoUnits, tTypeNoUnits, ode_uprev, - ode_uprev, ode_f, t0, zero(tType), reltol, p, - calck, - Val(isinplace(prob))) + uBottomEltypeNoUnits, tTypeNoUnits, ode_uprev, + ode_uprev, ode_f, t0, zero(tType), reltol, p, + calck, + Val(isinplace(prob))) # build dense interpolation of history ode_alg_choice = iscomposite(alg) ? Int[] : nothing ode_id = OrdinaryDiffEq.InterpolationData(ode_f, ode_timeseries, ode_ts, - ode_ks, - ode_alg_choice, true, ode_cache, - differential_vars, false) + ode_ks, + ode_alg_choice, true, ode_cache, + differential_vars, false) ode_sol = DiffEqBase.build_solution(ode_prob, alg.alg, ode_ts, ode_timeseries; - dense = true, k = ode_ks, interp = ode_id, - alg_choice = ode_alg_choice, - calculate_error = false, - stats = DiffEqBase.Stats(0)) + dense = true, k = ode_ks, interp = ode_id, + alg_choice = ode_alg_choice, + calculate_error = false, + stats = DiffEqBase.Stats(0)) # reserve capacity sizehint!(ode_sol, alg.alg, tspan, (), (); - save_everystep = true, adaptive = adaptive, internalnorm = internalnorm, - dt = dt, dtmin = dtmin) + save_everystep = true, adaptive = adaptive, internalnorm = internalnorm, + dt = dt, dtmin = dtmin) # create simple integrator tdirType = typeof(sign(zero(tType))) - ode_integrator = HistoryODEIntegrator{typeof(alg.alg), isinplace(prob), typeof(prob.u0), - tType, tdirType, typeof(ode_k), - typeof(ode_sol), typeof(ode_cache), - typeof(differential_vars)}(ode_sol, - ode_u, ode_k, - t0, - zero(tType), - ode_uprev, - t0, alg.alg, - zero(tType), - tdir, 1, 1, - ode_cache, - differential_vars) + ode_integrator = HistoryODEIntegrator{ + typeof(alg.alg), isinplace(prob), typeof(prob.u0), + tType, tdirType, typeof(ode_k), + typeof(ode_sol), typeof(ode_cache), + typeof(differential_vars)}(ode_sol, + ode_u, ode_k, + t0, + zero(tType), + ode_uprev, + t0, alg.alg, + zero(tType), + tdir, 1, 1, + ode_cache, + differential_vars) # combine the user-provided history function and the ODE integrator with dense solution # to a joint dense history of the DDE diff --git a/test/integrators/cache.jl b/test/integrators/cache.jl index 9649f511..d00a3b59 100644 --- a/test/integrators/cache.jl +++ b/test/integrators/cache.jl @@ -31,7 +31,7 @@ function affect!(integrator) end const prob = DDEProblem(f, [0.2], nothing, (0.0, 10.0); - callback = ContinuousCallback(condition, affect!)) + callback = ContinuousCallback(condition, affect!)) println("Check for stochastic errors") for i in 1:10 diff --git a/test/integrators/events.jl b/test/integrators/events.jl index c1c6ea1f..f6966c7b 100644 --- a/test/integrators/events.jl +++ b/test/integrators/events.jl @@ -7,14 +7,14 @@ const alg = MethodOfSteps(Tsit5(); constrained = false) # continuous callback @testset "continuous" begin cb = ContinuousCallback((u, t, integrator) -> t - 2.60, # Event when event_f(t,u,k) == 0 - integrator -> (integrator.u = -integrator.u)) + integrator -> (integrator.u = -integrator.u)) sol1 = solve(prob, alg, callback = cb) ts = findall(x -> x ≈ 2.6, sol1.t) @test length(ts) == 2 @test sol1.u[ts[1]] == -sol1.u[ts[2]] @test sol1(prevfloat(2.6); - continuity = :right)≈-sol1(prevfloat(2.6); continuity = :left) atol=1e-5 + continuity = :right)≈-sol1(prevfloat(2.6); continuity = :left) atol=1e-5 # fails on 32bit?! # see https://github.com/SciML/DelayDiffEq.jl/pull/180 diff --git a/test/integrators/iterator.jl b/test/integrators/iterator.jl index 02596eb4..1dbe6b8d 100644 --- a/test/integrators/iterator.jl +++ b/test/integrators/iterator.jl @@ -6,11 +6,11 @@ const prob = prob_dde_constant_1delay_scalar @testset "Basic iterator" begin # compute the solution of the DDE sol = solve(prob, MethodOfSteps(BS3()); - dt = 1 // 2^(4), tstops = [1.5], saveat = 0.01, save_everystep = true) + dt = 1 // 2^(4), tstops = [1.5], saveat = 0.01, save_everystep = true) # initialize integrator integrator = init(prob, MethodOfSteps(BS3()); - dt = 1 // 2^(4), tstops = [1.5], saveat = 0.01, save_everystep = true) + dt = 1 // 2^(4), tstops = [1.5], saveat = 0.01, save_everystep = true) # perform one step step!(integrator) @@ -40,15 +40,15 @@ end @testset "Advanced iterators" begin # move to grid point in one step integrator1 = init(prob, MethodOfSteps(Tsit5()); - dt = 1 // 2^(4), tstops = [0.5], advance_to_tstop = true) + dt = 1 // 2^(4), tstops = [0.5], advance_to_tstop = true) for (u, t) in tuples(integrator1) @test 0.5 ≤ t ≤ 10 end # move to grid point in one step and stop there integrator2 = init(prob, MethodOfSteps(Tsit5()); - dt = 1 // 2^(4), tstops = [0.5], advance_to_tstop = true, - stop_at_next_tstop = true) + dt = 1 // 2^(4), tstops = [0.5], advance_to_tstop = true, + stop_at_next_tstop = true) for (u, t) in tuples(integrator2) @test t == 0.5 end diff --git a/test/integrators/residual_control.jl b/test/integrators/residual_control.jl index ddb2e5b7..3d6a61ab 100644 --- a/test/integrators/residual_control.jl +++ b/test/integrators/residual_control.jl @@ -48,7 +48,7 @@ end @test sol.errors[:l2] > 4.5e-2 sol = solve(prob_wo, MethodOfSteps(OwrenZen5(); constrained = false); abstol = 1e-13, - reltol = 1e-13) + reltol = 1e-13) @test sol.errors[:l∞] > 1.1e-1 @test sol.errors[:final] > 1.2e-3 diff --git a/test/integrators/retcode.jl b/test/integrators/retcode.jl index 6bd19f97..204d1416 100644 --- a/test/integrators/retcode.jl +++ b/test/integrators/retcode.jl @@ -5,7 +5,7 @@ const prob = prob_dde_constant_1delay_ip @testset for composite in (true, false) alg = MethodOfSteps(composite ? AutoTsit5(Rosenbrock23()) : Tsit5(); - constrained = false) + constrained = false) sol1 = solve(prob, alg) @test sol1.retcode == ReturnCode.Success diff --git a/test/integrators/verner.jl b/test/integrators/verner.jl index e4f75145..b5413d8f 100644 --- a/test/integrators/verner.jl +++ b/test/integrators/verner.jl @@ -20,7 +20,7 @@ using Test sol_scalar = solve(prob_scalar, alg) # fails due to floating point issues - @test sol_ip(ts, idxs = 1) ≈ sol_scalar(ts) atol=1e-5 + @test sol_ip(ts, idxs = 1)≈sol_scalar(ts) atol=1e-5 end # Vern7 @@ -35,7 +35,7 @@ using Test sol_scalar = solve(prob_scalar, alg) - @test sol_ip(ts, idxs = 1) ≈ sol_scalar(ts) atol=1e-5 + @test sol_ip(ts, idxs = 1)≈sol_scalar(ts) atol=1e-5 end # Vern8 @@ -50,7 +50,7 @@ using Test sol_scalar = solve(prob_scalar, alg) - @test sol_ip(ts, idxs = 1) ≈ sol_scalar(ts) atol=1e-5 + @test sol_ip(ts, idxs = 1)≈sol_scalar(ts) atol=1e-5 end # Vern9 @@ -65,7 +65,7 @@ using Test sol_scalar = solve(prob_scalar, alg) - @test sol_ip(ts, idxs = 1) ≈ sol_scalar(ts) atol=1e-5 + @test sol_ip(ts, idxs = 1)≈sol_scalar(ts) atol=1e-5 end end diff --git a/test/interface/ad.jl b/test/interface/ad.jl index 6544c3ab..435465b5 100644 --- a/test/interface/ad.jl +++ b/test/interface/ad.jl @@ -12,9 +12,9 @@ h(p, t) = p[4] @testset "Gradient" begin function test(p) prob = DDEProblem(f, p[5], h, eltype(p).((0.0, 10.0)), copy(p); - constant_lags = (p[1],)) + constant_lags = (p[1],)) sol = solve(prob, MethodOfSteps(Tsit5()); abstol = 1e-14, reltol = 1e-14, - saveat = 1.0) + saveat = 1.0) sum(sol) end @@ -46,9 +46,9 @@ end @testset "Jacobian" begin function test(p) prob = DDEProblem(f, p[5], h, eltype(p).((0.0, 10.0)), copy(p); - constant_lags = (p[1],)) + constant_lags = (p[1],)) sol = solve(prob, MethodOfSteps(Tsit5()); abstol = 1e-14, reltol = 1e-14, - saveat = 1.0) + saveat = 1.0) sol.u end @@ -80,9 +80,9 @@ end @testset "Hessian" begin function test(p) prob = DDEProblem(f, p[5], h, eltype(p).((0.0, 10.0)), copy(p); - constant_lags = (p[1],)) + constant_lags = (p[1],)) sol = solve(prob, MethodOfSteps(Tsit5()); abstol = 1e-14, reltol = 1e-14, - saveat = 1.0) + saveat = 1.0) sum(sol) end diff --git a/test/interface/composite_solution.jl b/test/interface/composite_solution.jl index fe0d42bc..19f344e3 100644 --- a/test/interface/composite_solution.jl +++ b/test/interface/composite_solution.jl @@ -25,7 +25,7 @@ end compositealg = MethodOfSteps(CompositeAlgorithm((Tsit5(), RK4()), integrator -> 1)) prob = DDEProblem((du, u, h, p, t) -> (du[1] = -h(p, t - 1)[1]; nothing), - [1.0], (p, t) -> [1.0], (0.0, 5.0)) + [1.0], (p, t) -> [1.0], (0.0, 5.0)) sol = solve(prob, alg) compositesol = solve(prob, compositealg) @test compositesol isa SciMLBase.ODESolution @@ -33,7 +33,7 @@ end @test sol.u == compositesol.u prob_oop = DDEProblem((u, h, p, t) -> -h(p, t - 1), [1.0], (p, t) -> [1.0], - (0.0, 5.0)) + (0.0, 5.0)) sol_oop = solve(prob_oop, alg) compositesol_oop = solve(prob_oop, compositealg) @test compositesol_oop isa SciMLBase.ODESolution diff --git a/test/interface/discontinuities.jl b/test/interface/discontinuities.jl index 7b9a2ae9..0b382e08 100644 --- a/test/interface/discontinuities.jl +++ b/test/interface/discontinuities.jl @@ -33,7 +33,7 @@ end @test integrator.tracked_discontinuities == [Discontinuity(0.0, 0)] @test length(integrator.d_discontinuities_propagated) == 2 && issubset([Discontinuity(1 / 5, 1), Discontinuity(1 / 3, 1)], - integrator.d_discontinuities_propagated.valtree) + integrator.d_discontinuities_propagated.valtree) @test isempty(integrator.opts.d_discontinuities) @test isempty(integrator.opts.d_discontinuities_cache) end @@ -44,8 +44,8 @@ end discs = [Discontinuity(t, order) for (t, order) in ((0.0, 0), (1 / 5, 1), (1 / 3, 1), (2 / 5, 2), - (8 / 15, 2), (3 / 5, 3), - (2 / 3, 2), (11 / 15, 3), (13 / 15, 3))] + (8 / 15, 2), (3 / 5, 3), + (2 / 3, 2), (11 / 15, 3), (13 / 15, 3))] for (tracked, disc) in zip(integrator.tracked_discontinuities, discs) @test tracked.t ≈ disc.t && tracked.order == disc.order @@ -56,15 +56,15 @@ end # additional discontinuities @testset "DDE with discontinuities" begin integrator = init(prob, MethodOfSteps(BS3()); - d_discontinuities = [Discontinuity(0.3, 4), Discontinuity(0.6, 5)]) + d_discontinuities = [Discontinuity(0.3, 4), Discontinuity(0.6, 5)]) @test integrator.tracked_discontinuities == [Discontinuity(0.0, 0)] @test length(integrator.d_discontinuities_propagated) == 2 && issubset([Discontinuity(1 / 5, 1), Discontinuity(1 / 3, 1)], - integrator.d_discontinuities_propagated.valtree) + integrator.d_discontinuities_propagated.valtree) @test length(integrator.opts.d_discontinuities) == 2 && issubset([Discontinuity(0.3, 4), Discontinuity(0.6, 5)], - integrator.opts.d_discontinuities.valtree) + integrator.opts.d_discontinuities.valtree) @test integrator.opts.d_discontinuities_cache == [Discontinuity(0.3, 4), Discontinuity(0.6, 5)] end @@ -73,7 +73,7 @@ end @testset "#190" begin cb = ContinuousCallback((u, t, integrator) -> 1, integrator -> nothing) integrator = init(prob_dde_constant_1delay_ip, MethodOfSteps(Tsit5()); - callback = cb) + callback = cb) sol = solve!(integrator) for t in 0:5 @test t ∈ sol.t diff --git a/test/interface/fpsolve.jl b/test/interface/fpsolve.jl index f9198744..a88d24aa 100644 --- a/test/interface/fpsolve.jl +++ b/test/interface/fpsolve.jl @@ -7,7 +7,7 @@ const prob_oop = prob_dde_constant_2delays_long_oop const prob_scalar = prob_dde_constant_2delays_long_scalar const testsol = TestSolution(solve(prob, MethodOfSteps(Vern9()); - abstol = 1 / 10^14, reltol = 1 / 10^14)) + abstol = 1 / 10^14, reltol = 1 / 10^14)) @testset "NLFunctional" begin alg = MethodOfSteps(Tsit5(); fpsolve = NLFunctional(; max_iter = 10)) diff --git a/test/interface/history_function.jl b/test/interface/history_function.jl index 14c363e3..e0bdab06 100644 --- a/test/interface/history_function.jl +++ b/test/interface/history_function.jl @@ -26,9 +26,9 @@ end # combined history function history_notinplace = DelayDiffEq.HistoryFunction(h_notinplace, - integrator) + integrator) history_inplace = DelayDiffEq.HistoryFunction(h_inplace, - integrator) + integrator) # test evaluation of history function @testset "evaluation" for idxs in (nothing, [2]) @@ -83,7 +83,7 @@ end # test integrator interpolation @testset "integrator interpolation" for deriv in (Val{0}, Val{1}), - idxs in (nothing, [2]) + idxs in (nothing, [2]) # expected value trueval = OrdinaryDiffEq.current_interpolant(0.01, integrator, idxs, deriv) diff --git a/test/interface/mass_matrix.jl b/test/interface/mass_matrix.jl index e97b9849..853b27de 100644 --- a/test/interface/mass_matrix.jl +++ b/test/interface/mass_matrix.jl @@ -24,7 +24,7 @@ using Test prob_dde = DDEProblem(sir_dde!, u0, sir_history, tspan, p; constant_lags = (p.τ,)) sol_dde = TestSolution(solve(prob_dde, MethodOfSteps(Vern9()); reltol = 1e-14, - abstol = 1e-14)) + abstol = 1e-14)) function sir_ddae!(du, u, h, p, t) S, I, R = u @@ -40,13 +40,14 @@ using Test nothing end - prob_ddae = DDEProblem(DDEFunction{true}(sir_ddae!; - mass_matrix = Diagonal([1.0, 1.0, 0.0])), - u0, - sir_history, - tspan, - p; - constant_lags = (p.τ,)) + prob_ddae = DDEProblem( + DDEFunction{true}(sir_ddae!; + mass_matrix = Diagonal([1.0, 1.0, 0.0])), + u0, + sir_history, + tspan, + p; + constant_lags = (p.τ,)) ode_f = DelayDiffEq.ODEFunctionWrapper(prob_ddae.f, prob_ddae.h) @test ode_f.mass_matrix == Diagonal([1.0, 1.0, 0.0]) @@ -55,9 +56,9 @@ using Test @test int.f.mass_matrix == Diagonal([1.0, 1.0, 0.0]) for (alg, reltol) in ((Rosenbrock23(), nothing), - (Rodas4(), nothing), - (QNDF(), 1e-6), - (Trapezoid(), 1e-6)) + (Rodas4(), nothing), + (QNDF(), 1e-6), + (Trapezoid(), 1e-6)) sol_ddae = solve(prob_ddae, MethodOfSteps(alg); reltol = reltol) sol = appxtrue(sol_ddae, sol_dde) @test sol.errors[:L∞] < 5e-3 diff --git a/test/interface/parameters.jl b/test/interface/parameters.jl index 990d2a42..68fee383 100644 --- a/test/interface/parameters.jl +++ b/test/interface/parameters.jl @@ -15,10 +15,10 @@ h(p, t; idxs = nothing) = 0.1 # we specify order_discontinuity_t0 = 1 to indicate that the discontinuity at # t = 0 is of first order prob = DDEProblem(inplace ? f_inplace : f_scalar, - inplace ? [0.1] : 0.1, - h, (0.0, 50.0), [0.3]; - constant_lags = [1], - order_discontinuity_t0 = 1) + inplace ? [0.1] : 0.1, + h, (0.0, 50.0), [0.3]; + constant_lags = [1], + order_discontinuity_t0 = 1) # solve problem with initial parameter: sol1 = solve(prob, MethodOfSteps(Tsit5())) diff --git a/test/interface/save_idxs.jl b/test/interface/save_idxs.jl index fca491f2..fbc46a36 100644 --- a/test/interface/save_idxs.jl +++ b/test/interface/save_idxs.jl @@ -6,7 +6,7 @@ function f_notinplace(u, h, p, t) [-h(p, t - 1 / 5)[1] + u[1]; -h(p, t - 1 / 3)[2] - h(p, t - 1 / 5)[2]] end const prob_notinplace = DDEProblem(f_notinplace, ones(2), (p, t) -> zeros(2), (0.0, 100.0), - constant_lags = [1 / 5, 1 / 3]) + constant_lags = [1 / 5, 1 / 3]) # in-place problem function f_inplace(du, u, h, p, t) @@ -14,7 +14,7 @@ function f_inplace(du, u, h, p, t) du[2] = -h(p, t - 1 / 3)[2] - h(p, t - 1 / 5)[2] end const prob_inplace = DDEProblem(f_inplace, ones(2), (p, t) -> zeros(2), (0.0, 100.0), - constant_lags = [1 / 5, 1 / 3]) + constant_lags = [1 / 5, 1 / 3]) const alg = MethodOfSteps(BS3()) diff --git a/test/interface/saveat.jl b/test/interface/saveat.jl index f30c5e06..44559b1d 100644 --- a/test/interface/saveat.jl +++ b/test/interface/saveat.jl @@ -64,7 +64,8 @@ end # time point of solution if saveat isa Number - @test sol2.t == (save_end ? [0.0, 25.0, 50.0, 75.0, 100.0] : [0.0, 25.0, 50.0, 75.0]) + @test sol2.t == + (save_end ? [0.0, 25.0, 50.0, 75.0, 100.0] : [0.0, 25.0, 50.0, 75.0]) else @test sol2.t == (save_end ? [25.0, 50.0, 75.0, 100.0] : [25.0, 50.0, 75.0]) end @@ -79,7 +80,7 @@ end @testset "every step (save_start=$save_start)" for save_start in (false, true) for saveat in (25.0, [25.0, 50.0, 75.0]) dde_int2 = init(prob, alg; saveat = saveat, save_everystep = true, - save_start = save_start) + save_start = save_start) # end point is saved implicitly @test dde_int2.opts.save_end @@ -104,7 +105,7 @@ end @testset "every step (save_end=$save_end)" for save_end in (false, true) for saveat in (25.0, [25.0, 50.0, 75.0]) dde_int2 = init(prob, alg; saveat = saveat, save_everystep = true, - save_end = save_end) + save_end = save_end) # start point is saved implicitly @test dde_int2.opts.save_start @@ -117,7 +118,7 @@ end # time points of solution @test symdiff(sol.t, sol2.t) == - (save_end ? [25.0, 50.0, 75.0] : [100.0, 25.0, 50.0, 75.0]) + (save_end ? [25.0, 50.0, 75.0] : [100.0, 25.0, 50.0, 75.0]) # history is equal to solution above @test sol.t == dde_int2.integrator.sol.t @@ -134,19 +135,19 @@ end @testset "changing end time point saveat" begin _saveat = [0.0, 0.25, 0.5, 1.0] integ = init(DDEProblem((u, h, p, t) -> u, 0.0, (p, t) -> 0.0, (0.0, 1.0)), - MethodOfSteps(Tsit5()), saveat = _saveat) + MethodOfSteps(Tsit5()), saveat = _saveat) add_tstop!(integ, 2.0) solve!(integ) @test integ.sol.t == _saveat integ = init(DDEProblem((u, h, p, t) -> u, 0.0, (p, t) -> 0.0, (0.0, 1.0)), - MethodOfSteps(Tsit5()), saveat = _saveat, save_end = true) + MethodOfSteps(Tsit5()), saveat = _saveat, save_end = true) add_tstop!(integ, 2.0) solve!(integ) @test integ.sol.t == [0.0, 0.25, 0.5, 1.0, 2.0] integ = init(DDEProblem((u, h, p, t) -> u, 0.0, (p, t) -> 0.0, (0.0, 1.0)), - MethodOfSteps(Tsit5()), saveat = _saveat, save_end = false) + MethodOfSteps(Tsit5()), saveat = _saveat, save_end = false) add_tstop!(integ, 2.0) solve!(integ) @test integ.sol.t == [0.0, 0.25, 0.5] diff --git a/test/interface/unconstrained.jl b/test/interface/unconstrained.jl index 2dea734b..ad10f04d 100644 --- a/test/interface/unconstrained.jl +++ b/test/interface/unconstrained.jl @@ -9,12 +9,12 @@ using Test alg = MethodOfSteps(BS3(); constrained = false) alg1 = MethodOfSteps(Tsit5(); constrained = false, - fpsolve = NLFunctional(; max_iter = 100)) + fpsolve = NLFunctional(; max_iter = 100)) alg2 = MethodOfSteps(DP8(); constrained = false, - fpsolve = NLFunctional(; max_iter = 10)) + fpsolve = NLFunctional(; max_iter = 10)) alg3 = MethodOfSteps(Tsit5(); constrained = true) alg4 = MethodOfSteps(DP5(); constrained = false, - fpsolve = NLFunctional(; max_iter = 100)) + fpsolve = NLFunctional(; max_iter = 100)) ## Single constant delay @testset "single constant delay" begin @@ -91,7 +91,7 @@ end ## Non-standard history functions @testset "non-standard history" begin alg = MethodOfSteps(Tsit5(); constrained = false, - fpsolve = NLFunctional(; max_iter = 100)) + fpsolve = NLFunctional(; max_iter = 100)) @testset "idxs" begin function f(du, u, h, p, t) diff --git a/test/interface/units.jl b/test/interface/units.jl index c546a506..cc20a488 100644 --- a/test/interface/units.jl +++ b/test/interface/units.jl @@ -3,12 +3,13 @@ using Test using DDEProblemLibrary: remake_dde_constant_u0_tType -const probs = Dict(true => remake_dde_constant_u0_tType(prob_dde_constant_1delay_long_ip, - [1.0u"N"], - typeof(1.0u"s")), - false => remake_dde_constant_u0_tType(prob_dde_constant_1delay_long_scalar, - 1.0u"N", - typeof(1.0u"s"))) +const probs = Dict( + true => remake_dde_constant_u0_tType(prob_dde_constant_1delay_long_ip, + [1.0u"N"], + typeof(1.0u"s")), + false => remake_dde_constant_u0_tType(prob_dde_constant_1delay_long_scalar, + 1.0u"N", + typeof(1.0u"s"))) # we test the current handling of units for regressions # however, it is broken upstream: https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/issues/828 @@ -17,7 +18,7 @@ const probs = Dict(true => remake_dde_constant_u0_tType(prob_dde_constant_1delay prob = probs[inplace] alg = MethodOfSteps(Tsit5(); constrained = false, - fpsolve = NLFunctional(; max_iter = 100)) + fpsolve = NLFunctional(; max_iter = 100)) # default sol1 = solve(prob, alg) @@ -25,7 +26,7 @@ const probs = Dict(true => remake_dde_constant_u0_tType(prob_dde_constant_1delay # without units if inplace @test_throws Unitful.DimensionError solve(prob, alg; - abstol = 1e-6, reltol = 1e-3) + abstol = 1e-6, reltol = 1e-3) else sol2 = solve(prob, alg; abstol = 1e-6, reltol = 1e-3) @@ -49,9 +50,9 @@ const probs = Dict(true => remake_dde_constant_u0_tType(prob_dde_constant_1delay # with incorrect units for absolute tolerance @test_throws Unitful.DimensionError solve(prob, alg; - abstol = 1e-6u"s", reltol = 1e-3u"N") + abstol = 1e-6u"s", reltol = 1e-3u"N") # with incorrect units for relative tolerance @test_throws Unitful.DimensionError solve(prob, alg; - abstol = 1e-6u"N", reltol = 1e-3u"s") + abstol = 1e-6u"N", reltol = 1e-3u"s") end diff --git a/test/regression/waltman.jl b/test/regression/waltman.jl index 13a66750..234e4266 100644 --- a/test/regression/waltman.jl +++ b/test/regression/waltman.jl @@ -26,13 +26,14 @@ test_waltman_sol(sol1) # in-place LU factorization sol2 = solve(PROB_WALTMAN, - MethodOfSteps(Rosenbrock23(linsolve = GenericFactorization(lu!))); - PROB_KWARGS...) + MethodOfSteps(Rosenbrock23(linsolve = GenericFactorization(lu!))); + PROB_KWARGS...) test_waltman_sol(sol2) # out-of-place LU factorization -sol3 = solve(PROB_WALTMAN, MethodOfSteps(Rosenbrock23(linsolve = GenericFactorization(lu))); - PROB_KWARGS...) +sol3 = solve( + PROB_WALTMAN, MethodOfSteps(Rosenbrock23(linsolve = GenericFactorization(lu))); + PROB_KWARGS...) test_waltman_sol(sol3) # compare in-place and out-of-place LU factorization diff --git a/test/runtests.jl b/test/runtests.jl index 8377bced..ea629d2f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,38 +3,94 @@ using SafeTestsets const GROUP = get(ENV, "GROUP", "All") if GROUP == "All" || GROUP == "Interface" - @time @safetestset "AD Tests" begin include("interface/ad.jl") end - @time @safetestset "Backwards Tests" begin include("interface/backwards.jl") end - @time @safetestset "Composite Solution Tests" begin include("interface/composite_solution.jl") end - @time @safetestset "Constrained Time Steps Tests" begin include("interface/constrained.jl") end - @time @safetestset "Dependent Delay Tests" begin include("interface/dependent_delays.jl") end - @time @safetestset "Discontinuity Tests" begin include("interface/discontinuities.jl") end - @time @safetestset "Export Tests" begin include("interface/export.jl") end - @time @safetestset "Fixed-point Iteration Tests" begin include("interface/fpsolve.jl") end - @time @safetestset "History Function Tests" begin include("interface/history_function.jl") end - @time @safetestset "Jacobian Tests" begin include("interface/jacobian.jl") end - @time @safetestset "Mass matrix Tests" begin include("interface/mass_matrix.jl") end - @time @safetestset "Parameterized Function Tests" begin include("interface/parameters.jl") end - @time @safetestset "saveat Tests" begin include("interface/saveat.jl") end - @time @safetestset "save_idxs Tests" begin include("interface/save_idxs.jl") end - @time @safetestset "Unconstrained Time Steps Tests" begin include("interface/unconstrained.jl") end - @time @safetestset "Units Tests" begin include("interface/units.jl") end + @time @safetestset "AD Tests" begin + include("interface/ad.jl") + end + @time @safetestset "Backwards Tests" begin + include("interface/backwards.jl") + end + @time @safetestset "Composite Solution Tests" begin + include("interface/composite_solution.jl") + end + @time @safetestset "Constrained Time Steps Tests" begin + include("interface/constrained.jl") + end + @time @safetestset "Dependent Delay Tests" begin + include("interface/dependent_delays.jl") + end + @time @safetestset "Discontinuity Tests" begin + include("interface/discontinuities.jl") + end + @time @safetestset "Export Tests" begin + include("interface/export.jl") + end + @time @safetestset "Fixed-point Iteration Tests" begin + include("interface/fpsolve.jl") + end + @time @safetestset "History Function Tests" begin + include("interface/history_function.jl") + end + @time @safetestset "Jacobian Tests" begin + include("interface/jacobian.jl") + end + @time @safetestset "Mass matrix Tests" begin + include("interface/mass_matrix.jl") + end + @time @safetestset "Parameterized Function Tests" begin + include("interface/parameters.jl") + end + @time @safetestset "saveat Tests" begin + include("interface/saveat.jl") + end + @time @safetestset "save_idxs Tests" begin + include("interface/save_idxs.jl") + end + @time @safetestset "Unconstrained Time Steps Tests" begin + include("interface/unconstrained.jl") + end + @time @safetestset "Units Tests" begin + include("interface/units.jl") + end end if GROUP == "All" || GROUP == "Integrators" - @time @safetestset "Cache Tests" begin include("integrators/cache.jl") end - @time @safetestset "Event Tests" begin include("integrators/events.jl") end - @time @safetestset "Iterator Tests" begin include("integrators/iterator.jl") end - @time @safetestset "Reinitialization Tests" begin include("integrators/reinit.jl") end - @time @safetestset "Residual Control Tests" begin include("integrators/residual_control.jl") end - @time @safetestset "Return Code Tests" begin include("integrators/retcode.jl") end - @time @safetestset "Rosenbrock Tests" begin include("integrators/rosenbrock.jl") end - @time @safetestset "SDIRK Tests" begin include("integrators/sdirk.jl") end - @time @safetestset "Unique Timepoints Tests" begin include("integrators/unique_times.jl") end - @time @safetestset "Verner Tests" begin include("integrators/verner.jl") end + @time @safetestset "Cache Tests" begin + include("integrators/cache.jl") + end + @time @safetestset "Event Tests" begin + include("integrators/events.jl") + end + @time @safetestset "Iterator Tests" begin + include("integrators/iterator.jl") + end + @time @safetestset "Reinitialization Tests" begin + include("integrators/reinit.jl") + end + @time @safetestset "Residual Control Tests" begin + include("integrators/residual_control.jl") + end + @time @safetestset "Return Code Tests" begin + include("integrators/retcode.jl") + end + @time @safetestset "Rosenbrock Tests" begin + include("integrators/rosenbrock.jl") + end + @time @safetestset "SDIRK Tests" begin + include("integrators/sdirk.jl") + end + @time @safetestset "Unique Timepoints Tests" begin + include("integrators/unique_times.jl") + end + @time @safetestset "Verner Tests" begin + include("integrators/verner.jl") + end end if GROUP == "All" || GROUP == "Regression" - @time @safetestset "Inference Tests" begin include("regression/inference.jl") end - @time @safetestset "Waltman Problem Tests" begin include("regression/waltman.jl") end + @time @safetestset "Inference Tests" begin + include("regression/inference.jl") + end + @time @safetestset "Waltman Problem Tests" begin + include("regression/waltman.jl") + end end