Co-simulate two FMUs in PyFMI

asked 2021-04-27 02:25:09 -0600

manas_das's avatar

Hello, I'm trying to simulate two coupled FMUs of co-simulation type. However, while trying to set input values, i'm getting some issues.

import pyfmi
from pyfmi import load_fmu
from pyfmi.master import Master
import pylab as P
import numpy as np

sub_system1 = load_fmu("Simple_System_PI.fmu")
sub_system2 = load_fmu("Simple_System_Plant.fmu")
models = [sub_system1, sub_system2]

connections = [( sub_system1 ,"y",sub_system2 ,"u"),
                ( sub_system2 ,"y",sub_system1 ,"u")]


# Generate input
t = np.linspace (0, 10, 100)
u = np.cos(t)
u_traj = np.transpose(np.vstack((t,u)))
input_object = ('u', u_traj)
#print(input_object)
sub_system1.set('u',u[0])

master_simulator = Master (models, connections)
res = master_simulator.simulate(start_time = 0.0, final_time = 10.0, input = input_object)

On executing this i'm getting this error

Traceback (most recent call last):
  File "Simple_PI_SImple_Plant.py", line 25, in <module>
    res = master_simulator.simulate(start_time = 0.0, final_time = 10.0, input = input_object)
  File "src\pyfmi\master.pyx", line 1434, in pyfmi.master.Master.simulate
  File "src\pyfmi\master.pyx", line 1037, in pyfmi.master.Master.initialize
  File "src\pyfmi\master.pyx", line 1333, in pyfmi.master.Master.set_input
AttributeError: 'str' object has no attribute 'set'

Please guide.

Regards, Manas

edit retag flag offensive close merge delete