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.

import openmdao.api as om


class BranchGroup(om.Group):

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

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

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

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

c1 = p.model.Branch1.G1.G2.comp1
print(c1.pathname)

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