pythonsimulationmodelicafmipyfmi

PyFMI multiple inputs in Master simulation


I am trying to simulate two FMUs with the one having inputs as CSV files by using the Master. What I have tried is the following:

from pyfmi import load_fmu
from pyfmi import Master
import pandas as pd

electricity_network = load_fmu(r"C:\Users\kosmy\Pandapower_Reduced.fmu")
pv = load_fmu(r"C:\Users\kosmy\Photovoltaics.Model.PVandWeather_simple.fmu")

load_file = r"C:\Users\kosmy\load_prof_sec_res.csv"
load = pd.read_csv(load_file)

models = [electricity_network, pv] 

connections = [(pv, "P_MW", electricity_network, "P_pv1"),
               (pv, "P_MW", electricity_network, "P_pv2")]

master_simulator = Master(models, connections)

input_object = [((electricity_network, 'P_load1'), load), 
                ((electricity_network, 'P_load2'), load)]
 
res = master_simulator.simulate(final_time = 86400, input = input_object)

I am getting the following error:

Traceback (most recent call last):

  File "C:\Users\kosmy\run_csv_pyfmi.py", line 29, in <module>
    res = master_simulator.simulate(final_time = 86400, input = input_object)

  File "src\pyfmi\master.pyx", line 1474, in pyfmi.master.Master.simulate

  File "src\pyfmi\master.pyx", line 1369, in pyfmi.master.Master.specify_external_input

TypeError: tuple indices must be integers or slices, not tuple

Apparently, I do not give the correct format to the input, but I have not found an example demonstrating the correct format when using the Master.

Does anyone know how can I use the input in this case?


Solution

  • def load(t):
        return 10, math.cos(t)
    
    input_object = ([(electricity_network, 'P_load1'),(electricity_network, 'P_load2')],load)
    

    another option is

    data = np.transpose(np.vstack((t,u,v)))
    input_object = (['InputVarI','InputVarP'],data)
    

    error while creating a 2-tuple as input for model.simulate() of fmu model with pyfmi