modelon-community / PyFMI

PyFMI is a package for loading and interacting with Functional Mock-Up Units (FMUs) both for Model Exchange and Co-Simulation, which are compiled dynamic models compliant with the Functional Mock-Up Interface (FMI)
http://jmodelica.org/pyfmi
GNU Lesser General Public License v3.0
158 stars 38 forks source link

data delayed #251

Open YanceyYq opened 1 month ago

YanceyYq commented 1 month ago

environment ubuntu22.04 python=3.9.19 pyfmi=2.13.0 CoSimulation model fmiVersion=2 issue

model_sub1 = FMUModelCS2("./Sin.fmu") model_sub2 = FMUModelCS2("./Sin2.fmu")

models = [model_sub1, model_sub2]

connections = [(model_sub1, "o1", model_sub2, "int_in")]

master = Master(models, connections)

opts = master.simulate_options()

opts["step_size"] = 1.0 total_duration = 5.0 # 5秒

res = master.simulate(options=opts, final_time=total_duration)

y1_values = res[0]['o1'] y3_values = res[1]['int_out'] y2_values = res[1]['int_in'] times = res[0]['time']

In the above implementation, the extracted results y1-values are consistent with y2-values, but y3-values will be delayed by 1 second compared to y1-values. Is this the mechanism of pyfmi?

PeterMeisrimelModelon commented 1 month ago

Hi YanceyYq,

this is not about PyFMI, this is a general feature/limitation of Co-simulation. If you haven't yet, I recommend to read https://fmi-standard.org/docs/3.0/#fmi-for-co-simulation (even though this is FMI3, the concepts are the same; or read the corresponding FMI2 parts). If you want a more direct coupling and your models allow it, you might want to consider using ME FMUs instead.

/Peter

YanceyYq commented 1 month ago

Thank you for your response