Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical...

49
Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source Modelica Consortium Programming Environment Laboratory Department of Computer and Information Science Linköping University 2009-02-02 2010-02-08 www.OpenModelica.org

Transcript of Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical...

Page 1: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

Technical Overview of OpenModelica and its Development Environment

Adrian Pop

Open Source Modelica ConsortiumProgramming Environment Laboratory

Department of Computer and Information ScienceLinköping University

2009-02-02

2010-02-08

www.OpenModelica.org

Page 2: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

2

Outline

OpenModelicaWhat is OpenModelica?The past and present

OpenModelica Technical OverviewOMC, OMShell, OMNotebook, SimForge

OpenModelica Development EnvironmentMetaModelicaThe Eclipse Environment

OpenModelica Latest Developments (2009-2010)

Page 3: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

3

What is OpenModelica? (I)Advanced Interactive Modelica compiler (OMC)

Supports most of the Modelica Language v. 2.2 and v. 3.1

Basic environments for creating modelsOMShell – an interactive command handlerOMNotebook – a literate programming notebookMDT – an advanced textual environment in Eclipse

Page 4: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

4

What Is OpenModelica? (II)Advanced Eclipse-based Development EnvironmentModelica Development Tooling (MDT) - started in 2005

Code Assistance, Debugging, Outline & a lot moreNow working on UML/SysML integration and better debuggingUsed heavily for OpenModelica developmentUsed in 6 OpenModelica Development Courses (INRIA, PELAB)

Page 5: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

5

What is OpenModelica? (III)Open-source community services

Website and Support ForumVersion-controlled source baseBug database (unfortunately)Development courses

Page 6: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

6

What is OpenModelica? (IV)

An incubator platform for research 4 PhDs since 2004 (Debugging, Parallelization, PDEs Extensions)15 Master’s theses since 2004Both the students and the project benefit

Master theses at PELAB 2006-2010Refactoring/Parsing and Language extensionsUML/SysML view of Modelica code2D and 3D visualization toolsStatic and runtime debugging toolsAdvanced code generation and parallelization of simulation codeBootstrapping and Java InterfaceFunction pointers NVIDIA Cuda parallel simulation

External Master thesesModel based diagnostics at ISY (Dep. Of Electrical Engineering)Monte-Carlo simulation of Satellite Separation Systems at SAABInteractive Simulations (EADS)Additional Solvers + Event handling (FH-Bielefeld)

A Base for commercial and open source productsMathCore AB, Bosch Rexroth, InterCAX (MagicDraw SysML), VTT

Page 7: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

7

OpenModelica Roadmap - Past1997 - started as a master thesis 2003 – first usable internal version2004 – first external version: OpenModelica 1.12005 – more development: OpenModelica 1.3.1

2006 – major milestoneTranslated the whole compiler to MetaModelicaIntegrated Development Environment for the compilerOpenModelica website startedMoved the code repository to Subversion managementExtended the OpenModelica environment with new tools4 versions released during the yearExternal people start using OpenModelica

~ 200 downloads/monthfirst development course at INRIA

Page 8: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

8

OpenModelica Roadmap - Past2007 – continued development and community involvement

Improvement in website, support and documentationAnswered ~1000 questions on the forumPortability is highly improved, ported to 4 platforms

Linux, Mac, Solaris, Windows (version 1.4.3)

Improvement of the compiler development tools in EclipseOpenModelica Community starts to react

contribute code & report bugs & request enhancements & participate in answering questions in the OpenModelica forumparticipate at courses and workshops

New server acquired for better community servicesIncreased usage: ~600 downloads/monthOpen Modelica Consortium created in December 4

4 months of work9 organizations as members already (3 Universities, 6 Companies)discussions are ongoing with other 6 companies

Page 9: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

9

OpenModelica Roadmap - Past

2008 – Further work on the compilerRelease 1.4.4 and 1.4.5

Linux, Mac, Solaris, Windows

New Solver InterfaceRefactoringDynamic loading of functionsMerging of MathCore front-end code744 commits in SubversionMuch more other things I don’t remember

Page 10: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

10

OpenModelica Roadmap – Past & Present2009 – 2010

Work mainly happened in OSMC (partially on a non-public branch)Front-end

Refactoring (OSMC)Enumerations (OSMC)Java Interface and Booststrapping (Martin Sjölund)MultiBody flattening (OSMC)Braking of constraint connection graph (VTT + OSMC)Support for Modelica 3.x and 3.x annotations (OSMC)

Back-endTearing in the back-end (Jens Frenkel)Template Code Generation and CSharp backend (Pavol Privitzer, Charles University Prague)Interactive Simulations (EADS)C++ Code generation (Bosch Rexroth)Java Interface and Booststrapping (Martin Sjölund)Additional Solvers + Events (Willi Braun, FH-Bielefeld)

GeneralNew MDT based on Xtext (Antanas Pavlov, SysMO and BMW)New ModelicaML + SysML prototype (EADS)1144 commits in subversion (Since 2009 to February 8, 2010)Bug fixes (OSMC)Release 1.5.0 and 1.5.0-RC_X (Linux, Mac, Solaris, Windows)

More things I don’t remember

Page 11: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

11

OpenModelica Statistics (I)

Mature code base~ 1000K lines of code, doubled since 2005

Page 12: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

OpenModelica Statistics (II)

12

Page 13: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

OpenModelica Statistics (III)

13

Page 14: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

14

Outline

OpenModelicaWhat is OpenModelica?The past and present

OpenModelica Technical OverviewOMC, OMShell, OMNotebook, SimForge

OpenModelica Development EnvironmentMetaModelicaThe Eclipse Environment

OpenModelica Latest Developments (2009-2010)

Page 15: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

15

OMShell & OMNotebook

Demo?

Page 16: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

16

SimForge - Demo? Maybe a movie!

Page 17: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

17

The OMC CompilerImplemented mainly in MetaModelica and C/C++The compiler has 91 packages (in my local working copy)

SCode/explode

Lookup

Parse DAELowInst

Ceval

Static

Absyn SCode DAE: Equations

Algorithms

(Env, name)SCode.Class

Exp.Exp

SCode.Exp(Exp.Exp,

Types.Type)

(Env, name)

Mod Connect

Derive

CodeGen

VarTransform

ClassInf

Prefix

SimCodeGen

DAE: Functions

Absyn

Data Type Modules:

SCode

Types

Algorithm

DAE

Exp

DAEEXT

Dump

Utility Modules:

Debug

ModUtil

SystemPrint RTOpts

Builtin

DAELow.DAELow

C code

DAE, substlist

DAEExp.Exp Exp.Exp

ClassInf.Event

Exp.Ident Prefix.Prefix

Types.Mod SCode.Mod Exp.Componentref DAE

ClassInf.State

.mo

Main

Util

ClassLoader

DumpDAEFlat Modelica

MetaUtil

DFA

Patternm

Values.Value

Exp.Exp

Page 18: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

18

Modelica->AST->SCode->DAE->C Code

// Parse the file and get an AST backast = Parse.parse(modelicaFile);

// Elaborate the filescode = SCode.elaborate(ast);

// instantiate the simplified code(cache, dae1) = Inst.instantiate(Env.emptyCache, scode);

// Transform all if equations to if expressionsdae2 = DAE.transformIfEqToExpr(dae1);

// Retrieve the last class name from the AST. This class will be instantiated.lastClassName = Absyn.lastClassname(ast);

// Call the function that optimizes the DAEoptimizeDae(scode, ast, dae, dae, lastClassName);

Page 19: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

19

Simulation Runtime Overview

Two libraries:libc_runtime.a

Runtime used by the generated functions in the modelLinked with the model

libsim.aRuntime used for simulations, it contains solver implementations and a main function for the simulation

Page 20: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

20

Simulation Runtime Main

OMC Generated CodeOMC Simulation Runtime Library

globalData = initializeDataStruc(FLAGS);setLocalData(globalData);read_input(globalData, simParams);switch (method)“dassl”: dassl_main(simParams);“euler”: euler_main(simParams);

deInitializeDataStruct(DATA, FLAGS);

main: simulation_runtime.cpp

Executable Model

initializeDataStruc

DATA *globalData: simulation_runtime.h DATA *localData

setLocalData

simParams:start,stop,stepSize,outputSteps,tolerance, method

deInitializeDataStruc

dassl_main: solver_dasrt.cpp

euler_main: solver_euler.cpp

read_input: simulation_input.cpp

Page 21: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

21

Simulation Runtime SolverOMC Generated CodeOMC Simulation Runtime Library

// set the solver parameters and calculate step from simParamsinitializeEventData(); initializeResult(numpoints, globalData);bound_parameters(); initial_function();storeExtrapolationData(); initialize(init_method);function_updateDependents();CheckForInitialEvents(globalData->timeValue);StartEventIteration(globalData->timeValue);// calculate initial derivativesfunctionODE();// calculate initial output valuesfunctionDAE_output(); functionDAE_output2();// take a tiny steptout = globalData->timeValue + epsilon;function_updateDependents(); saveall(); emit();calcEnabledZeroCrossings();// call the solver for that tiny stepDDASTR(functionDAE_res, function_zeroCrossing, jroot);checkForInitialZeroCrossings(jroot);// check if we can continue the simulation functionDAE_res(globalData); functionDAE_output();// calculate the next steptout = newTime(tout, step, stop);// enter solver loop

dassl_main: solver_dasrt.cpp

initializeDataStruc

setLocalDatadeInitializeDataStruc

DATA *globalData: simulation_runtime.h DATA *localDatasimParams:start,stop,stepSize,outputSteps,tolerance, method

bound_parametersinitial_functionfunctionODEfunctionDAE_outputfunctionDAE_output2function_updateDependentsfunctionDAE_resfunction_zeroCrossing

storeExtrapolationData: simulation_runtime.cppinitializeResult: simulation_result.cppemit: simulation_result.cppinitializeEventData: simulation_events.cppCheckForInitialEvents: simulation_events.cppStartEventIteration: simulation_events.cppsaveall: simulation_events.cppinitialize: simulation_init.cpp

Page 22: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

22

Outline

OpenModelicaWhat is OpenModelica?The past and present

OpenModelica Technical OverviewOMC, OMShell, OMNotebook

OpenModelica Development EnvironmentMetaModelicaThe Eclipse Environment

OpenModelica Latest Developments (2009-2010)

Page 23: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

23

MetaModelica

OMCImplemented mainly in MetaModelica and C/C++

Modelicaclasses, models, records, functions, packagesbehavior is defined by equations or/and functionsequations

differential algebraic equations and conditional equations

MetaModelica extensionslocal equations pattern equationsmatch expressionshigh-level data structures: lists, tuples, option and uniontypes

Page 24: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

24

OpenModelica Context

Parse

Client: Eclipse Plugin

Corba

Client: OMShell Interactive

Session Handler

Server: Main ProgramIncluding Compiler,

Interpreter, etc.

InteractiveSCode

Inst

Ceval plot

system

etc.

Untyped API

Typed Checked Command API

Client: Graphic Model Editor

Page 25: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

25

Modelica Perspective

The MDT Eclipse Environment (I)

Modelica Editor

Modelica Browser

Modelica Code Assistant

MetaModelica Debugging

Page 26: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

26

The MDT Eclipse Environment (II)

.mo file

OMC Compiler

Small Modelica Parser

Eclipse

Modelica model

AST Information

Modelica Browser

Modelica Code Assistant

Modelica Editor

MetaModelica Builder

MetaModelica Build console

MMCCompiler

MetaModelica Debugging

Page 27: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

27

The MDT Eclipse Environment (III)

.mo fileMMC

Compiler

Eclipse

MetaModelicaDebugging

Modelica Editor

Executable+

Debugging runtime

Page 28: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

28

Creating Modelica projects (I)

Creation of Modelica projects using wizards

Page 29: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

29

Creating Modelica projects (II)

Modelica project

Page 30: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

30

Creating Modelica packages

Creation of Modelica packages using wizards

Page 31: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

31

Creating Modelica classes

Creation of Modelica classes, models, etc, using wizards

Page 32: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

32

Code browsing

Code Browsing foreasy navigation within Modelica files. Automatic update on file save.

Page 33: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

33

Error detection (I)

Parse error detection on file save

Page 34: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

34

Error detection (II)

Semantic error detection on compilation

Page 35: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

35

Code assistance (I)

Code Assistance on imports

Page 36: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

36

Code assistance (II)

Code Assistance on assignments

Page 37: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

37

Code assistance (III)

Code Assistance on function calls

Page 38: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

38

Code indentation

Code Indentation

Page 39: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

39

Code Outline and Hovering Info

Code Outline foreasy navigation within Modelica files

Identifier Info on Hovering

Page 40: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

40

Eclipse Debugging Environment

Type information for all variables

Browsing of complex data structures

Page 41: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

41

Eclipse environment for ModelicaML

Page 42: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

42

Requirements Modeling in Eclipse

Page 43: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

43

Outline

OpenModelicaWhat is OpenModelica?The past and present

OpenModelica Technical OverviewOMC, OMShell, OMNotebook

OpenModelica Development EnvironmentMetaModelicaThe Eclipse Environment

OpenModelica Latest Developments (2009-2010)

Page 44: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

44

Latest Developments (2009-2010)2009 – 2010

Work mainly happened in OSMC (partially on a non-public branch)Front-end

Refactoring (OSMC)Enumerations (OSMC)Java Interface and Booststrapping (Martin Sjölund)MultiBody flattening (OSMC)Braking of constraint connection graph (VTT + OSMC)Support for Modelica 3.x and 3.x annotations (OSMC)Better structuring of the compiler (OSMC)

Back-endTearing in the back-end (Jens Frenkel)Template Code Generation and CSharp backend (Pavol Privitzer, Charles University Prague)Interactive Simulations (EADS)C++ Code generation (Bosch Rexroth)Java Interface and Booststrapping (Martin Sjölund)Additional Solvers + Events (Willi Braun, FH-Bielefeld)

GeneralNew MDT based on Xtext (Antanas Pavlov, SysMO and BMW)New ModelicaML + SysML prototype (EADS)1144 commits in subversion (Since 2009 to February 8, 2010)Bug fixes (OSMC)Release 1.5.0 and 1.5.0-RC_X (Linux, Mac, Solaris, Windows)

More things I don’t remember

Page 45: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

MultiBody library

General Modelica issues solvedarray aliases (100%) enumerations (95%)

using enumerations as array indexes remains to be doneinner outer with modifications on inner (95%)

works for constant modificationsstarted another implementation that uses the inner object directly

MultiBody specific issuescalling functions via component i.e. world.gravityAcceleration (100%)

not legal modelica and on plus the gravityAcceleration function is protectedbraking of over constrained connection graph (90%)

implemented by VTT (Hannu)constraint types (100%)some issues with inner/outer ovelapping connection braking.

performance issues (40%)faster handling of inner outermore caching in the compiler

expandable connectors (90%)Implementation as a phase before instantiationSome small bugs still to be fixed

45

Page 46: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

Media library

The most evil Modelica standard library

problems with partial functions in partial packagesproblems with full packages in partial packages used via the fully qualified pathproblems with redeclare replaceable model extends x.modifiers are in the wrong scope in the presence of redeclare replaceable model extends x.functions using redelclare replaceable function extends used to set constants in partial packages.

46

Page 47: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

Template Code Generation

Pavol Privitzer, Charles University in Prague, Creative Connections s.r.o. Czech Republic

Simple model of right heart Starling law IDA solver behind (in F#) linked with the code of the model (completely generated using the Susan template code generation in OpenModelica)The generated model runs in the Browser on top of Silverlight!

47

Input Pressure to Right Heart vs. Volume

Input Pressure to Right Heart vs. BlodFlow

Page 48: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

Modelica Development Tooling based on Xtext

Atanas Pavlov, SysMo & BMW 48

Page 49: Technical Overview of OpenModelica and its Development ...petfr27/OpenModelica2010... · Technical Overview of OpenModelica and its Development Environment Adrian Pop Open Source

49

End

Thank You!Questions?

OpenModelica Projecthttp://www.OpenModelica.org