Introduction to Object-Oriented Modeling
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Object-Oriented Modeling, Modelica/OpenModelica Tutorial Plan for the Simulation, Debugging and Dynamic Optimization MOSES 2016 Workshop with Modelica using OpenModelica • Wednesday slot 24. The Modelica language part 1. MOSES 2016 Workshop Introductory hands-on Modelica modeling. Tutorial, Version May 18, 2016 Peter Fritzson Slides 8 – 49 Linköping University, [email protected] Director of the Open Source Modelica Consortium • Thursday slot 28. The OpenModelica tool. (slides Vice Chairman of Modelica Association Bernhard Thiele, Ph.D., [email protected] 50 – 78) The Modelica language part 2. (slides 95- Researcher at PELAB, Linköping University 115) Slides • Thursday slot 29. Hands-on with Modelica textual Based on book and lecture notes by Peter Fritzson Contributions 2004-2005 by Emma Larsdotter Nilsson, Peter Bunus equation-based modeling (slides 95-115) Contributions 2006-2008 by Adrian Pop and Peter Fritzson Contributions 2009 by David Broman, Peter Fritzson, Jan Brugård, and Mohsen Torabzadeh-Tari Contributions 2010 by Peter Fritzson Contributions 2011 by Peter F., Mohsen T,. Adeel Asghar, Contributions 2012, 2013, 2014, 2015, 2016 by Peter Fritzson, Lena Buffoni, Mahder Gebremedhin, Bernhard Thiele 2016-05-16 2 Copyright © Open Source Modelica Consortium Tutorial Based on Book, Decembr 2014 Introductory Download OpenModelica Software Modelica Book Peter Fritzson September 2011 232 pages Principles of Object Oriented Modeling and Simulation with 2015 –Translations Modelica 3.3 available in A Cyber-Physical Approach Chinese, Japanese, Can be ordered from Wiley or Amazon Spanish Wiley-IEEE Press, 2014, 1250 pages Wiley IEEE Press • OpenModelica For Introductory • www.openmodelica.org Short Courses on • Modelica Association Object Oriented • www.modelica.org Mathematical Modeling 3 Copyright © Open Source Modelica Consortium 4 Copyright © Open Source Modelica Consortium Acknowledgements, Usage, Copyrights Outline • If you want to use the Powerpoint version of these slides in your own course, send an email to: [email protected] Part I Part II • Thanks to Emma Larsdotter Nilsson, Peter Bunus, David Introduction to Modelica and a Modelica environments Broman, Jan Brugård, Mohsen-Torabzadeh-Tari, Adeel demo example Asghar, Lena Buffoni, for contributions to these slides. • Most examples and figures in this tutorial are adapted with permission from Peter Fritzson’s book ”Principles of Object Oriented Modeling and Simulation with Modelica 2.1”, copyright Wiley-IEEE Press • Some examples and figures reproduced with permission Part III Part IV and Part V from Modelica Association, Martin Otter, Hilding Elmqvist, Modelica language concepts Graphical modeling and the Wolfram MathCore, Siemens and textual modeling Modelica standard library • Modelica Association: www.modelica.org Dynamic Optimization • OpenModelica: www.openmodelica.org 5 Copyright © Open Source Modelica Consortium 6 Copyright © Open Source Modelica Consortium 1 Detailed Schedule (morning version) 09.00-12.30 Software Installation - Windows 09:00 - Introduction to Modeling and Simulation • Start installation of OpenModelica including OMEdit graphic editor 09:10 - Modelica – The Next Generation Modeling Language 09:25 - Exercises Part I (15 minutes) • Start the software installation • Short hands-on exercise on graphical modeling using OMEdit– RL Circuit 09:50 – Part II: Modelica Environments and the OpenModelica Environment 10:10 – Part III: Modelica Textual Modeling • Install OpenModelica-1.9.4beta.exe from the USB 10:15 - Exercises Part IIIa (10 minutes) • Hands-on exerciseson textual modeling using the OpenModelica environment Stick 10:25 – Coffee Break 10:40 - Modelica Discrete Events, Hybrid, Clocked Properties (Bernhard Thiele) 11:00- Exercises Part IIIb (15 minutes) • Hands-on exercises on textual modeling using the OpenModelica environment 11:20– Part IV: Components, Connectors and Connections - Modelica Libraries 11:30 –Part V Dynamic Optimization (Bernhard Thiele) • Hands-on exercise on dynamic optimization using OpenModelica 12:00 – Exercise Graphical Modeling DCMotor using OpenModelica 7 Copyright © Open Source Modelica Consortium 8 Copyright © Open Source Modelica Consortium Software Installation – Linux (requires internet connection) Software Installation – MAC (requires internet connection) •Go to •Go to https://openmodelica.org/index.php/download/down https://openmodelica.org/index.php/download/down load-mac and follow the instructions or follow the load-linux and follow the instructions. instructions written below. • The installation uses MacPorts. After setting up a MacPorts installation, run the following commands on the terminal (as root): • echo rsync://build.openmodelica.org/macports/ >> /opt/local/etc/macports/sources.conf # assuming you installed into /opt/local • port selfupdate • port install openmodelica-devel 9 Copyright © Open Source Modelica Consortium 10 Copyright © Open Source Modelica Consortium Modelica Background: Stored Knowledge Model knowledge is stored in books and human Part I minds which computers cannot access Introduction to Modelica and a demo example “The change of motion is proportional to the motive force impressed “ –Newton 11 Copyright © Open Source Modelica Consortium 12 Copyright © Open Source Modelica Consortium 2 Modelica Background: The Form – Equations What is Modelica? • Equations were used in the third millennium B.C. A language for modeling of complex cyber-physical systems • Equality sign was introduced by Robert Recorde in 1557 • Robotics • Automotive Newton still wrote text (Principia, vol. 1, 1686) • Aircrafts “The change of motion is proportional to the motive force • Satellites impressed ” • Power plants CSSL (1967) introduced a special form of “equation”: variable = expression • Systems biology v = INTEG(F)/m Programming languages usually do not allow equations! 13 Copyright © Open Source Modelica Consortium 14 Copyright © Open Source Modelica Consortium What is Modelica? What is Modelica? A language for modeling of complex cyber-physical systems A language for modeling of complex cyber-physical systems i.e., Modelica is not a tool Free, open language There exist several free and commercial specification: tools, for example: • OpenModelica from OSMC • Dymola from Dassault systems • Wolfram System Modeler fr Wolfram MathCore • SimulationX from ITI • MapleSim from MapleSoft • AMESIM from LMS • JModelica.org from Modelon Primary designed for simulation, but there are also other Available at: www.modelica.org • MWORKS from Tongyang Sw & Control usages of models, e.g. optimization. Developed and standardized • IDA Simulation Env, from Equa by Modelica Association • ESI Group Modeling tool, ESI Group 15 Copyright © Open Source Modelica Consortium 16 Copyright © Open Source Modelica Consortium Modelica – The Next Generation Modeling Language Modelica Acausal Modeling Declarative language What is acausal modeling/design? Equations and mathematical functions allow acausal modeling, high level specification, increased correctness Why does it increase reuse? Multi-domain modeling The acausality makes Modelica library classes more Combine electrical, mechanical, thermodynamic, hydraulic, reusable than traditional classes containing assignment biological, control, event, real-time, etc... statements where the input-output causality is fixed. Everything is a class Example: a resistor equation: Strongly typed object-oriented language with a general class concept, Java & MATLAB-like syntax R*i = v; Visual component programming can be used in three ways: Hierarchical system architecture capabilities i := v/R; Efficient, non-proprietary v := R*i; Efficiency comparable to C; advanced equation compilation, e.g. 300 000 equations, ~150 000 lines on standard PC R := v/i; 17 Copyright © Open Source Modelica Consortium 18 Copyright © Open Source Modelica Consortium 3 What is Special about Modelica? What is Special about Modelica? Cyber-Physical Modeling Multi-Domain 3 domains Modeling • Multi-Domain Modeling -electric Physical - mechanics • Visual acausal hierarchical component modeling - control • Typed declarative equation-based textual language • Hybrid modeling and simulation Cyber 19 Copyright © Open Source Modelica Consortium 20 Copyright © Open Source Modelica Consortium What is Special about Modelica? What is Special about Modelica? Multi-Domain Visual Acausal Multi-Domain Hierarchical system Visual Acausal Modeling Keeps the physical Hierarchical Modeling modeling Hierarchical structure Component k2 Component i axis6 qddRef cut joint Modeling qdRef qRef k1 r3Control Modeling r3Motor r3Drive1 tn 1 1 i 1 S S qd axis5 Acausal model l qdRef Kd (Modelica) S 0.03 rel joint=0 Jmotor=J spring=c axis4 S pSum Kv sum wSum rate2 rate3 qRef iRef gear=i +1 b(s) 340.8 0.3 - +1 - a(s) S fric=Rv0 axis3 rate1 tacho2 tacho1 b(s) b(s) g5 PT1 a(s) a(s) Causal axis2 Ra=250 q qd Rp2=50 C=0.004*D/w m Rd1=100 Rp1=200 block-based La=(250/(2*D*w m)) Srel = n*transpose(n)+(identity(3)-Rd2=100 n*transpose(n))*cos(q)- axis1 Ri=10 skew(n)*sin(q); - - - + + model wrela = n*qd; diff + pow er zrela = n*qdd; OpI Vs Sb = Sa*transpose(Srel); Rd4=100 (Simulink) r0b = r0a; emf vb = Srel*va; g3 y wb = Srel*(wa + wrela); Rd3=100 g1 x ab = Srel*aa; inertial zb = Srel*(za + zrela + cross(wa,hall2 wrela)); hall1 w r Courtesy of Martin Otter g4 g2 qd q 21 Copyright © Open Source Modelica Consortium 22 Copyright © Open Source Modelica Consortium What is Special about Modelica? What is Special about Modelica? Visual Acausal