Skip to content

Commit

Permalink
Merge pull request #80 from JuliaReach/mforets/79
Browse files Browse the repository at this point in the history
#79 - Update IVPs interface for TMJets
  • Loading branch information
mforets authored Apr 2, 2020
2 parents 5f4cdaa + d8210f5 commit 79d62a8
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 18 deletions.
6 changes: 5 additions & 1 deletion src/Algorithms/TMJets/post.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ function post(alg::TMJets{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan; kwarg
T = tend(tspan)

# vector field
f! = VectorField(ivp)
if islinear(ivp) || isaffine(ivp) # TODO: refactor with inplace_field!
f! = inplace_field!(ivp)
else
f! = VectorField(ivp)
end
n = statedim(ivp)

# initial set
Expand Down
16 changes: 16 additions & 0 deletions src/Flowpipes/fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,19 @@ end
function vector_field(sys::AbstractSystem, args...)
return evaluate(VectorField(sys), args...)
end

function outofplace_field(ivp::InitialValueProblem)
# function closure over the inital-value problem
f = function f_outofplace(x, p, t)
VectorField(ivp)(x)
end
return f
end

function inplace_field!(ivp::InitialValueProblem)
# function closure over the inital-value problem
f! = function f_inplace!(dx, x, p, t)
dx .= VectorField(ivp)(x)
end
return f_inplace!
end
16 changes: 0 additions & 16 deletions src/Initialization/init_DifferentialEquations.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
using .DifferentialEquations

function outofplace_field(ivp::InitialValueProblem)
# function closure over the inital-value problem
f = function f_outofplace(x, p, t)
VectorField(ivp)(x)
end
return f
end

function inplace_field!(ivp::InitialValueProblem)
# function closure over the inital-value problem
f! = function f_inplace!(dx, x, p, t)
dx .= VectorField(ivp)(x)
end
return f_inplace!
end

# extend the solve API for initial-value problems
function DifferentialEquations.solve(ivp::InitialValueProblem, args...; kwargs...)
tspan = _get_tspan(args...; kwargs...)
Expand Down
27 changes: 27 additions & 0 deletions test/algorithms/TMJets.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@testset "TMJets with a linear IVP" begin
prob, tspan = exponential_1d()
sol = solve(prob, tspan=tspan, TMJets())
@test sol.alg isa TMJets
end

@testset "TMJets interface" begin
prob, tspan = vanderpol()

# default algorithm for nonlinear systems
sol = solve(prob, tspan=tspan)
@test sol.alg isa TMJets

# pass the algorithm explicitly
sol = solve(prob, tspan=tspan, TMJets())
@test sol.alg isa TMJets

# TODO: try different options
end

#=
alg = TMJets(abs_tol=1e-10, orderT=10, orderQ=2)
# reach mode
sol = solve(P, T=7.0, alg)
@test set(sol[1]) isa Hyperrectangle # check default set representation
=#
7 changes: 7 additions & 0 deletions test/models/linear/exponential1D.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function exponential_1d()
s = @system(x' = -x)
x0 = Interval(0.4, 0.5)
prob = InitialValueProblem(s, x0)
tspan = (0.0, 1.0)
return prob, tspan
end
42 changes: 42 additions & 0 deletions test/models/nonlinear/vanderpol.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# =======================================
# Van der Pol oscillator
# #include("models/lotka_volterra.jl")
# https://en.wikipedia.org/wiki/Van_der_Pol_oscillator
# Number of state variables: 2
# =======================================

@taylorize function vanderPol!(dx, x, params, t)
local μ = 1.0
dx[1] = x[2]
dx[2] =* x[2]) * (1 - x[1]^2) - x[1]
return dx
end

function vanderpol()
X0 = Hyperrectangle(low=[1.25, 2.35], high=[1.55, 2.45])
prob = @ivp(x' = vanderPol!(x), dim: 2, x(0) X0)
tspan = (0.0, 5.0)

return prob, tspan
end

#=
OLD
# check mode
property = (t, x) -> x[2] <= 2.75
sol = solve(P, T=7.0, property=property, alg)
# test set representation option
sol = solve(P, T=7.0, setrep=:Hyperrectangle, alg)
@test set(sol[1]) isa Hyperrectangle
sol = solve(P, T=7.0, setrep=:IntervalBox, alg)
@test set(sol[1]) isa IntervalBox
sol = solve(P, T=7.0, setrep=:Zonotope, alg)
@test set(sol[1]) isa Zonotope
sol = solve(P, T=7.0, setrep=:TaylorModel, alg)
@test set(sol[1]) isa TaylorModel
=#
9 changes: 8 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ include("solve.jl")
include("reachsets.jl")
#include("traces.jl")

# load test models
include("models/linear/exponential1D.jl")
include("models/nonlinear/vanderpol.jl")

# check algorithms
#include("algorithms/INT.jl")
#include("algorithms/BOX.jl")
#include("algorithms/GLGM06.jl")
#include("algorithms/BFFPSV18.jl")
#include("algorithms/TMJets.jl")
include("algorithms/TMJets.jl")

0 comments on commit 79d62a8

Please sign in to comment.