Skip to content

Commit

Permalink
implement retcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Mar 30, 2017
1 parent 2349ac0 commit f84c545
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
12 changes: 7 additions & 5 deletions src/solutions/dae_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type DAESolution{uType,duType,tType,ID,P,A} <: AbstractODESolution
interp::Function
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::DAESolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::DAESolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)
Expand All @@ -26,22 +27,23 @@ type DAETestSolution{uType,duType,uType2,uEltype,tType,ID,P,A} <: AbstractODESol
interp::Function
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::DAETestSolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::DAETestSolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)

function build_solution{uType,duType,tType,isinplace,F}(
prob::AbstractDAEProblem{uType,duType,tType,isinplace,F},
alg,t,u;dense=false,du=[],
interp_data=[],interp = (tvals) -> nothing,kwargs...)
DAESolution(u,du,t,interp_data,prob,alg,interp,dense,0)
interp_data=[],interp = (tvals) -> nothing,retcode = :Default, kwargs...)
DAESolution(u,du,t,interp_data,prob,alg,interp,dense,0,retcode)
end

function build_solution{uType,duType,tType,isinplace,F}(
prob::AbstractDAETestProblem{uType,duType,tType,isinplace,F},
alg,t,u;dense=false,du=[],
interp_data=[],interp = (tvals) -> nothing,
timeseries_errors=true,dense_errors=true,kwargs...)
timeseries_errors=true,dense_errors=true, retcode = :Default, kwargs...)

u_analytic = Vector{uType}(0)
for i in 1:size(u,1)
Expand All @@ -66,10 +68,10 @@ function build_solution{uType,duType,tType,isinplace,F}(
end
end
end
DAETestSolution(u,du,u_analytic,errors,t,interp_data,prob,alg,interp,dense,0)
DAETestSolution(u,du,u_analytic,errors,t,interp_data,prob,alg,interp,dense,0,retcode)
end

function build_solution(sol::AbstractDAESolution,u_analytic,errors)
DAETestSolution(sol.u,sol.du,u_analytic,errors,sol.t,sol.interp_data,
sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation)
sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation,sol.retcode)
end
12 changes: 7 additions & 5 deletions src/solutions/dde_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type DDESolution{uType,tType,rateType,P,A,IType} <: AbstractDDESolution
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::DDESolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::DDESolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)
Expand All @@ -24,26 +25,27 @@ type DDETestSolution{uType,uType2,uEltype,tType,rateType,P,A,IType} <: AbstractD
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::DDETestSolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::DDETestSolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)

function build_solution{uType,tType,isinplace}(
prob::AbstractDDEProblem{uType,tType,isinplace},
alg,t,u;dense=false,
k=[],interp = (tvals) -> nothing,kwargs...)
ODESolution(u,t,k,prob,alg,interp,dense,0)
k=[],interp = (tvals) -> nothing, retcode = :Default, kwargs...)
ODESolution(u,t,k,prob,alg,interp,dense,0,retcode)
end

function build_solution{uType,tType,isinplace}(
prob::AbstractDDETestProblem{uType,tType,isinplace},
alg,t,u;dense=false,
k=[],interp = (tvals) -> nothing,
timeseries_errors=true,dense_errors=true,
calculate_error = true,kwargs...)
calculate_error = true,retcode = :Default, kwargs...)
u_analytic = Vector{uType}(0)
errors = Dict{Symbol,eltype(u[1])}()
sol = ODETestSolution(u,u_analytic,errors,t,k,prob,alg,interp,dense,0)
sol = ODETestSolution(u,u_analytic,errors,t,k,prob,alg,interp,dense,0,retcode)
if calculate_error
calculate_solution_errors!(sol;timeseries_errors=timeseries_errors,dense_errors=dense_errors)
end
Expand Down Expand Up @@ -76,5 +78,5 @@ function calculate_solution_errors!(sol::AbstractDDETestSolution;fill_uanalytic=
end

function build_solution(sol::AbstractDDESolution,u_analytic,errors)
DDETestSolution(sol.u,u_analytic,errors,sol.t,sol.k,sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation)
DDETestSolution(sol.u,u_analytic,errors,sol.t,sol.k,sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation,sol.retcode)
end
12 changes: 7 additions & 5 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type ODESolution{uType,tType,rateType,P,A,IType} <: AbstractODESolution
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::ODESolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::ODESolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)
Expand All @@ -24,26 +25,27 @@ type ODETestSolution{uType,uType2,uEltype,tType,rateType,P,A,IType} <: AbstractO
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::ODETestSolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::ODETestSolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)

function build_solution{uType,tType,isinplace}(
prob::AbstractODEProblem{uType,tType,isinplace},
alg,t,u;dense=false,
k=[],interp = (tvals) -> nothing,kwargs...)
ODESolution(u,t,k,prob,alg,interp,dense,0)
k=[],interp = (tvals) -> nothing, retcode = :Default, kwargs...)
ODESolution(u,t,k,prob,alg,interp,dense,0,retcode)
end

function build_solution{uType,tType,isinplace}(
prob::AbstractODETestProblem{uType,tType,isinplace},
alg,t,u;dense=false,
k=[],interp = (tvals) -> nothing,
timeseries_errors=true,dense_errors=true,
calculate_error = true,kwargs...)
calculate_error = true,retcode = :Default,kwargs...)
u_analytic = Vector{uType}(0)
errors = Dict{Symbol,eltype(u[1])}()
sol = ODETestSolution(u,u_analytic,errors,t,k,prob,alg,interp,dense,0)
sol = ODETestSolution(u,u_analytic,errors,t,k,prob,alg,interp,dense,0,retcode)
if calculate_error
calculate_solution_errors!(sol;timeseries_errors=timeseries_errors,dense_errors=dense_errors)
end
Expand Down Expand Up @@ -76,5 +78,5 @@ function calculate_solution_errors!(sol::AbstractODETestSolution;fill_uanalytic=
end

function build_solution(sol::AbstractODESolution,u_analytic,errors)
ODETestSolution(sol.u,u_analytic,errors,sol.t,sol.k,sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation)
ODETestSolution(sol.u,u_analytic,errors,sol.t,sol.k,sol.prob,sol.alg,sol.interp,sol.dense,sol.tslocation,sol.retcode)
end
12 changes: 7 additions & 5 deletions src/solutions/sde_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type SDESolution{uType,tType,IType,randType,P,A} <: AbstractSDESolution
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::SDESolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::SDESolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)
Expand All @@ -28,6 +29,7 @@ type SDETestSolution{uType,uType2,uEltype,tType,IType,randType,P,A} <: AbstractS
interp::IType
dense::Bool
tslocation::Int
retcode::Symbol
end
(sol::SDETestSolution)(t,deriv::Type=Val{0};idxs=nothing) = sol.interp(t,idxs,deriv)
(sol::SDETestSolution)(v,t,deriv::Type=Val{0};idxs=nothing) = sol.interp(v,t,idxs,deriv)
Expand All @@ -36,21 +38,21 @@ function build_solution{uType,tType,isinplace,NoiseClass,F,F2,F3}(
prob::AbstractSDEProblem{uType,tType,isinplace,NoiseClass,F,F2,F3},
alg,t,u;W=[],maxstacksize=0,maxstacksize2=0,
interp = (tvals) -> nothing,
dense = false,kwargs...)
SDESolution(u,t,W,prob,alg,maxstacksize,maxstacksize2,interp,dense,0)
dense = false,retcode = :Default, kwargs...)
SDESolution(u,t,W,prob,alg,maxstacksize,maxstacksize2,interp,dense,0,retcode)
end

function build_solution{uType,tType,isinplace,NoiseClass,F,F2,F3}(
prob::AbstractSDETestProblem{uType,tType,isinplace,NoiseClass,F,F2,F3},
alg,t,u;W=[],timeseries_errors=true,dense_errors=false,calculate_error=true,
maxstacksize=0,maxstacksize2=0,
interp = (tvals) -> nothing,
dense = false,kwargs...)
dense = false, retcode = :Default, kwargs...)

u_analytic = Vector{uType}(0)
save_timeseries = length(u) > 2
errors = Dict{Symbol,eltype(u[1])}()
sol = SDETestSolution(u,u_analytic,errors,t,W,prob,alg,maxstacksize,maxstacksize2,interp,dense,0)
sol = SDETestSolution(u,u_analytic,errors,t,W,prob,alg,maxstacksize,maxstacksize2,interp,dense,0,retcode)
if calculate_error
calculate_solution_errors!(sol;timeseries_errors=timeseries_errors,dense_errors=dense_errors)
end
Expand All @@ -76,5 +78,5 @@ function calculate_solution_errors!(sol::AbstractSDETestSolution;fill_uanalytic=
end

function build_solution(sol::AbstractSDESolution,u_analytic,errors)
SDETestSolution(sol.u,u_analytic,errors,sol.t,sol.W,sol.prob,sol.alg,sol.maxstacksize,sol.dense,sol.tslocation)
SDETestSolution(sol.u,u_analytic,errors,sol.t,sol.W,sol.prob,sol.alg,sol.maxstacksize,sol.dense,sol.tslocation,sol.retcode)
end

0 comments on commit f84c545

Please sign in to comment.