MetaModelica A Unified Equation-Based Semantical and Mathematical Modeling Language

Similar documents
Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages

Towards Run-time Debugging of Equation-based Object-oriented Languages

High Level Mathematical Modeling and Parallel/GRID Computing with Modelica. Peter Fritzson

Towards Unified System Modeling with the ModelicaML UML Profile

Increasing programmability

Modelica Language Concepts. Classes and Inheritance

Vice Chairman of Modelica Association Director of Open Source Modelica Consortium

Modelica. Language, Libraries, Tools, Workshop and EU-Project RealSim

Towards Comprehensive Meta-Modeling and Meta-Programming Capabilities in Modelica

An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications

Meta-Programming with Modelica. Model Transformations

Modeling Kernel Language (MKL)

MathModelica An Extensible Modeling and Simulation Environment with Integrated Graphics and Literate Programming

CIM 2 Modelica Factory

MapleSim User's Guide

GENERATING A MODELICA COMPILER FROM NATURAL SEMANTICS SPECIFICATIONS

Meta-Programming and Language Modeling with MetaModelica 1.0

Modelica Meta-Programming and Symbolic Transformations

MathWorks Technology Session at GE Physical System Modeling with Simulink / Simscape

Towards Modelica 4 Meta-Programming and Language Modeling with MetaModelica 2.0

Physical Modelling with Simscape

Wolfram SystemModeler. Getting Started

The Modelica Object-Oriented Equation-Based Language and Its OpenModelica Environment with MetaModeling, Interoperability, and Parallel Execution

Modelica Based Parser Generator with Good Error Handling

Introduction to Physical Modelling Rory Adams Senior Application Engineer

Simulink Based Robot Arm Control Workstation. Figure 1-1 High Level Block Diagram

OpenModelica Environment and Modelica Overview

Dymola Dynamic Modeling Laboratory

Modelica- A cyber-physical modeling language and the OpenModelica environment

A Portable Debugger for Algorithmic Modelica Code

Oriented Modeling and Simulation with Modelica

OpenModelica Eclipse Plugin and MetaModelica Exercises

Introduction to Object Introduction to Object--Oriented Oriented Modeling, Simulation and Control with Modelica T torial Tut Tu or o ia i l for

Behavioral Model Composition in Simulation-Based Design

Parallel Code Generation in MathModelica / An Object Oriented Component Based Simulation Environment

Model Library Mechanics

Translation of Modelica Code into Hybrid Automata

Rotational3D Efficient modelling of 3D effects in rotational mechanics

Modeling and Simulation of Electromechanical Systems

Predictable Timing of Cyber-Physical Systems Future Research Challenges

Appending Variable-Structure to Modelica Models (WIP)

INTRODUCTION TO OBJECT-ORIENTED MODELING AND SIMULATION WITH MODELICA USING THE OPENMODELICA ENVIRONMENT

OpenModelica Development Environment with Eclipse Integration for Browsing, Modeling, and Debugging

Dymola Dynamic Modeling Laboratory

Components, Connectors and Connections. 1 Peter Fritzson Copyright Open Source Modelica Consortium

Com S 541. Programming Languages I

An Overview of the SysML-Modelica Transformation Specification

sum: tree -> int sum_leaf: tree -> int sum_leaf: tree -> int Representing Trees Next: Lets get cosy with Recursion Sum up the leaf values. E.g.

Vom Konzept zum Modell physikalischer Systeme Smarter Modellieren mit Simscape

Semantics of programming languages

Yacc: A Syntactic Analysers Generator

OpenModelica Compiler (OMC) Overview

OpenModelica Compiler (OMC) Overview

The Montana Toolset: OSATE Plugins for Analysis and Code Generation

THE DESIGNER'S GUIDE TO VERILOG-AMS First Edition June 2004

CS 242. Fundamentals. Reading: See last slide

An Easy-to-use Generic Model Configurator for Models in Multiple Tool Formats

Control Systems Laboratory Manual Hardware and Software Overview. 2 Hardware Equipment. 2.1 Analog Plant Simulator (EE357 Only)

Modeling Technical Systems [ ] Mag MA MA Schweiger Gerald TU Graz Spring 2017

Modeling physical properties. Controller, plant and environment model

COMPILERS AND INTERPRETERS Lesson 4 TDDD16

The Language for Cyber-Physical Systems

Semantics of programming languages

This is the published version of a paper presented at IEEE PES General Meeting 2013.

200W ISCM4805 / 8005 INTELLIGENT SERVO CONTROL MODULES FEATURES DIGITAL MOTOR CONTROL FOR BRUSHLESS, DC BRUSH, LINEAR AND STEP MOTORS

IBL2401 INTELLIGENT SERVO DRIVE DIGITAL DRIVE FOR BRUSHLESS, DC BRUSH, LINEAR AND STEP MOTORS 25W FEATURES

Semantics of programming languages

COP 3402 Systems Software Syntax Analysis (Parser)

Computer Simulation And Modeling

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Estimation of Model Parameters Using Limited Data for the Simulation of Electric Power Systems

Quick Start Training Guide

DSP-BASED MOTOR CONTROLLER FOR THREE-PHASE BRUSHLESS DC MOTORS

EXPRESSING REQUIREMENTS IN MODELICA

What Is SimMechanics?

Contents. Chapter 1 SPECIFYING SYNTAX 1

AN INTEGRATED MODELICA ENVIRONMENT FOR MODELING, DOCUMENTATION AND SIMULATION

Υπολογιστικά πειράματα με το MATLAB Σύνδεση με Arduino & Raspberry Pi Ζαχαρίας Γκέτσης Μηχανικός Εφαρμογών

Recap: Functions as first-class values

MWorks: a Modern IDE for Modeling and Simulation of Multidomain Physical Systems Based on Modelica

When Modeling meets Productivity. Sven Efftinge - itemis

Denotational Semantics. Domain Theory

2015 The MathWorks, Inc. 1

Determining Over- and Under-Constrained Systems of Equations using Structural Constraint Delta

Modelica: An International Effort to Design the Next Generation Modelling Language

A conceptual framework for building good DSLs. Markus Voelter independent/itemis

Using Modelica for Interactive Simulations of Technical Systems in a Virtual Reality Environment

What s inside your experiment kit: Checklist: Find Inspect Check off KIT CONTENTS. GOOD TO KNOW! If you are missing any. No. Description Qty. Item No.

The OpenModelica Modeling, Simulation, and Development Environment

TERRA support for architecture modeling. K.J. (Karim) Kok. MSc Report. C e Dr.ir. J.F. Broenink Z. Lu, MSc Prof.dr.ir. A. Rensink.

TDDD55 - Compilers and Interpreters Lesson 3

Model driven Engineering & Model driven Architecture

TDDD55- Compilers and Interpreters Lesson 3

OMEdit OpenModelica Connection Editor

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

CIM-Compliant Model-to-Model Transformation

Simulation and Verification of Timed and Hybrid Systems

Overall Sequential Design Flow. VHDL, Verilog, C?, C++?, Java? CS150 Spring 98 R. Newton & K. Pister CS150 Newton/Pister. Behavioral.

LOGIC AND DISCRETE MATHEMATICS

6.1 Combinational Circuits. George Boole ( ) Claude Shannon ( )

Transcription:

MetaModelica A Unified Equation-Based emantical and Mathematical Modeling Language Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information cience Linköping University 2006-09-14 JMLC 2006, eptember 13-15, Oxford, UK

Outline Modelica Introduction Language properties Example MetaModelica Motivation MetaModelica extensions to Modelica Example Future Work Conclusions 2

Modelica General Formalism to Model Complex ystems Robotics Automotive Aircrafts atellites Biomechanics Power plants Hardware-in-the-loop, real-time simulation etc 3

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 trongly typed object-oriented language with a general class concept, Java & Matlab like syntax Visual component programming Hierarchical system architecture capabilities Efficient, nonproprietary Efficiency comparable to C; advanced equation compilation, e.g. 300 000 equations 4

Declarative and Object-Oriented Modelica Language Properties Equation-based; continuous and discrete equations Parallel process modeling of concurrent applications, according to synchronous data flow principle Functions with algorithms without global side-effects (but local data updates allowed) Type system inspired by Abadi/Cardelli (Theory of Objects) Everything is a class Real, Integer, models, functions, packages, parameterized classes... 5

Modelica Background The Form - Equations Equations were used in the third millenium B.C. Equality sign was introduced by Robert Recorde in 1557 Newton (Principia, vol. 1, 1686) still wrote text: The change of motion is proportional to the motive force impressed;... d dt ( m v) = Fi CL (1967) introduced special form of equation : variable = expression v = INTEG(F) / m Programming languages usually do not allow equations 6

Modelica Acausal Modeling emantics What is acausal modeling/design? Why does it increase reuse? The acausality makes Modelica classes more reusable than traditional classes containing assignment statements where the input-output causality is fixed. Example: a resistor equation: R*i = v; can be used in three ways: i := v/r; v := R*i; R := v/i; 7

Modelica - Reusable Class Libraries Info R= C= L= G Info bar= body= bodybar= AC= DC= Info Vs shaft= shaft3d= Is shaft3d= gear2= shaft= inertial cylbody=bodyhape= rev= prism= screw = cyl= D T - + diff= Op V gear1= i planet= planetary= ring= univ planar= sphere free rev= prism= : 1 bearing sun= fixtooth cyl= univ planar= sphere free E move move screw = c= d= barc= y spherec c= d= cer= torque fric= C x barc2= C frictab clutch= converter r force torque lineforce= linetorque= sensor lineensor s sd w a t fixedbase advanced Library drive Library translation Library state 8

Graphical Modeling - Drag and Drop Composition 9

Hierarchical Composition Diagram for a Model of a Robot k2 i qddref qdref 1 qref 1 k1 i r3control r3motor r3drive1 1 cut joint qd tn axis6 axis5 l qdref Kd 0.03 rel qref pum - Kv 0.3 sum +1 +1 wum - rate2 b(s) a(s) rate3 340.8 iref Jmotor=J spring=c fric=rv0 gear=i joint=0 axis4 axis3 rate1 tacho2 tacho1 b(s) a(s) b(s) a(s) PT1 g5 axis2 q Rd2=100 Vs qd Rd3=100 hall2 g2 Rd1=100 - + diff Ri=10 qd Rp2=50 C=0.004*D/w m Rp1=200 - + pow er - rel = n*n' + (identity(3) - n*n')*cos(q) - skew(n)*sin(q); + wrela = n*qd; OpI zrela = n*qdd; Rd4=100 b = a*rel'; emf r0b = r0a; g3 vb = rel*va; g1 wb = rel*(wa + wrela); ab = rel*aa; zb = rel*(za + zrela + cross(wa, wrela)); fa = rel'*fb; ta = rel'*tb; hall1 g4 w Ra=250 La=(250/(2*D*w m)) q r axis1 y x inertial 10

Multi-Domain Modelica Model - DCMotor A DC motor can be thought of as an electrical circuit which also contains an electromechanical component. model DCMotor Resistor R(R=100); Inductor L(L=100); VsourceDC DC(f=10); Ground G; ElectroMechanicalElement EM(k=10,J=10, b=2); Inertia load; equation R connect(dc.p,r.n); connect(r.p,l.n); DC connect(l.p, EM.n); connect(em.p, DC.n); connect(dc.n,g.p); connect(em.flange,load.flange); G end DCMotor L EM load 11

Modelica compilation stages Modelica ource Code Modelica model Translator Flat model Analyzer Topologically sorted equations Optimizer Code Generator Optimized sorted equations C code C Compiler Executable imulation 12

Corresponding DCMotor Model Equations The following equations are automatically derived from the Modelica model: (load component not included) 13

Connector Classes, Components and Connections connector Pin Voltage v; flow Current i; end Pin; Keyword flow indicates that currents of connected pins sums to zero. Connection between Pin1 and Pin2 A connect statement in Modelica connect(pin1,pin2) corresponds to Pin1.v = Pin2.v Pin1.i + Pin2.i = 0 14

Common Component tructure as uperclass model TwoPin uperclass of elements with two electrical pins Pin p,n; Voltage v; Current i; equation v = p.v n.v; 0 = p.i + n.i; i = p.i; end TwoPin; 15

Electrical Components Reuse TwoPin uperclass model Resistor Ideal electrical resistor extends TwoPin; parameter Real R Resistance ; equation R*i = u end Resistor; model Inductor Ideal electrical inductor extends TwoPin; parameter Real L Inductance ; equation L*der(i) = u end Inductor; 16

Corresponding DCMotor Model Equations The following equations are automatically derived from the Modelica model: (load component not included) 17

MetaModelica - Context yntax - there are many efficient parser generator tools lex (flex), yacc (bison), ANTLR, Coco, etc. emantics: there are no standard efficient and easy to use compiler-compiler tools 18

MetaModelica - Motivation Can we adapt the Modelica equation-based style to define semantics of programming languages? Answer: Yes! MetaModelica is just a part of the answer executable language specification based on a model (abstract syntax tree) semantic functions over the model elaboration and typechecking translation meta-programming transformation etc. Further improvement more reuse of language specification parts when building specifications for a new language (Future Work) 19

MetaModelica - Idea We started from The Relational Meta-Language (RML) A system for building executable natural semantics specifications Used to specify Java, Pascal-subset, C-subset, Mini-ML, etc. The OpenModelica compiler for Modelica specified in RML Idea: integrate RML meta-modeling and metaprogramming facilities within OpenModelica by extending the Modelica language. The notion of equation is used as the unifying feature Now we have The MetaModelica language The Modelica executable language specification (OpenModelica compiler) in MetaModelica (~114232 lines of code) Meta-programming facilities for Modelica 20

MetaModelica extensions to Modelica (I) Modelica classes, models, records, functions, packages behaviour is defined by equations or/and functions equations differential equations algebraic equations partial differential equations difference equations conditional equations MetaModelica extensions local equations pattern equations match expressions lists, tuples, option and uniontypes 21

MetaModelica extensions to Modelica (II) pattern equations unbound variables get their value by unification Env.BOOLVAL(x,y) = eval_something(env, e); match expressions pattern matching case rules pattern := match expression optional-local-declarations case pattern-expression opt-local-declarations optional-local-equations then value-expression; case...... else optional-local-declarations optional-local-equations then value-expression; end match; 22

MetaModelica Example (I) package ExpressionEvaluator // abstract syntax declarations... // semantic functions... end ExpressionEvaluator; 23

MetaModelica Example (II) package ExpressionEvaluator PLU // abstract syntax declarations uniontype Exp record RCONT Real x1; end RCONT; 12 record PLU Exp x1; Exp x2; end PLU; record UB Exp x1; Exp x2; end UB; record MUL Exp x1; Exp x2; end MUL; record DIV Exp x1; Exp x2; end DIV; record NEG Exp x1; end NEG; end Exp; // semantic functions... end ExpressionEvaluator; RCONT RCONT 5 MUL RCONT 13 Expression: 12+5*13 Representation: PLU( RCONT(12), MUL( RCONT(5), RCONT(13) ) ) 24

MetaModelica Example (III) package ExpressionEvaluator // abstract syntax declarations... // semantic functions function eval input Exp in_exp; output Real out_real; algorithm out_real := match in_exp local Real v1,v2,v3; Exp e1,e2; case RCONT(v1) then v1; case ADD(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 + v2; then v3; case UB(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 - v2; then v3; case MUL(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 * v2; then v3; case DIV(e1,e2) equation v1 = eval(e1); v2 = eval(e2); v3 = v1 / v2; then v3; case NEG(e1) equation v1 = eval(e1); v2 = -v1; then v2; end match; end eval; end ExpressionEvaluator; 25

Modelica/MetaModelica Development Tooling (MDT) upports textual editing of Modelica/MetaModelica code as an Eclipse plugin Was created to ease the development of the OpenModelica development (114232 lines of code) and to support advanced Modelica library development It has most of the functionality expected from a Development Environment code browsing code assistance code indentation code highlighting error detection automated build of Modelica/MetaModelica projects debugging 26

Modelica/MetaModelica Development Tooling Code Assistance on function calling. 27

Conclusions and Future Work MetaModelica a language that integrates modeling of physical systems programming language semantics at the equation level MetaModelica is a step towards reusable libraries of specifications for programming language semantics Future Work How do devise a suitable component model for the specification of a programming language semantics in terms of reusable components. Tools to support such language modeling. 28

End Thank you! Questions? http://www.ida.liu.se/labs/pelab/rml http://www.ida.liu.se/labs/pelab/modelica/openmodelica.html 29