From b4661756fa2f8ac2d9c7e61f4c6cb07600c7901b Mon Sep 17 00:00:00 2001 From: obiajulu Date: Fri, 9 Sep 2016 12:35:14 -0400 Subject: [PATCH 1/2] Added ProgressMeter functionality --- REQUIRE | 1 + src/ODE.jl | 1 + src/options.jl | 10 ++++++++-- src/top-interface.jl | 22 ++++++++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/REQUIRE b/REQUIRE index ffc6c5b..7b5030a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -2,3 +2,4 @@ julia 0.5- Polynomials ForwardDiff Compat 0.4.1 +ProgressMeter diff --git a/src/ODE.jl b/src/ODE.jl index 73de9a6..d2d3941 100644 --- a/src/ODE.jl +++ b/src/ODE.jl @@ -22,6 +22,7 @@ using Polynomials using Compat import Compat.String using ForwardDiff +using ProgressMeter import Base: start, next, done, collect, show, convert diff --git a/src/options.jl b/src/options.jl index 6194c10..a6b7cac 100644 --- a/src/options.jl +++ b/src/options.jl @@ -16,6 +16,7 @@ General: - norm function to calculate the norm in step control - maxiters ::T maximum number of steps - isoutofdomain::Function checks if the solution is outside of the allowed domain +- progressmeter ::Bool display progressmeter """ immutable AdaptiveOptions{T,N<:Function,O<:Function} <: Options{T} @@ -28,6 +29,7 @@ immutable AdaptiveOptions{T,N<:Function,O<:Function} <: Options{T} norm::N maxiters::T isoutofdomain::O + progressmeter ::Bool end @compat function (::Type{AdaptiveOptions{T}}){T,N,O}(; @@ -41,9 +43,10 @@ end norm::N = y->maxabs(y), maxiters = T(1//0), isoutofdomain::O = Base.isnan, + progressmeter = false, kargs...) @assert minstep>=T(0) && maxstep>=T(0) && initstep>=T(0) # TODO: move to inner constructor - AdaptiveOptions{T,N,O}(tstop,reltol,abstol,minstep,maxstep,initstep,norm,maxiters,isoutofdomain) + AdaptiveOptions{T,N,O}(tstop,reltol,abstol,minstep,maxstep,initstep,norm,maxiters,isoutofdomain,progressmeter) end """ @@ -55,20 +58,23 @@ General: - initstep ::T initial step (always positive) - tstop ::T end integration time +- progressmeter ::Bool display progressmeter """ immutable FixedOptions{T} <: Options{T} tstop::T initstep::T + progressmeter ::Bool end @compat function (::Type{FixedOptions{T}}){T}(; tout = [T(1//0)], tstop = tout[end], initstep = T(1//100), + progressmeter = false, kargs...) @assert initstep>=0 - FixedOptions{T}(tstop,initstep) + FixedOptions{T}(tstop,initstep,progressmeter) end function show{T}(io::IO, opts :: Options{T}) diff --git a/src/top-interface.jl b/src/top-interface.jl index b72446a..c2dfff9 100644 --- a/src/top-interface.jl +++ b/src/top-interface.jl @@ -33,11 +33,25 @@ function ode{T,Y,M<:AbstractSolver}(F, y0::Y, to = Array(T,0) yo = Array(Y,0) - for (t,y) in prob - push!(to,t) - push!(yo, extract ? y[1] : copy(y)) - end + if !prob.solver.opts.progressmeter + for (t,y) in prob + (to,t) + push!(yo, extract ? y[1] : copy(y)) + end + else + t0 = prob.ivp.t0 + tf = prob.solver.opts.tstop + tdir = sign(tf-t0) + prog = Progress(round(Int,1000*tdir*(tf-t0)), "Solving:") + + for (t,y) in prob + (to,t) + push!(yo, extract ? y[1] : copy(y)) + prog.counter = max(1,round(Int,1000.0*tdir*(t-t0))) + ProgressMeter.updateProgress!(prog; showvalues = [(:current_t,t),(:final_t,prob.solver.opts.tstop)]) + end + end return (to,yo) end From f9fa142bf852b6ac87a3a9ed055d8cff96b6b755 Mon Sep 17 00:00:00 2001 From: obiajulu Date: Fri, 9 Sep 2016 14:21:32 -0400 Subject: [PATCH 2/2] caught small typo and updated README --- README.md | 1 + src/top-interface.jl | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3af94c6..816cbaf 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ The adaptive solvers accept the following keywords - `maxstep`, `minstep` and `initstep`: determine the maximal, minimal and initial integration step (defaults `minstep=|tspan[end] - tspan[1]|/1e9`, `maxstep=|tspan[end] - tspan[1]|/2.5` and automatic initial step estimation). - `points=:all` (default): output is given for each value in `tspan` as well as for each intermediate point the solver used. - `points=:specified`: output is given only for each value in `tspan`. +- `progressmeter = false` (default): if true, a progress meter of how much of the time span has been solved already will be displayed while the ODE solver is running Additionally, `ode23s` solver supports - `jacobian = G(t,y)`: user-supplied Jacobian G(t,y) = dF(t,y)/dy (default estimate by finite-difference method). diff --git a/src/top-interface.jl b/src/top-interface.jl index c2dfff9..cbbccd5 100644 --- a/src/top-interface.jl +++ b/src/top-interface.jl @@ -36,7 +36,7 @@ function ode{T,Y,M<:AbstractSolver}(F, y0::Y, if !prob.solver.opts.progressmeter for (t,y) in prob - (to,t) + push!(to,t) push!(yo, extract ? y[1] : copy(y)) end else @@ -46,7 +46,7 @@ function ode{T,Y,M<:AbstractSolver}(F, y0::Y, prog = Progress(round(Int,1000*tdir*(tf-t0)), "Solving:") for (t,y) in prob - (to,t) + push!(to,t) push!(yo, extract ? y[1] : copy(y)) prog.counter = max(1,round(Int,1000.0*tdir*(t-t0))) ProgressMeter.updateProgress!(prog; showvalues = [(:current_t,t),(:final_t,prob.solver.opts.tstop)])