OpenModelica / OpenModelica

OpenModelica is an open-source Modelica-based modeling and simulation environment intended for industrial and academic usage.
https://openmodelica.org
Other
838 stars 306 forks source link

Simulations in -daeMode fails with IDA error -6 #8639

Open casella opened 2 years ago

casella commented 2 years ago

Description

There are many models in the newInst-daeMode testsuite, e.g. Modelica.Fluid.Examples.AST_BatchPlant.Test.OneTank or ModelicaTest.Fluid.TestExamplesVariants.IncompressibleFluidNetwork_StandardWaterOnePhase that fail with this error:

assert            | debug   | ##IDA## discrete update failed flag -6!
assert            | info    | simulation terminated by an assertion at initialization

According to the IDA manual, error -6 is IDA LSETUP FAIL -6 The linear solver’s setup function failed in an unrecoverable manner. I'm not sure if this is really what the runtime refers to, since it also mention "discrete update", whatever that means.

Steps to Reproduce

Run the models with --daeMode.

Expected Behavior

The models should run as in odeMode.

AnHeuermann commented 2 years ago

The function returning this error code is

flag = IDACalcIC(ida mem, icopt, tout1);

and will indeed return IDA_LSETUP_FAIL as you already noticed. See ida_solver.c#L759-L780

The first call of IDANlsIC is failing. Its task is to solves a nonlinear system for consistent initial conditions using IDANewtonIC. But inside that the linear solver setup function is failing with an error code of -809 (==> IDA_LSETUP_FAIL).

Apparently KLU (the used linear solver) is failing to compute the LU factorization in sun_klu_factor(). KLU_factor is reporting: "Matrix is singular, and the Numeric object is only partially defined because we halted early. This is the default case for a singular matrix" and breaks.

I didn't had any test cases for daeMode when updating SUNDIALS to v5.4.0, so there is a good chance I missed something. I'll have a look into this, probably next week.

phannebohm commented 2 years ago

We also have similar problems with KLU in Jacobians of nonlinear loops. See e.g. https://libraries.openmodelica.org/branches/master/ClaRa_dev/files/ClaRa_dev_ClaRa.Basics.ControlVolumes.FluidVolumes.Check.Validation_VolumeVLE_L2_HeatTransfer_1ph_shell.sim Maybe we are using it wrong in general?

AnHeuermann commented 2 years ago

We could try the sanity check of the jacobian / sparsity pattern in this one.

casella commented 2 years ago

Sounds like a good idea! if the sparsity pattern is wrong, it's small wonder that sparse solvers fail.

casella commented 1 year ago

@AnHeuermann, @phannebohm, any chance you can continue on this?