OpenModelica System Documentation

This document is part of OpenModelica: http://www.openmodelica.org .... Chapter
11 Interoperability ? C, Java, and Python ...... Exercises have been written in
order to elucidate language constructs step by step based on the pedagogical
assumption that ...... OPC_Interfaces_in_OpenModelica.pdf (Accessed 10 June
2011).

Part of the document




OpenModelica Users Guide


Version 2012-03-29
for OpenModelica 1.8.1


March 2012


Peter Fritzson
Adrian Pop, Adeel Asghar, Willi Braun, Jens Frenkel,
Lennart Ochel, Martin Sjölund, Per Östlund, Peter Aronsson,
Mikael Axin, Bernhard Bachmann, Vasile Baluta, Robert Braun, David Broman,
Stefan Brus, Francesco Casella, Filippo Donida, Anand Ganeson, Mahder
Gebremedhin, Pavel Grozman, Daniel Hedberg, Michael Hanke, Alf Isaksson,
Kim Jansson, Daniel Kanth, Tommi Karhela, Juha Kortelainen, Abhinn Kothari,
Petter Krus, Alexey Lebedev, Oliver Lenord, Ariel Liebman, Rickard
Lindberg, Håkan Lundvall, Abhi Raj Metkar, Eric Meyers, Tuomas Miettinen,
Afshin Moghadam, Maroun Nemer, Hannu Niemistö, Peter Nordin, Kristoffer
Norling, Karl Pettersson, Pavol Privitzer, Jhansi Reddy, Reino Ruusu, Per
Sahlin,Wladimir Schamai, Gerhard Schmitz, Anton Sodja, Ingo Staack,
Kristian Stavåker, Sonia Tariq, Mohsen Torabzadeh-Tari, Parham Vasaiely,
Niklas Worschech, Robert Wotzlaw, Björn Zackrisson,
Azam Zia



Copyright by:

Open Source Modelica Consortium
Copyright © 1998-CurrentYear, Open Source Modelica Consortium (OSMC), c/o
Linköpings universitet, Department of Computer and Information Science, SE-
58183 Linköping, Sweden

All rights reserved.

THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR THIS
OSMC PUBLIC LICENSE (OSMC-PL). ANY USE, REPRODUCTION OR DISTRIBUTION OF
THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE
OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE.

The OpenModelica software and the OSMC (Open Source Modelica Consortium)
Public License (OSMC-PL) are obtained from OSMC, either from the above
address, from the URLs: http://www.openmodelica.org or
http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica
distribution. GNU version 3 is obtained from:
http://www.gnu.org/copyleft/gpl.html.

This program is distributed WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS
EXPRESSLY SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE
CONDITIONS OF OSMC-PL.

See the full OSMC Public License conditions for more details.



This document is part of OpenModelica: http://www.openmodelica.org
Contact: OpenModelica@ida.liu.se



Modelica® is a registered trademark of the Modelica Association,
http://www.Modelica.org

MathModelica® is a registered trademark of MathCore Engineering AB,
www.mathcore.com

Mathematica® is a registered trademark of Wolfram Research Inc,
www.wolfram.com




Table of Contents

Table of Contents 3
Preface 9

Chapter 1 Introduction 11

1.1 System Overview 12
1.2 Interactive Session with Examples 13
1.2.1 Starting the Interactive Session 13
1.2.2 Using Compiler Debug Trace Flags in Interactive Mode 14
1.2.3 Trying the Bubblesort Function 17
1.2.4 Trying the system and cd Commands 17
1.2.5 Modelica Library and DCMotor Model 18
1.2.6 The val() function 21
1.2.7 BouncingBall and Switch Models 21
1.2.8 Clear All Models 23
1.2.9 VanDerPol Model and Parametric Plot 23
1.2.10 Using Japanese or Chinese Characters 24
1.2.11 Scripting with For-Loops, While-Loops, and If-Statements 25
1.2.12 Variables, Functions, and Types of Variables 26
1.2.13 Getting Information about Error Cause 27
1.2.14 Alternative Simulation Output Formats 27
1.2.15 Using External Functions 27
1.2.16 Using Parallel Simulation via OpenMP Multi-Core Support 27
1.2.17 Loading Specific Library Version 28
1.2.18 Calling the Model Query and Manipulation API 28
1.2.19 Quit OpenModelica 29
1.2.20 Dump XML Representation 30
1.2.21 Dump Matlab Representation 30
1.3 Summary of Commands for the Interactive Session Handler 31
1.4 References 32

Chapter 2 OMEdit - The OpenModelica Connection Editor 33

2.1 Starting OMEdit 33
2.1.1 Microsoft Windows 33
2.1.2 Linux 34
2.1.3 Mac OS X 34
2.2 Introductory Modeling in OMEdit 35
2.2.1 Creating a New File 35
2.2.2 Adding Component Models 36
2.2.3 Making Connections 36
2.2.4 Simulating the Model 38
2.2.5 Plotting Variables from Simulated Models 39
2.3 How to Create User Defined Shapes - Icons 41
2.4 OMEdit Views 43
2.4.1 Modeling View 43
2.4.2 Plotting View 43
2.4.3 Interactive Simulation View 43
2.5 OMEdit Windows/Tabs 44
2.5.1 Library Window 44
2.5.2 Designer Window 45
2.5.3 Plot Variables Window 46
2.5.4 Messages Window 46
2.5.5 Documentation Window 46
2.5.6 Model Browser Window 47
2.6 Dialogs 48
2.6.1 New Model Dialog 48
2.6.2 Simulation Dialog 48
2.6.3 Model Properties Dialog 48
2.6.4 Model Attributes Dialog 49
2.7 Interactive Simulation in OMEdit 50
2.7.1 Invoking Interactive Simulation 50
2.7.2 Interactive Simulation View 50

Chapter 3 2D Plotting and 3D Animation 52

3.1 Enhanced Qt-based 2D Plot Functionality 52
3.2 Simple 2D Plot 53
3.2.1 Plot Functions and Their Options 57
3.2.2 Zooming 59
3.2.3 Plotting all variables of a model 60
3.2.4 Plotting During Simulation 61
3.2.5 Programmable Drawing of 2D Graphics 61
3.2.6 Plotting of Table Data 62
3.3 Java-based PtPlot 2D plotting 63
3.4 3D Animation 64
3.4.1 Object Based Visualization 64
3.4.2 BouncingBall 65
3.4.3 Pendulum 3D Example 67
3.5 References 70

Chapter 4 OMNotebook with DrModelica and DrControl 72

4.1 Interactive Notebooks with Literate Programming 72
4.1.1 Mathematica Notebooks 72
4.1.2 OMNotebook 72
4.2 DrModelica Tutoring System - an Application of OMNotebook 73
4.3 DrControl Tutorial for Teaching Control Theory 79
4.3.1 Feedback Loop 79
4.3.2 Mathematical Modeling with Characteristic Equations 82
4.4 OpenModelica Notebook Commands 88
4.4.1 Cells 88
4.4.2 Cursors 88
4.4.3 Selection of Text or Cells 89
4.4.4 File Menu 89
4.4.5 Edit Menu 90
4.4.6 Cell Menu 90
4.4.7 Format Menu 91
4.4.8 Insert Menu 91
4.4.9 Window Menu 92
4.4.10 Help Menu 92
4.4.11 Additional Features 92
4.5 References 93

Chapter 5 Interactive Simulation 95

5.1 OpenModelica Interactive 95
5.1.1 Interactively Changeable Parameters 95
5.1.2 OpenModelica Interactive Components description 96
5.1.3 Communication Interface 96
5.1.4 Network configuration Settings 97
5.1.5 Interactive Simulation general Procedure 99
5.1.6 Interactive Simulation Example 99
5.2 OPC and OPC UA Interfaces 102
5.2.1 Introduction to the OPC Interfaces 102
5.2.2 Implemented Features 102
5.2.3 Test clients 105
5.2.4 References 105

Chapter 6 Model Import and Export with FMI 1.0 107

6.1 FMI Import 107
6.2 FMI Export 108

Chapter 7 OMOptim - Optimization with OpenModelica 110

7.1 Introduction 110
7.2 Preparing the Model 110
7.2.1 Parameters 110
7.2.2 Constraints 110
7.2.3 Objectives 111
7.3 Set problem in OMOptim 111
7.3.1 Launch OMOptim 111
7.3.2 Create a new project 111
7.3.3 Load models 111
7.3.4 Create a new optimization problem 112
7.3.5 Select Optimized Variables 113
7.3.6 Select objectives 114
7.3.7 Select and configure algorithm 114
7.3.8 Launch 115
7.3.9 Stopping Optimization 115
7.4 Results 115
7.4.1 Obtaining all Variable Values 115
7.5 Window Regions in OMOptim GUI 116

Chapter 8 MDT - The OpenModelica Development Tooling Eclipse Plugin
117

8.1 Introduction 117
8.2 Installation 117
8.3 Getting Started 118
8.3.1 Configuring the OpenModelica Compiler 118
8.3.2 Using the Modelica Perspective 118
8.3.3 Selecting a Workspace Folder 118
8.3.4 Creating one or more Modelica Projects 118
8.3.5 Building and Running a Project 118
8.3.6 Switching to Another Perspective 119
8.3.7 Creating a Package 120
8.3.8 Creating a Class 120
8.3.9 Syntax Checking 121
8.3.10 Automatic Indentation Support 122
8.3.11 Code Completion 122
8.3.12 Code Assistance on Identifiers when Hovering 123
8.3.13 Go to Definition Support 123
8.3.14 Code Assistance on Writing Records 123
8.3.15 Using the MDT Console for Plotting 124

Chapter 9 Modelica Performance Analyzer 126

9.1 Example Report Generated for the A Model 127
9.1.1 Information 127
9.1.2 Settings 127
9.1.3 Summary 127
9.1.4 Global Steps 128
9.1.5 Measured Function Calls 128
9.1.6 Measured Blocks 128
9.1.7 Genenerated XML for the Example 129

Chapter 10 Modelica Algorithmic Subset Debugger 131

10.1 The Eclipse-based Debugging Environment 131
10.2 Starting the Modelica Debugging Perspective 132
10.2.1 Create mos file 132
10.2.2 Setting the debug configuration 133
10.2.3 Setting/Deleting Breakpoints 134
10.2.4 Starting the debugging session and enabling the debug
perspective 135
10.3 Debugging OpenModelica 136
10.4 The Debugging Perspective 136

Chapter 11 I