OpenModelica / OMSimulator

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

Performance issue: Algebraic loop solution with KINSol #1334

Open rruusu opened 3 weeks ago

rruusu commented 3 weeks ago

Description

There are some performance issues when using KINSol for algebraic loops (i.e. the default).

  1. The state of the KINSol solver is not mainteined between successive solutions

    • This means that the solver has to start estimating the Jacobian from zero each time
  2. The last residual is always evaluated twice in succession

    • Once by KINSol and once by OMSimulator, only for checking the residual value
    • The residual value can be retrieved from KINSol instead.

Expected behavior

Repeated evaluation of the last residual (via calls to fmi2SetReal / fmi2GetReal) is entirely unnecessary.

Solution iterations can be greatly reduced by keeping information from previous solutions.

Version and OS

rruusu commented 3 weeks ago

I will push a solution for this to my fork shortly.

lochel commented 1 week ago

@rruusu Thank you for the feedback! Please feel free to open a pull request with your changes.