OpenModelica / OMSimulator

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

RHS function for CVODE calls fmi2SetTime() with wrong time value before calculating state derivatives #1325

Open rruusu opened 3 days ago

rruusu commented 3 days ago

Description

When simulating a strongly coupled model, the RHS function that is provided to CVODE calls fmi2SetTime with the wrong time value before reading the state derivative values.

All evaluations performed by CVODE are made using the end of the previous time step as the time value, which creates strange effects when state derivatives have a direct dependence on the simulation time, for example via an input from a signal source.

Steps to reproduce the behavior

  1. Create a model with state derivatives that depend directly on time
  2. Log FMI calls
  3. Observe that fmi2SetTime is always called with time value that matches one used before previous call to fmi2CompletedIntegratorStep

Expected behavior

The time value provided to oms::cvode_rhs should be passed to the FMUs using fmi2SetTime before the calls to fmi2GetDerivatives, but the fmi2SetTime calls performed by oms::SystemSC::updateInputs are made using the field oms::System::time, which still has the value of the last completed integrator step.

Version and OS

rruusu commented 3 days ago

I have a fix for this that I will push shortly to my fork.