Openmodelica User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
OpenModelica Users Guide Version 2015-03-10 for OpenModelica 1.9.2 March 2015 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, Lena Buffoni, David Broman, Stefan Brus, Francesco Casella, Filippo Donida, Atiyah Elsheikh, 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, Abhir Raj Metkar, Eric Meyers, Tuomas Miettinen, Afshin Moghadam, Kenneth Nealy, Nemer, Hannu Niemistö, Peter Nordin, Kristoffer Norling, Arunkumar Palanisamy, Karl Pettersson, Pavol Privitzer, Jhansi Reddy, Reino Ruusu, Per Sahlin,Wladimir Schamai, Gerhard Schmitz, Alachew Shitahun, Anton Sodja, Ingo Staack, Kristian Stavåker, Sonia Tariq, Mohsen Torabzadeh-Tari, Parham Vasaiely, Marcus Walter, Volker Waurich, Niklas Worschech, Robert Wotzlaw, Azam Zia Copyright by: Open Source Modelica Consortium 2 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: [email protected] Modelica® is a registered trademark of the Modelica Association, http://www.Modelica.org Mathematica® is a registered trademark of Wolfram Research Inc, www.wolfram.com 3 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 ......................................................................................... 14 1.2.2 Using the Interactive Mode ............................................................................................... 14 1.2.3 Trying the Bubblesort Function ......................................................................................... 16 1.2.4 Trying the system and cd Commands ................................................................................ 17 1.2.5 Modelica Library and DCMotor Model ............................................................................ 17 1.2.6 The val() function .............................................................................................................. 20 1.2.7 BouncingBall and Switch Models ..................................................................................... 20 1.2.8 Clear All Models ............................................................................................................... 22 1.2.9 VanDerPol Model and Parametric Plot ............................................................................. 22 1.2.10 Using Japanese or Chinese Characters .............................................................................. 23 1.2.11 Scripting with For-Loops, While-Loops, and If-Statements ............................................. 24 1.2.12 Variables, Functions, and Types of Variables ................................................................... 25 1.2.13 Getting Information about Error Cause ............................................................................. 26 1.2.14 Alternative Simulation Output Formats............................................................................. 26 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 ..................................................................................... 27 1.2.18 Calling the Model Query and Manipulation API .............................................................. 27 1.2.19 Quit OpenModelica ........................................................................................................... 29 1.2.20 Dump XML Representation .............................................................................................. 29 1.2.21 Dump Matlab Representation ............................................................................................ 29 1.3 Summary of Commands for the Interactive Session Handler ................................................ 30 1.4 Running the compiler from command line ............................................................................ 31 1.5 References .............................................................................................................................. 32 Chapter 2 OMEdit – OpenModelica Connection Editor ............................................................... 33 2.1 Starting OMEdit ..................................................................................................................... 33 2.1.1 Microsoft Windows ........................................................................................................... 33 2.1.1 Linux ................................................................................................................................. 33 2.1.2 Mac OS X .......................................................................................................................... 33 2.2 MainWindow & Browsers ..................................................................................................... 34 2.2.1 Search Browser .................................................................................................................. 35 2.2.2 Libraries Browser .............................................................................................................. 36 2.2.3 Documentation Browser .................................................................................................... 37 2.2.4 Variables Browser ............................................................................................................. 37 2.2.5 Messages Browser ............................................................................................................. 38 2.3 Perspectives ............................................................................................................................ 39 2.3.1 Welcome Perspective ........................................................................................................ 39 2.3.2 Modeling Perspective ........................................................................................................ 39 2.3.3 Plotting Perspective ........................................................................................................... 40 4 2.4 Modeling a Model .................................................................................................................. 41 2.4.1 Creating a New Modelica class ......................................................................................... 41 2.4.2 Opening a Modelica File ................................................................................................... 41 2.4.3 Opening a Modelica File with Encoding ........................................................................... 42 2.4.4 Model Widget .................................................................................................................... 42 2.4.5 Adding Component Models .............................................................................................. 43 2.4.6 Making Connections .......................................................................................................... 43 2.5 Simulating a Model ................................................................................................................ 43 2.5.1 General Tab ....................................................................................................................... 43 2.5.2 Output Tab ........................................................................................................................