-
-
Notifications
You must be signed in to change notification settings - Fork 233
Closed
Labels
Description
I want to share parameter arrays and variable arrays between root system and child systems. ParentScope
works on parameters
and variables
, but I don't know how to ParentScope
a variable array or a parameter array. It seems ParentScope
failed on a variable array.
MWE:
using ModelingToolkit
using ModelingToolkit: ParentScope
function a(; name)
@parameters t
@variables x(t)[1:2], xx(t)[1:2]
D = Differential(t)
eq = [D(xx[1]) ~ ParentScope(x[1]), D(xx[2]) ~ ParentScope(x[2])]
return ODESystem(eq; name)
end
function main(; name)
@parameters t
@variables x(t)[1:2]
D = Differential(t)
@named s1 = a()
eqs = [D(x[1]) ~ 1, D(x[2]) ~ 1]
sys = compose(ODESystem(eqs; name), s1)
return sys
end
@named sys = main()
structural_simplify(sys)
And I got:
ERROR: ExtraVariablesSystemException: The system is unbalanced. There are 6 highest order derivative variables and 4 equations.
More variables than equations, here are the potential extra variable(s):
(x(t))[1]
(x(t))[2]
(s1₊xx(t))[1]
(s1₊xx(t))[2]
(s1₊x(t))[1]
(s1₊x(t))[2]
Root system and subsystem s1
have different x[1]
and x[2]
, and I expect (x(t))[1] (x(t))[2] (s1₊xx(t))[1] (s1₊xx(t))[2]
only.
I also tried x=ParentScope.(x)
, x1=ParentScope(x[1])
and some other stuff, and all these failed. Could anyone show me the right way to do this? Or it's just unworkable temporarily?