Openmodelica User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
OpenModelica User’s Guide Release v1.16.0-dev-523-g925d782559 Open Source Modelica Consortium Jul 01, 2020 CONTENTS 1 Introduction 3 1.1 System Overview...........................................4 1.2 Interactive Session with Examples..................................5 1.3 Summary of Commands for the Interactive Session Handler.................... 22 1.4 Running the compiler from command line.............................. 23 2 OMEdit – OpenModelica Connection Editor 25 2.1 Starting OMEdit........................................... 25 2.2 MainWindow & Browsers...................................... 26 2.3 Perspectives............................................. 30 2.4 File Menu............................................... 34 2.5 Edit Menu.............................................. 35 2.6 View Menu.............................................. 35 2.7 Simulation Menu........................................... 36 2.8 Debug Menu............................................. 36 2.9 SSP Menu.............................................. 36 2.10 Sensitivity Optimization Menu.................................... 36 2.11 Tools Menu.............................................. 37 2.12 Help Menu.............................................. 37 2.13 Modeling a Model.......................................... 37 2.14 Simulating a Model......................................... 39 2.15 2D Plotting.............................................. 42 2.16 Re-simulating a Model........................................ 43 2.17 3D Visualization........................................... 43 2.18 Animation of Realtime FMUs.................................... 45 2.19 Interactive Simulation........................................ 46 2.20 How to Create User Defined Shapes – Icons............................. 47 2.21 Global head section in documentation................................ 48 2.22 Options................................................ 48 2.23 __OpenModelica_commandLineOptions Annotation........................ 55 2.24 __OpenModelica_simulationFlags Annotation........................... 56 2.25 Debugger............................................... 56 2.26 Editing Modelica Standard Library................................. 56 2.27 State Machines............................................ 56 2.28 Using OMEdit as Text Editor.................................... 59 2.29 Temporary Directory, Working Directory and Log Files...................... 60 3 2D Plotting 65 3.1 Example............................................... 65 3.2 Plot Command Interface....................................... 67 4 Solving Modelica Models 69 4.1 Integration Methods......................................... 69 4.2 DAE Mode Simulation........................................ 71 i 5 Debugging 73 5.1 The Equation-based Debugger.................................... 73 5.2 The Algorithmic Debugger...................................... 75 6 Generating Graph Representations for Models 81 7 FMI and TLM-Based Simulation and Co-simulation of External Models 83 7.1 Functional Mock-up Interface - FMI................................. 83 7.2 Transmission Line Modeling (TLM) Based Co-Simulation..................... 88 7.3 Composite Model Editing of External Models............................ 88 8 OMSimulator 103 9 System Identification 105 10 OpenModelica Encryption 107 10.1 Encrypting the Library........................................ 107 10.2 Loading an Encrypted Library.................................... 107 10.3 Notes................................................. 107 11 OMNotebook with DrModelica and DrControl 109 11.1 Interactive Notebooks with Literate Programming......................... 109 11.2 DrModelica Tutoring System – an Application of OMNotebook.................. 110 11.3 DrControl Tutorial for Teaching Control Theory.......................... 116 11.4 OpenModelica Notebook Commands................................ 128 11.5 References.............................................. 135 12 Optimization with OpenModelica 137 12.1 Builtin Dynamic Optimization with OpenModelica and IpOpt................... 137 12.2 Compiling the Modelica code.................................... 137 12.3 An Example............................................. 137 12.4 Different Options for the Optimizer IPOPT............................. 140 12.5 Dynamic Optimization with OpenModelica and CasADi...................... 140 12.6 Parameter Sweep Optimization using OMOptim.......................... 145 13 Parameter Sensitivities with OpenModelica 153 13.1 Background.............................................. 153 13.2 An Example............................................. 153 14 PDEModelica1 157 14.1 PDEModelica1 language elements.................................. 157 14.2 Limitations.............................................. 158 14.3 Viewing results............................................ 158 15 MDT – The OpenModelica Development Tooling Eclipse Plugin 159 15.1 Introduction............................................. 159 15.2 Installation.............................................. 159 15.3 Getting Started............................................ 160 16 MDT Debugger for Algorithmic Modelica 173 16.1 The Eclipse-based Debugger for Algorithmic Modelica....................... 173 17 Modelica Performance Analyzer 179 17.1 Profiling information for ProfilingTest................................ 180 17.2 Genenerated JSON for the Example................................. 182 17.3 Using the Profiler from OMEdit................................... 183 18 Simulation in Web Browser 185 ii 19 Interoperability – C and Python 187 19.1 Calling External C functions..................................... 187 19.2 Calling external Python Code from a Modelica model....................... 188 19.3 Calling OpenModelica from Python Code.............................. 190 20 OpenModelica Python Interface and PySimulator 193 20.1 OMPython – OpenModelica Python Interface............................ 193 20.2 Enhanced OMPython Features.................................... 196 20.3 PySimulator............................................. 200 21 OMMatlab – OpenModelica Matlab Interface 201 21.1 Features of OMMatlab........................................ 201 21.2 Test Commands........................................... 201 21.3 WorkDirectory............................................ 203 21.4 BuildModel.............................................. 203 21.5 Standard get methods........................................ 203 21.6 Usage of getMethods......................................... 203 21.7 Standard set methods......................................... 205 21.8 Usage of setMethods......................................... 205 21.9 Advanced Simulation........................................ 206 21.10 Linearization............................................. 206 21.11 Usage of Linearization methods................................... 207 22 OMJulia – OpenModelica Julia Scripting 209 22.1 Features of OMJulia......................................... 209 22.2 Test Commands........................................... 209 22.3 WorkDirectory............................................ 211 22.4 BuildModel.............................................. 211 22.5 Standard get methods........................................ 211 22.6 Usage of getMethods......................................... 211 22.7 Standard set methods......................................... 212 22.8 Usage of setMethods......................................... 213 22.9 Advanced Simulation........................................ 213 22.10 Linearization............................................. 214 22.11 Usage of Linearization methods................................... 214 22.12 Sensitivity Analysis......................................... 214 22.13 Usage................................................. 215 23 Jupyter-OpenModelica 217 24 Scripting API 219 24.1 OpenModelica Scripting Commands................................ 219 24.2 Simulation Parameter Sweep..................................... 289 24.3 Examples............................................... 290 25 Package manager 295 25.1 Installing packages.......................................... 295 25.2 How the package index works.................................... 297 26 OpenModelica Compiler Flags 299 26.1 Options................................................ 299 26.2 Debug flags.............................................. 315 26.3 Flags for Optimization Modules................................... 321 27 Small Overview of Simulation Flags 323 27.1 OpenModelica (C-runtime) Simulation Flags............................ 323 28 Technical Details 331 28.1 The MATv4 Result File Format................................... 331 iii 29 DataReconciliation 333 29.1 Defining DataReconciliation Problem in OpenModelica...................... 333 29.2 DataReconcilation Support with Scripting Interface......................... 334 29.3 DataReconciliation Support in OMEdit............................... 335 29.4 DataReconcilation Results...................................... 337 30 Frequently Asked Questions (FAQ) 341 30.1 OpenModelica General........................................ 341 30.2 OMNotebook............................................. 341 30.3 OMDev - OpenModelica Development Environment........................ 342 31 Major OpenModelica Releases 343 31.1 Release Notes for OpenModelica 1.16.0............................... 343 31.2 Release Notes for OpenModelica 1.15.0..............................