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
1 change: 1 addition & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ end

function collect_var!(unknowns, parameters, var, iv)
isequal(var, iv) && return nothing
getmetadata(var, SymScope, LocalScope()) == LocalScope() || return nothing
if iscalledparameter(var)
callable = getcalledparameter(var)
push!(parameters, callable)
Expand Down
25 changes: 21 additions & 4 deletions test/variable_scope.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using ModelingToolkit
using ModelingToolkit: SymScope
using Symbolics: arguments, value
using ModelingToolkit: SymScope, t_nounits as t, D_nounits as D
using Symbolics: arguments, value, getname
using Test

@independent_variables t
@variables a b(t) c d e(t)

b = ParentScope(b)
Expand Down Expand Up @@ -52,7 +51,6 @@ end
@test renamed([:foo :bar :baz], c) == Symbol("foo₊c")
@test renamed([:foo :bar :baz], d) == :d

@independent_variables t
@parameters a b c d e f
p = [a
ParentScope(b)
Expand Down Expand Up @@ -84,3 +82,22 @@ arr1 = ODESystem(Equation[], t, [], []; name = :arr1) ∘ arr0
arr_ps = ModelingToolkit.getname.(parameters(arr1))
@test isequal(arr_ps[1], Symbol("xx"))
@test isequal(arr_ps[2], Symbol("arr0₊xx"))

function Foo(; name, p = 1)
@parameters p = p
@variables x(t)
return ODESystem(D(x) ~ p, t; name)
end
function Bar(; name, p = 2)
@parameters p = p
@variables x(t)
@named foo = Foo(; p)
return ODESystem(D(x) ~ p + t, t; systems = [foo], name)
end
@named bar = Bar()
bar = complete(bar)
@test length(parameters(bar)) == 2
@test sort(getname.(parameters(bar))) == [:foo₊p, :p]
defs = ModelingToolkit.defaults(bar)
@test defs[bar.p] == 2
@test isequal(defs[bar.foo.p], bar.p)
Loading