Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding interface for getting current state of integrator. #16

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DormandPrince"
uuid = "5e45e72d-22b8-4dd0-9c8b-f96714864bcd"
authors = ["John Long<[email protected]>", "Phillip Weinberg<[email protected]>"]
version = "0.2.0"
version = "0.3.0"

[deps]

Expand Down
7 changes: 4 additions & 3 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# integrate to first time
integrate(solver_iter.solver, first(solver_iter.times))
# return value and index which is the state
return (solver_iter.times[1], solver_iter.solver.y), 2
return (solver_iter.times[1], get_current_state(solver_iter.solver)), 2
end

# gets the next (t,y), return index+! which is the updated state
Expand All @@ -21,14 +21,15 @@
# integrate to next time
integrate(solver_iter.solver, solver_iter.times[index])
# return time and state
return (solver_iter.times[index], solver_iter.solver.y), index+1
return (solver_iter.times[index], get_current_state(solver_iter.solver)), index+1
end

# 3 modes of operation for integrate
# 1. integrate(solver, time) -> state (modify solver object in place)
# 2. integrate(solver, times) -> iterator
# 3. integrate(callback, solver, times) -> vector of states with callback applied

get_current_state(::AbstractDPSolver) = error("not implemented")

Check warning on line 32 in src/interface.jl

View check run for this annotation

Codecov / codecov/patch

src/interface.jl#L32

Added line #L32 was not covered by tests
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}
Expand All @@ -37,7 +38,7 @@
result = []
for time in times
integrate(solver, time)
push!(result, callback(time, solver.y))
push!(result, callback(time, get_current_state(solver)))
end

return result
Expand Down
2 changes: 2 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,5 @@ function DP8Solver(
DP8Solver(f, x, y, k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, y1;kw...)
end

get_current_state(solver::DP5Solver) = solver.y
get_current_state(solver::DP8Solver) = solver.y
Loading