Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/structural_transformation/symbolics_tearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,10 @@ function update_simplified_system!(
# Algebraic variables are shifted forward by one, so we backshift them.
unknowns = map(enumerate(unknowns)) do (i, var)
if iscall(var) && operation(var) isa Shift && operation(var).steps == 1
backshift_expr(var, iv)
# We might have shifted a variable with io metadata. That is irrelevant now
# because we handled io variables earlier in `_mtkcompile!` so just ignore
# it here.
setio(backshift_expr(var, iv), false, false)
else
var
end
Expand Down
9 changes: 9 additions & 0 deletions test/symbolic_events.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1410,3 +1410,12 @@ end
sol = solve(prob, FBDF())
@test SciMLBase.successful_retcode(sol)
end

@testset "Algebraic equation with input variable in symbolic affect" begin
# Specifically happens when the variable marked as an input is an algebraic variable
# in the affect system.
@variables x(t) [input = true] y(t)
dev = ModelingToolkit.SymbolicDiscreteCallback(1.0, [y ~ Pre(y) + 1])
@named sys = System([D(y) ~ 2x + 1, x^2 ~ 2y^3], t; discrete_events = [dev])
sys = @test_nowarn mtkcompile(sys)
end
Loading