Modelica — the New Object-Oriented Modeling Language
Total Page:16
File Type:pdf, Size:1020Kb
The 12th European Simulation Multiconference, ESM'98, June 16--19, 1998, Manchester, UK MODELICA — THE NEW OBJECT-ORIENTED MODELING LANGUAGE Hilding Elmqvist Sven Erik Mattsson Martin Otter Dynasim AB Department of Automatic Control DLR Oberpfaffenhofen Research Park Ideon Lund Institute of Technology D-82230 Wessling, Germany SE-223 70 Lund, Sweden Box 118, SE-221 00 Lund, Sweden E-mail: [email protected] E-mail: [email protected] E-mail: [email protected] KEYWORDS body systems, drive trains, hydraulics, thermodynami- cal systems, and chemical processes etc. It supports sev- Modelica, modeling language, object-orientation, hierar- eral formalisms: ordinary differential equations (ODE), chical systems, differential-algebraic equations differential-algebraic equations (DAE), bond graphs, fi- nite state automata, and Petri nets etc. Modelica is in- ABSTRACT tended to serve as a standard format so that models arising in different domains can be exchanged between A standardized language for reuse and exchange of tools and users. models is needed. An international design group has designed such a language called Modelica. Modelica is This paper gives an introduction to Modelica by means a modern language built on non-causal modeling with of an example. An overview of the work on supporting mathematical equations and object-oriented constructs libraries and the plans for further development is given. to facilitate reuse of modeling knowledge. Another aim of the paper is to interest individuals to participate in developing Modelica further. INTRODUCTION MODELICA BASICS Modeling and simulation are becoming more important since engineers need to analyse increasingly complex As an introduction to Modelica, consider modeling of systems often composed of subcomponents from differ- a simple motor drive system as defined in Fig. 1. The ent domains. Typical examples comes from mechatronic system can be broken up into a set of connected compo- systems within automotive, aerospace and robotics ap- nents: an electrical motor, a gearbox, a load and a con- plications. Such systems are composed of components trol system. A Modelica model of the motor drive system from domains like electrical, mechanical, hydraulical, is given in Fig. 2. It is a composite model which speci- control, etc. Today’s tools are generally weak in treat- fies the topology of the system to be modeled in terms of ing such multi-domain models because the general tools components and connections between the components. are block-oriented and thus demand a huge amount of The statement “ Gearbox gearboxn=100;” declares a Gearbox manual rewriting to get the equations into explicit form. component gearbox of class and sets the de- fault value of the gear ratio, n, to 100. There is too large a gap between the user’s problem and the model description that the simulation program Much of the Modelica syntax is normally hidden from understands. Modeling should be much closer to the the end-user. Models of standard components are typ- way an engineer builds a real system, first trying ically available in model libraries. Using a graphical to find standard components like motors, pumps and model editor, a model can be defined by drawing a model valves from manufacturers’ catalogues with appropriate diagram as shown in Fig. 1, by positioning icons that specifications and interfaces. Only if there does not exist represent the models of the components, drawing con- a particular subsystem, the engineer would actually nections and giving parameter values in dialogue boxes. construct it. Constructs for including graphical annotations in Mod- elica make icons and model diagrams portable. Reuse is a key issue for handling complexity. There have been several attempts to define object-oriented lan- A component model may be a composite model to guages for physical modeling. However, the ability to support hierarchical modeling. The object diagram of reuse and exchange models relies on a standardized for- the model class Motor is shown in Fig. 3. mat. It was thus important to bring this expertise to- gether and unify the concepts and notations. A language controller design group was thus formed in September 1996 and wr motor Jl=10 one year later the Modelica1 language was available. PI Modelica is intended for modeling within many ap- n=100 wl plication domains such as electrical circuits, multi- 1ModelicaTM is a trade mark of the Modelica Design Group Figure 1 Schematic picture of a motor drive. 1 model MotorDrive second corresponds to Kirchhoff’s current law saying motor; Motor that the current sums to zero at a node. Similar laws controller; PI apply to flow rates in a piping network and to forces gearboxn=100; Gearbox and torques in a mechanical system. The sum-to-zero Shaft JlJ=10; equations are generated when the prefix flow is used Tachometer wl; equation in the connector declarations. connectcontroller.out, motor.in; , gearbox.a; connectmotor.flange Partial models and inheritance , Jl.a; connectgearbox.b A very important feature in order to build reusable , wl.a; connectJl.b descriptions is to define and reuse partial models.A , controller.in; connectwl.w common property of many electrical components is that end MotorDrive; they have two pins. This means that it is useful to define p an interface model class TwoPin, that has two pins, Figure 2 A Modelica model of the system in Fig. 1. v and n, and a quantity, , that defines the voltage drop across the component. Variables partial model TwoPin Physical modeling deals with specifying relations be- Pin p, n; tween physical quantities. For the drive system, quan- Voltage v; tities such as angle and torque are of interest. Their equation p.i + n.i = 0; types are declared in Modelica as v = p.v - n.v; end TwoPin; = Realquantity = "Angle", type Angle unit = "rad", The equations define common relations between quanti- displayUnit = "deg"; ties of a simple electrical component. The keyword par- type Torque = Realquantity = "Torque", tial indicates that the model class is incomplete. To be unit = "N.m"; useful, a constitutive equation must be added. To define a model for a resistor, start from TwoPin and add a pa- where Real is a predefined type, which has a set of attributes such as name of quantity, unit of measure, rameter for the resistance and Ohm’s law to define the default display unit for input and output, minimum behavior. value, maximum value and initial value. model Resistor "Ideal resistor" extends TwoPin; Connectors and Connections parameter Resistance R; equation Connections specify interactions between components. A connector should contain all quantities needed to R*p.i = v; end Resistor; describe the interaction. Voltage and current are needed for electrical components. Angle and torque are needed A string between the name of a class and its body is for drive train elements. treated as a comment attribute. Tools may display this Flange connector Pin connector documentation in special ways. The keyword param- Angle r; Voltage v; eter specifies that the quantity is constant during a Torque t; flow Current i; flow simulation experiment, but can change values between Flange; end Pin; end experiments. For the mechanical parts, it is also useful to define a Pin1 A connection, connectPin1, Pin2, with and shell model with two flange connectors, Pin Pin2 of connector class , connects the two pins such that they form one node. This implies two equations, partial model TwoFlange Flange a, b; Pin1.i + Pin2.i = 0 namely Pin1.v = Pin2.v and . The first equation indicates that the voltages on both end TwoFlange; branches connected together are the same, and the A model of a rotating inertia is given by model Shaft La=0.05 extends TwoFlange; Ra=0.5 parameter Inertia J = 1; AngularVelocity w; Jm=1.0E-3 equation Vs a.r = b.r; emf dera.r = w; J*derw = a.t + b.t; end Shaft; w Figure 3 A motor model. where derw means the time derivative of . 2 THE IDEAS BEHIND MODELICA ADVANCED MODELING FEATURES Among the recent research results in modeling and The modeling power of Modelica is large. Modeling of, simulation the two concepts object-oriented and non- for example, multi-body systems and control systems causal modeling have had a strong impact on the Mod- is done conveniently by utilizing matrix equations.Itis elica design. A new attempt at introducing interop- also possible to have arrays of components and to define erability and openness to the world of modeling and regular connection patterns. Reuse of model library simulation systems is justified by the combined power components is further supported by allowing model of the two concepts together with proven technology class parameters. from existing modeling languages such as ASCEND Modelica supports hybrid modeling. Realistic physical [Piela et al. (1991)],Dymola[Elmqvist et al. (1996)], models often contain discontinuities, discrete events or gPROMS [Barton and Pantelides (1994)],NMF[Sahlin changes of structure. Examples are relays, switches, et al. (1996)], ObjectMath [Fritzson et al. (1995)], friction, impact, sampled data systems etc. Algorithms Omola [Mattsson et al. (1993)], SIDOPS+[Breunese and functions are supported in Modelica for modeling and Broenink (1997), Smile [Kloas et al. (1995)], U.L.M. parts of a system in procedural programming style. [Jeandel et al. (1996)] and VHDL-AMS [IEEE (1997)]. Non-Causal Modeling STANDARD LIBRARIES In Modelica it is possible to write balance and other In order that Modelica is useful for model exchange,it equations in their natural forms as a system of is important that libraries of the most commonly used differential-algebraic equations (DAE). Modelica has components are available, ready to use, and sharable been carefully designed in such a way that computer between applications. For this reason, an extensive algebra can be utilized to achieve as efficient simula- Modelica base library is under development which tion code as if the model would be converted to ODE will become an intrinsic part of Modelica.