1
1
using ModelingToolkit
2
- using ModelingToolkit: t_nounits as t, D_nounits as D, iscomplete, does_namespacing
2
+ using ModelingToolkit: t_nounits as t, D_nounits as D, iscomplete, does_namespacing,
3
+ renamespace
3
4
4
5
@variables x (t)
5
6
@parameters p
@@ -24,3 +25,23 @@ nsys = toggle_namespacing(sys, false)
24
25
25
26
@test_throws [" namespacing" , " inner" ] System (
26
27
Equation[], t; systems = [nsys], name = :a )
28
+
29
+ @testset " Variables of variables" begin
30
+ @variables x (t) y (x)
31
+ @named inner = System ([D (x) ~ x, y ~ 2 x + 1 ], t)
32
+ @test issetequal (unknowns (inner), [x, y])
33
+ ss = mtkcompile (inner)
34
+ @test isequal (only (unknowns (ss)), x)
35
+ @test isequal (only (observed (ss)), y ~ 2 x + 1 )
36
+
37
+ @named sys = System (Equation[], t; systems = [inner])
38
+ xx, yy = let sys = inner
39
+ xx = renamespace (sys, x)
40
+ yy = only (@variables y (xx))
41
+ xx, renamespace (sys, yy)
42
+ end
43
+ @test issetequal (unknowns (sys), [xx, yy])
44
+ ss = mtkcompile (sys)
45
+ @test isequal (only (unknowns (ss)), xx)
46
+ @test isequal (only (observed (ss)), yy ~ 2 xx + 1 )
47
+ end
0 commit comments