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
affect isa AbstractVector &&isnothing(iv) &&@warn"No independent variable specified. If t appears in an affect equation explicitly, like x ~ t + 1, then this must be specified. Otherwise this can be disregarded."
212
214
conditions = (conditions isa AbstractVector) ? conditions : [conditions]
isempty(algeeqs) &&@warn"No algebraic equations were found. If the system has no algebraic equations, this can be disregarded. Otherwise consider passing in `algeeqs` to the SymbolicContinuousCallbacks constructor."
@warn"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)."
235
-
collect_vars!(unknowns, params, eq, nothing; op = Pre)
237
+
!haspre(eq) &&
238
+
@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)."
239
+
collect_vars!(dvs, params, eq, iv; op = Pre)
240
+
end
241
+
for eq in algeeqs
242
+
collect_vars!(dvs, params, eq, iv)
243
+
end
244
+
ifisnothing(iv)
245
+
iv =isempty(dvs) ? iv :only(arguments(dvs[1]))
236
246
end
237
-
iv =isempty(unknowns) ? t_nounits :only(arguments(unknowns[1]))
238
247
239
248
# System parameters should become unknowns in the ImplicitDiscreteSystem.
240
249
cb_params = Any[]
241
250
discretes = Any[]
242
-
p_as_unknowns= Any[]
251
+
p_as_dvs= Any[]
243
252
for p in params
244
253
ifiscall(p) && (operation(p) isa Pre)
245
254
push!(cb_params, p)
246
255
elseifiscall(p) &&length(arguments(p)) ==1&&
247
256
isequal(only(arguments(p)), iv)
248
257
push!(discretes, p)
249
-
push!(p_as_unknowns, tovar(p))
258
+
push!(p_as_dvs, tovar(p))
250
259
else
251
260
push!(discretes, p)
252
261
name =iscall(p) ?nameof(operation(p)) :nameof(p)
253
262
p =wrap(Sym{FnType{Tuple{symtype(iv)}, Real}}(name)(iv))
254
263
p =setmetadata(p, Symbolics.VariableSource, (:variables, name))
255
-
push!(p_as_unknowns, p)
264
+
push!(p_as_dvs, p)
256
265
end
257
266
end
258
-
aff_map =Dict(zip(p_as_unknowns, discretes))
267
+
aff_map =Dict(zip(p_as_dvs, discretes))
259
268
rev_map =Dict([v => k for (k, v) in aff_map])
260
269
affect = Symbolics.substitute(affect, rev_map)
261
-
@mtkbuild affectsys =ImplicitDiscreteSystem(affect, iv, collect(union(unknowns, p_as_unknowns)), cb_params)
270
+
@mtkbuild affectsys =ImplicitDiscreteSystem(vcat(affect, algeeqs), iv, collect(union(dvs, p_as_dvs)), cb_params)
271
+
# get accessed parameters p from Pre(p) in the callback parameters
c =is_timed_condition(condition) ? condition :value(scalarize(condition))
402
+
403
+
isnothing(iv) &&@warn"No independent variable specified. If t appears in an affect equation explicitly, like x ~ t + 1, then this must be specified. Otherwise this can be disregarded."
0 commit comments