Book a Demo
Prev Next

Troubleshooting OpenModelica Simulation

Whilst this topic describes possible problems that can arise when using OpenModelica, many of the points are equally applicable to performing a simulation using MATLAB Simulink.

Common Simulation Issues

This table describes some common issues that can prevent a model being simulated when using OpenModelica. 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 OpenModelica source code. This will help you locate most of the errors.

Issue

Description

The number of equations is less than the number of variables. You might have forgotten to set some properties to 'PhSConstant', which means the value doesn't change during simulation. You might have to provide the 'PhSConstant' 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. For example, a Block 'ChargePort' contains two parts — 'v : Voltage' and 'i: Current'. The property 'i : Current' should be defined as PhSVariable with the attribute 'isConserved' set to 'True'.

PhSConstants might not have default values — they should be provided with them.

A PhSVariable 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, ConstraintBlocks, 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 you to find a potential modeling error.

In the TwoTanks example, if we clear the Tank.area property 'PhSConstant' 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 properties for 'PhSConstant'.

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 'PhSConstant' and provide an initial value to fix the issue.

Model Validation Examples

Message

Discussion

Variable Not Defined in Constraint

In the TwoTanks example, when we browse to 'constraintBlock.Outcontrol.Constraint', suppose we find a typing error: 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 are found and the issue is fixed.

Tips: Using the SysML Simulation Configuration view is a shortcut 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. Assume that we gave two properties the same name:

  • Right-click on e1, select the 'Find in Project Browser' option, 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 are found and the issue is fixed.

Properties Defined in ConstraintBlocks Not Used

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

Assume that we add a property 'c' and potentially a new constraint, but we forget to synchronize for the instances - the ConstraintProperties. 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 ConstraintProperty highlighted. The ConstraintProperty is typed to outFlow and the new parameter 'c' is missing.

Right-click on the ConstraintProperty in the configuration list, select the 'Find in all Diagrams' option and right-click on the 'Constraint' property on the diagram; select 'Features | 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 ConstraintBlock and a constraint is defined by using 'c', then we need to add a property in the context of the ConstraintProperty 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 the Ctrl+D keys. (The corresponding ConstraintProperties will have 'c' deleted automatically.)

Learn More