Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodel outputs might not be set correctly #3200

Closed
johnjasa opened this issue Apr 18, 2024 · 0 comments · Fixed by #3239
Closed

Submodel outputs might not be set correctly #3200

johnjasa opened this issue Apr 18, 2024 · 0 comments · Fixed by #3239
Assignees
Labels

Comments

@johnjasa
Copy link
Member

Description

Might be a similar fix to #3192? I'm not certain of the inner workings. Seems it might be related to the names of the subsystems or the order? I've attached an a test showing the desired behavior and the failing behavior.

Example

import unittest
import numpy as np

import openmdao.api as om
from openmdao.utils.assert_utils import assert_near_equal


def build_submodel(subsystem_name):
    p = om.Problem()
    supmodel = om.Group()
    supmodel.add_subsystem('supComp', om.ExecComp('diameter = r * theta'),
                            promotes_inputs=['*'],
                            promotes_outputs=['*', ('diameter', 'aircraft:fuselage:diameter')])

    subprob1 = om.Problem()
    submodel1 = subprob1.model.add_subsystem('submodel1', om.Group(), promotes=['*'])

    submodel1.add_subsystem(subsystem_name, om.ExecComp('x = diameter * 2 * r * theta'), promotes=['*', ('diameter', 'aircraft:fuselage:diameter')])
    submodel1.add_subsystem('b', om.ExecComp('y = mass * donkey_kong'), promotes=['*', ('mass', 'dynamic:mission:mass'), ('donkey_kong', 'aircraft:engine:donkey_kong')])

    p.model.add_subsystem('supModel', supmodel, promotes_inputs=['*'],
                            promotes_outputs=['*'])


    submodel = om.SubmodelComp(problem=subprob1, inputs=['*'], outputs=['*'])
    p.model.add_subsystem('sub1', submodel,
                            promotes_inputs=['*'],
                            promotes_outputs=['*'])

    p.model.set_input_defaults('r', 1.25)
    p.model.set_input_defaults('theta', np.pi)

    p.setup(force_alloc_complex=True)

    p.set_val('r', 1.25)
    p.set_val('theta', 0.5)
    p.set_val('dynamic:mission:mass', 2.0)
    p.set_val('aircraft:engine:donkey_kong', 3.0)
    p.set_val('aircraft:fuselage:diameter', 3.5)

    return p



class TestSubModelBug(unittest.TestCase):
    
    def test_submodel_bug(self):
        p = build_submodel(subsystem_name='a')

        p.run_model()

        assert_near_equal(p.get_val('y'), 2.0 * 3.0)
    
    
    def test_submodel_bug_fails(self):
        p = build_submodel(subsystem_name='c')

        p.run_model()

        assert_near_equal(p.get_val('y'), 2.0 * 3.0)


if __name__ == '__main__':
    unittest.main()

OpenMDAO Version

3.31.2-dev

Relevant environment information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants