• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python fmi.load_fmu函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_reset

    def test_reset(self):
        """
        Test resetting an FMU. (Multiple instances is NOT supported on Dymola
        FMUs)
        """
        #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
        #bounce.initialize()
        res = bounce.simulate(final_time=3., options=opts)
        
        nose.tools.assert_almost_equal(res.initial('h'),1.000000,5)
        nose.tools.assert_almost_equal(res.final('h'),-0.9804523,5)
        
        bounce.reset()
        #bounce.initialize()
        
        nose.tools.assert_almost_equal(bounce.get('h'), 1.00000,5)
        
        res = bounce.simulate(final_time=3.,options=opts)

        nose.tools.assert_almost_equal(res.initial('h'),1.000000,5)
        nose.tools.assert_almost_equal(res.final('h'),-0.9804523,5)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:25,代码来源:test_assimulo_interface_fmi.py


示例17: test_simulate_options

    def test_simulate_options(self):
        """
        Test the method simulate_options in FMUModelME2
        """
        coupled = load_fmu(CoupledME2, path_to_fmus_me2)

        opts=coupled.simulate_options()
        assert opts['initialize']
        assert not opts['with_jacobian']
        assert opts['ncp'] == 0

        #Test the result file
        res=coupled.simulate()
        assert res.result_file == 'Modelica_Mechanics_Rotational_Examples_CoupledClutches_result.txt'
        assert os.path.exists(res.result_file)

        coupled.reset()
        opts = {'result_file_name':'Modelica_Mechanics_Rotational_Examples_CoupledClutches_result_test.txt'}
        res=coupled.simulate(options=opts)
        assert res.result_file == 'Modelica_Mechanics_Rotational_Examples_CoupledClutches_result_test.txt'
        assert os.path.exists(res.result_file)

        #Test the option in the simulate method
        coupled.reset()
        opts={}
        opts['ncp'] = 250
        opts['initialize'] = False
        coupled.initialize(tolControlled=False)
        res=coupled.simulate(options=opts)
        assert len(res['time']) > 250
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:30,代码来源:test_fmi_2.py


示例18: test_check_against_unneccesary_derivatives_eval

 def test_check_against_unneccesary_derivatives_eval(self):
     name = compile_fmu("RLC_Circuit",os.path.join(path_to_mofiles,"RLC_Circuit.mo"), compiler_options={"generate_html_diagnostics":True, "log_level":6})
     
     model = load_fmu(name, log_level=6)
     model.set("_log_level", 6)
     model.initialize()
     
     len_log = len(model.get_log())
     model.time = 1e-4
     model.get_derivatives()
     assert len(model.get_log()) > len_log
     len_log = len(model.get_log())
     model.get_derivatives()
     len_log_diff = len(model.get_log())-len_log
     model.time = 1e-4
     len_log = len(model.get_log())
     model.get_derivatives()
     assert len(model.get_log())-len_log_diff == len_log
     len_log = len(model.get_log())
     model.continuous_states = model.continuous_states
     model.get_derivatives()
     assert len(model.get_log())-len_log_diff == len_log
     len_log = len(model.get_log())
     model.continuous_states = model.continuous_states+1
     model.get_derivatives()
     assert len(model.get_log())-len_log_diff > len_log
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:26,代码来源:test_fmi.py


示例19: test_terminate

 def test_terminate(self):
     """
     Test the method terminate in FMUModelME2
     """
     coupled = load_fmu(CoupledME2, path_to_fmus_me2)
     coupled.initialize(tolControlled=False)
     coupled.terminate()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:7,代码来源:test_fmi_2.py


示例20: test_cc_with_dopri

 def test_cc_with_dopri(self):
     model = load_fmu("Modelica_Mechanics_Rotational_Examples_CoupledClutches.fmu")
     opts = model.simulate_options()
     opts["solver"] = "Dopri5"
     
     res = model.simulate(final_time=1.5,options=opts)
     
     assert (N.abs(res.final("J1.w") - 3.2450903041811698)) < 1e-3
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:8,代码来源:test_assimulo_interface_fmi.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyfmt.format_code函数代码示例发布时间:2022-05-25
下一篇:
Python pyfmi.load_fmu函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap