Professional Documents
Culture Documents
Chris Paredis
Objectives
Become familiar with the Modelica Language
Classes Connectors Variables, Parameters, Constants Equations Operators If and when clauses
Scope
This is not a comprehensive overview of Modelica Mindset: You will copy and modify existing models Other sources for help:
By example look at other existing models in the standard library Brief documentation in "Modelica Reference" (top package in browser) Modelica tutorial: Help / Documentation / Modelica Tutorial Modelica specification: Help / Documentation / Modelica Specification ReadingMaterial section B
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 3
Modelica
model Damper "Linear 1D translational damper" extends Interfaces.Compliant; parameter Real d ( final unit= "N/ (m/s)", final min=0) = 0 "damping constant"; SI.Velocity v_rel "relative velocity between flange_a and flange_b"; equation v_rel = der(s_rel); d*v_rel = f; end Damper;
Class consists of declaration + equations Specify the default value for parameters Modelica is case sensitive Objects are declared as instances of classes Equations are acausal Use dot-notation to refer to object variables
6
This model is abstract and cannot be instantiated Comments appear in parameter dialog and results browser
Connectors
Can include only declarations no equations allowed "Through variables" are preceded by the keyword "flow" Why is this important? There may be multiple across and through variables Refer to a specific connector's variables using the dot-notation
connector Flange "1D translational flange" SI.Position s "absolute position of flange"; flow SI.Force f "cut force directed into flange"; end Flange;
Constants
constant keyword, followed by type, name, value
constant Real g = 9.81 "gravity";
Parameters
parameter keyword, followed by type, name, default value
parameter Real C = 1 "Capacitance";
Needs to be "square"
Number of equations = number of variables (constants and parameters are not variables)
12
Modelica Operators
Complete list in Modelica Reference
Logical: and, or, not, ==, <> Mathematical: abs(.), ceil(.), floor(.), sign(.), sqrt(.), min(.,.), max(.,.), Matrices: cross(.,.), diagonal(.), ones(.), zeros(.), size(.), Events: change(.), edge(.), pre(.), reinit(.), noEvent(.), smooth(.) Time related: initial(), terminate(.) Error checking: assert(.,.)
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 13
Expression
equation y = if linear then x + 1 else (if quad then x^2 + x + 1 else Modelica.Math.sin(x));
14
When Clause
Should be read as: "When condition becomes true then do" pre(.) is the value right before the condition became true Why is pre(.) not needed in algorithm?
[] Boolean u_pos = u>=0; algorithm when change(u_pos) then []
2008-2012 Copyright Georgia Tech. All Rights Reserved.
model ZeroCounter import Modelica.Blocks.*; Interfaces.RealInput u; Interfaces.IntegerOutput y; equation when u>=0 then y = pre(y) + 1; end when; end ZeroCounter; [] algorithm when u>=0 then y := y + 1; end when; end ZeroCounter;
15
I
s>0
s<0
s=0
Vth
Modeling assumptions
No resistance Linearity
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 16
Summary
Introduced the Modelica Language
Classes Connectors Variables, Parameters, Constants Equations Operators If and when clauses
18
Model gravity
Gravity is only applied to masses
Simulate
Winch drum with diameter = 0.3m Cable compliance per length = 1e-4 (m/N)/m (very flexible to make it interesting) Driven by the DC motor from HW1 After 1 second, connected to 60V battery Lifting mass of 100kg Mass starts 10m below winch; 10m of cable unwound Stop simulation when mass is at 1m below winch
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 19
Further Reading
Peter Fritzson, Principles of Object-Oriented Modeling and Simulation with Modelica 2.1, Wiley-IEEE Computer Society Press, 2003. (ISBN: 047147163) Modelica Tutorial
http://www.modelica.org/documents/ModelicaTutorial14.pdf Should contain everything you need to know
Modelica Specification
http://www.modelica.org/documents/ModelicaSpec22.pdf Advanced reference document
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 20
Solutions
21
Simulation Model
dCMotor cableWinch=0...
stepVoltage
ground
+ -
fixed
fixed1=0
slidingMassGravity
22
Winch Model
Modify Modelica.Mechanics.Rotational.IdealGearR2T
Modifications are high-lighted in red
model Winch "Winch with flexible cable" parameter Modelica.SIunits.Length R = 0.2 "Radius of winch drum"; parameter Real c(final unit="(m/N)/m", final min=0) = 1e-6 "Cable compliance per unit length"; parameter Modelica.SIunits.Length L0=0 "initial length of unwound cable"; Modelica.SIunits.Length length "rest length of unwound cable"; Modelica.SIunits.Length stretchedLength "stretched length of cable"; Modelica.SIunits.Torque tau_support; Modelica.SIunits.Force f_support; // NOTE: "initial equations" are enforced only at start of simulation initial equation length = L0; stretchedLength = L0;
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 23
Winch Continued
equation // make sure the length never goes to zero because that would // result in a singularity assert(length>0,"length of unwound cable must be positive"); // distance between translational connectors is the stretched length stretchedLength = bearingT.s - flange_b.s; // the equation for cable strain c*f_support = (stretchedLength-length)/length; // relate the angle to the length (flange_a.phi - bearingR.phi) = -length/R; 0 = flange_a.tau/R + flange_b.f; 0 = flange_a.tau + tau_support; 0 = flange_b.f + f_support; [] end Winch;
24
25
Simulation Model
model WinchTest Components.Winch cableWinch(L0=10, R=0.15, c=1e-4); ElectricVehicle.Components.DCMotor dCMotor; Modelica.Electrical.Analog.Basic.Ground ground; Components.SlidingMassGravity slidingMassGravity(m=100); Modelica.Mechanics.Translational.Fixed fixed; Modelica.Mechanics.Rotational.Fixed fixed1; Modelica.Electrical.Analog.Sources.StepVoltage stepVoltage(V=60, startTime=1); equation connect(dCMotor.flange_b, cableWinch.flange_a); connect(cableWinch.flange_b, slidingMassGravity.flange_a); connect(fixed.flange_b, cableWinch.bearingT); connect(fixed1.flange_b, cableWinch.bearingR); connect(stepVoltage.n, ground.p); connect(stepVoltage.p, dCMotor.pin_n); connect(stepVoltage.n, dCMotor.pin_p); algorithm when cableWinch.length <= 1 then Add this to stop the terminate("mass reached top"); simulation end when; end WinchTest;
2008-2012 Copyright Georgia Tech. All Rights Reserved. ASE 6002: Systems Design and Analysis 26
Alternative Approach
y
world
actuatedPris... n={0,1,0}
dCMotor
cableWinch=0...
stepVoltage
ground
m=100
+ -
fixed1=0
pointMass
27