Book a Demo
Prev Next

Modeling and Simulation with OpenModelica Library

This feature is available from Enterprise Architect release 14.1 onwards.

The OpenModelica Libraries are comprehensive resources that provide many useful types, functions and models. When creating SysML models in Enterprise Architect, you can reference resources available in the OpenModelica Libraries.

Referencing a Type Defined in OpenModelica Library

To configure a simulation to reference an OpenModelica Library, you first create a ValueType element pointing to the OpenModelica library, and register this in the Simulation configuration.

Create an element for a Referenced OpenModelica Type

  • Create a ValueType element with the full name of the OpenModelica Library path

Configure the ValueType element as 'ReferencedType':

  • Double-click on the SysMLSimConfiguration element to open the 'Configure SysML Configuration' tab
  • Navigate to the ValueType element
  • In the drop-down field set the value to 'ReferencedType'

As the ValueType element is configured as 'ReferencedType', the element will not display in the 'Dependencies' list and will not be generated as a new Class definition to the OpenModelica file.

Set the type for a Property to the ValueType element

In Enterprise Architect, a SysML Property can be set to be a primitive type or an element such as a Block or a ValueType.

Option 1:

  • Select the Property (Part or Port)
  • Press Ctrl+2 to open the Properties window
  • Switch to the 'Property' tab and choose 'Select Type...'
  • Browse to the ValueType element you created

Option 2:

  • Select the Property (Part or Port)
  • Press Ctrl+L on the Property
  • Browse to the ValueType element you created

Including an OpenModelica Library in a Simulation

When using referenced types from an OpenModelica library in a model, you must load the OpenModelica model in the environment for the simulation to work.

  • Expand the menu option and select 'Include Modelica Library'
  • If this option is ticked, this function will be generated to 'Solve.mos' by default:
         loadModel(Modelica);

Click here for a detailed description of the loadModel() scripting function.

Customize the OpenModelica Script Template

You can modify the OpenModelica script template to add extra libraries required by the model and simulation. Select the ribbon option:

     Develop > Source Code > Options > Edit Code Templates

In the 'Language' field select 'Modelica', and in the 'Scripts' list select 'SysMLSim Script'.

As you are appending extra libraries after 'loadModel(Modelica)', the libraries' resources can be referenced by your model.

SquareWave Example

This example is based on Figure 13-11 in: Principles of Object-Oriented Modeling and Simulation with Modelica 3.3: A Cyber-Physical, Second Edition, by Peter Fritzson.

In this example:

  • We create a ValueType Modelica.SIunits.Time, which is used for the properties first and interval of the Block SquareWave
  • ValueType Modelica.SIunits.Time is configured as 'ReferencedType' in the SysML Simulation window
  • Select the menu item 'Include Modelica Library'

Run the simulation; the variable x is plotted like this:

SampleTime Example

This example is based on Figure 13-13 in: Principles of Object-Oriented Modeling and Simulation with Modelica 3.3: A Cyber-Physical, Second Edition, by Peter Fritzson.

In this example:

  • We have created a ValueType Clock, which is used for the property clk of Block SampleTime
  • ValueType Clock is configured as 'ReferencedType' in the SysML Simulation window
  • The menu item 'Include Modelica Library' is unselected

Run the simulation; the variable x and stime plot resembles this: