Exemple #1
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")
Exemple #2
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")
Exemple #3
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)