Skip to content

Commit 92289a1

Browse files
committed
remove use of rename in some places
1 parent 16c1fc5 commit 92289a1

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

src/systems/abstractsystem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,22 +226,22 @@ function Base.getproperty(sys::AbstractSystem, name::Symbol; namespace=true)
226226
i = findfirst(x->getname(x) == name, sts)
227227

228228
if i !== nothing
229-
return namespace ? rename(sts[i],renamespace(sysname,name)) : sts[i]
229+
return namespace ? renamespace(sysname,sts[i]) : sts[i]
230230
end
231231

232232
if has_ps(sys)
233233
ps = get_ps(sys)
234234
i = findfirst(x->getname(x) == name,ps)
235235
if i !== nothing
236-
return namespace ? rename(ps[i],renamespace(sysname,name)) : ps[i]
236+
return namespace ? renamespace(sysname,ps[i]) : ps[i]
237237
end
238238
end
239239

240240
if has_observed(sys)
241241
obs = get_observed(sys)
242242
i = findfirst(x->getname(x.lhs)==name,obs)
243243
if i !== nothing
244-
return namespace ? rename(obs[i].lhs,renamespace(sysname,name)) : obs[i]
244+
return namespace ? renamespace(sysname,obs[i]) : obs[i]
245245
end
246246
end
247247

@@ -321,7 +321,7 @@ function namespace_equation(eq::Equation,name,iv)
321321
end
322322

323323
function namespace_expr(O::Sym,name,iv)
324-
isequal(O, iv) ? O : rename(O,renamespace(name,nameof(O)))
324+
isequal(O, iv) ? O : renamespace(name,O)
325325
end
326326

327327
_symparam(s::Symbolic{T}) where {T} = T

test/variable_scope.jl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
using ModelingToolkit
22
using Test
33

4-
@variables a b c
4+
@variables a b c d
55

6-
b = ParentScope(ParentScope(b))
7-
c = GlobalScope(c)
6+
b = ParentScope(b)
7+
c = ParentScope(ParentScope(c))
8+
d = GlobalScope(d)
89

910
renamed(nss, sym) = nameof(foldr(ModelingToolkit.renamespace, nss, init=sym))
1011

1112
@test renamed([:foo :bar :baz], a) == :foo₊bar₊baz₊a
12-
@test renamed([:foo :bar :baz], b) == :foo₊b
13-
@test renamed([:foo :bar :baz], c) == :c
13+
@test renamed([:foo :bar :baz], b) == :foo₊bar₊b
14+
@test renamed([:foo :bar :baz], c) == :foo₊c
15+
@test renamed([:foo :bar :baz], d) == :d
16+
17+
eqs = [
18+
0 ~ a
19+
0 ~ b
20+
0 ~ c
21+
0 ~ d
22+
]
23+
@named sub4 = NonlinearSystem(eqs, [a, b, c, d], [])
24+
@named sub3 = NonlinearSystem(eqs, [a, b, c, d], [])
25+
@named sub2 = NonlinearSystem([], [], [], systems=[sub3, sub4])
26+
@named sub1 = NonlinearSystem([], [], [], systems=[sub2])
27+
@named sys = NonlinearSystem([], [], [], systems=[sub1])
28+
29+
names = nameof.(states(sys))
30+
@test :d in names
31+
@test :sub1₊c in names
32+
@test :sub1₊sub2₊b in names
33+
@test :sub1₊sub2₊sub3₊a in names
34+
@test :sub1₊sub2₊sub4₊a in names

0 commit comments

Comments
 (0)