FMPy icon indicating copy to clipboard operation
FMPy copied to clipboard

fmpy 0.3.7/0.3.9 triggering thousands of events where dymola continues after a few events

Open FraFabi opened this issue 2 years ago • 3 comments

Hi, we try to simulate a ME FMU created in dymola with cvode in fmpy. However the simulation takes a lot longer in fmpy compared to dymola. We tried to track down the problem and it seems to be connected to a bunch of events being triggered in fmpy, creating this output:

fmi2SetTime(component=0x1feaa511690, time=48.364453068203765) -> OK fmi2SetContinuousStates(component=0x1feaa511690, x=[29867908.095835138, 546305.8135140014, 101299.99998246912, 27635.62776833913, 340678.5999762286, 29867908.096154887, 1e-05, 1e-20, 1e-20, 9.135720271743551e-06, 1.000094195854802e-08], nx=11) -> OK fmi2GetEventIndicators(component=0x1feaa511690, eventIndicators=[1.0000000000000002, 1.0000000000000002, -1.0, -1.0, 1.0000000000000002, 1.0000000000000002, -1.0, -1.0, 3.401989316228659e-10, 3.401989316228659e-10, -1.0000043142267403e-10, -1.0000043142267403e-10, -3.401989316228659e-10, -3.401989316228659e-10, 1.000094205854802e-08, 1.000094205854802e-08, -1.000004943298624e-10, -1.000004943298624e-10, 467908.0961548902, 467908.0961548902, -14298699.993006626, -14298699.993006626, 1.000004943298624e-10, 1.000004943298624e-10, 1.306098130289474e-10, 1.306098130289474e-10], ni=26) -> OK fmi2SetTime(component=0x1feaa511690, time=48.364440517999256) -> OK fmi2SetContinuousStates(component=0x1feaa511690, x=[29867908.095834944, 546305.813514, 101299.99998246468, 27635.627768335384, 340678.59997491946, 29867908.09590099, 1e-05, 1e-20, 1e-20, 9.135611802870121e-06, 1.0000941982191565e-08], nx=11) -> OK fmi2GetEventIndicators(component=0x1feaa511690, eventIndicators=[1.0000000000000002, 1.0000000000000002, -1.0, -1.0, 1.0000000000000002, 1.0000000000000002, -1.0, -1.0, -9.202707511428696e-12, -9.202707511428696e-12, -1.0000043142267403e-10, -1.0000043142267403e-10, 9.202707511428696e-12, 9.202707511428696e-12, 1.0000942082191565e-08, 1.0000942082191565e-08, -1.000004943298624e-10, -1.000004943298624e-10, 467908.09590099304, 467908.09590099304, -14298699.993006626, -14298699.993006626, 1.000004943298624e-10, 1.000004943298624e-10, 1.3061717544975308e-10, 1.3061717544975308e-10], ni=26) -> OK fmi2SetTime(component=0x1feaa511690, time=48.36444084855255) -> OK fmi2SetContinuousStates(component=0x1feaa511690, x=[29867908.095834948, 546305.813514, 101299.9999824648, 27635.627768335482, 340678.599974954, 29867908.095907677, 1e-05, 1e-20, 1e-20, 9.13561465977521e-06, 1.000094198156883e-08], nx=11) -> OK fmi2GetEventIndicators(component=0x1feaa511690, eventIndicators=[1.0000000000000002, 1.0000000000000002, -1.0, -1.0, 1.0000000000000002, 1.0000000000000002, -1.0, -1.0, 1.4302065691089383e-12, 1.4302065691089383e-12, -1.0000043142267403e-10, -1.0000043142267403e-10, -1.4302065691089383e-12, -1.4302065691089383e-12, 1.000094208156883e-08, 1.000094208156883e-08, -1.000004943298624e-10, -1.000004943298624e-10, 467908.09590767993, 467908.09590767993, -14298699.993006626, -14298699.993006626, 1.000004943298624e-10, 1.000004943298624e-10, 1.306169577933795e-10, 1.306169577933795e-10], ni=26) -> OK [...]

This seems to be triggered around 100,000 times, while in dymola it only triggers a few times. We tried counteracting by adjusting the solver variables, but it only shifted the problem to a later time in the simulation. Is this behaviour a known limitation when exporting from Dymola, or should we be able to simulate with similar CPU-times in fmpy? We can also provide a minimal example of the problem, if necessary. I'll just need some time to trim down the code that is needed to reproduce the problem.

FraFabi avatar May 18 '22 08:05 FraFabi

@KarlWernersson, do you have an idea what might cause the different behavior?

t-sommer avatar May 18 '22 11:05 t-sommer

Some probably more an issue of FMPY than Dymola but if the original Modelica model could be provided or the minimal example I can look at it.

KarlWernersson avatar May 18 '22 12:05 KarlWernersson

Thanks for your answers! I arranged a minimal example and uploaded it here: Minimal_Example.zip

It should be working out of the box. At around 49 seconds of simulation time, the spike of events occurs as V4 is being opened by the callback function. I am aware that the print(time) call in the callback function worsens the problem significantly, but I left it in, so the problem is easier to comprehend.

In the output a peak in pressure can be observed as V4 is opened. To my understanding this should not lead to such a spike of events though, as the peak is marginally small at around 2e-6 bar.

FraFabi avatar May 19 '22 08:05 FraFabi