You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/state_indexing.jl
+18-6Lines changed: 18 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -48,6 +48,20 @@ See: [`is_timeseries`](@ref)
48
48
"""
49
49
function state_values end
50
50
51
+
"""
52
+
set_state!(sys, val, idx)
53
+
54
+
Set the state at index `idx` to `val` for system `sys`. This defaults to modifying
55
+
`state_values(sys)`. If any additional bookkeeping needs to be performed or the
56
+
default implementation does not work for a particular type, this method needs to be
57
+
defined to enable the proper functioning of [`setu`](@ref).
58
+
59
+
See: [`state_values`](@ref)
60
+
"""
61
+
functionset_state!(sys, val, idx)
62
+
state_values(sys)[idx] = val
63
+
end
64
+
51
65
"""
52
66
current_time(p)
53
67
@@ -164,12 +178,10 @@ Return a function that takes an integrator or problem of `sys` and a value, and
164
178
the state `sym` to that value. Note that `sym` can be a direct numerical index, a symbolic state, or an array/tuple of the aforementioned.
165
179
166
180
Requires that the integrator implement [`state_values`](@ref) and the
167
-
returned collection be a mutable reference to the state vector in the integrator/problem.
181
+
returned collection be a mutable reference to the state vector in the integrator/problem. Alternatively, if this is not possible or additional actions need to
182
+
be performed when updating state, [`set_state!`](@ref) can be defined.
168
183
This function does not work on types for which [`is_timeseries`](@ref) is
169
184
[`Timeseries`](@ref).
170
-
171
-
In case `state_values` cannot return such a mutable reference, `setu` needs to be
172
-
implemented manually.
173
185
"""
174
186
functionsetu(sys, sym)
175
187
symtype =symbolic_type(sym)
@@ -184,15 +196,15 @@ end
184
196
185
197
function_setu(sys, ::NotSymbolic, sym)
186
198
returnfunctionsetter!(prob, val)
187
-
state_values(prob)[sym] =val
199
+
set_state!(prob, val, sym)
188
200
end
189
201
end
190
202
191
203
function_setu(sys, ::ScalarSymbolic, sym)
192
204
is_variable(sys, sym) ||error("Invalid symbol $sym for `setu`")
0 commit comments