Skip to content

Commit c1978a5

Browse files
committed
precompute ordered set of discrete parameters
1 parent f686a3c commit c1978a5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/systems/callbacks.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ function Symbolics.fast_substitute(aff::SymbolicAffect, rules)
3131
map(substituter, aff.discrete_parameters))
3232
end
3333

34-
all_equations(a::SymbolicAffect) = [a.affect; a.alg_eqs]
35-
3634
struct AffectSystem
3735
"""The internal implicit discrete system whose equations are solved to obtain values after the affect."""
3836
system::AbstractSystem
@@ -80,13 +78,14 @@ function AffectSystem(affect::Vector{Equation}; discrete_parameters = Any[],
8078

8179
dvs = OrderedSet()
8280
params = OrderedSet()
81+
dp_set = OrderedSet(discrete_parameters)
8382
_varsbuf = Set()
8483
for eq in affect
8584
if !haspre(eq) && !(symbolic_type(eq.rhs) === NotSymbolic() ||
8685
symbolic_type(eq.lhs) === NotSymbolic())
8786
@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."
8887
end
89-
if ModelingToolkit.isparameter(eq.lhs) && (eq.lhs OrderedSet(discrete_parameters))
88+
if ModelingToolkit.isparameter(eq.lhs) && (eq.lhs dp_set)
9089
error("Detected explicit update to parameter $(eq.lhs), but it has not been passed in as a `discrete_parameters` to the callback constructor, for example: \n\n(SymbolicDiscreteCallback(cond => aff, discrete_parameters = [$(eq.lhs)])\n\nAs a result, the parameter update will fail.")
9190
end
9291
collect_vars!(dvs, params, eq, iv; op = Pre)

0 commit comments

Comments
 (0)