本文整理汇总了Python中pyfmi.load_fmu函数的典型用法代码示例。如果您正苦于以下问题:Python load_fmu函数的具体用法?Python load_fmu怎么用?Python load_fmu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_fmu函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: load
def load(self, fmu_path, output_dir):
"""Load the FMU for continued simulation in :meth:`continue_run`.
"""
import pyfmi
if 'log_level' in self._options:
self.fmu = pyfmi.load_fmu(fmu_path, log_level=self.log_level)
else:
self.fmu = pyfmi.load_fmu(fmu_path)
# Initialize the fmu, only call setup_experiment for FMUs 2.0
try:
self.fmu.setup_experiment()
version = 2
except AttributeError:
version = 1
self.fmu.initialize()
# Copy the log file to the result directory
log = ''
if version == 1:
log = self.fmu.get_identifier()
if version == 2:
log = self.fmu.get_name()
log += '_log.txt'
source = os.path.join(os.getcwd(), log)
destination = os.path.join(output_dir, 'log%i.txt' % self.interval)
move(source, destination)
开发者ID:kdavies4,项目名称:ModelicaRes,代码行数:30,代码来源:simulators.py
示例2: simulate_multiple_fmus
def simulate_multiple_fmus():
"""Simulate one CYMDIST FMU coupled to a GridDyn FMU.
"""
cymdist=load_fmu("CYMDIST.fmu", log_level=7)
gridyn=load_fmu("GridDyn.fmu", log_level=7)
models = [cymdist, gridyn]
connections = [(gridyn, "VMAG_A", cymdist, "VMAG_A"),
(gridyn, "VMAG_B", cymdist, "VMAG_B"),
(gridyn, "VMAG_C", cymdist, "VMAG_C"),
(gridyn, "VANG_A", cymdist, "VANG_A"),
(gridyn, "VANG_B", cymdist, "VANG_B"),
(gridyn, "VANG_C", cymdist, "VANG_C"),
(cymdist, "KWA_800032440", gridyn, "KWA_800032440"),
(cymdist, "KWB_800032440", gridyn, "KWB_800032440"),
(cymdist, "KWC_800032440", gridyn, "KWC_800032440"),
(cymdist, "KVARA_800032440", gridyn, "KVARA_800032440"),
(cymdist, "KVARB_800032440", gridyn, "KVARB_800032440"),
(cymdist, "KVARC_800032440", gridyn, "KVARC_800032440"),]
coupled_simulation = Master (models, connections)
opts=coupled_simulation.simulate_options()
opts['step_size']=1.0
opts['logging']=True
res=coupled_simulation.simulate(options=opts,
start_time=0.0,
final_time=1.0)
开发者ID:tsnouidui,项目名称:cyder,代码行数:30,代码来源:coupling.py
示例3: simulate_cymdist_griddyn_fmus
def simulate_cymdist_griddyn_fmus():
"""Simulate one CYMDIST FMU coupled to a dummy griddyn FMU.
"""
# Parameters which will be arguments of the function
start_time = 0.0
stop_time = 0.1
step_size = 0.1
# Path to configuration file
path_config="Z:\\thierry\\proj\\cyder_repo\\NO_SHARING\\CYMDIST\\config.json"
cymdist_con_val_str = bytes(path_config, 'utf-8')
cymdist=load_fmu("../fmus/CYMDIST/CYMDIST.fmu", log_level=7)
griddyn=load_fmu("../fmus/griddyn/griddyn14bus.fmu", log_level=7)
models = [cymdist, griddyn]
connections = [(griddyn, "Bus11_VA", cymdist, "VMAG_A"),
(griddyn, "Bus11_VB", cymdist, "VMAG_B"),
(griddyn, "Bus11_VC", cymdist, "VMAG_C"),
(griddyn, "Bus11_VAngleA", cymdist, "VANG_A"),
(griddyn, "Bus11_VAngleB", cymdist, "VANG_B"),
(griddyn, "Bus11_VAngleC", cymdist, "VANG_C"),
(cymdist, "IA", griddyn, "Bus11_IA"),
(cymdist, "IB", griddyn, "Bus11_IB"),
(cymdist, "IC", griddyn, "Bus11_IC"),
(cymdist, "IAngleA", griddyn, "Bus11_IAngleA"),
(cymdist, "IAngleB", griddyn, "Bus11_IAngleB"),
(cymdist, "IAngleC", griddyn, "Bus11_IAngleC")]
coupled_simulation = Master (models, connections)
opts=coupled_simulation.simulate_options()
opts['step_size']=step_size
# Get the configuration file
cymdist_con_val_ref = cymdist.get_variable_valueref("_configurationFileName")
cymdist.set("_saveToFile", 0)
cymdist.set_string([cymdist_con_val_ref], [cymdist_con_val_str])
# Set the communication step size
cymdist.set("_communicationStepSize", step_size)
# Set the value of the multiplier
griddyn.set('multiplier', 3.0)
# Run simulation
start = datetime.now()
res=coupled_simulation.simulate(options=opts,
start_time=start_time,
final_time=stop_time)
end = datetime.now()
print('This is the voltage value (VMAG_A) in Cymdist' + str(res[cymdist]['VMAG_A']))
print('This is the current value (IA) in Cymdist' + str(res[cymdist]['IA']))
print('Ran a coupled CYMDIST/GridDyn simulation in ' +
str((end - start).total_seconds()) + ' seconds.')
开发者ID:tsnouidui,项目名称:cyder,代码行数:59,代码来源:coupling.py
示例4: 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
示例5: 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
示例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: furuta_dfo_cost
def furuta_dfo_cost(x):
# We need to scale the inputs x down since they are scaled up
# versions of the parameters (x = scalefactor*[param1 param2])
armFrictionCoefficient = x[0]/1e3
pendulumFrictionCoefficient = x[1]/1e3
model = load_fmu(os.path.join(curr_dir, '..', 'examples', 'files', 'FMUs', 'Furuta.fmu'))
# Set new parameter values into the model
model.set('armFriction', armFrictionCoefficient)
model.set('pendulumFriction', pendulumFrictionCoefficient)
# Create options object and set verbosity to zero to disable printouts
opts = model.simulate_options()
opts['CVode_options']['verbosity'] = 0
# Simulate model response with new parameter values
res = model.simulate(start_time=0., final_time=40, options=opts)
# Load simulation result
phi_sim = res['armJoint.phi']
theta_sim = res['pendulumJoint.phi']
t_sim = res['time']
# Evaluate the objective function
y_meas = N.vstack((phi_meas, theta_meas))
y_sim = N.vstack((phi_sim, theta_sim))
obj = dfo.quad_err(t_meas, y_meas, t_sim, y_sim)
return obj
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:31,代码来源:furuta_dfo_cost.py
示例8: test_inlined_switches
def test_inlined_switches(self):
""" Test a model that need in-lined switches to initialize. """
path = os.path.join(get_files_path(), 'Modelica', 'event_init.mo')
fmu_name = compile_fmu('Init', path)
model = load_fmu(fmu_name)
model.initialize()
assert N.abs(model.get("x") - (-2.15298995)) < 1e-3
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:7,代码来源:test_init.py
示例9: 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
示例10: 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
示例11: simulate_single_griddyn_fmu
def simulate_single_griddyn_fmu():
"""Simulate one griddyn FMU.
"""
# Parameters which will be arguments of the function
start_time = 0.0
stop_time = 0.1
griddyn=load_fmu("../../../../NO_SHARING/griddyn/Test/griddyn.fmu", log_level=7)
# Set the inputs
opts=griddyn.simulate_options()
opts['ncp']=1.0
# Set the model name reference to be completed in Python API
griddyn.set("power", 10)
# Run simulation
start = datetime.now()
res=griddyn.simulate(start_time=start_time,
final_time=stop_time,
options=opts)
end = datetime.now()
print('This is the time value ' + str(res['time']))
print('This is the load value ' + str(res['load']))
print('Ran a single GridDyn simulation in ' +
str((end - start).total_seconds()) + ' seconds.')
开发者ID:tsnouidui,项目名称:cyder,代码行数:27,代码来源:coupling.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: f1
def f1(x):
model = load_fmu(fmu_name)
# We need to scale the inputs x down since they are scaled up
# versions of a1 and a2 (x = scalefactor*[a1 a2])
a1 = x[0]/1e6
a2 = x[1]/1e6
# Set new values for a1 and a2 into the model
model.set('qt.a1',a1)
model.set('qt.a2',a2)
# Create options object and set verbosity to zero to disable printouts
opts = model.simulate_options()
opts['CVode_options']['verbosity'] = 0
# Simulate model response with new parameters a1 and a2
res = model.simulate(input=(['u1','u2'],u),start_time=0.,final_time=60,options=opts)
# Load simulation result
x1_sim = res['qt.x1']
x2_sim = res['qt.x2']
t_sim = res['time']
# Evaluate the objective function
y_meas = N.vstack((y1_meas,y2_meas))
y_sim = N.vstack((x1_sim,x2_sim))
obj = dfo.quad_err(t_meas,y_meas,t_sim,y_sim)
return obj
开发者ID:jnorthrup,项目名称:jmodelica,代码行数:31,代码来源:qt_par_est_dfo.py
示例14: 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
示例15: 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
示例16: run_demo
def run_demo(with_plots=True):
"""
Demonstrates how to simulate an FMU with an input function.
See also simulation_with_input.py
"""
fmu_name = O.path.join(path_to_fmus_me1,'SecondOrder.fmu')
# Create input object
input_object = ('u', N.cos)
# Load the dynamic library and XML data
model = load_fmu(fmu_name)
# Simulate
res = model.simulate(final_time=30, input=input_object, options={'ncp':3000})
x1_sim = res['x1']
x2_sim = res['x2']
u_sim = res['u']
time_sim = res['time']
assert N.abs(res.final('x1') - (-1.646485144)) < 1e-3
assert N.abs(res.final('x2')*1.e1 - (-7.30591626709)) < 1e-3
assert N.abs(res.final('u')*1.e1 - (1.54251449888)) < 1e-3
if with_plots:
fig = p.figure()
p.subplot(2,1,1)
p.plot(time_sim, x1_sim, time_sim, x2_sim)
p.subplot(2,1,2)
p.plot(time_sim, u_sim)
p.show()
开发者ID:astefano,项目名称:PyFMI,代码行数:33,代码来源:fmu_with_input_function.py
示例17: 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
示例18: 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
示例19: run_demo
def run_demo(with_plots=True):
"""
Demonstrates how to simulate an FMU with an input function.
See also simulation_with_input.py
"""
fmu_name = O.path.join(path_to_fmus, "SecondOrder.fmu")
# Create input object
input_object = ("u", N.cos)
# Load the dynamic library and XML data
model = load_fmu(fmu_name)
# Simulate
res = model.simulate(final_time=30, input=input_object, options={"ncp": 3000})
x1_sim = res["x1"]
x2_sim = res["x2"]
u_sim = res["u"]
time_sim = res["time"]
assert N.abs(x1_sim[-1] - (-1.646485144)) < 1e-3
assert N.abs(x2_sim[-1] * 1.0e1 - (-7.30591626709)) < 1e-3
assert N.abs(u_sim[-1] * 1.0e1 - (1.54251449888)) < 1e-3
if with_plots:
fig = p.figure()
p.subplot(2, 1, 1)
p.plot(time_sim, x1_sim, time_sim, x2_sim)
p.subplot(2, 1, 2)
p.plot(time_sim, u_sim)
p.show()
开发者ID:xogeny,项目名称:PyFMI,代码行数:35,代码来源:fmu_with_input_function.py
示例20: run_demo
def run_demo(with_plots=True):
"""
Demonstrates how to use PyFMI for simulation of
Co-Simulation FMUs (version 1.0).
"""
fmu_name = O.path.join(path_to_fmus,'bouncingBall.fmu')
model = load_fmu(fmu_name)
res = model.simulate(final_time=2.)
# Retrieve the result for the variables
h_res = res['h']
v_res = res['v']
t = res['time']
assert N.abs(res.final('h') - (0.0424044)) < 1e-2
# Plot the solution
if with_plots:
# Plot the height
fig = P.figure()
P.clf()
P.subplot(2,1,1)
P.plot(t, h_res)
P.ylabel('Height (m)')
P.xlabel('Time (s)')
# Plot the velocity
P.subplot(2,1,2)
P.plot(t, v_res)
P.ylabel('Velocity (m/s)')
P.xlabel('Time (s)')
P.suptitle('FMI Bouncing Ball')
P.show()
开发者ID:astefano,项目名称:PyFMI,代码行数:33,代码来源:fmi_bouncing_ball_cs.py
注:本文中的pyfmi.load_fmu函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论