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
functionmake_affect(affect::Vector{Equation}; iv =nothing, algeeqs::Vector{Equation}= Equation[])
244
+
functionmake_affect(affect::Vector{Equation}; discrete_parameters = Any[], iv =nothing, algeeqs::Vector{Equation}= Equation[])
244
245
isempty(affect) &&returnnothing
245
246
isempty(algeeqs) &&@warn"No algebraic equations were found for the callback defined by $(join(affect, ", ")). If the system has no algebraic equations, this can be disregarded. Otherwise pass in `algeeqs` to the SymbolicContinuousCallback constructor."
246
247
248
+
for p in discretes
249
+
# Check if p is time-dependent
250
+
false&&error("Non-time dependent parameter $p passed in as a discrete. Must be declared as $p(t).")
251
+
end
252
+
247
253
explicit =true
248
254
dvs =OrderedSet()
249
255
params =OrderedSet()
@@ -265,38 +271,21 @@ function make_affect(affect::Vector{Equation}; iv = nothing, algeeqs::Vector{Equ
265
271
isnothing(iv) &&@warn"No independent variable specified and could not be inferred. If the iv appears in an affect equation explicitly, like x ~ t + 1, then it must be specified as an argument to the SymbolicContinuousCallback or SymbolicDiscreteCallback constructor. Otherwise this warning can be disregarded."
266
272
end
267
273
268
-
# Parameters in affect equations should become unknowns in the ImplicitDiscreteSystem.
269
-
cb_params = Any[]
270
-
discretes = Any[]
271
-
p_as_dvs = Any[]
272
-
for p in params
273
-
ifiscall(p) && (operation(p) isa Pre)
274
-
push!(cb_params, p)
275
-
elseifiscall(p) &&length(arguments(p)) ==1&&
276
-
isequal(only(arguments(p)), iv)
277
-
push!(discretes, p)
278
-
push!(p_as_dvs, tovar(p))
279
-
else
280
-
push!(discretes, p)
281
-
name =iscall(p) ?nameof(operation(p)) :nameof(p)
282
-
p =wrap(Sym{FnType{Tuple{symtype(iv)}, Real}}(name)(iv))
283
-
p =setmetadata(p, Symbolics.VariableSource, (:variables, name))
284
-
push!(p_as_dvs, p)
285
-
end
286
-
end
287
-
aff_map =Dict(zip(p_as_dvs, discretes))
288
-
rev_map =Dict([v => k for (k, v) in aff_map])
289
-
affect = Symbolics.substitute(affect, rev_map)
290
-
@named affectsys =ImplicitDiscreteSystem(vcat(affect, algeeqs), iv, collect(union(dvs, p_as_dvs)), cb_params)
@@ -907,6 +897,14 @@ function compile_equational_affect(aff::Union{AffectSystem, Vector{Equation}}, s
907
897
end
908
898
end
909
899
900
+
struct UnsolvableCallbackError
901
+
eqs::Vector{Equation}
902
+
end
903
+
904
+
function Base.showerror(io, err::UnsolvableCallbackError)
905
+
println(io, "The callback defined by the equations, $(join(err.eqs, "\n")), with discrete parameters is not solvable. Please check the algebraic equations, affect equations, and declared discrete parameters.")
0 commit comments