-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from SciML/as/prob-state-history
feat: add optional history function to `ProblemState`
- Loading branch information
Showing
3 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
""" | ||
struct ProblemState | ||
function ProblemState(; u = nothing, p = nothing, t = nothing) | ||
function ProblemState(; u = nothing, p = nothing, t = nothing, h = nothing) | ||
A value provider struct which can be used as an argument to the function returned by | ||
[`getsym`](@ref) or [`setsym`](@ref). It stores the state vector, parameter object and | ||
current time, and forwards calls to [`state_values`](@ref), [`parameter_values`](@ref), | ||
[`current_time`](@ref), [`set_state!`](@ref), [`set_parameter!`](@ref) to the contained | ||
objects. | ||
A history function may be provided using the `h` keyword, which will be returned with | ||
[`get_history_function`](@ref). | ||
""" | ||
struct ProblemState{U, P, T} | ||
struct ProblemState{U, P, T, H} | ||
u::U | ||
p::P | ||
t::T | ||
h::H | ||
end | ||
|
||
ProblemState(; u = nothing, p = nothing, t = nothing) = ProblemState(u, p, t) | ||
function ProblemState(; u = nothing, p = nothing, t = nothing, h = nothing) | ||
ProblemState(u, p, t, h) | ||
end | ||
|
||
state_values(ps::ProblemState) = ps.u | ||
parameter_values(ps::ProblemState) = ps.p | ||
current_time(ps::ProblemState) = ps.t | ||
set_state!(ps::ProblemState, val, idx) = set_state!(ps.u, val, idx) | ||
set_parameter!(ps::ProblemState, val, idx) = set_parameter!(ps.p, val, idx) | ||
get_history_function(ps::ProblemState) = ps.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters