Modelica Model

21
GI A Generic FMU Interface for Modelica Wuzhu Chen 1 Michaela Huhn 1 Peter Fritzson 2 1 Institut für Informatik, Technische Universität Clausthal, Germany {Wuzhu.Chen | Michaela.Huhn}@tu-clausthal.de 2 Department of Computer and Information Science, Linköping University, Sweden [email protected]

Transcript of Modelica Model

GI

A Generic FM U Interfacefor M odelica

Wuzhu C hen1 M ichaela Huhn1 Peter Fritzson2

1Institut für Informatik, Technische Universität Clausthal, Germany{Wuzhu.Chen | M ichaela.Huhn}@tu-clausthal.de

2Department of Computer and Information Science, Linköping University, [email protected]

Wuzhu ChenInstitut für Informatik 2EO O LT Workshop 2011

GI

Overview

1. Introduction to M odelica & FM I2. Approaches for FM U Import3. Prototype Implementation4. Case Study5. Conclusion

Wuzhu ChenInstitut für Informatik 3EO O LT Workshop 2011

GI

Introduction 1

M odel Exchange in M odelica

- M odelica is an EO O L for modeling and simulation- A bunch of modeling and simulation tools based on M odelica- Generally no problem for model exchange btw. these tools

ModelicaModels

OpenModelica

DymolaSimulationX

MathModelica

ModifySimulate

other tools

Wuzhu ChenInstitut für Informatik 4EO O LT Workshop 2011

GI

Introduction 2

Functional M ock-up Interface (FM I) 1.0 for M odel Exchange

- Specification of a C interface for models (FM Us)- An FM U instance presents the model attributes and behavior- FM Us are distributed in a compressed form- FM Us may be exchanged btw. any tools for variant purposes

M O DELISAR

Wuzhu ChenInstitut für Informatik 5EO O LT Workshop 2011

GI

Introduction 3

Enhance M odel Reusability and Interoperability in M odelica

- Functionality for FM U export to non-M odelica-based tools- Functionality to import generated FM Us

M odeling languagefor hybrid dynamicsystems

FM I for M odel Exchange 1.0 Specification

M odelica ToolsNon-M odelica-Based Tools

FM Uexport/import ? export/import

Wuzhu ChenInstitut für Informatik 6EO O LT Workshop 2011

GI

Overview

1. Introduction to M odelica & FM I2. Approaches for FM U Import3. Prototype Implementation4. Case Study5. Conclusion

Wuzhu ChenInstitut für Informatik 7EO O LT Workshop 2011

GI

Approaches for FM U Import 1

Stand-alone FM U Import

- Decompression of the archived .fmu file- Parsing model description XM L file- Wrapper around interface functions- Connection with solver- Result analysis and presentation

FM U Import in M odelica

- Decompression of the archived .fmu file- Parsing model description XM L file- M apping interface functions onto M odelica external functions- M apping FM I structures onto M odelica constructs

- Integration of model attributes and behaviors

Wuzhu ChenInstitut für Informatik 8EO O LT Workshop 2011

GI

Approaches for FM U Import 2

Workflow of FM U Import in M odelica

FMUModel

Interface

Model Description

Variable Information

fmuWrapper.c

parser

wrapper

.mo generator

ModelicaModel

unzip

Wuzhu ChenInstitut für Informatik 9EO O LT Workshop 2011

GI

Overview

1. Introduction to M odelica & FM I2. Approaches for FM U Import3. Prototype Implementation4. Case Study5. Conclusion

Wuzhu ChenInstitut für Informatik 10EO O LT Workshop 2011

GI

Prototype Implementation 1

1. Decompression of FM Us

- 7-zip is used to decompress FM Us- Decompressed files stored in a sub-directory in O penM odelica- Temporary files may be deleted after code generation

2. Parsing modelDescription.xml

- M odel variables and their attributes are stored in this xml file- O pen-source library Expat is used- Result is a tree-like structure with nodes attached on it- Variable attributes can be queried by traversing the structure- Validation of the xml file not yet implemented

Wuzhu ChenInstitut für Informatik 11EO O LT Workshop 2011

GI

dll

FM I 1.0

loaded

at runtime

Template

FM U block

FM U Interface for M odelica

Prototype Implementation 2

3. Generic Interface Generation

- FM I interface functions in a dynamic link library (dll)- Load the library via information from the xml file- Wrapper functions are then created around FM I functions- Some extra helper functions- FM I interface is represented as M odelica external function constrcuts- Code generation from a template file

Wrapper

Wuzhu ChenInstitut für Informatik 12EO O LT Workshop 2011

GI

FM U block

FM U Interface for M odelica

Prototype Implementation 2

4. M odelica M odels Generation

- Calling sequence guaranteed by M odelica algorithm constructs- Specific data-flows ensured by the restricted class block- Internal variables defined based on the information from the xml file- The FM U block body generated by incorporating variable information

and interact with the model via interface functions

M odel Description

Wrapper

Code Generator

Wuzhu ChenInstitut für Informatik 13EO O LT Workshop 2011

GI

Overview

1. Introduction to M odelica & FM I2. Approaches for FM U Import3. Prototype Implementation4. Case Study5. Conclusion

Wuzhu ChenInstitut für Informatik 14EO O LT Workshop 2011

GI

Case Study 1 : Heat Transfer Equation

Imported CPU Cooling M odel (Dymola 7.4)

- Continuous dynamic system- FM U import functionality of the prototype from other simulator in

O penM odelica

Wuzhu ChenInstitut für Informatik 15EO O LT Workshop 2011

GI

Case Study 1 : Heat Transfer Equation

O riginal M odelica CPU Cooling M odel (Dymola)

Wuzhu ChenInstitut für Informatik 16EO O LT Workshop 2011

GI

Case Study 2 : Hybrid DAE System

Bouncing Ball M odel (fmusdk)

- Hybrid dynamic system- Testing FM U import functionality of the prototype

Wuzhu ChenInstitut für Informatik 17EO O LT Workshop 2011

GI

Case Study 2 : Hybrid DAE System

Bouncing Ball M odel (fmusdk)

- Testing capability of multiple instances of an FM U

Wuzhu ChenInstitut für Informatik 18EO O LT Workshop 2011

GI

Case Study 2 : Hybrid DAE System

Bouncing Ball M odel (fmusdk)

- Testing capability of native-connection btw. the imported FM U and pure M odelica model

Wuzhu ChenInstitut für Informatik 19EO O LT Workshop 2011

GI

Overview

1. Introduction to M odelica & FM I2. Approaches for FM U Import3. Prototype Implementation4. Case Study5. Conclusion

Wuzhu ChenInstitut für Informatik 20EO O LT Workshop 2011

GI

Conclusion

We realized

- FM U Import

- multiple FM U instances

- native-connections between imported FM U and pure M odelica

model

The interface is vendor-neutral and open-source

Automatic code-generation fully compliant with M odelica

language specification is achieved as well

Wuzhu ChenInstitut für Informatik 21EO O LT Workshop 2011

GI

Thanks for your attention!Questions are welcomed