diff --git a/src/ODEInterfaceDiffEq.jl b/src/ODEInterfaceDiffEq.jl index 6f3b56b..71007e8 100644 --- a/src/ODEInterfaceDiffEq.jl +++ b/src/ODEInterfaceDiffEq.jl @@ -6,6 +6,7 @@ using Reexport @reexport using DiffEqBase using ODEInterface, Compat, DataStructures, FunctionWrappers, Roots +using LinearAlgebra import DiffEqBase: solve @@ -14,7 +15,7 @@ const warnkeywords = :calck, :progress, :timeseries_steps, :dense,:save_start) function __init__() - const global warnlist = Set(warnkeywords) + global warnlist = Set(warnkeywords) end @compat const KW = Dict{Symbol,Any} diff --git a/src/algorithms.jl b/src/algorithms.jl index 7357eb2..b05d69f 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -1,12 +1,12 @@ # ODEInterface.jl Algorithms @compat abstract type ODEInterfaceAlgorithm <: DiffEqBase.AbstractODEAlgorithm end -immutable dopri5 <: ODEInterfaceAlgorithm end -immutable dop853 <: ODEInterfaceAlgorithm end -immutable odex <: ODEInterfaceAlgorithm end -immutable seulex <: ODEInterfaceAlgorithm end -immutable radau <: ODEInterfaceAlgorithm end -immutable radau5 <: ODEInterfaceAlgorithm end -immutable rodas <: ODEInterfaceAlgorithm end -immutable ddeabm <: ODEInterfaceAlgorithm end -immutable ddebdf <: ODEInterfaceAlgorithm end +struct dopri5 <: ODEInterfaceAlgorithm end +struct dop853 <: ODEInterfaceAlgorithm end +struct odex <: ODEInterfaceAlgorithm end +struct seulex <: ODEInterfaceAlgorithm end +struct radau <: ODEInterfaceAlgorithm end +struct radau5 <: ODEInterfaceAlgorithm end +struct rodas <: ODEInterfaceAlgorithm end +struct ddeabm <: ODEInterfaceAlgorithm end +struct ddebdf <: ODEInterfaceAlgorithm end diff --git a/src/callbacks.jl b/src/callbacks.jl index bd0f121..7230b8c 100644 --- a/src/callbacks.jl +++ b/src/callbacks.jl @@ -29,11 +29,11 @@ end @inline function determine_event_occurance(integrator,callback) event_occurred = false - Θs = linspace(typeof(integrator.t)(0),typeof(integrator.t)(1),callback.interp_points) + Θs = range(typeof(integrator.t)(0),stop=typeof(integrator.t)(1),length=callback.interp_points) interp_index = 0 dt = integrator.t - integrator.tprev # Check if the event occured - if typeof(callback.idxs) <: Void + if typeof(callback.idxs) <: Nothing previous_condition = callback.condition(integrator.uprev,integrator.tprev,integrator) elseif typeof(callback.idxs) <: Number previous_condition = callback.condition(integrator.uprev[callback.idxs],integrator.tprev,integrator) @@ -69,14 +69,14 @@ end end prev_sign_index = 1 - if typeof(callback.idxs) <: Void + if typeof(callback.idxs) <: Nothing next_sign = sign(callback.condition(integrator.u,integrator.t,integrator)) elseif typeof(callback.idxs) <: Number next_sign = sign(callback.condition(integrator.u[callback.idxs],integrator.t,integrator)) else next_sign = sign(callback.condition(@view(integrator.u[callback.idxs]),integrator.t,integrator)) end - if ((prev_sign<0 && !(typeof(callback.affect!)<:Void)) || (prev_sign>0 && !(typeof(callback.affect_neg!)<:Void))) && prev_sign*next_sign<=0 + if ((prev_sign<0 && !(typeof(callback.affect!)<:Nothing)) || (prev_sign>0 && !(typeof(callback.affect_neg!)<:Nothing))) && prev_sign*next_sign<=0 event_occurred = true interp_index = callback.interp_points elseif callback.interp_points!=0 # Use the interpolants for safety checking @@ -92,7 +92,7 @@ end prev_sign = sign(new_sign) prev_sign_index = i end - if ((prev_sign<0 && !(typeof(callback.affect!)<:Void)) || (prev_sign>0 && !(typeof(callback.affect_neg!)<:Void))) && prev_sign*new_sign<0 + if ((prev_sign<0 && !(typeof(callback.affect!)<:Nothing)) || (prev_sign>0 && !(typeof(callback.affect_neg!)<:Nothing))) && prev_sign*new_sign<0 event_occurred = true interp_index = i break @@ -106,7 +106,7 @@ function find_callback_time(integrator,callback) event_occurred,interp_index,Θs,prev_sign,prev_sign_index = determine_event_occurance(integrator,callback) dt = integrator.t - integrator.tprev if event_occurred - if typeof(callback.condition) <: Void + if typeof(callback.condition) <: Nothing new_t = zero(typeof(integrator.t)) else if callback.interp_points!=0 @@ -170,13 +170,13 @@ function apply_callback!(integrator,callback::ContinuousCallback,cb_time,prev_si integrator.u_modified = true if prev_sign < 0 - if typeof(callback.affect!) <: Void + if typeof(callback.affect!) <: Nothing integrator.u_modified = false else callback.affect!(integrator) end elseif prev_sign > 0 - if typeof(callback.affect_neg!) <: Void + if typeof(callback.affect_neg!) <: Nothing integrator.u_modified = false else callback.affect_neg!(integrator) diff --git a/src/solve.jl b/src/solve.jl index 127d155..05264f8 100644 --- a/src/solve.jl +++ b/src/solve.jl @@ -1,4 +1,4 @@ -function solve{uType,tuptType,isinplace,AlgType<:ODEInterfaceAlgorithm}( +function solve( prob::DiffEqBase.AbstractODEProblem{uType,tuptType,isinplace}, alg::AlgType, timeseries=[],ts=[],ks=[]; @@ -6,7 +6,8 @@ function solve{uType,tuptType,isinplace,AlgType<:ODEInterfaceAlgorithm}( verbose=true,save_everystep = isempty(saveat), save_start=true, timeseries_errors=true,dense_errors=false, - callback=nothing,kwargs...) + callback=nothing,kwargs...) where + {uType,tuptType,isinplace,AlgType<:ODEInterfaceAlgorithm} tType = eltype(tuptType) @@ -15,7 +16,7 @@ function solve{uType,tuptType,isinplace,AlgType<:ODEInterfaceAlgorithm}( warned = !isempty(kwargs) && check_keywords(alg, kwargs, warnlist) if !(typeof(prob.f) <: DiffEqBase.AbstractParameterizedFunction) && isstiff if DiffEqBase.has_tgrad(prob.f) - warn("Explicit t-gradient given to this stiff solver is ignored.") + @warn("Explicit t-gradient given to this stiff solver is ignored.") warned = true end end @@ -55,8 +56,8 @@ function solve{uType,tuptType,isinplace,AlgType<:ODEInterfaceAlgorithm}( o[:RHS_CALLMODE] = ODEInterface.RHS_CALL_INSITU if save_everystep - _timeseries = Vector{uType}(0) - ts = Vector{tType}(0) + _timeseries = Vector{uType}(undef,0) + ts = Vector{tType}(undef,0) else _timeseries = [copy(u0)] ts = [tspan[1]] diff --git a/test/algorithm_tests.jl b/test/algorithm_tests.jl index a40b86f..5d37a38 100644 --- a/test/algorithm_tests.jl +++ b/test/algorithm_tests.jl @@ -1,4 +1,7 @@ using ODEInterfaceDiffEq, DiffEqProblemLibrary, DiffEqBase, Test +using DiffEqProblemLibrary.ODEProblemLibrary: importodeproblems; importodeproblems() +import DiffEqProblemLibrary.ODEProblemLibrary: prob_ode_linear, + prob_ode_2Dlinear, prob_ode_vanderpol prob = prob_ode_linear sol =solve(prob,dopri5(),dt=1//2^(4)) diff --git a/test/callbacks.jl b/test/callbacks.jl index 514bd41..fb2732d 100644 --- a/test/callbacks.jl +++ b/test/callbacks.jl @@ -1,4 +1,4 @@ -using ODEInterfaceDiffEq, Base.Test +using ODEInterfaceDiffEq, Test callback_f = function (du,u,p,t) du[1] = u[2] diff --git a/test/jac_tests.jl b/test/jac_tests.jl index 8881e6e..9c62a05 100644 --- a/test/jac_tests.jl +++ b/test/jac_tests.jl @@ -1,5 +1,5 @@ using ODEInterfaceDiffEq, DiffEqProblemLibrary, DiffEqBase -using Base.Test +using Test jac_called = false diff --git a/test/mass_matrix_tests.jl b/test/mass_matrix_tests.jl index f312402..1c2ec19 100644 --- a/test/mass_matrix_tests.jl +++ b/test/mass_matrix_tests.jl @@ -1,5 +1,8 @@ using ODEInterfaceDiffEq, DiffEqProblemLibrary, DiffEqBase -using Base.Test +using Test + +using DiffEqProblemLibrary.ODEProblemLibrary: importodeproblems; importodeproblems() +import DiffEqProblemLibrary.ODEProblemLibrary: prob_ode_mm_linear prob = prob_ode_mm_linear diff --git a/test/runtests.jl b/test/runtests.jl index 1b37778..a3a260b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using ODEInterfaceDiffEq, DiffEqProblemLibrary, DiffEqBase -using Base.Test +using Test @time @testset "Algorithms" begin include("algorithm_tests.jl") end @time @testset "Saving" begin include("saving_tests.jl") end diff --git a/test/saving_tests.jl b/test/saving_tests.jl index bd74ec6..4378cdd 100644 --- a/test/saving_tests.jl +++ b/test/saving_tests.jl @@ -1,5 +1,8 @@ using ODEInterfaceDiffEq, DiffEqProblemLibrary, DiffEqBase -using Base.Test +using Test + +using DiffEqProblemLibrary.ODEProblemLibrary: importodeproblems; importodeproblems() +import DiffEqProblemLibrary.ODEProblemLibrary: prob_ode_linear prob = prob_ode_linear sol =solve(prob,dopri5(),dt=1//2^(4))