Skip to content

Commit

Permalink
Merge pull request #429 from Vaibhavdixit02/save_start
Browse files Browse the repository at this point in the history
Change save_start to take saveat into consideration
  • Loading branch information
ChrisRackauckas authored Jul 13, 2018
2 parents be73bb1 + 29aeafc commit 45611bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ function init{algType<:OrdinaryDiffEqAlgorithm,recompile_flag}(
d_discontinuities= eltype(prob.tspan)[],
save_idxs = nothing,
save_everystep = isempty(saveat),
save_timeseries = nothing,save_start = true,save_end = true,
save_timeseries = nothing,
save_start = save_everystep || isempty(saveat) || typeof(saveat) <: Number ? true : prob.tspan[1] in saveat,
save_end = save_everystep || isempty(saveat) || typeof(saveat) <: Number ? true : prob.tspan[2] in saveat,
callback=nothing,
dense = save_everystep && !(typeof(alg) <: FunctionMap),
dense = save_everystep && !(typeof(alg) <: FunctionMap) && isempty(saveat),
calck = (callback != nothing && callback != CallbackSet()) || # Empty callback
(prob.callback != nothing && prob.callback != CallbackSet()) || # Empty prob.callback
(!isempty(setdiff(saveat,tstops)) || dense), # and no dense output
Expand Down
52 changes: 27 additions & 25 deletions test/ode/ode_saveat_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,67 @@ using OrdinaryDiffEq, DiffEqProblemLibrary, Base.Test
@testset "saveat Tests" begin
prob = prob_ode_linear

sol =solve(prob,DP5(),dt=1//2^(2),save_everystep=false,dense=false)
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,dense=false,saveat=[1/2])
sol =solve(prob,DP5(),dt=1//2^(2),save_everystep=false)
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,saveat=[1/2])

@test symdiff(sol.t,sol2.t) == [1/2]
@test sort!(symdiff(sol.t,sol2.t)) == [0.0,1/2,1.0]

sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,dense=false,saveat=1/2)
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,saveat=[0.0,1/2,1.0])

@test symdiff(sol.t,sol2.t) == [1/2]

sol3=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,dense=false,saveat=[1/2],tstops=[1/2])
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,saveat=1/2)

@test sort!(symdiff(sol.t,sol2.t)) == [1/2]

sol3=solve(prob,DP5(),dt=1//2^(2),save_everystep=false,saveat=[1/2],tstops=[1/2])

@test sol3.t == [0.0,0.5,1.00]
@test sol3.t == [1/2]

sol3=solve(prob,DP5(),dt=1//2^(2),saveat=[1/2],tstops=[1/2])
sol3=solve(prob,DP5(),dt=1//2^(2),saveat=[0.0,1/2,1.0],tstops=[1/2])

@test sol3.t == [0.0,0.5,1.00]
@test sol3.t == [0.0,1/2,1.0]

sol3=solve(prob,DP5(),dt=1//2^(2),saveat=1/10,tstops=[1/2])

@test sol3.t == collect(0.0:0.1:1.00)

#plot(0:1//2^(4):1,interpd)

sol =solve(prob,RK4(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,RK4(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,RK4(),dt=1/2^(2),save_everystep=true,adaptive=false)
sol2=solve(prob,RK4(),dt=1/2^(2),save_everystep=true,adaptive=false,saveat=[.125,.6,.61,.8])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]

sol =solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true)
sol2=solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,saveat=[.125,.6,.61,.8])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]

sol =solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true)
sol2=solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,saveat=[.125,.6,.61,.8])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]

prob = prob_ode_2Dlinear

sol =solve(prob,DP5(),dt=1//2^(2),save_everystep=true,dense=false)
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=true,dense=false,saveat=[1/2])
sol =solve(prob,DP5(),dt=1//2^(2),save_everystep=true)
sol2=solve(prob,DP5(),dt=1//2^(2),save_everystep=true,saveat=[0.0,1/2,1.0])

@test symdiff(sol.t,sol2.t) == [1/2]

sol =solve(prob,RK4(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,RK4(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,RK4(),dt=1/2^(2),save_everystep=true,adaptive=false)
sol2=solve(prob,RK4(),dt=1/2^(2),save_everystep=true,adaptive=false,saveat=[0.0,.125,.6,.61,.8,1.0])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]

sol =solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true)
sol2=solve(prob,Rosenbrock32(),dt=1/2^(2),save_everystep=true,saveat=[.125,.6,.61,.8])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]

sol =solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,dense=false)
sol2=solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[.125,.6,.61,.8])
sol =solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=false)
sol2=solve(prob,GenericTrapezoid(),dt=1/2^(2),saveat=[.125,.6,.61,.8])

@test symdiff(sol.t,sol2.t) == [.125,.6,.61,.8]
@test sort!(symdiff(sol.t,sol2.t)) == [0.0,.125,.6,.61,.8,1.0]

sol=solve(prob,GenericTrapezoid(),dt=1/2^(2),save_everystep=true,dense=false,saveat=[0,.125,.6,.61,.8])

Expand Down

0 comments on commit 45611bc

Please sign in to comment.