Accessing Subsystems Within a Group

To access a Component or another Group within a Group, just access the attribute with the name of the subsystem.

Usage

The class BranchGroup, seen here, is used in the example that follows.

class BranchGroup(Group):

    def __init__(self):
        super(BranchGroup, self).__init__()

        b1 = self.add_subsystem('Branch1', Group())
        g1 = b1.add_subsystem('G1', Group())
        g2 = g1.add_subsystem('G2', Group())
        g2.add_subsystem('comp1', ExecComp('b=2.0*a', a=3.0, b=6.0))

        b2 = self.add_subsystem('Branch2', Group())
        g3 = b2.add_subsystem('G3', Group())
        g3.add_subsystem('comp2', ExecComp('b=3.0*a', a=4.0, b=12.0))

This example shows accessing components that are two nested branches from the top.

from openmdao.api import Problem
from openmdao.core.tests.test_group import BranchGroup

p = Problem(model=BranchGroup())
p.setup()

c1 = p.model.Branch1.G1.G2.comp1
print(c1.pathname)
Branch1.G1.G2.comp1
c2 = p.model.Branch2.G3.comp2
print(c2.pathname)
Branch2.G3.comp2