Skip to content

Commit f686a3c

Browse files
committed
add error for discrete parameter update, do not add observed to algebraic equations
1 parent 918a083 commit f686a3c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/systems/abstractsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,12 @@ function complete(
648648
if has_continuous_events(sys) && is_time_dependent(sys)
649649
@set! sys.continuous_events = complete.(
650650
get_continuous_events(sys); iv = get_iv(sys),
651-
alg_eqs = [alg_equations(sys); observed(sys)])
651+
alg_eqs = alg_equations(sys))
652652
end
653653
if has_discrete_events(sys) && is_time_dependent(sys)
654654
@set! sys.discrete_events = complete.(
655655
get_discrete_events(sys); iv = get_iv(sys),
656-
alg_eqs = [alg_equations(sys); observed(sys)])
656+
alg_eqs = alg_equations(sys))
657657
end
658658
end
659659
if split && has_index_cache(sys)

src/systems/callbacks.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ 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+
3436
struct AffectSystem
3537
"""The internal implicit discrete system whose equations are solved to obtain values after the affect."""
3638
system::AbstractSystem
@@ -84,6 +86,9 @@ function AffectSystem(affect::Vector{Equation}; discrete_parameters = Any[],
8486
symbolic_type(eq.lhs) === NotSymbolic())
8587
@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."
8688
end
89+
if ModelingToolkit.isparameter(eq.lhs) && (eq.lhs OrderedSet(discrete_parameters))
90+
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.")
91+
end
8792
collect_vars!(dvs, params, eq, iv; op = Pre)
8893
empty!(_varsbuf)
8994
vars!(_varsbuf, eq; op = Pre)

0 commit comments

Comments
 (0)