debuggingmodelicadymoladivide-by-zero

Dymola division by zero during initialization, how to debug


I have a Modelica model that fails to initialize, with below division by zero error message:

Error: The following error was detected at time: 0
Model error - division by zero: (0.0) / (0.0) = (0) / (0)
Error: Integrator failed to start model.

Is there a way to also see the names of variables involved, or nonlinear block ID (like initialization.nonlinear[3]), or class and line of code?


Solution

  • One way to find the issue could be to set Advanced.OutputModelicaCode = true;, by copying the command to the command line. When translating the model the next time, Dymola will generate dsmodel.mof in the current working directory. You can get the currently used directory by typing cd or via the GUI (File -> Working Directory -> Open in File Browser/Copy Path). Screenshot of Dymola File-Menu for Working Directory

    The generated file dsmodel.mof contains all the (causal) statements generated from the overall model. Therefore this is a single place to look for the error. Additionally it could help to set Evaluate = true; and Advanced.EvaluateAlsoTop = true; (as an alternative you can use the GUI, via Simulation Ribbon -> Setup -> Translation, checking the top two boxes). Screenshot of Dymola Simulation Setup GUI

    With a bit of luck you can search for 0.0/0.0 or something similar in dsmodel.mof.

    Note: To avoid problems of that kind in Dymola it could make sense to use either the function DymolaModels.Functions.Math.divNoZero or the respective block DymolaModels.Blocks.Math.DivNoZero.