Skip to content

Commit 09f8e50

Browse files
Handle derivatives of observed variables
If you have a variable `x` which is not a state and substitute it out because some equation `y ~ x`, you would hope that `D(x) => 1` effectively means `D(y) => 1`. This PR does a fixed point substitution on any derivative of observed variables in order to rephrase it into the chosen variable. This fixes the case of aliasing but not the general case of if you are doing the derivative of some observed expression, i.e. `x ~ y + z` where `x` is factored out to be an observed variable, then you want to set `D(x) => 1`.
1 parent 7ff933a commit 09f8e50

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/systems/nonlinear/initializesystem.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function generate_initializesystem(sys::ODESystem;
2020

2121
eqs_diff = eqs[idxs_diff]
2222
diffmap = Dict(getfield.(eqs_diff, :lhs) .=> getfield.(eqs_diff, :rhs))
23+
observed_diffmap = Dict(Differential(get_iv(sys)).(getfield.((observed(sys)), :lhs)) .=> Differential(get_iv(sys)).(getfield.((observed(sys)), :rhs)))
2324

2425
full_states = unique([sts; getfield.((observed(sys)), :lhs)])
2526
set_full_states = Set(full_states)
@@ -36,7 +37,9 @@ function generate_initializesystem(sys::ODESystem;
3637
filtered_u0 = Pair[]
3738
for x in u0map
3839
y = get(schedule.dummy_sub, x[1], x[1])
40+
y = ModelingToolkit.fixpoint_sub(y, observed_diffmap)
3941
y = get(diffmap, y, y)
42+
4043
if y isa Symbolics.Arr
4144
_y = collect(y)
4245

0 commit comments

Comments
 (0)