本文整理汇总了Python中pymodelica.compile_fmu函数的典型用法代码示例。如果您正苦于以下问题:Python compile_fmu函数的具体用法?Python compile_fmu怎么用?Python compile_fmu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了compile_fmu函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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()
示例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()
示例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()
示例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()
示例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()
示例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()
示例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)
示例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
示例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()
示例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()
示例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()
示例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()
示例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()
示例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)