I am trying to add an affect function to a discrete event. Not working:
function bb_affect!(integ, u, p, ctx)
println(integ.u)
end
discrete_events = [[1.0, 4.0] => bb_affect!]
@named sys = ODESystem(eqs, t; discrete_events = discrete_events)
Error message:
ERROR: MethodError: no method matching compile_affect(::var"#bb_affect!#17", ::ODESystem, ::Vector{SymbolicUtils.BasicSymbolic{Real}}, ::Vector{SymbolicUtils.BasicSymbolic{Real}}; expression::DataType, postprocess_affect_expr!::Nothing)
Closest candidates are:
compile_affect(::ModelingToolkit.FunctionalAffect, ::Any, ::Any, ::Any; kwargs...)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:452
compile_affect(::Vector{Equation}, ::Any, ::Any, ::Any; outputidxs, expression, checkvars, postprocess_affect_expr!, kwargs...)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:303
compile_affect(::ModelingToolkit.SymbolicContinuousCallback, ::Any...; kwargs...)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:282
Stacktrace:
[1] generate_timed_callback(cb::ModelingToolkit.SymbolicDiscreteCallback, sys::ODESystem, dvs::Vector{SymbolicUtils.BasicSymbolic{…}}, ps::Vector{SymbolicUtils.BasicSymbolic{…}}; postprocess_affect_expr!::Nothing, kwargs::@Kwargs{})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:459
[2] generate_timed_callback
@ ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:456 [inlined]
[3] generate_discrete_callback(cb::ModelingToolkit.SymbolicDiscreteCallback, sys::ODESystem, dvs::Vector{SymbolicUtils.BasicSymbolic{…}}, ps::Vector{SymbolicUtils.BasicSymbolic{…}}; postprocess_affect_expr!::Nothing, kwargs::@Kwargs{})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:473
[4] generate_discrete_callback
@ ~/.julia/packages/ModelingToolkit/Gpzyo/src/systems/callbacks.jl:470 [inlined]
[5] #331
What do I miss?
See: Event Handling and Callback Functions · ModelingToolkit.jl