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

Python pymodelica.compile_fmu函数代码示例

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

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



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

示例1: test_ExtFuncShared

 def test_ExtFuncShared(self):
     """ 
     Test compiling a model with external functions in a shared library. Real, Integer, and Boolean arrays.
     """
     fmu_name = compile_fmu(self.cpath, self.fpath, compiler_options={'variability_propagation':True})
     model = load_fmu(fmu_name)
     s_ceval = model.get('s')
     res = model.simulate()
     s_sim1 = res.final('s')
     
     fmu_name = compile_fmu(self.cpath, self.fpath, compiler_options={'variability_propagation':False})
     model = load_fmu(fmu_name)
     res = model.simulate()
     s_sim2 = res.final('s')
     nose.tools.assert_equals(s_sim1, s_sim2)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:15,代码来源:test_extfunctions.py


示例2: run_demo

def run_demo(with_plots=True):
    """
    Distillation2 model
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__));

    fmu_name = compile_fmu("JMExamples.Distillation.Distillation2", 
    curr_dir+"/files/JMExamples.mo")
    dist2 = load_fmu(fmu_name)
    
    res = dist2.simulate(final_time=7200)

    # Extract variable profiles
    x16	= res['x[16]']
    x32	= res['x[32]']
    t	= res['time']
    
    print "t = ", repr(N.array(t))
    print "x16 = ", repr(N.array(x16))
    print "x32 = ", repr(N.array(x32))

    if with_plots:
        # Plot
        plt.figure(1)
        plt.plot(t,x16,t,x32)
        plt.grid()
        plt.ylabel('x')
        
        plt.xlabel('time')
        plt.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:31,代码来源:distillation2_fmu.py


示例3: run_demo

def run_demo(with_plots=True):
    """
    An example on how to simulate a model using the DAE simulator. The result 
    can be compared with that of sim_rlc.py which has solved the same problem 
    using dymola. Also writes information to a file.
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__));

    class_name = 'RLC_Circuit'
    mofile = curr_dir+'/files/RLC_Circuit.mo'
    
    fmu_name = compile_fmu(class_name, mofile)
    rlc = load_fmu(fmu_name)
    
    res = rlc.simulate(final_time=30)
    
    sine_y = res['sine.y']
    resistor_v = res['resistor.v']
    inductor1_i = res['inductor1.i']
    t = res['time']

    assert N.abs(res.final('resistor.v') - 0.159255008028) < 1e-3
    
    if with_plots:
        fig = p.figure()
        p.plot(t, sine_y, t, resistor_v, t, inductor1_i)
        p.legend(('sine.y','resistor.v','inductor1.i'))
        p.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:29,代码来源:RLC.py


示例4: run_demo

def run_demo(with_plots=True):
    """
    An example on how to simulate a model using the ODE simulator.
    """
    curr_dir = os.path.dirname(os.path.abspath(__file__));
    file_name = os.path.join(curr_dir,'files','VDP.mop')
    
    fmu_name = compile_fmu("JMExamples.VDP.VDP", 
    curr_dir+"/files/JMExamples.mo")

    model = load_fmu(fmu_name)
    
    opts = model.simulate_options()
    opts["CVode_options"]["rtol"] = 1e-6
    
    res = model.simulate(final_time=10, options=opts)

    assert N.abs(res.final('x1') - 7.34186386e-01) < 1e-3
    assert N.abs(res.final('x2') + 1.58202722)    < 1e-3
    
    x1 = res['x1']
    x2 = res['x2']
    
    if with_plots:
        plt.figure()
        plt.plot(x2, x1)
        plt.legend(('x1(x2)'))
        plt.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:28,代码来源:VDP_sim.py


示例5: run_demo

def run_demo(with_plots=True):
    
    curr_dir = os.path.dirname(os.path.abspath(__file__));
    class_name = 'ExtFunctions.addTwo'
    mofile = os.path.join(curr_dir, 'files', 'ExtFunctions.mo')
    
    # Compile and load model
    fmu_name = compile_fmu(class_name, mofile)
    model = load_fmu(fmu_name)

    # Simulate
    res = model.simulate()
    
    # Load result data
    sim_a = res['a']
    sim_b = res['b']
    sim_c = res['c']
    t     = res['time']

    assert N.abs(res.final('a') - 1) < 1e-6
    assert N.abs(res.final('b') - 2) < 1e-6
    assert N.abs(res.final('c') - 3) < 1e-6

    if with_plots:
        fig = p.figure()
        p.clf()
        p.subplot(3,1,1)
        p.plot(t, sim_a)
        p.subplot(3,1,2) 
        p.plot(t, sim_b) 
        p.subplot(3,1,3)
        p.plot(t, sim_c)
        p.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:33,代码来源:extfunctions.py


示例6: run_demo

def run_demo(with_plots=True, version="2.0"):	

	# Compile model
	fmu_name = compile_fmu("IBPSA.Fluid.FixedResistances.Examples.PlugFlowPipe","C:\My_Libs\modelica-ibpsa\IBPSA")
	fmu_name=("IBPSA_Fluid_FixedResistances_Examples_PlugFlowPipe.fmu")
	#print("FMU compiled",fmu_name)
	print(fmu_name)

	# Load model
	pipe = load_fmu(fmu_name)

	print("FMU loaded", pipe)

	res = pipe.simulate(final_time=100)
		
	x1 = res['Tin.offset']
	x2 = res['sou.m_flow']
	t = res['time']
		
	plt.figure(1)
	plt.plot(t, x1, t, x2)
	plt.legend(('Tin (K)','mdot (kg/s)'))
	plt.title('Pipe')
	plt.ylabel('y axis')
	plt.xlabel('Time (s)')
	plt.show()
开发者ID:MonicaKTH,项目名称:IntegrCiTy2,代码行数:26,代码来源:runPipe.py


示例7: run_demo

def run_demo(with_plots=True):
    """
    An example on how to simulate a model using a DAE simulator with Assimulo. 
    The model used is made by Maja Djačić.
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__));

    m_name = 'SolAngles'
    mofile = curr_dir+'/files/SolAngles.mo'
    
    fmu_name = compile_fmu(m_name, mofile)
    model = load_fmu(fmu_name)
    
    res = model.simulate(final_time=86400.0, options={'ncp':86400})

    theta = res['theta']
    azim = res['azim']
    N_day = res['N_day']
    time = res['time']
    
    assert N.abs(res.final('theta') - 90.28737353) < 1e-3
    
    # Plot results
    if with_plots:
        p.figure(1)
        p.plot(time, theta)
        p.xlabel('time [s]')
        p.ylabel('theta [deg]')
        p.title('Angle of Incidence on Surface')
        p.grid()
        p.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:32,代码来源:SolAng.py


示例8: test_ExtFuncStatic

 def test_ExtFuncStatic(self):
     """ 
     Test compiling a model with external functions in a static library.
     """
     cpath = "ExtFunctionTests.ExtFunctionTest1"
     fmu_name = compile_fmu(cpath, TestExternalStatic.fpath)
     model = load_fmu(fmu_name)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:7,代码来源:test_extfunctions.py


示例9: simulate

    def simulate(self):
        ''' TODO: LOG all command omc '''
#         tic= timeit.default_timer()
        # Simulation process with JModelica
        fullMoFile= self.moPath+ '/'+ self.moFile
        fullMoLib= self.libPath+ '/'+ self.libFile
        '''build the fmu block from the modelica model '''
#         fmu_name= compile_fmu(self.moModel, absolutePath,
#                                compiler_options = {'extra_lib_dirs':self.libPath})
        fmu_name= compile_fmu(self.moModel, [fullMoFile, fullMoLib])
        ''' Load the model '''
        model_fmu= load_fmu(fmu_name)
    
        ''' Load the list of options for the JModelica compiler '''
        opts = model_fmu.simulate_options()
        opts['solver']= self.config.getSolver()
        opts['ncp']= self.config.getNcp()
    #     for key,value in simOpt.getOptions().items():
    #         print key,value
    #         opts[key] = value
        print opts
        result = model_fmu.simulate(start_time= self.config.getStartTime(), 
                                    final_time= self.config.getStopTime(), 
                                    options=opts)
    
#         toc= timeit.default_timer()
#         print 'Simulation time ', toc- tic
        
        return result
开发者ID:fran-jo,项目名称:ScriptMEE,代码行数:29,代码来源:engineJModelica.py


示例10: run_demo

def run_demo(with_plots=True):
    
    curr_dir = os.path.dirname(os.path.abspath(__file__));
    class_name = 'ExtFunctions.transposeSquareMatrix'
    mofile = os.path.join(curr_dir, 'files', 'ExtFunctions.mo')
    
    # Compile and load model
    fmu_name = compile_fmu(class_name, mofile)
    model = load_fmu(fmu_name)

    # Simulate
    res = model.simulate()
    
    # Get result data
    b1_1 = res['b_out[1,1]']
    b1_2 = res['b_out[1,2]']
    b2_1 = res['b_out[2,1]']
    b2_2 = res['b_out[2,2]']
    t = res['time']

    assert N.abs(res.final('b_out[1,1]') - 1) < 1e-6
    assert N.abs(res.final('b_out[1,2]') - 3) < 1e-6
    assert N.abs(res.final('b_out[2,1]') - 2) < 1e-6
    assert N.abs(res.final('b_out[2,2]') - 4) < 1e-6 
           
    if with_plots:
        fig = p.figure()
        p.clf()
        p.plot(t, b1_1, label='b1_1')
        p.plot(t, b1_2, label='b1_2')
        p.plot(t, b2_1, label='b2_1')
        p.plot(t, b2_2, label='b2_2')
        p.legend()
        p.grid()
        p.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:35,代码来源:extFunctions_matrix.py


示例11: run_demo

def run_demo(with_plots=True):
    """
    This example shows how to simulate a system that contains switches. The 
    example model is simple in the sense that no reinitialization of the 
    variables is needed at the event points.
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__));

    class_name = 'IfExpExamples.IfExpExample2'
    mofile = curr_dir+'/files/IfExpExamples.mo'

    fmu_name = compile_fmu(class_name, mofile)

    # Load the dynamic library and XML data
    model = load_fmu(fmu_name)

    # Simulate
    res = model.simulate(final_time=5.0)
    
    # Get results
    x = res['x']
    u = res['u']
    t = res['time']
    
    assert N.abs(res.final('x') - 3.5297217)    < 1e-3
    assert N.abs(res.final('u') - (-0.2836621)) < 1e-3

    if with_plots:
        fig = p.figure()
        p.plot(t, x, t, u)
        p.legend(('x','u'))
        p.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:33,代码来源:if_example_2.py


示例12: run_demo

def run_demo(with_plots=True):
    """
    Demonstrates how to use an JMODELICA generated FMU for sensitivity
    calculations.
    """
    curr_dir = os.path.dirname(os.path.abspath(__file__));

    fmu_name = compile_fmu("Robertson", curr_dir+"/files/Robertson.mo")
        
    model = load_fmu(fmu_name)
        
    # Get and set the options
    opts = model.simulate_options()
    opts['sensitivities'] = ["p1","p2","p3"]
    opts['ncp'] = 400

    #Simulate
    res = model.simulate(final_time=4, options=opts)

    dy1dp1 = res['dy1/dp1']
    dy2dp1 = res['dy2/dp1']
    time = res['time']
        
    nose.tools.assert_almost_equal(dy1dp1[40], -0.35590, 3)
    nose.tools.assert_almost_equal(dy2dp1[40],  3.9026e-04, 6)
    
    if with_plots:
        plt.plot(time, dy1dp1, time, dy2dp1)
        plt.legend(('dy1/dp1', 'dy2/dp1'))
        plt.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:30,代码来源:robertson_fmu.py


示例13: run_demo

def run_demo(with_plots=True):
    """ 
    Example demonstrating how to use index reduction.
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__));

    # Compile model
    fmu_name = compile_fmu("Pendulum_pack.PlanarPendulum", 
        curr_dir+"/files/Pendulum_pack.mop",compiler='optimica')

    # Load model
    model = load_fmu(fmu_name)
    
    # Options
    opts = model.simulate_options()
    opts["CVode_options"]["rtol"] = 1e-6
    
    # Load result file
    res = model.simulate(final_time=10., options=opts)

    x = res['x']
    st = res['st']
    ct = res['ct']
    err = res['err']
    y = res['y']
    vx = res['vx']
    vy = res['vy']
    t = res['time']
    maxerr = N.max(err)

    if maxerr > 1e-6:
        print "Maximum error: ", maxerr 
        assert maxerr < 1e-4
    
    assert N.abs(res.final('x') - 0.38735171)       < 1e-3
    assert N.abs(res.final('st') - 0.38733358)      < 1e-3
    assert N.abs(res.final('ct') + 0.92193964)      < 1e-3
    assert N.abs(res.final('err') - 1.96716163e-05) < 1e-3
    assert N.abs(res.final('y') + 0.92193202)       < 1e-3
    assert N.abs(res.final('vx') - 6.04839823e-01)  < 1e-3
    assert N.abs(res.final('vy') - 2.54124747e-01)  < 1e-3

    if with_plots:
        plt.figure(1)
        plt.subplot(3,1,1)
        plt.plot(t,x,t,y)
        plt.grid(True)
        plt.legend(['x','y'])
        plt.subplot(3,1,2)
        plt.plot(t,vx,t,vy)
        plt.grid(True)
        plt.legend(['vx','vy'])
        plt.subplot(3,1,3)
        plt.plot(t,err)
        plt.grid(True)
        plt.legend(['err'])
        plt.xlabel('time [s]')
        plt.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:59,代码来源:planar_pendulum.py


示例14: run_demo

def run_demo(with_plots=True):
    """
    Simulation of a model that predicts the blood glucose levels of a type-I 
    diabetic. The objective is to predict the relationship between insulin 
    injection and blood glucose levels.
    
    Reference:
     S. M. Lynch and B. W. Bequette, Estimation based Model Predictive Control of Blood Glucose in 
     Type I Diabetes: A Simulation Study, Proc. 27th IEEE Northeast Bioengineering Conference, IEEE, 2001.
     
     S. M. Lynch and B. W. Bequette, Model Predictive Control of Blood Glucose in type I Diabetics 
     using Subcutaneous Glucose Measurements, Proc. ACC, Anchorage, AK, 2002. 
    """

    curr_dir = os.path.dirname(os.path.abspath(__file__))

    fmu_name1 = compile_fmu("JMExamples.BloodGlucose.BloodGlucose1", os.path.join(curr_dir, "files", "JMExamples.mo"))
    bg = load_fmu(fmu_name1)

    opts = bg.simulate_options()
    opts["CVode_options"]["rtol"] = 1e-6

    res = bg.simulate(final_time=400, options=opts)

    # Extract variable profiles
    G = res["G"]
    X = res["X"]
    I = res["I"]
    t = res["time"]

    assert N.abs(res.final("G") - 19.77650) < 1e-4
    assert N.abs(res.final("X") - 14.97815) < 1e-4
    assert N.abs(res.final("I") - 2.7) < 1e-4

    if with_plots:
        plt.figure(1)

        plt.subplot(2, 2, 1)
        plt.plot(t, G)
        plt.title("Plasma Glucose Conc")
        plt.grid(True)
        plt.ylabel("Plasma Glucose Conc. (mmol/L)")
        plt.xlabel("time")

        plt.subplot(2, 2, 2)
        plt.plot(t, X)
        plt.title("Plasma Insulin Conc.")
        plt.grid(True)
        plt.ylabel("Plasma Insulin Conc. (mu/L)")
        plt.xlabel("time")

        plt.subplot(2, 2, 3)
        plt.plot(t, I)
        plt.title("Plasma Insulin Conc.")
        plt.grid(True)
        plt.ylabel("Plasma Insulin Conc. (mu/L)")
        plt.xlabel("time")

        plt.show()
开发者ID:zlongshen,项目名称:jmodelica,代码行数:59,代码来源:blood_glucose.py


示例15: test_ExtFuncSharedCeval

 def test_ExtFuncSharedCeval(self):
     """ 
     Test compiling a model with external functions in a shared library. Constant evaluation during compilation.
     """
     cpath = "ExtFunctionTests.ExtFunctionTest1"
     fmu_name = compile_fmu(cpath, TestExternalShared.fpath, compiler_options={'variability_propagation':True})
     model = load_fmu(fmu_name)
     nose.tools.assert_equals(model.get('c'), 3)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:8,代码来源:test_extfunctions.py


示例16: test_ModelicaUtilities

 def test_ModelicaUtilities(self):
     """ 
     Test compiling a model with external functions using the functions in ModelicaUtilities.
     """
     fpath = path(get_files_path(), 'Modelica', "ExtFunctionTests.mo")
     cpath = "ExtFunctionTests.ExtFunctionTest3"
     jmu_name = compile_fmu(cpath, fpath)
     model = load_fmu(jmu_name)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:8,代码来源:test_extfunctions.py


示例17: test_simulate

 def test_simulate(self):
     cpath = 'Asserts.ModelicaError'
     fmu_name = compile_fmu(cpath, TestModelicaError.fpath)
     model = load_fmu(fmu_name)
     try:
         model.simulate(final_time = 3)
         assert False, 'Simulation not stopped by calls to ModelicaError()'
     except CVodeError, e:
         assert abs(e.t - 2.0) < 0.01, 'Simulation stopped at wrong time'
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:9,代码来源:test_extfunctions.py


示例18: run_demo

def run_demo(with_plots=True,with_blocking_factors = False):
    """ 
    FMU simulation of a distillation column. The distillation column model is 
    documented in the paper:

    @Article{hahn+02,
    title={An improved method for nonlinear model reduction using balancing of 
        empirical gramians},
    author={Hahn, J. and Edgar, T.F.},
    journal={Computers and Chemical Engineering},
    volume={26},
    number={10},
    pages={1379-1397},
    year={2002}
    }
    """
    
    curr_dir = os.path.dirname(os.path.abspath(__file__));

    # Compile the stationary initialization model into a JMU
    fmu_name = compile_fmu('DISTLib.Examples.Simulation', 
        os.path.join(curr_dir, 'files', 'DISTLib.mo'))

    # Load a model instance into Python
    model = load_fmu(fmu_name)
    
    # Simulate
    res = model.simulate(final_time=200)

    x_16 = res['binary_dist_initial.x[16]']
    y_16 = res['binary_dist_initial.y[16]']
    x_32 = res['binary_dist_initial.x[32]']
    y_32 = res['binary_dist_initial.y[32]']
    t = res['time']

    assert N.abs(res.final('binary_dist_initial.x[16]') - 0.49931368) < 1e-3
    assert N.abs(res.final('binary_dist_initial.y[16]') - 0.61473464) < 1e-3
    assert N.abs(res.final('binary_dist_initial.x[32]') - 0.18984724) < 1e-3
    assert N.abs(res.final('binary_dist_initial.y[32]') - 0.27269352) < 1e-3

    # Plot the results
    if with_plots:
        plt.figure(1)
        plt.clf()
        plt.subplot(2,1,1)
        plt.plot(t,x_16,'b')
        plt.hold(True)
        plt.plot(t,x_32,'b')
        plt.title('Liquid composition')
        plt.grid(True)
        plt.subplot(2,1,2)
        plt.plot(t,y_16,'b')
        plt.hold(True)
        plt.plot(t,y_32,'b')
        plt.title('Vapor composition')
        plt.grid(True)
        plt.show()
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:57,代码来源:distillation_fmu.py


示例19: test_ExtFuncBool

    def test_ExtFuncBool(self):
        """ 
        Test compiling a model with external functions in a shared library. Boolean arrays.
        """
        fmu_name = compile_fmu(self.cpath, self.fpath, compiler_options={'variability_propagation':False})
        model = load_fmu(fmu_name)
        model.simulate()
        fmu_name = compile_fmu(self.cpath, self.fpath, compiler_options={'variability_propagation':True})
        model2 = load_fmu(fmu_name)
        model2.simulate()
        trueInd  = {1,2,3,5,8}
        falseInd = {4,6,7}
        for i in trueInd:
            assert(model.get('res[' + str(i) + ']'))
            assert(model2.get('res[' + str(i) + ']'))
        for i in falseInd:
		    assert(not model.get('res[' + str(i) + ']'))
		    assert(not model2.get('res[' + str(i) + ']'))
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:18,代码来源:test_extfunctions.py


示例20: test_compile_fmu_mop

    def test_compile_fmu_mop(self):
        """
        Test that it is possible to compile an FMU from a .mop file with 
        pymodelica.compile_fmu.
        """
        fmuname = compile_fmu(Test_Compiler.cpath_mc, Test_Compiler.fpath_oc)

        assert os.access(fmuname, os.F_OK) == True, \
               fmuname+" was not created."
        os.remove(fmuname)
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:10,代码来源:test_compiler.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pymodule.PassingData类代码示例发布时间:2022-05-27
下一篇:
Python pdu.ModbusResponse类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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