Skip to content

Commit df6cc6a

Browse files
vyuduAayushSabharwal
authored andcommitted
fix: fix SII issue in the implicit affect
1 parent 4733044 commit df6cc6a

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/systems/callbacks.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function make_affect(affect::Vector{Equation}; discrete_parameters = Any[],
283283
for eq in affect
284284
if !haspre(eq) && !(symbolic_type(eq.rhs) === NotSymbolic() ||
285285
symbolic_type(eq.lhs) === NotSymbolic())
286-
@warn "Affect equation $eq has no `Pre` operator. As such it will be interpreted as an algebraic equation to be satisfied after the callback. If you intended to use the value of a variable x before the affect, use Pre(x). Errors may be thrown if there is no `Pre` and algebraic equations are unsatisfiable, such as X ~ X + 1."
286+
@warn "Affect equation $eq has no `Pre` operator. As such it will be interpreted as an algebraic equation to be satisfied after the callback. If you intended to use the value of a variable x before the affect, use Pre(x). Errors may be thrown if there is no `Pre` and the algebraic equation is unsatisfiable, such as X ~ X + 1."
287287
end
288288
collect_vars!(dvs, params, eq, iv; op = Pre)
289289
diffvs = collect_applied_operators(eq, Differential)
@@ -937,31 +937,36 @@ function compile_equational_affect(
937937
return let dvs_to_update = dvs_to_update, aff_map = aff_map, sys_map = sys_map,
938938
affsys = affsys, ps_to_update = ps_to_update, aff = aff, sys = sys
939939

940-
dvs_to_access = unknowns(affsys)
941-
ps_to_access = parameters(affsys)
940+
dvs_to_access = [aff_map[u] for u in unknowns(affsys)]
941+
ps_to_access = [unPre(p) for p in parameters(affsys)]
942942

943-
u_getter = getsym(sys, [aff_map[u] for u in dvs_to_access])
944-
p_getter = getsym(sys, [unPre(p) for p in ps_to_access])
943+
affu_getter = getsym(sys, dvs_to_access)
944+
affp_getter = getsym(sys, ps_to_access)
945+
affu_setter! = setsym(affsys, unknowns(affsys))
946+
affp_setter! = setsym(affsys, parameters(affsys))
945947
u_setter! = setsym(sys, dvs_to_update)
946948
p_setter! = setsym(sys, ps_to_update)
947-
affu_getter = getsym(affsys, [sys_map[u] for u in dvs_to_update])
948-
affp_getter = getsym(affsys, [sys_map[p] for p in ps_to_update])
949+
u_getter = getsym(affsys, [sys_map[u] for u in dvs_to_update])
950+
p_getter = getsym(affsys, [sys_map[p] for p in ps_to_update])
949951

950-
affprob = ImplicitDiscreteProblem(affsys, [dv => 0 for dv in dvs_to_access],
951-
(0, 0), [p => 0 for p in ps_to_access];
952+
affprob = ImplicitDiscreteProblem(affsys, [dv => 0 for dv in unknowns(affsys)],
953+
(0, 0), [p => 0. for p in parameters(affsys)];
952954
build_initializeprob = false, check_length = false)
953955

954956
function implicit_affect!(integ)
955-
new_us = u_getter(integ)
956-
new_ps = p_getter(integ)
957+
new_u0 = affu_getter(integ)
958+
affu_setter!(affprob, new_u0)
959+
new_ps = affp_getter(integ)
960+
affp_setter!(affprob, new_ps)
961+
957962
affprob = remake(
958-
affprob, u0 = new_us, p = new_ps, tspan = (integ.t, integ.t))
963+
affprob, tspan = (integ.t, integ.t))
959964
affsol = init(affprob, IDSolve())
960965
(check_error(affsol) === ReturnCode.InitialFailure) &&
961966
throw(UnsolvableCallbackError(all_equations(aff)))
962967

963-
u_setter!(integ, affu_getter(affsol))
964-
p_setter!(integ, affp_getter(affsol))
968+
u_setter!(integ, u_getter(affsol))
969+
p_setter!(integ, p_getter(affsol))
965970
end
966971
end
967972
end

0 commit comments

Comments
 (0)