Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Added ProgressMeter functionality [Experimental/RFC] #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ julia 0.5-
Polynomials
ForwardDiff
Compat 0.4.1
ProgressMeter
1 change: 1 addition & 0 deletions src/ODE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using Polynomials
using Compat
import Compat.String
using ForwardDiff
using ProgressMeter

import Base: start, next, done, collect, show, convert

Expand Down
10 changes: 8 additions & 2 deletions src/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}(;
Expand All @@ -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

"""
Expand All @@ -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})
Expand Down
22 changes: 18 additions & 4 deletions src/top-interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
push!(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
push!(to,t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4-indent

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

Expand Down