Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #122 from JuliaDiffEq/interface_update
Browse files Browse the repository at this point in the history
Update common interface
  • Loading branch information
ChrisRackauckas authored Apr 12, 2017
2 parents 5196eea + 74e2866 commit 4294ed1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
Polynomials
Compat 0.9
DiffEqBase
DiffEqBase 0.15.0
50 changes: 42 additions & 8 deletions src/common.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
function solve{uType,tType,isinplace,AlgType<:ODEjlAlgorithm,F}(prob::AbstractODEProblem{uType,tType,isinplace,F},
alg::AlgType,timeseries=[],ts=[],ks=[];dense=true,save_timeseries=true,
saveat=tType[],timeseries_errors=true,reltol = 1e-5, abstol = 1e-8,
function solve{uType,tType,isinplace,AlgType<:ODEjlAlgorithm}(prob::AbstractODEProblem{uType,tType,isinplace},
alg::AlgType,timeseries=[],ts=[],ks=[];dense=true,
save_timeseries=nothing,
saveat=tType[],reltol = 1e-5, abstol = 1e-8,
save_everystep=isempty(saveat),
save_start = true,
dtmin = abs(prob.tspan[2]-prob.tspan[1])/1e-9,
dtmax = abs(prob.tspan[2]-prob.tspan[1])/2.5,
timeseries_errors=true,dense_errors=false,
dt = 0.,norm = Base.vecnorm,
kwargs...)

if save_timeseries != nothing
warn("save_timeseries is deprecated. Use save_everystep instead")
save_everystep = save_timeseries
end

tspan = prob.tspan

u0 = prob.u0

Ts = unique([tspan[1];saveat;tspan[2]])
if typeof(saveat) <: Number
saveat_vec = convert(Vector{tType},saveat:saveat:(tspan[end]-saveat))
# Exclude the endpoint because of floating point issues
else
saveat_vec = convert(Vector{tType},collect(saveat))
end

if save_timeseries
if !isempty(saveat_vec) && saveat_vec[end] == tspan[2]
pop!(saveat_vec)
end

if !isempty(saveat_vec) && saveat_vec[1] == tspan[1]
Ts = unique([saveat_vec;tspan[2]])
else
Ts = unique([tspan[1];saveat_vec;tspan[2]])
end

if save_everystep
points = :all
else
points = :specified
Expand Down Expand Up @@ -41,16 +65,26 @@ function solve{uType,tType,isinplace,AlgType<:ODEjlAlgorithm,F}(prob::AbstractOD
initstep=dt,
points=points)

# Reshape the result if needed

if save_start
start_idx = 1 # The index to start making the timeseries from
else
start_idx = 2
ts = ts[2:end]
end

# Reshape the result if needed
if uType <: AbstractArray
timeseries = Vector{uType}(0)
for i=1:length(timeseries_tmp)
for i=start_idx:length(timeseries_tmp)
push!(timeseries,reshape(timeseries_tmp[i],sizeu))
end
else
timeseries = timeseries_tmp
end

build_solution(prob,alg,ts,timeseries,
timeseries_errors = timeseries_errors)
timeseries_errors = timeseries_errors,
dense_errors = dense_errors,
retcode = :Succss)
end

0 comments on commit 4294ed1

Please sign in to comment.