OpenModelica / OMSimulator

The OpenModelica FMI & SSP-based co-simulation environment.
Other
71 stars 51 forks source link

Implement proper state event detection in OMSimulator #1271

Open casella opened 1 year ago

casella commented 1 year ago

Currently, OMSimulator only checks for event-triggering conditions (e.g. zero-crossing functions changing their sign) at each time step, but doesn't try to figure out the exact time when the zero-crossing function changed sign. This results in delays of up to one time step in the triggering of events.

In many cases this is no big deal, but in some cases this may seriously change or disrupt the simulation results.

We should eventually implement a proper state event detection mechanism in OMSimulator.

rruusu commented 1 week ago

One easy step to improve the accuracy of event processing, in lieu of implementing a more accurate zero-crossing solver, at least when using CVODE, would be to check for events after each integrator step instead of the precision provided by the maximum time step size, as is currently done by oms::SystemSC::doStep

I will push an implementation for this to my fork shortly.

casella commented 1 week ago

Please make a PR out of it so we can run it on our testsuite and see what happens