当前位置: 首页>>代码示例>>Python>>正文


Python fmi.load_fmu函数代码示例

本文整理汇总了Python中pyfmi.fmi.load_fmu函数的典型用法代码示例。如果您正苦于以下问题:Python load_fmu函数的具体用法?Python load_fmu怎么用?Python load_fmu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_fmu函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_directional_derivative

    def test_get_directional_derivative(self):
        """
        Test the method get_directional_derivative in FMUModelME2
        """
        bounce = load_fmu(ME2, path_to_fmus_me2, False)

        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        bounce.initialize()
        coupled.initialize(tolControlled=False)

        nose.tools.assert_raises(FMUException, bounce.get_directional_derivative, [1], [1], [1])
        nose.tools.assert_raises(FMUException, coupled.get_directional_derivative, [1], [1], [1,2])

        states_list = coupled.get_states_list()
        der_list    = coupled.get_derivatives_list()
        states_ref  = [s.value_reference for s in states_list.values()]
        der_ref     = [s.value_reference for s in der_list.values()]

        nose.tools.assert_raises(FMUException, coupled.get_directional_derivative, [1], [der_ref[0]], [1])

        dir_der = coupled.get_directional_derivative(states_ref, der_ref, [1]*len(states_ref))
        assert len(dir_der) == len(der_list)
        nose.tools.assert_almost_equal(dir_der[1], 0)
        nose.tools.assert_almost_equal(dir_der[2], 1.000000)

        dir_der2 = coupled.get_directional_derivative(states_ref, der_ref, [2]*len(states_ref))
        assert len(dir_der) == len(der_list)
        diff = dir_der2 - 2*dir_der
        nose.tools.assert_almost_equal(sum(diff), 0)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:30,代码来源:test_fmi_2.py

示例2: test_get_derivatives

    def test_get_derivatives(self):
        """
        Test the method get_derivatives in FMUModelME2
        """
        bounce = load_fmu(ME2, path_to_fmus_me2, False)
        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        bounce.initialize()
        coupled.initialize(tolControlled=False)

        nx = bounce.get_ode_sizes()[0]
        der=bounce.get_derivatives()
        assert nx == len(der)

        nose.tools.assert_almost_equal(der[0], 4.000000)
        nose.tools.assert_almost_equal(der[1], -9.810000)

        bounce.set_real(1, 2.)
        bounce.set_real(2, -5.)
        der=bounce.get_derivatives()

        nose.tools.assert_almost_equal(der[0], 2.000000)
        nose.tools.assert_almost_equal(der[1], -5.000000)

        der_list = coupled.get_derivatives_list()
        der_ref  = N.array([s.value_reference for s in der_list.values()])
        der = coupled.get_derivatives()
        diff = N.sort(N.array([coupled.get_real(i) for i in der_ref]))-N.sort(der)
        nose.tools.assert_almost_equal(N.sum(diff), 0.)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:29,代码来源:test_fmi_2.py

示例3: test_default_simulation

    def test_default_simulation(self):
        """
        This test the default values of the simulation using simulate.
        """
        #Writing continuous
        bounce = load_fmu('bouncingBall.fmu', path_to_fmus_me1)
        opts = bounce.simulate_options()
        opts["CVode_options"]["rtol"] = 1e-4
        opts["CVode_options"]["atol"] = 1e-6
        res = bounce.simulate(final_time=3., options=opts)

        nose.tools.assert_almost_equal(res.solver.rtol, 1e-4, 6)
        assert res.solver.iter == 'Newton'
        
        nose.tools.assert_almost_equal(res.initial('h'),1.000000,5)
        nose.tools.assert_almost_equal(res.final('h'),-0.9804523,5)
        nose.tools.assert_almost_equal(res.final('time'),3.000000,5)
        
        #Writing continuous
        bounce = load_fmu('bouncingBall.fmu', path_to_fmus_me1)
        #bounce.initialize(options={'initialize':False})
        res = bounce.simulate(final_time=3.,
            options={'initialize':True,'CVode_options':{'iter':'FixedPoint','rtol':1e-6,'atol':1e-6}})
    
        nose.tools.assert_almost_equal(res.solver.rtol, 0.00000100, 7)
        assert res.solver.iter == 'FixedPoint'
        
        nose.tools.assert_almost_equal(res.initial('h'),1.000000,5)
        nose.tools.assert_almost_equal(res.final('h'),-0.98018113,5)
        nose.tools.assert_almost_equal(res.final('time'),3.000000,5)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:30,代码来源:test_assimulo_interface_fmi.py

示例4: test_initialize

    def test_initialize(self):
        """
        Test the method initialize in FMUModelCS2
        """
        self._bounce=load_fmu(CS2, path_to_fmus_cs2, False)
        self._coupledCS2 = load_fmu(CoupledCS2, path_to_fmus_cs2, False)

        for i in range(10):
            self._bounce.initialize(relTol = 10**-i)  #Initialize multiple times with different relTol
            self._bounce.reset_slave()
        self._bounce.initialize()    #Initialize with default options
        self._bounce.reset_slave()

        self._bounce.initialize(tStart = 4.5)
        nose.tools.assert_almost_equal(self._bounce.time, 4.5)
        self._bounce.reset_slave()

        #Try to simulate past the defined stop
        self._coupledCS2.initialize(tStop=1.0 , StopTimeDefined = True)
        step_size=0.1
        total_time=0
        for i in range(10):
            self._coupledCS2.do_step(total_time, step_size)
            total_time += step_size
        status=self._coupledCS2.do_step(total_time, step_size)
        assert status != 0
        self._coupledCS2.reset_slave()

        #Try to initialize twice when not supported
        self._coupledCS2.initialize()
        nose.tools.assert_raises(FMUException, self._coupledCS2.initialize)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:31,代码来源:test_fmi_2.py

示例5: test_correct_loading

    def test_correct_loading(self):

        model = load_fmu("Modelica_Mechanics_Rotational_Examples_CoupledClutches_ME.fmu",path_to_fmus_me1)
        assert isinstance(model, FMUModelME1)

        model = load_fmu("Modelica_Mechanics_Rotational_Examples_CoupledClutches_CS.fmu",path_to_fmus_cs1)
        assert isinstance(model, FMUModelCS1)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:7,代码来源:test_fmi.py

示例6: test_multiple_loadings_and_simulations

    def test_multiple_loadings_and_simulations(self):
        model = load_fmu("bouncingBall.fmu",path_to_fmus_me1,enable_logging=False)
        res = model.simulate(final_time=1.0)
        h_res = res.final('h')

        for i in range(40):
            model = load_fmu("bouncingBall.fmu",path_to_fmus_me1,enable_logging=False)
            res = model.simulate(final_time=1.0)
        assert N.abs(h_res - res.final('h')) < 1e-4
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:9,代码来源:test_fmi.py

示例7: test_log_file_name

 def test_log_file_name(self):
     model = load_fmu("bouncingBall.fmu",path_to_fmus_me1)
     assert os.path.exists("bouncingBall_log.txt")
     model = load_fmu("bouncingBall.fmu",path_to_fmus_me1,log_file_name="Test_log.txt")
     assert os.path.exists("Test_log.txt")
     model = FMUModelME1("bouncingBall.fmu",path_to_fmus_me1)
     assert os.path.exists("bouncingBall_log.txt")
     model = FMUModelME1("bouncingBall.fmu",path_to_fmus_me1,log_file_name="Test_log.txt")
     assert os.path.exists("Test_log.txt")
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:9,代码来源:test_fmi.py

示例8: setUp

 def setUp(self):
     """
     Load the test model.
     """
     self._bounce  = load_fmu('bouncingBall.fmu',path_to_fmus_me1)
     self._dq = load_fmu('dq.fmu',path_to_fmus_me1)
     self._bounce.initialize()
     self._dq.initialize()
     self._bounceSim = FMIODE(self._bounce)
     self._dqSim     = FMIODE(self._dq)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:10,代码来源:test_assimulo_interface_fmi.py

示例9: test_init

    def test_init(self):
        """
        Test the method __init__ in FMUModelME2
        """
        bounce = load_fmu(ME2, path_to_fmus_me2, False)
        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        assert bounce.get_identifier() == 'BouncingBall2'
        nose.tools.assert_raises(FMUException, FMUModelME2, fmu=CS2, path=path_to_fmus_cs2, enable_logging=False)
        nose.tools.assert_raises(FMUException, FMUModelME2, fmu=CS1, path=path_to_fmus_cs1, enable_logging=False)
        nose.tools.assert_raises(FMUException, FMUModelME2, fmu=ME1, path=path_to_fmus_me1, enable_logging=False)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:11,代码来源:test_fmi_2.py

示例10: setUp

 def setUp(self):
     """
     Sets up the test case.
     """
     self.rlc  = load_fmu('RLC_Circuit.fmu')
     self._bounce  = load_fmu('bouncingBall.fmu',path_to_fmus_me1)
     self._dq = load_fmu('dq.fmu',path_to_fmus_me1)
     self._bounce.initialize()
     self._dq.initialize()
     self.dep = load_fmu("DepParTests_DepPar1.fmu")
     self.dep.initialize()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:11,代码来源:test_fmi.py

示例11: test_instantiate_model

    def test_instantiate_model(self):
        """
        Test the method instantiate_model in FMUModelME2
        """
        bounce = load_fmu(ME2, path_to_fmus_me2, False)
        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        for i in range(5):
            name1 = 'model1' + str(i)
            #name2 = 'model2' + str(i)
            #coupled.instantiate_model(name=name2)
            bounce.instantiate_model(name=name1)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:12,代码来源:test_fmi_2.py

示例12: test_reset_slave

    def test_reset_slave(self):
        """
        Test the method reset_slave in FMUModelCS2
        """
        self._bounce=load_fmu(CS2, path_to_fmus_cs2, False)
        self._bounce.initialize()
        self._coupledCS2 = load_fmu(CoupledCS2, path_to_fmus_cs2, False)
        self._coupledCS2.initialize()

        self._bounce.reset_slave()
        self._bounce.initialize()
        self._coupledCS2.reset_slave()
        self._coupledCS2.initialize()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:13,代码来源:test_fmi_2.py

示例13: test_reset

    def test_reset(self):
        """
        Test the method reset in FMUModelME2
        """
        bounce = load_fmu(ME2, path_to_fmus_me2, False)
        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        bounce.initialize()
        coupled.initialize(tolControlled=False)

        bounce.reset()
        coupled.reset()

        assert bounce.time is None
        assert coupled.time is None
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:15,代码来源:test_fmi_2.py

示例14: test_event_iteration

    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)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:27,代码来源:test_assimulo_interface_fmi.py

示例15: test_relation_geinit

 def test_relation_geinit(self):
     model = load_fmu("RelationTests_RelationGEInit.fmu")
     
     res = model.simulate(final_time=0.1)
     
     nose.tools.assert_almost_equal(res.initial("x"),0.0,places=3)
     nose.tools.assert_almost_equal(res.initial("y"),1.0,places=3)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:7,代码来源:test_assimulo_interface_fmi.py


注:本文中的pyfmi.fmi.load_fmu函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。