OpenModelica icon indicating copy to clipboard operation
OpenModelica copied to clipboard

Extend the Newton Diagnostics feature to also use numerical Jacobians

Open casella opened this issue 10 months ago • 1 comments

The current implementation of the Newton Diagnostics only works if analytic Jacobians are available:

https://github.com/OpenModelica/OpenModelica/blob/dffd48b921cd5f99e20322f0cf16e6932fdf83c3/OMCompiler/SimulationRuntime/c/simulation/solver/newton_diagnostics.c#L110-L118

In cases the analytic jacobian is not available, e.g. because there are functions involved, or because it is not generated for scalar equations, as in these two MWEs, a warning is printed and the the simulation executable crashes because the null pointers are really not handled.

model MWE2
 Real x,y;

 function f
   input Real x;
   output Real y;
 algorithm
   y := sin(x);
 annotation(Inline = false);
 end f;
 
equation
  f(x) + cos(y) = 0;
  x + y = 0;
annotation(__OpenModelica_simulationFlags(lv = "LOG_NLS_NEWTON_DIAGNOSTICS"),
__OpenModelica_commandLineOptions = "--maxSizeNonlinearTearing=0 --postOptModules-=wrapFunctionCalls");
end MWE2;
model MWE3
  Real x;
equation
  sin(x) + cos(x) = 0;
annotation(__OpenModelica_simulationFlags(lv = "LOG_NLS_NEWTON_DIAGNOSTICS"),
__OpenModelica_commandLineOptions = "--maxSizeNonlinearTearing=0 --postOptModules-=wrapFunctionCalls");
end MWE3;

We should make sure that we compute the numerical Jacobian values instead (also for Hessian computation) in these cases.

casella avatar Jan 30 '25 15:01 casella

the simulation executable crashes because the null pointers are really not handled.

purely for cross-reference, this is filed in #13056

bilderbuchi avatar Jan 30 '25 15:01 bilderbuchi