I have two components in ModelingToolkit.jl, and I want to have an equation across components, such as comp1.x ~ comp2.y
. But I’d like that equation to only be there when Comp2()
is used (I have an alternative GooeyComp2()
where the equation is unneeded).
@mtkmodel Comp1 begin
@variables begin
x(t)
end
end
@mtkmodel Comp2 begin
@variables begin
y(t)
end
end
@mtkmodel Room begin
@components begin
comp1 = Comp1()
comp2 = Comp2()
end
end
How should I do that?
- The natural place to put it is in
Room
’s equation block, but then I have to remember to put that equation every time I write a Room with aComp2
(and not when I use aGooeyComp2
). - I’d like to write it inside of
Comp2
’s equation block, but I’m not sure how. Is that a use case for scopes? I triedParentScope(comp1).x ~ y
, and it did not work. - I guess I could use connectors? In my case, it doesn’t feel so appropriate, and then it’s basically like the first solution above: I’ll have to remember to write the
connect
equation when I use aComp2
.