integrated model-based development with openmodelica and ...petfr27/modprod2010talks/... ·...

38
Linköping University 2010-02-10 Peter Fritzson Integrated Model-Based Development with OpenModelica and ModelicaML partly in the OPENPROD project class x { public int a; float b; int func (int a,int b); Asa asad Asda ad Asd ad cc Aac sdscfcc c a Ascccv ca Ascc cac } class x { public int a; float b; int func (int a,int b); Asa asad Asda ad Asd ad cc Aac sdscfcc c a Ascccv ca Ascc cac } class x { public int a; float b; int func (int a,int b); Asa asad Asda ad Asd ad cc Aac sdscfcc c a Ascccv ca Ascc cac } class x { public int a; float b; int func (int a,int b); Asa asad Asda ad Asd ad cc Aac sdscfcc c a Ascccv ca Ascc cac }

Upload: others

Post on 08-May-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

Linköping University 2010-02-10

Peter Fritzson

Integrated Model-Based Development with OpenModelica and ModelicaML

partly in the OPENPROD project

class x {publicint a;float b;int func (int a,int b);Asa asadAsda ad Asd ad ccAac sdscfcc c aAscccv caAscc cac}

class x {publicint a;float b;int func (int a,int b);Asa asadAsda ad Asd ad ccAac sdscfcc c aAscccv caAscc cac}

class x {publicint a;float b;int func (int a,int b);Asa asadAsda ad Asd ad ccAac sdscfcc c aAscccv caAscc cac}

class x {publicint a;float b;int func (int a,int b);Asa asadAsda ad Asd ad ccAac sdscfcc c aAscccv caAscc cac}

Page 2: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

2 © Peter Fritzson

MODPROD Center Associated Project:OPENPROD – Large 3-year ITEA2 EU Project28 partners from 5 countries: 11 large industries, 7 SMEs, 5 research institutes, and 5 universities. Project size: > 90 person years, Budget: About 11 Mill. €, Duration June 2009 - Aug 2012.Coordination by Sune Horkeby, Peter Fritzson

Page 3: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

3 © Peter Fritzson

OPENPROD System Structure

Model-Driven Development Environment, WP2

Compiler frontend

Compiler Middleend

Model Compiler WP3

CodeGen & Simulation WP4

Interoperability WP5

Graphical Presentation WP2

Parallel Code Multi-core

Real-time Code Gen

Hybrid QSS Simul

TLM-based Co-simulation

On-line analysis

3D animation

2D/3D Graphic Model Spec

Browser &Debugger

Requirement modeling

Graphical Presentation

Aspect orientation

Model Ext Format

Modeling Ontology

Control Interop

Uncertainty Sensitivity

Modelica UML Integr

Page 4: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

4 © Peter Fritzson

OPENPROD Vision of Integrated Model-Based Product Development

Product models

Requirementsmodels

Unified Modeling: Meta-modeling& Modelica& UML & OWL

BusinessProcessControl

RequirementsCapture

Model-Driven Design(PIM)

Compilation & Code Gen

(PSM)

SystemSimulation

Software &Syst Product

Feedback

Platformmodels

Processmodels

Product models

Requirementsmodels

Unified Modeling: Meta-modeling& Modelica& UML & OWL

BusinessProcessControl

RequirementsCapture

Model-Driven Design(PIM)

Compilation & Code Gen

(PSM)

SystemSimulation

Software &Syst Product

Feedback

Platformmodels

Processmodels

OPENPROD Vision of unified modeling framework for model-driven product development from platform independent models (PIM) to platform specific models (PSM)

Current work based on Eclipse, UML/SysML, OpenModelica

Page 5: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

5 © Peter Fritzson

Business Process Models

BusinessProcessControl

Processmodels

BusinessProcessControl

Processmodels

• In OPENPROD WP2:

• VTT develops business processing tool using Simantics and OpenModelica, based on System Dynamics.

• Industrial applications by partners: Nokia, Metso, Pyöru

Page 6: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

6 © Peter Fritzson

Modeling Business Processes (VTT)

• Problem Articulation• Problem, variables, time scale, interfaces…• (Model only aspects relevant to the problem)

• Formulation of Dynamic Hypothesis• Hypothesis, causal relations

• Formulation of a Simulation Model• Structure, submodels, parameter estimation,

...

• Testing• Comparison to historical data, sensitivity...

• Policy Design and Evaluation• Scenarios, new policies, strategies, ”what if”-

simulation, sensitivity in different situations

Page 7: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

7 © Peter Fritzson

Capturing and Transformations of Requirements

Requirementsmodels

RequirementsCapture

Requirementsmodels

RequirementsCapture

• Approach 1: SysMLText boxes

• Approach 2: ModelicaML –requirements in text and slightly formalized

• Approach 3: Use the behavior engineering approach on capturing and formalizing requirements

Page 8: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

8 © Peter Fritzson

Approach 1: SysML Requirement diagrams (= text boxes) in ModelicaML-2007

Page 9: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

9 © Peter Fritzson 9

Approach 1 &2: Requirements Modeling in Eclipse using ModelicaML-2007. Also use equations

Page 10: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

10 © Peter Fritzson

Approach 1 & 2: ModelicaML-2009Example: Representation of System Requirements

Textual Requirement Formalized Requirement

Page 11: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

11 © Peter Fritzson

ModelicaML-2009: Simulation and Requirements Evaluation

Req. 001 is instantiated 2 times (there are 2 tanks in

the system)

tank-height is 0.6m

Req. 001 for the tank2 is violated

Req. 001 for the tank1 is not violated

Page 12: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

12 © Peter Fritzson

Approach 3 – Use Behavior Engineering for More Formal Requirements Capture and Analysis

Developed by Prof. Geoff Dromey, Griffith Univ, Brisbane• 5 Large-scale industry projects

• In Defence, Transportation, Banking and Finance• Between 800-1250 requirements

• All previously reviewed with respective organisations internal review processes

• Defect detection rate approximately 2 to 3 times that of traditional ad-hoc, checklist-based, and scenario-based reading techniques reported in Porter, 1998.

Requirements Evaluation Using Behavior TreesFindings from Industry

Daniel Powellhttp://aswec07.cs.latrobe.edu.au/5.zip

Page 13: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

13 © Peter Fritzson

Formalization - Requirements Translation

Formalization – clarification and preservation of intent– strict use of original vocabulary– removes ambiguity, aliases, etc– aids stakeholder validation, understanding– approaches repeatability

1 CAR?? Arrives ??

1 GATE? Open ? 1 GATE

? Closed ?

Functional RequirementWhen a car is arrives,

if the gate is open the car proceeds,otherwise if the gate is closed, when

the driver presses the buttonit causes the gate to open 1 CAR

[ Proceeds ] 1 DRIVER??[[Presses]Button]??

1 BUTTON[ Pressed ]

1 GATE[ Open ]

Behavior TreeBehavior Tree

Page 14: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

14 © Peter Fritzson

A Brief Introduction to Behavior Engineering (BE)

• Behavior Engineering (BE) acronyms …

Behavior Modeling Process (BMP)

Behavior Modeling Language (BML)

Behavior Trees (BT) Composition Trees (CT)

Requirements TranslationRequirement Behavior Trees

(RBTs)Requirement Composition Tree

(RCT)

Requirements IntegrationIntegrated Behavior Tree

(IBT)Integrated Composition Tree

(ICT)

System SpecificationModel Behavior Tree

(MBT)Model Composition Tree

(MCT)

System DesignDesign Behavior Tree

(DBT)Design Composition Tree

(DCT)

Page 15: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

15 © Peter Fritzson

A Brief Introduction to Behavior EngineeringSummary of Behavior Tree Notation

Summary of the

Behavior Tree

Notation

Page 16: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

16 © Peter Fritzson

Translation from a Requirement in Englishto a Requirement Behavior Tree (RBT)

How to translate from a Requirement in Natural Language to an RBT

R6. If a caution signal is returned to the ATP controller then the alarmis enabled within the driver’s cab. Furthermore, once the alarmhas been enabled, if the speed of the train is not observed to bedecreasing then the ATP controller activates the train’s brakingsystem.

The Tag traces these Behavior Tree nodes back to Requirement 6.

A ‘+’ and a yellow color denote the behavior is implied by the requirements

Flow of

Control

Red color denotes behavior is missing in the requirements

Page 17: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

17 © Peter Fritzson

Case Study: An Automated Train Protection System

BE Model of the ATP System(yellow: implied from requirements, red: missing)

Page 18: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

18 © Peter Fritzson

Case Study: An Automated Train Protection SystemModelica Model of the ATP System (graphical view)

Page 19: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

19 © Peter Fritzson

Modeldriven Design

Product models

Model-Driven Design(PIM)

Product models

Model-Driven Design(PIM)

• Graphical modeling of software and systems using UML and SysML• software models, system overview models

• Graphical modeling using Modelica• Models of physical systems and embedded system

software as well as system architecture

• Textual modeling using Modelica• OpenModelica MDT Eclipse plugin

Page 20: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

20 © Peter Fritzson

Modelica Graphic Connection Diagram and ModelicaML/UML Class Internal Diagram

• Modelica Connection diagram• Better visual comprehension• Predefined connector

locations

• Class Internal diagram• Nested models• Top-model parameters and

variables• Flow direction• Other ModelicaML elements

Page 21: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

21 © Peter Fritzson

Example: ModelicaMLRepresentation of System Behavior

State Machine of

the Tank

State Machine of the

Controller

Conditional Algorithm

(Activity Diagram)

Page 22: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

22 © Peter Fritzson 22

Modelica Perspective

The OpenModelica MDT Eclipse Environment for Textual Modeling (I)

Modelica Editor

Modelica Browser

Modelica Code Assistant

MetaModelica Debugging

Page 23: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

23 © Peter Fritzson 23

MDT: Code Browsing

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

Page 24: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

24 © Peter Fritzson 24

MDT: Parse Error detection

Parse error detection on file save

Page 25: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

25 © Peter Fritzson 25

MDT: Semantic Error Detection

Semantic error detection on compilation

Page 26: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

26 © Peter Fritzson 26

MDT: Code Assistance – on import Statements

Code Assistance on imports

Page 27: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

27 © Peter Fritzson 27

MDT: Code Assistance on Function Calls

Code Assistance on function calls

Page 28: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

28 © Peter Fritzson 28

MDT: Code Indentation

Code Indentation

Page 29: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

29 © Peter Fritzson 29

MDT: Code Outline and Hovering Info

Code Outline foreasy navigation within Modelica files

Identifier Info on Hovering

Page 30: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

30 © Peter Fritzson 30

OpenModelica Eclipse MDT Debugging Environment

Type information for all variables

Browsing of complex data structures

Page 31: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

31 © Peter Fritzson

Compilation and Code Generation

Compilation &Code Gen

(PSM)

Platformmodels

Compilation &Code Gen

(PSM)

Platformmodels

• Compilation to C code.

• OpenModelica Text template language for transformation to different platform languages.

• Generation to parallel platforms (Intel multi-core, Nvidia multi-core)

Page 32: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

32 © Peter Fritzson 32

The OpenModelica OMC Compiler – From Modelicato C Code• Implemented mainly in MetaModelica and C/C++• The compiler has 91 packages

SCode /explode

Lookup

Parse DAELow Inst

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

System Print RTOpts

Builtin

DAELow.DAELow

C code

DAE, substlist

DAE Exp.Exp Exp.Exp

ClassInf.Event

Exp.Ident Prefix.Prefix

Types.Mod SCode.Mod Exp.Componentref DAE

ClassInf.State

.mo

Main

Util

ClassLoader

Dump DAE Flat Modelica

MetaUtil

DFA

Patternm

Values.Value

Exp.Exp

Page 33: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

33 © Peter Fritzson

Template Definition ExampleOpenModelica Text Template Language

hello(String person) ::= <<Hello <person>!>>

whileStmt(String cond, list<String> statements) ::=<<while(<cond>) {

<statements \n>}>>

Used to easily produce differenent code generators, to C, C#, Java, etc.

A text template is a text with holes in it

Page 34: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

34 © Peter Fritzson

Integrating Parallelism and Mathematical ModelsThree Approaches

• Automatic Parallelization of Mathematical Models (ModPar)• Parallelism over the numeric solver method.• Parallelism over time. • Parallelism over the model equation system

• ... with fine-grained task scheduling

• Coarse-Grained Explicit Parallelization Using Components• The programmer partitions the application into computational components

using strongly-typed communication interfaces. • Co-Simulation, Transmission-Line Modeling (TLM)

• Explicit Parallel Programming • Providing general, easy-to-use explicit parallel programming constructs

within the algorithmic part of the modeling language. • NestStepModelica

Page 35: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

35 © Peter Fritzson

Generating Parallel Code from Modelica Task Graphs and Parallelized Application

12

32

21

41

52

62

71

81

5 0

0 0 0

0 010

Clustered Task Graph

1 2 4 8 16# Proc

0.5

1

1.5

2

2.5

3Speedup

Thermofluid Pipe Application

Page 36: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

36 © Peter Fritzson

Equation tasks

Equation tasks

S

Equation tasks

S

Equation tasks

Equation tasks

Equation tasks

S

S

S

S

S

S

S

S

S

SS

Use a graph rewriting system to merge tasks into larger tasks, based on latency and bandwidth.

Task Merging vs New Approach with Pipelining/Inlining

Some tasks are duplicated to avoid communication within a step

• Try to keep communication as close as possible

• Only communicate in one direction inside a time step.

• Solver Inlining –distribute the solver across all the processors

Page 37: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

37 © Peter Fritzson

Recent Speedup Measurements on NVIDIA (nov 2009)Modelica Model, Generated Code, Function of Problem Size

Page 38: Integrated Model-Based Development with OpenModelica and ...petfr27/MODPROD2010talks/... · Integrated Model-Based Development with OpenModelica and ModelicaML. partly in the OPENPROD

38 © Peter Fritzson

Conclusions• Businesss process modeling on the way based on

System Dynamics

• Several ways of capturing and formalizing requirements in ModelicaML and Behavior Engineering+OpenModelica

• Graphic Modeling (ModelicaML, etc.) and tool support for advanced textual modeling (MDT Eclipse plugin)

• Code generation from OpenModelica, now also using a text template language.

• Parallelization and code generation to parallel platforms