Prev Next

Troubleshooting OpenModelica Simulation

Common Simulation Issues

This table describes some of the common issues that can prevent a model being simulated. Check the output in the 'Build' tab of the System Output window. The messages are dumped from the OpenModelica compiler (omc.exe), which normally points you to the lines of the Modelica source code. This will help you pick up most of the errors.

Issue

Description

The number of equations is less than the number of variables. You might have forgotten to set some of the properties to 'SimConstant', which means the value doesn't change during simulation. You might have to provide the 'SimConstant' property values before the simulation is started. (Set the values through a Simulation Data Set.)

The Blocks that are typing to Ports might not contain conserved properties. If, for example, a Block 'ChargePort' contains two parts - 'v : Voltage' and 'i: Current' - the property 'i : Current' should be defined as SimVariable with the attribute 'isConserved' set to 'True'.

SimConstants might not have default values - they should be provided with them.

A SimVariable might not have an initial value to start with - one should be provided.

The properties might be typed by elements (Blocks or Value Type) external to the configured Package; use a Package Import connector to fix this.

SysML Simulation Configuration Filters

The 'SysML Simulation Configuration' dialog shows all the elements in the Package by default, including Value Types, Blocks, Constraint Blocks, Parts and Ports, Constraint Properties, Connectors, Constraints and Data Sets. For a medium-sized model, the full list can be quite long and it can be difficult for the user to find a potential modeling error.

In the TwoTanks example, if we clear the Tank.area's property 'SimConstant' and then do a validation, we will find this error:

     Error: Too few equations, under-determined system. The model has 11 equation(s) and 13 variable(s).

This error indicates that we might have forgotten to set some of the properties to 'SimConstant'.

What we can do now is click on the second button from the right on the toolbar (Filter for the configuration) and open the dialog shown here. Click on the All button, then deselect the 'Suppress Block' and 'Suppress Variable Part' checkboxes and click on the OK button.

Now we will have a much shorter list of variables, from which we can find that 'area' does not change during simulation. Then we define this as a 'SimConstant' and provide an initial value to fix the issue.

Model Validation Examples

Variable not defined in Constraint

In the TwoTanks example, when we browse to 'constraintBlock.Outcontrol.Constraint', suppose we find a typo - we typed 'V' instead of 'B' in the constraint.

     So, instead of:

          a=b*(c+d)

     We typed:

          a=v*(c+d)

Click on the Validate button on the toolbar. These error messages will appear in the 'Modelica' tab:

     Validating model...

     Error: Variable v not found in scope OutControl. (Expression: " a=v*(c+d);")

     Error: Error occurred while flattening model TanksConnectedPI

     Number of Errors and Warnings found: 2

Double-click on the error line; the configuration list displays with the constraint highlighted.

Change 'v' back to 'b' and click on the Validate button again. No errors should be found and the issue is fixed.

Tips: Using the SysML Simulation Configuration view is a short cut way of changing the constraints for a Block or Constraint Block. You can:

  • Change a constraint in place
  • Delete using the context menu of a constraint
  • Add a new constraint using the context menu of a Block or Constraint Block

Duplicate Variable Names

In the TwoTanks example, browse to block.tank.constraintProperty.e1. Suppose we gave two properties the same name:

  • Right-click on e1, select 'Find in Project Browser', and change the name to e2; reload the 'SysML Simulation Configuration' dialog

Click on the Validate button on the toolbar; these error messages appear in the 'Modelica' tab:

     Validating model...

     Error: Duplicate elements (due to inherited elements) not identical: (Expression: "SensorValue e2;")

     Error: Error occurred while flattening model TanksConnectedPI

     Number of Errors and Warnings found: 2

Double-click on the error line; the configuration list displays with the constraint properties highlighted.

Change the name of one of them from e2 back to e1 and click on the Validate button again; no errors should be found and the issue is fixed.

Properties defined in Constraint Blocks not used

In the TwoTanks example, in the Project Browser, we browse to the element 'Example Model.Systems Engineering.ModelicaExamples.TwoTanks.constraints.OutFlow'.

Suppose we add a property 'c' and potentially a new constraint, but we forget to synchronize for the instances - the constraint properties. This will cause a Too few equations, under-determined system error if we don't run validation.

Reload the Package in the 'SysML Simulation Configuration' dialog and click on the Validate button on the toolbar. These error messages will appear in the 'Modelica' tab:

     Validating model...

     Error: ConstraintProperty 'e4' is missing parameters defined in the typing ConstraintBlock 'OutFlow'. (Missing: c)

     Error: Too few equations, under-determined system. The model has 11 equation(s) and 12 variable(s).

     Number of Errors and Warnings found: 2

Double-click on the error line; the configuration list displays with the constraint property highlighted. The constraint property is typed to outFlow and the new parameter 'c' is missing.

Right-click on the constraint property in the configuration list, select 'Find in All Diagrams', then right-click on the constraint property on the diagram and select 'Features & Properties  | Parts / Properties' and select the 'Show Owned / Inherited' checkbox, then click on 'c'.

Reload the model in the 'SysML Simulation Configuration' dialog and click on the Validate button. These error messages will appear in the 'Modelica' tab:

     Validating model...

     Error: ConstraintProperty 'e4' does not have any incoming or outgoing binding connectors for parameter 'c'.

     Error: Too few equations, under-determined system. The model has 11 equation(s) and 12 variable(s).

     Number of Errors and Warnings found: 2

In order to fix this issue, we can do either of two things based on the real logic:

  1. If the property 'c' is necessary in the Constraint Block and a constraint is defined by using 'c', then we need to add a property in the context of the constraint property and bind to the parameter 'c'.
  2. If the property 'c' is not required, then we can click on this property in the constraint block and press Ctrl+D. (The corresponding constraint properties will have 'c' deleted automatically.)