diff --git a/src/interface.jl b/src/interface.jl index 1c10423..06c0512 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -1,5 +1,5 @@ -struct DP5Iterator{T <: Real} +struct SolverIterator{T <: Real} solver::AbstractDPSolver times::AbstractVector{T} end @@ -7,7 +7,7 @@ end # gets the first (t,y), return index which is the state # here we choose 2 because 1 is the initial state which # is has been returned by the iterator -function Base.iterate(dp5_iterator::DP5Iterator) +function Base.iterate(dp5_iterator::SolverIterator) length(dp5_iterator.times) == 0 && return nothing # empty iterator # integrate to first time integrate(dp5_iterator.solver, first(dp5_iterator.times)) @@ -16,7 +16,7 @@ function Base.iterate(dp5_iterator::DP5Iterator) end # gets the next (t,y), return index+! which is the updated state -function Base.iterate(dp5_iterator::DP5Iterator, index::Int) +function Base.iterate(dp5_iterator::SolverIterator, index::Int) index > length(dp5_iterator.times) && return nothing # end of iterator # integrate to next time integrate(dp5_iterator.solver, dp5_iterator.times[index]) @@ -29,7 +29,7 @@ end # 2. integrate(solver, times) -> iterator # 3. integrate(callback, solver, times) -> vector of states with callback applied -integrate(solver::AbstractDPSolver{T}, times::AbstractVector{T}) where {T <: Real} = DP5Iterator(solver, times) +integrate(solver::AbstractDPSolver{T}, times::AbstractVector{T}) where {T <: Real} = SolverIterator(solver, times) function integrate(callback, solver::AbstractDPSolver{T}, times::AbstractVector{T}; sort_times::Bool = true) where {T <: Real} times = sort_times ? sort(collect(times)) : times