Professional Documents
Culture Documents
Lecture01 - Introduction PDF
Lecture01 - Introduction PDF
Object--Oriented
Modeling and Simulation
with Modelica
Peter Fritzson
Linköping University, petfr@ida.liu.se
Mohsen Torabzadeh-
Torabzadeh-Tari
Linköping University, mohto@ida.liu.se
Martin Sjölund
Linköping University, marsj@ida.liu.se
Slides
Based on book and lecture notes by Peter Fritzson
Contributions 2004-2005 by Emma Larsdotter Nilsson, Peter Bunus
Contributions 2007-2008 by Adrian Pop, Peter Fritzson
Contributions 2009 by David Broman, Jan Brugård, Mohsen
Torabzadeh-Tari, Peter Fritzson
Contributions 2010 by Mohsen Torabzadeh-Tari, Peter Fritzson
Peter Fritzson
Principles of Object Oriented
Modeling and Simulation with
Modelica 2.1
Wiley-IEEE Press
940 pages
1
Outline Day 1
Part I Part II
Introduction to Modelica and a Modelica environments
demo example
2
Software Installation
• (If
( you
y have a Mac or Linux computer,
p install
OpenModelica-1.5.0)
Outline
• Introduction to Modeling and Simulation
• Modelica - The next generation modeling and
g g
Simulation Language
• Modeling and Simulation Environments and
OpenModelica
• Classes
• Components, Connectors and Connections
q
• Equations
• Discrete Events and Hybrid Systems
• Algorithms and Functions
• Demonstrations
6 Peter Fritzson Copyright © Open Source Modelica Consortium pelab
3
Why Modeling & Simulation ?
What is a system?
Collector
Storage tank
Hot water
Heater
Electricity
4
Examples of Complex Systems
• Robotics
• Automotive
• Aircrafts
• Satellites
• Biomechanics
• Power plants
• Hardware-in-the-loop,
real-time simulation
Experiments
5
Model concept
Simulation
6
Reasons for Simulation
Dangers of Simulation
7
Building Models Based on Knowledge
System knowledge
• The collected general experience in relevant domains
• The system itself
8
Dynamic vs. Static Models
Input current
pulse
Capacitor voltage - dynamic
time
Continuous-Time vs.
Continuous-
Discrete--Time Dynamic Models
Discrete
Continuous-time models may evolve their variable values
continuously during a time period
Discrete-time variables changeg values a finite number of times
during a time period
Continuous
Discrete
time
9
Quantitative vs. Qualitative Models
Superb
Tasty
Good
Mediocre
time
Level of Abstraction
Experience Feedback
System Maintenance
requirements
Product verification and
Calibration
Specification deployment
Preliminary feature design
Subsystem level integration test
Design calibration and verification
Integration
Architectural design and
Design Subsystem level integration and
system functional design Verification
Refinement verification
Detailed feature design and
implementation Component verification
erification
Realization
10
Principles of Graphical Equation-
Equation-Based Modeling
Component 3
• Physical behavior of a component is
described by equations
• Hierarchical decomposition of components
i
axis6
qddRef cut joint
qdRef
1
qRef
1
k1 r3Control
r3Motor r3Drive1 tn
i 1
S S
qd axis5
qdRef Kd
S
0.03 rel
Jmotor=J joint=0
spring=c axis4
S
qRef pSum Kv sum w Sum rate2 rate3 iRef gear=i
fric=Rv0
+1 b(s) 340.8
0.3
- +1 - a(s) S
axis3
q
qd
Rp2=50
Rd1=100
C=0.004*D/w m Rp1=200 axis1
Rd2=100
Ri=10
- -
-
+ +
diff + pow er
OpI
Vs
Rd4=100
Srel = n*transpose(n)+(identity(3)- n*transpose(n))*cos(q)- emf
y
skew(n)*sin(q);
Rd3=100
x
g3
wrela = n*qd; inertial
zrela = n*qdd; g1
Sb = Sa*transpose(Srel);
hall2
11
GTX Gas Turbine Power Cutoff Mechanism
Developed
Hello
by MathCore
for Siemens
Courtesy of Siemens Industrial Turbomachinery AB
12
Modelica in Avionics
Modelica in Biomechanics
13
Modelica –
The Next Generation
Modeling Language
Stored Knowledge
14
The Form – Equations
• Equations were used in the third millennium B.C.
• Equality sign was introduced by Robert Recorde in 1557
What is Modelica?
• Robotics
R b ti
• Automotive
• Aircrafts
• Satellites
• Power plants
• Systems biology
15
What is Modelica?
What is Modelica?
16
Modelica – The Next Generation Modeling
Language
Declarative language
Equations and mathematical functions allow acausal modeling,
high level specification, increased correctness
Multi-domain modeling
Combine electrical, mechanical, thermodynamic, hydraulic,
biological, control, event, real-time, etc...
Everything is a class
Strongly typed object-oriented language with a general class
concept, Java & MATLAB-like syntax
Visual component programming
Hierarchical system architecture capabilities
Efficient, non-proprietary
Efficiency comparable to C; advanced equation compilation,
e.g. 300 000 equations, ~150 000 lines on standard PC
MATLAB similarities
MATLAB-like array and scalar arithmetic, but strongly typed and
efficiency comparable to C.
Non-Proprietary
• Open Language Standard
• Both
B th Open-Source
O S and
dCCommercial
i l iimplementations
l t ti
17
Modelica Language Properties
Object Oriented
Mathematical Modeling with Modelica
• The static declarative structure of a mathematical
model is emphasized
• OO is primarily used as a structuring concept
• OO is not viewed as dynamic object creation and
sending messages
• Dynamic model properties are expressed in a
declarative way through equations.
• Acausal classes supports better reuse of modeling
and design knowledge than traditional classes
36 Peter Fritzson Copyright © Open Source Modelica Consortium pelab
18
Brief Modelica History
• First Modelica design group meeting in fall 1996
• International group of people with expert knowledge
in both language design and physical modeling
• Industry and academia
• Modelica Versions
• 1.0 released September 1997
• 2.0 released March 2002
• 2.2 released March 2005
• 3 0 released
3.0 l dSSeptember
t b 2007
• 3.1 released May 2009
Modelica Conferences
• The 1st International Modelica conference October, 2000
19
Exercises Part I
Hands--on graphical modeling
Hands
(20 minutes)
Graphical Modeling
Using Drag and Drop Composition
Courtesy
MathCore
Engineering AB
20
Exercises Part I – Basic Graphical Modeling
• (See instructions on next two pages)
• Start the simForge editor
• Draw the RL-Circuit
• Simulate
R1 L
R=10
R=100 L=1
L=0.1
A
C
21
Exercises Part I – simForge Instructions Page 2
• Go to File menu and choose New File. Write RL_circuit and press OK.
• In the Add Class pop-up dialog box change the Type from package to
class and press OK.
• Double click on the RL_circuit under the Modelica classes and the
graphical window will appear.
• Drag and Drop components from the standard Modelica library to your
model.
• For connecting components, move the cursor to the target pin and press
shift+click once and just move the cursor with the mouse to the
destination pin and press again shift+click.
• Under the Edit menu ->
Advanced properties you can
• Start the simulation with simulation button. tick
i k the
h visible
i ibl legend
l d bar.
b
• In the simulation pop-up you can leave out
some fields like the Stop time, which will result
in a default value of 1 sec. will be used.
22