OpenModelica icon indicating copy to clipboard operation
OpenModelica copied to clipboard

Improve the logic to select initial guesses in the hybrid solver

Open casella opened this issue 1 year ago • 6 comments

In #11010, an interesting case is discussed where the hybrid solver needs to handle a nonlinear system with initial guesses that are not good enough. In particular, there is one variable which has no start attribute (hence it starts from zero), a nominal value of 1 (which should be meant for scaling!) and min = 0, max = 0.05.

The solver first tries with 0, then it apparently uses the nominal attribute 1 as a second best candidate guess value. The problem is, that value is outside the min/max bound, and it causes a singularity.

I would suggest to improve the hybrid solver by always limiting initial guess values with the min and max attributes.

casella avatar Apr 04 '24 13:04 casella

Adding @bilderbuchi to the loop.

casella avatar Apr 04 '24 13:04 casella

I would suggest to improve the hybrid solver by always limiting initial guess values with the min and max attributes.

#12201 changes the behavior so that iteration variables are always clamped between their min/max before every newton step, not only at the initial guess(es).

phannebohm avatar Apr 05 '24 17:04 phannebohm

Excellent! I'm curious to see if this improves some simulation in the library testsuite. Thanks!

casella avatar Apr 05 '24 19:04 casella

Is this only for the hybrid solver or also for the damped Newton solver?

casella avatar Apr 05 '24 19:04 casella

Currently only hybrid. But I will look at it again and try to find a better place to do the clamping. I'd prefer to do it at a single place in the code, but perhaps this needs to be copied to several places...

phannebohm avatar Apr 08 '24 07:04 phannebohm

OK. In fact, this could be a double-edged sword, since in some cases min-max attributes could be a bit bogus, as demonstrated by the few regressions we got.

Ideally, we should try with clamping first, and if if fails, retry without.

casella avatar Apr 08 '24 10:04 casella