Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.
Prev | Next |
Modeling and Simulation with Modelica Library
This feature is available from Enterprise Architect Release 14.1.
The Modelica 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 Modelica Libraries.
Referencing a Type defined in Modelica Library
To configure a simulation to reference a Modelica Library, you first create a ValueType element pointing to the Modelica library, and register this in the Simulation configuration.
First, create an element for a Referenced Modelica Type
- Create a ValueType element with the full name of the Modelica 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 Modelica file.
Next, 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 Properties window to open the element
- 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 on the Property
- Browse to the ValueType element you created
Including a Modelica Library in a Simulation
When using referenced types from a Modelica library in a model, you must load the Modelica 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 Modelica Script Template
You can modify the Modelica script template to add extra libraries required by the model and simulation.
Access
Ribbon: Code | Configure | 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 property 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 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: