About Analyzing a Failed Initialization

This is an example of analyzing a failed initialization. The example covers the use of some options, but only principally, that is, depending on the app you are working with, you may see the model below as the Modelica code in a behavior or in an experiment rather than a stand-alone model.

Important: To be able to analyze the variables after a failed translation, you must, before the translation, activate the option Store variables after failed initialization in the simulation setup, the Debug tab.

For more information on how to reach this option, and other options in this topic, see Setting up a Simulation. For more information about the dialog box alternatives, see Simulation Setup Dialog Box.

If you have activated this option, all variables, ready for plotting, are now available in the Variable Browser after a failed simulation. The value of each variable depends on how far the initialization process came before failing. If the variable was initialized the result of that initialization is presented. The simulation log contains information on what made the initialization fail.

Note: Advanced users can study the execution order in dsmodel.mof, see the tip at the end.

Consider the example model:

model InitializationFailure
   Real x(start=-0.5, fixed=true);
   Real dx(start=-0.9);
   input Real u;
   output Real y1(start=-1);
   output Real y2(start=-1);
equation
   der(x) = dx;
   u*dx + exp(dx) = x;
   y1 = x^3;
   y2 = der(x)^3;
end InitalizationFailure;

To compute the variable der(x) = dx the system, during translation, generates a nonlinear equation in this variable. When simulating the model this nonlinear equation cannot be solved and the simulation fails. A message is displayed about this in the log. Plotting the iteration variable der(x) = dx gives the last attempted value in the Newton iteration.

By a closer look at the model you can see that the nonlinear equation depends on the variables u and x. This information is also readily available in the translation log if you, before translation, activate the option List non-linear iteration variables in the simulation setup, the Translation tab. For more information about this option see the references above.

Notes:

Plotting these variables reveals that u = 0 and x = -0.5. Thus, the nonlinear equation reduces to exp(dx) = -0.5, which lacks solution. The source of the initialization problem is found.

Tip: For advanced users: Advanced users can, before translation, set the flag Advanced.OutputModelicaCode=true to generate a file dsmodel.mof when translating. The file is located in the working directory, by default %LOCALAPPDATA%\DassaultSystemes\CATTemp\SVE. This file lists the result of the translation in a Modelica-like language. In this file you can see, for example, the execution order and the dependencies, as referred to in the notes above.

As extra information about this example, a look into dsmodel.mof reveals that y1 is computed before the attempt to solve the nonlinear equation. The variable y2 is computed after. This agrees with the values presented when plotting these variables: y1 = -0.125 and y2 = -1. The former variable has its computed value x^3, whereas the latter variable has its start value -1.