Esempio n. 1
0
    def test_load_system_cases_with_units(self):
        comp = IndepVarComp()
        comp.add_output('distance', val=1., units='m')
        comp.add_output('time', val=1., units='s')

        prob = Problem()
        model = prob.model
        model.add_subsystem('c1', comp)
        model.add_subsystem('c2', SpeedComp())
        model.add_subsystem('c3', ExecComp('f=speed',speed={'units': 'm/s'}))
        model.connect('c1.distance', 'c2.distance')
        model.connect('c1.time', 'c2.time')
        model.connect('c2.speed', 'c3.speed')

        model.add_recorder(self.recorder)

        prob.setup()
        prob.run_model()

        cr = CaseReader(self.filename)
        case = cr.system_cases.get_case(0)

        # Add one to all the inputs just to change the model
        # so we can see if loading the case values really changes the model
        for name in model._inputs:
            model._inputs[name] += 1.0
        for name in model._outputs:
            model._outputs[name] += 1.0

        # Now load in the case we recorded
        prob.load_case(case)

        _assert_model_matches_case(case, model)
Esempio n. 2
0
    def test_speed(self):
        from openmdao.api import Problem, Group, IndepVarComp, ExecComp
        from openmdao.core.tests.test_units import SpeedComp

        comp = IndepVarComp()
        comp.add_output('distance', val=1., units='m')
        comp.add_output('time', val=1., units='s')

        prob = Problem(model=Group())
        prob.model.add_subsystem('c1', comp)
        prob.model.add_subsystem('c2', SpeedComp())
        prob.model.add_subsystem('c3',
                                 ExecComp('f=speed', speed={'units': 'm/s'}))
        prob.model.connect('c1.distance', 'c2.distance')
        prob.model.connect('c1.time', 'c2.time')
        prob.model.connect('c2.speed', 'c3.speed')

        prob.setup()
        prob.run_model()

        assert_rel_error(self, prob['c1.distance'], 1.)  # units: m
        assert_rel_error(self, prob['c2.distance'], 1.e-3)  # units: km

        assert_rel_error(self, prob['c1.time'], 1.)  # units: s
        assert_rel_error(self, prob['c2.time'], 1. / 3600.)  # units: h

        assert_rel_error(self, prob['c2.speed'], 3.6)  # units: km/h
        assert_rel_error(self, prob['c3.f'], 1.0)  # units: km/h
Esempio n. 3
0
    def test_speed(self):
        import openmdao.api as om
        from openmdao.core.tests.test_units import SpeedComp

        comp = om.IndepVarComp()
        comp.add_output('distance', val=1., units='m')
        comp.add_output('time', val=1., units='s')

        prob = om.Problem()
        prob.model.add_subsystem('c1', comp)
        prob.model.add_subsystem('c2', SpeedComp())
        prob.model.add_subsystem('c3', om.ExecComp('f=speed',speed={'units': 'm/s'}))
        prob.model.connect('c1.distance', 'c2.distance')
        prob.model.connect('c1.time', 'c2.time')
        prob.model.connect('c2.speed', 'c3.speed')

        prob.setup()
        prob.run_model()

        assert_near_equal(prob['c1.distance'], 1.)  # units: m
        assert_near_equal(prob['c2.distance'], 1.e-3)  # units: km

        assert_near_equal(prob['c1.time'], 1.)  # units: s
        assert_near_equal(prob['c2.time'], 1./3600.)  # units: h

        assert_near_equal(prob['c2.speed'], 3.6)  # units: km/h
        assert_near_equal(prob['c3.f'], 1.0)  # units: km/h
Esempio n. 4
0
    def test_speed(self):
        import openmdao.api as om
        from openmdao.core.tests.test_units import SpeedComp

        prob = om.Problem()
        prob.model.add_subsystem('c1', SpeedComp())
        prob.model.add_subsystem('c2', om.ExecComp('f=speed',speed={'units': 'm/s'}))

        prob.model.set_input_defaults('c1.distance', val=1., units='m')
        prob.model.set_input_defaults('c1.time', val=1., units='s')

        prob.model.connect('c1.speed', 'c2.speed')

        prob.setup()
        prob.run_model()

        assert_near_equal(prob.get_val('c1.distance'), 1.e-3)  # units: km
        assert_near_equal(prob.get_val('c1.time'), 1./3600.)   # units: h
        assert_near_equal(prob.get_val('c1.speed'), 3.6)       # units: km/h

        assert_near_equal(prob.get_val('c2.f'), 1.0)           # units: m/s