Skip to content

Can't directly access a sub-subcomponents variables #3631

Open
@AnalogBitTwiddler

Description

@AnalogBitTwiddler

Is your feature request related to a problem? Please describe.

When attempting to make a top level variable that summarizes leaf variables, the leaf variables required duplicating at all intermediate levels.

Describe the solution you’d like

Treat the components of a subcomponent as accessible elements. See commented version below.

Describe alternatives you’ve considered

Workaround is available by introducing intermediate variables at all intermediate levels of hierarchy.

Additional context

using ModelingToolkit  

@mtkmodel AMdl begin
    @description "A Model"
    @variables begin
        a(t)::Float64 = 0
    end
    @equations begin  
        a ~ sin(2π * t / 10) 
    end
end
@mtkmodel Bmdl begin
    @description "B Model"
    @components begin
        a = [AMdl() for i in 1:2]
    end
    @variables begin  # added to show accessing through a variable
        b(t)[1:2]
    end
    @equations begin  # added to show accessing through a variable
        [b[i] ~ a[i].a for i in 1:2]
    end
end
@mtkmodel Cmdl begin
    @description "C Model"
    @components begin
        b = Bmdl()
    end
    @variables begin
        c(t)[1:2]
    end
    @equations begin  
        # [c[i] ~ b.a[i].a for i in 1:2]  # does not work - accessing through a component
        [c[i] ~ b.b[i].a for i in 1:2]  # works - accessing through a variable
    end
end
@mtkbuild cmdl = Cmdl()
observed(cmdl) # Check the observed variables

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions