コード例 #1
0
    def test_get_directional_derivative_capability(self):
        bounce = Dummy_FMUModelME2([],
                                   "bouncingBall.fmu",
                                   os.path.join(file_path, "files", "FMUs",
                                                "XML", "ME2.0"),
                                   _connect_dll=False)
        bounce.setup_experiment()
        bounce.initialize()

        # Bouncing ball don't have the capability, check that this is handled
        nose.tools.assert_raises(FMUException,
                                 bounce.get_directional_derivative, [1], [1],
                                 [1])

        bounce = Dummy_FMUModelCS2([],
                                   "bouncingBall.fmu",
                                   os.path.join(file_path, "files", "FMUs",
                                                "XML", "CS2.0"),
                                   _connect_dll=False)
        bounce.setup_experiment()
        bounce.initialize()

        # Bouncing ball don't have the capability, check that this is handled
        nose.tools.assert_raises(FMUException,
                                 bounce.get_directional_derivative, [1], [1],
                                 [1])
コード例 #2
0
 def test_binary_options_cs2(self):
     simple_alias = Dummy_FMUModelCS2([("x", "y")],
                                      "NegatedAlias.fmu",
                                      os.path.join(file_path, "files",
                                                   "FMUs", "XML", "CS2.0"),
                                      _connect_dll=False)
     _run_negated_alias(simple_alias, "binary")
コード例 #3
0
    def test_simulation_without_initialization(self):
        model = Dummy_FMUModelME2([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "ME2.0"), _connect_dll=False)
        opts = model.simulate_options()
        opts["initialize"] = False

        nose.tools.assert_raises(FMUException, model.simulate, options=opts)
        
        model = Dummy_FMUModelCS2([], "bouncingBall.fmu", os.path.join(file_path, "files", "FMUs", "XML", "CS2.0"), _connect_dll=False)
        opts = model.simulate_options()
        opts["initialize"] = False

        nose.tools.assert_raises(FMUException, model.simulate, options=opts)
コード例 #4
0
    def test_integer_to_real_connections(self):
        model_sub1 = Dummy_FMUModelCS2([],
                                       "IntegerStep.fmu",
                                       cs2_xml_path,
                                       _connect_dll=False)
        model_sub2 = Dummy_FMUModelCS2([],
                                       "GainTestReal.fmu",
                                       cs2_xml_path,
                                       _connect_dll=False)

        model_sub1.set("y", 1)

        def do_step1(current_t, step_size, new_step=True):
            model_sub1.values[model_sub1.get_variable_valueref(
                "y")] = 1 if current_t + step_size < 0.5 else 3
            model_sub1.completed_integrator_step()
            return 0

        def do_step2(current_t, step_size, new_step=True):
            u = model_sub2.values[model_sub2.get_variable_valueref("u")]
            model_sub2.values[model_sub2.get_variable_valueref("y")] = 10 * u
            model_sub2.completed_integrator_step()
            return 0

        model_sub1.do_step = do_step1
        model_sub2.do_step = do_step2

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, 'y', model_sub2, 'u')]

        master = Master(models, connections)

        opts = master.simulate_options()
        opts["block_initialization"] = True

        res = master.simulate(start_time=0.0, final_time=2.0, options=opts)

        assert res[model_sub2]["u"][0] == 1.0
        assert res[model_sub2]["u"][-1] == 3.0
コード例 #5
0
    def test_unstable_simulation(self):
        model_sub1 = Dummy_FMUModelCS2(
            [],
            "LinearCoSimulation_LinearSubSystem1.fmu",
            cs2_xml_path,
            _connect_dll=False)
        model_sub2 = Dummy_FMUModelCS2(
            [],
            "LinearCoSimulation_LinearSubSystem2.fmu",
            cs2_xml_path,
            _connect_dll=False)

        model_sub2.set("d2", 1.1)  #Coupled system becomes unstable

        a1 = model_sub1.values[model_sub1.get_variable_valueref("a1")]
        b1 = model_sub1.values[model_sub1.get_variable_valueref("b1")]
        c1 = model_sub1.values[model_sub1.get_variable_valueref("c1")]
        d1 = model_sub1.values[model_sub1.get_variable_valueref("d1")]

        a2 = model_sub2.values[model_sub2.get_variable_valueref("a2")]
        b2 = model_sub2.values[model_sub2.get_variable_valueref("b2")]
        c2 = model_sub2.values[model_sub2.get_variable_valueref("c2")]
        d2 = model_sub2.values[model_sub2.get_variable_valueref("d2")]

        def do_step1(current_t, step_size, new_step=True):
            u1 = model_sub1.values[model_sub1.get_variable_valueref("u1")]

            model_sub1.continuous_states = 1.0 / a1 * (
                np.exp(a1 * step_size) - 1.0) * b1 * u1 + np.exp(
                    a1 * step_size) * model_sub1.continuous_states
            model_sub1.values[model_sub1.get_variable_valueref(
                "y1")] = c1 * model_sub1.continuous_states + d1 * u1
            model_sub1.completed_integrator_step()
            return 0

        def do_step2(current_t, step_size, new_step=True):
            u2 = model_sub2.values[model_sub2.get_variable_valueref("u2")]

            model_sub2.continuous_states = 1.0 / a2 * (
                np.exp(a2 * step_size) - 1.0) * b2 * u2 + np.exp(
                    a2 * step_size) * model_sub2.continuous_states
            model_sub2.values[model_sub2.get_variable_valueref(
                "y2")] = c2 * model_sub2.continuous_states + d2 * u2
            model_sub2.completed_integrator_step()
            return 0

        model_sub1.do_step = do_step1
        model_sub2.do_step = do_step2

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        master = Master(models, connections)

        opts = master.simulate_options()
        opts["step_size"] = 0.0005

        res = master.simulate(final_time=0.3, options=opts)

        assert abs(res[model_sub1].final("x1")) > 100
        assert abs(res[model_sub2].final("x2")) > 100
コード例 #6
0
    def _basic_simulation(self, result_handling):
        model_sub1 = Dummy_FMUModelCS2(
            [],
            "LinearCoSimulation_LinearSubSystem1.fmu",
            cs2_xml_path,
            _connect_dll=False)
        model_sub2 = Dummy_FMUModelCS2(
            [],
            "LinearCoSimulation_LinearSubSystem2.fmu",
            cs2_xml_path,
            _connect_dll=False)

        a1 = model_sub1.values[model_sub1.get_variable_valueref("a1")]
        b1 = model_sub1.values[model_sub1.get_variable_valueref("b1")]
        c1 = model_sub1.values[model_sub1.get_variable_valueref("c1")]
        d1 = model_sub1.values[model_sub1.get_variable_valueref("d1")]

        a2 = model_sub2.values[model_sub2.get_variable_valueref("a2")]
        b2 = model_sub2.values[model_sub2.get_variable_valueref("b2")]
        c2 = model_sub2.values[model_sub2.get_variable_valueref("c2")]
        d2 = model_sub2.values[model_sub2.get_variable_valueref("d2")]

        def do_step1(current_t, step_size, new_step=True):
            u1 = model_sub1.values[model_sub1.get_variable_valueref("u1")]

            model_sub1.continuous_states = 1.0 / a1 * (
                np.exp(a1 * step_size) - 1.0) * b1 * u1 + np.exp(
                    a1 * step_size) * model_sub1.continuous_states
            model_sub1.values[model_sub1.get_variable_valueref(
                "y1")] = c1 * model_sub1.continuous_states + d1 * u1
            model_sub1.completed_integrator_step()
            return 0

        def do_step2(current_t, step_size, new_step=True):
            u2 = model_sub2.values[model_sub2.get_variable_valueref("u2")]

            model_sub2.continuous_states = 1.0 / a2 * (
                np.exp(a2 * step_size) - 1.0) * b2 * u2 + np.exp(
                    a2 * step_size) * model_sub2.continuous_states
            model_sub2.values[model_sub2.get_variable_valueref(
                "y2")] = c2 * model_sub2.continuous_states + d2 * u2
            model_sub2.completed_integrator_step()
            return 0

        model_sub1.do_step = do_step1
        model_sub2.do_step = do_step2

        models = [model_sub1, model_sub2]
        connections = [(model_sub1, "y1", model_sub2, "u2"),
                       (model_sub2, "y2", model_sub1, "u1")]

        master = Master(models, connections)

        opts = master.simulate_options()
        opts["step_size"] = 0.0005
        opts["result_handling"] = result_handling

        res = master.simulate(options=opts)

        nose.tools.assert_almost_equal(res[model_sub1].final("x1"),
                                       0.0859764038708439, 3)
        nose.tools.assert_almost_equal(res[model_sub2].final("x2"),
                                       0.008392664839635064, 4)