ModelingToolkit.jl icon indicating copy to clipboard operation
ModelingToolkit.jl copied to clipboard

`continuous_events` and `difference_callbacks` fail if states are moved to `observed`

Open contradict opened this issue 3 years ago • 2 comments

Running limit_example() from this script produces the error

ERROR: AssertionError: maximum(eq_ind2affect) == length(affect_functions)

As a guess, I changed that == to a <= and got this error:

ERROR: UndefVarError: l₊fixed₊x not defined

Which looks like maybe it can't see observed states? Stack traces here

contradict avatar Dec 01 '21 18:12 contradict

Hello and thank you for the issue! I believe your idea about the observed equations is correct, I see the same problem in the discrete callbacks for systems with discrete update equations. I'll look into it, the solution will probably be the same in both cases, i.e., reconstructing states from observed equations if required

baggepinnen avatar Dec 02 '21 12:12 baggepinnen

Hi,

has there be some progress about this issue or a workaround? The issue about observed variables is especially a problem when buildung acausal models. For these models there are many algebraic constraints, even if only a small number of components are used. In my case I want to use the callbacks to handle discontinuous dynamics like diodes to catch the moment if it is blocking or te current starts to flow again.

I also think it is linked to #1409

Thanks for any response.

SLiemann avatar May 06 '22 14:05 SLiemann