def test_event_iteration(self):
        """
        This tests FMUs with event iteration (JModelica.org).
        """
        fmu_name = compile_fmu('EventIter.EventMiddleIter', os.path.join(path_to_mos,'EventIter.mo'))

        model = load_fmu(fmu_name)

        sim_res = model.simulate(final_time=10)

        nose.tools.assert_almost_equal(sim_res.initial('x'), 2.00000, 4)
        nose.tools.assert_almost_equal(sim_res.final('x'), 10.000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('y'), 3.0000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('z'), 2.0000000, 4)
        
        fmu_name = compile_fmu('EventIter.EventStartIter', os.path.join(path_to_mos,'EventIter.mo'))
        
        model = FMUModel(fmu_name)

        sim_res = model.simulate(final_time=10)

        nose.tools.assert_almost_equal(sim_res.initial('x'), 1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.initial('y'), -1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.initial('z'), 1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.final('x'), -2.000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('y'), -1.0000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('z'), 4.0000000, 4)
Example #2
0
    def test_event_iteration(self):
        """
        This tests FMUs with event iteration (JModelica.org).
        """
        fmu_name = compile_fmu('EventIter.EventMiddleIter',
                               os.path.join(path_to_mos, 'EventIter.mo'))

        model = load_fmu(fmu_name)

        sim_res = model.simulate(final_time=10)

        nose.tools.assert_almost_equal(sim_res.initial('x'), 2.00000, 4)
        nose.tools.assert_almost_equal(sim_res.final('x'), 10.000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('y'), 3.0000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('z'), 2.0000000, 4)

        fmu_name = compile_fmu('EventIter.EventStartIter',
                               os.path.join(path_to_mos, 'EventIter.mo'))

        model = FMUModel(fmu_name)

        sim_res = model.simulate(final_time=10)

        nose.tools.assert_almost_equal(sim_res.initial('x'), 1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.initial('y'), -1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.initial('z'), 1.00000, 4)
        nose.tools.assert_almost_equal(sim_res.final('x'), -2.000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('y'), -1.0000000, 4)
        nose.tools.assert_almost_equal(sim_res.final('z'), 4.0000000, 4)
Example #3
0
 def setUp(self):
     """
     Sets up the test case.
     """
     self._bounce = FMUModel('bouncingBall.fmu', path_to_fmus_me1)
     self._dq = FMUModel('dq.fmu', path_to_fmus_me1)
     self._bounce.initialize()
     self._dq.initialize()
Example #4
0
 def setUp(self):
     """
     Sets up the test case.
     """
     self._bounce  = FMUModel('bouncingBall.fmu',path_to_fmus_me1)
     self._dq = FMUModel('dq.fmu',path_to_fmus_me1)
     self._bounce.initialize()
     self._dq.initialize()
Example #5
0
class test_ResultWriterDymola:
    """Tests the class ResultWriterDymola."""
    def setUp(self):
        """
        Sets up the test case.
        """
        self._bounce = FMUModel('bouncingBall.fmu', path_to_fmus_me1)
        self._dq = FMUModel('dq.fmu', path_to_fmus_me1)
        self._bounce.initialize()
        self._dq.initialize()

    @testattr(fmi=True)
    def test_work_flow(self):
        """Tests the work flow of write_header, write_point, write_finalize."""

        bouncingBall = fmi_ResultHandlerFile(self._bounce)

        bouncingBall.set_options(self._bounce.simulate_options())
        bouncingBall.simulation_start()
        bouncingBall.initialize_complete()
        bouncingBall.integration_point()
        bouncingBall.simulation_end()

        res = ResultDymolaTextual('bouncingBall_result.txt')

        h = res.get_variable_data('h')
        derh = res.get_variable_data('der(h)')
        g = res.get_variable_data('g')

        nose.tools.assert_almost_equal(h.x, 1.000000, 5)
        nose.tools.assert_almost_equal(derh.x, 0.000000, 5)


#        nose.tools.assert_almost_equal(g.x, 9.810000, 5)

    @testattr(windows=True)
    def test_variable_alias(self):
        """ 
        Tests the variable with parameter alias is presented as variable in the 
        result.
        """
        simple_alias = load_fmu('SimpleAlias.fmu', path_to_fmus_me1)
        res = simple_alias.simulate()

        # test that res['y'] returns a vector of the same length as the time
        # vector
        nose.tools.assert_equal(len(res['y']), len(res['time']),
                                "Wrong size of result vector.")

        # test that y really is saved in result as a parameter
        res_traj = res.result_data.get_variable_data('y')
        nose.tools.assert_equal(
            len(res_traj.x), 2,
            "Wrong size of y returned by result_data.get_variable_data")
Example #6
0
class test_ResultWriterDymola:
    """Tests the class ResultWriterDymola."""
    
    def setUp(self):
        """
        Sets up the test case.
        """
        self._bounce  = FMUModel('bouncingBall.fmu',path_to_fmus_me1)
        self._dq = FMUModel('dq.fmu',path_to_fmus_me1)
        self._bounce.initialize()
        self._dq.initialize()
        
    @testattr(stddist = True)
    def test_work_flow(self):
        """Tests the work flow of write_header, write_point, write_finalize."""
        
        
        bouncingBall = fmi_ResultHandlerFile(self._bounce)
        
        bouncingBall.set_options(self._bounce.simulate_options())
        bouncingBall.simulation_start()
        bouncingBall.initialize_complete()
        bouncingBall.integration_point()
        bouncingBall.simulation_end()
        
        res = ResultDymolaTextual('bouncingBall_result.txt')
        
        h = res.get_variable_data('h')
        derh = res.get_variable_data('der(h)')
        g = res.get_variable_data('g')

        nose.tools.assert_almost_equal(h.x, 1.000000, 5)
        nose.tools.assert_almost_equal(derh.x, 0.000000, 5)
#        nose.tools.assert_almost_equal(g.x, 9.810000, 5)

    @testattr(windows = True)
    def test_variable_alias(self):
        """ 
        Tests the variable with parameter alias is presented as variable in the 
        result.
        """
        simple_alias = load_fmu('SimpleAlias.fmu',path_to_fmus_me1)
        res = simple_alias.simulate()
        
        # test that res['y'] returns a vector of the same length as the time
        # vector
        nose.tools.assert_equal(len(res['y']),len(res['time']), 
            "Wrong size of result vector.")
            
        # test that y really is saved in result as a parameter
        res_traj = res.result_data.get_variable_data('y')
        nose.tools.assert_equal(len(res_traj.x), 2, 
            "Wrong size of y returned by result_data.get_variable_data")
Example #7
0
    def test_changed_starttime(self):
        """
        This tests a simulation with different start time.
        """
        bounce = FMUModel('bouncingBall.fmu', path_to_fmus_me1)
        #bounce.initialize()
        opts = bounce.simulate_options()
        opts["CVode_options"]["rtol"] = 1e-4
        opts["CVode_options"]["atol"] = 1e-6
        res = bounce.simulate(start_time=2., final_time=5., options=opts)

        nose.tools.assert_almost_equal(res.initial('h'), 1.000000, 5)
        nose.tools.assert_almost_equal(res.final('h'), -0.98048862, 4)
        nose.tools.assert_almost_equal(res.final('time'), 5.000000, 5)
    def test_changed_starttime(self):
        """
        This tests a simulation with different start time.
        """
        bounce = FMUModel('bouncingBall.fmu', path_to_fmus_me1)
        #bounce.initialize()
        opts = bounce.simulate_options()
        opts["CVode_options"]["rtol"] = 1e-4
        opts["CVode_options"]["atol"] = 1e-6
        res = bounce.simulate(start_time=2.,final_time=5.,options=opts)

        nose.tools.assert_almost_equal(res.initial('h'),1.000000,5)
        nose.tools.assert_almost_equal(res.final('h'),-0.98048862,4)
        nose.tools.assert_almost_equal(res.final('time'),5.000000,5)
Example #9
0
    def test_simulation_completed_step_lsodar(self):
        model = load_fmu('Pendulum_0Dynamic.fmu', path_to_fmus_me1)

        opts = model.simulate_options()
        opts["solver"] = "LSODAR"
        res = model.simulate(final_time=10, options=opts)

        assert N.abs(res.final('y') + 0.956993467) < 1e-1
        assert N.abs(res.final('x') - 0.290109468) < 1e-1

        model = FMUModel('Pendulum_0Dynamic.fmu', path_to_fmus_me1)

        opts["ncp"] = 1000
        res = model.simulate(final_time=10, options=opts)

        assert N.abs(res.final('y') + 0.956993467) < 1e-1
        assert N.abs(res.final('x') - 0.290109468) < 1e-1
    def test_simulation_completed_step_lsodar(self):
        model = load_fmu('Pendulum_0Dynamic.fmu', path_to_fmus_me1)
        
        opts = model.simulate_options()
        opts["solver"] = "LSODAR"
        res = model.simulate(final_time=10, options=opts)
    
        assert N.abs(res.final('y')+0.956993467) < 1e-1
        assert N.abs(res.final('x')-0.290109468) < 1e-1
        
        model = FMUModel('Pendulum_0Dynamic.fmu', path_to_fmus_me1)
        
        opts["ncp"] = 1000
        res = model.simulate(final_time=10, options=opts)

        assert N.abs(res.final('y')+0.956993467) < 1e-1
        assert N.abs(res.final('x')-0.290109468) < 1e-1
Example #11
0
    def test_simulation_completed_step_cvode(self):
        """
        This tests a simulation of a Pendulum with dynamic state selection.
        """
        model = load_fmu('Pendulum_0Dynamic.fmu', path_to_fmus_me1)

        res = model.simulate(final_time=10)

        nose.tools.assert_almost_equal(res.initial('x'), 1.000000, 4)
        nose.tools.assert_almost_equal(res.initial('y'), 0.000000, 4)
        nose.tools.assert_almost_equal(res.final('x'), 0.290109468, 4)
        nose.tools.assert_almost_equal(res.final('y'), -0.956993467, 4)

        model = FMUModel('Pendulum_0Dynamic.fmu', path_to_fmus_me1)

        res = model.simulate(final_time=10, options={'ncp': 1000})

        nose.tools.assert_almost_equal(res.initial('x'), 1.000000, 4)
        nose.tools.assert_almost_equal(res.initial('y'), 0.000000, 4)
 def test_simulation_completed_step_cvode(self):
     """
     This tests a simulation of a Pendulum with dynamic state selection.
     """
     model = load_fmu('Pendulum_0Dynamic.fmu', path_to_fmus_me1)
     
     res = model.simulate(final_time=10)
 
     nose.tools.assert_almost_equal(res.initial('x'), 1.000000, 4)
     nose.tools.assert_almost_equal(res.initial('y'), 0.000000, 4)
     nose.tools.assert_almost_equal(res.final('x'), 0.290109468, 4)
     nose.tools.assert_almost_equal(res.final('y'), -0.956993467, 4)
     
     model = FMUModel('Pendulum_0Dynamic.fmu', path_to_fmus_me1)
     
     res = model.simulate(final_time=10, options={'ncp':1000})
 
     nose.tools.assert_almost_equal(res.initial('x'), 1.000000, 4)
     nose.tools.assert_almost_equal(res.initial('y'), 0.000000, 4)