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
2 changes: 1 addition & 1 deletion lib/ModelingToolkitBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ StochasticDiffEq = "6.82.0, 7"
Sundials = "6"
SymbolicIndexingInterface = "0.3.39"
SymbolicUtils = "4.35.3"
Symbolics = "7.31"
Symbolics = "7.32.1"
TaskLocalValues = "0.1.3"
Test = "1"
Tracker = "0.2.30"
Expand Down
11 changes: 9 additions & 2 deletions lib/ModelingToolkitBase/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,15 @@ function collect_var!(unknowns::OrderedSet{SymbolicT}, parameters::OrderedSet{Sy
)
end
arr, isarr = split_indexed_var(var)
if isarr && SU.is_array_shape(SU.shape(var))
# `var` is indexed, and it is an array, so it must be a slice. Replace it with `arr`.
if isarr && (
# `var` is indexed, and it is an array, so it must be a slice. Replace it with `arr`.
SU.is_array_shape(SU.shape(var)) ||
# `var` is of the form `x[i]` where `i` is also a variable/expression
any(!SU.isconst, Iterators.drop(arguments(var), 1))
)
for arg in Iterators.drop(arguments(var), 1)
collect_vars!(unknowns, parameters, arg, iv)
end
var = arr
end
check_scope_depth(getmetadata(arr, SymScope, LocalScope())::AllScopes, depth) || return nothing
Expand Down
6 changes: 6 additions & 0 deletions lib/ModelingToolkitBase/test/system_building.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ ModelingToolkitBase.validate_operator(::MyOp, args...; kws...) = nothing
@named sys = System([D(x) ~ x + SU.term(MyOp(), [0.0]; type = Real, shape = SU.ShapeVecT())], t)
@test issetequal(unknowns(sys), [x])
end

@testset "Variable discovery `x[i]` where `i` is a variable" begin
@variables x(t)[1:2] i(t)::Int
@named sys = System([x[i] ~ 0], t)
@test issetequal(unknowns(sys), [x, i])
end
Loading