Das Functional Mockup Interface zum Austausch Dynamischer Modelle Martin Otter (DLR-RM) Torsten Blochwitz (ITI) Hilding Elmqvist (Dassault Systèmes – Dynasim) Andreas Junghanns (QTronic) Jakob Mauss (QTronic) Hans Olsson (Dassault Systèmes – Dynasim) ASIM Workshop, 4. - 5. März 2010 Contents 1. Functional Mockup Interface (FMI) – Overview 2. FMI - Motivation 3. FMI for Model Exchange – Overview 4. Model Distribution 5. Model Description Schema 6. Model C-Interface 7. Tool Support for FMI 8. Comparison with SIMULINK S-Function Interface 9. Outlook 10. Acknowledgements Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 2 1. Functional Mock-up Interface (FMI) – Overview The FMI development is part of the ITEA2 MODELISAR project. FMI development initiated, organized and headed by Daimler AG Improved Software/Model/Hardware-in-the-Loop Simulation, of physical models and of AUTOSAR controller models from different vendors for automotive applications with different levels of detail. Open Standard 14 automotive use cases for evaluation in MODELISAR etc. Engine with ECU Gearbox with ECU Thermal systems Automated Chassis components, cargo door roadway, ECU (e.g. ESP) functional mockup interface for model exchange and tool coupling courtesy Daimler Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 3 Task is complex since the different parts are complex by themselves: Model Exchange (ODE/DAE components without integrators) Co-Simulation (ODE/DAE components with integrators) Co-Simulation with PDE solver (MpCCI) AUTOSAR (discrete components with complex communication) Simulation Backplane In Jan. 2010, the first version of "FMI for Model Exchange" was released. It was mainly developed by Dassault Systèmes (Dynasim), DLR, ITI, QTronic. www.functional-mockup-interface.org specification xml schema files C header files software development kit (QTronic) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 4 MODELISAR ITEA2 project 3 years (2008 – 2011) 29 project partners Coordinators Dassault Systèmes Daimler AG Budget / Funding 30M€ / 10M€ Funded by Germany (BMBF) France (DGCIS) Sweden (VINNOVA) Belgium Austria Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 5 2. FMI - Motivation supplier1 Problems / Needs supplier2 supplier3 supplier4 supplier5 Component development by supplier Integration by OEM OEM Many different simulation tools ? Solution supplier1 supplier2 supplier3 supplier4 supplier5 tool 4 tool 5 Reuse of supplier models by OEM: DLL (model import) and/or tool 1 tool 2 tool 3 Tool coupling (co-simulation) Added Value OEM FMI Protection of model IP of supplier supplier1 ! OEM Early validation of design Increased process efficiency and quality slide from Nick Suyam, Daimler (adapted) supplier2 supplier3 Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 6 Example Scenario: Power Lift Gate models solved with SIMPACK integrators (= central integration) supplier1 supplier2 supplier3 AMESim (Modelica) Dymola (Modelica) SimulationX (Modelica) model export FMI model exchange (DLL) model import OEM, dept. 1 Simpack (multi-body) OEM, dept. 2 TargetLink (software) model export FMI tool coupling FMI model exchange (C) model import co-simulation Silver (system model) + TestWeaver (testing) slide from Nick Suyam, Daimler (adapted) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 7 3. FMI for Model Exchange - Overview Import and export of input/output blocks (FMU – Functional Mock-up Unit) described by differential-, algebraic-, discrete equations, with time-, state, and step-events An FMU can be large (e.g. 100000 variables) An FMU can be used in an embedded system (small overhead) FMUs can be connected together Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 8 Signals of an FMU: For example: 10 input/output signals (u/y) for connection and 100000 internal variables (v) for plotting Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 9 Mathematical description of an FMU: Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 10 4. Model Distribution A model is distributed as one zip-file with extension ".fmu". Content: XML model description file All model information that is not needed during integration of model, e.g., signal names and attributes. Advantage: No overhead for model execution. Tools can read this information (= complicated data structure) with their prefered language (C++, C#, Java, ...) Model equations defined by a small set of C-functions. In zip-file: C source code and/or Binary code (DLL) for one or more platforms (Windows, Linux, ...) Resources Documentation (html files) Model icon (bitmap file) Maps and tables (read by model during initialization) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 11 Structure of an FMU zip-file modelDescription.xml model.png documentation // Description of model (required file) // Optional image file of model icon // Optional directory containing the model // documentation _main.html // Entry point of the documentation <other documentation files> sources // Optional directory containing all C-sources // all needed C-sources and C-header files to compile and link the model // with exception of: fmiModelTypes.h and fmiModelFunctions.h binaries // Optional directory containing the binaries win32 // Optional binaries for 32-bit Windows <modelIdentifier>.dll // DLL of the model interface implementation VisualStudio8 // Microsoft Visual Studio 8 (2005) <modelIdentifier>.lib // Binary libraries gcc3.1 // Binaries for gcc 3.1. win64 // Optional binaries for 64-bit Windows ... linux32 // Optional binaries for 32-bit Linux ... resources // Optional resources needed by the model < data in model specific files which will be read during initialization > Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 12 control simulator GUI reads XML schema (.xsd) defined by the FMI specification references model.dll run 1 or many modelDescription.xml .fmu simulator solver Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 13 5. Model Description Schema All model information not needed for execution is stored in one xml-file (modelVariables.xml in zip-file) defined by xml schema files. Advantage: Complex data structures give still simple interface, and tool can use its favorite programming language for reading (e.g., C++, C#, Java). Definition of display units Definition of type defaults Default stop time, tol. etc. Tool specific data Variable names and attributes Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 14 Model attributes. Most important modelIndentifier is a C-name that is used as prefix for the C-functions (model interface) guid is a globally unique identifier ("fingerprint" of all releveant information in the xml file) that is also stored in the C-functions to gurantee consisteny Number of continuous states and of event indicators; numbers are fixed (meaning of states can change dynamically during simulation) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 15 ModelVariables data types ordered set of scalar variables (arrays, records, etc. must be mapped to scalars when generating code). Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 16 Attributes of ModelVariables unique name handle to identify variable in C-functions ... Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 17 Data types allow to store all (relevant) Modelica attributes, including units. Defaults from TypeDefinitions Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 18 Example modelDescription.xml <?xml version="1.0" encoding="UTF8"?> <fmiModelDescription fmiVersion="1.0" modelName="Modelica.Mechanics.Rotational.Examples.Friction" modelIdentifier="Modelica_Mechanics_Rotational_Examples_Friction" guid="{8c4e810f-3df3-4a00-8276-176fa3c9f9e0}" ... numberOfContinuousStates="6" numberOfEventIndicators="34"/> <UnitDefinitions> <BaseUnit unit="rad"> <DisplayUnitDefinition displayUnit="deg" gain="57.2957795130823"/> </BaseUnit> </UnitDefinitions> <TypeDefinitions> <Type name="Modelica.SIunits.AngularVelocity"> <RealType quantity="AngularVelocity" unit="rad/s"/> </Type> </TypeDefinitions> <ModelVariables> <ScalarVariable name="inertia1.J" valueReference="16777217" description="Moment of inertia" variability="parameter"> <Real declaredType="Modelica.SIunits.Torque" start="1"/> </ScalarVariable> ... </ModelVariables> </fmiModelDescription> Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 19 6. Model C-Interface Two C-header files Platform dependent definitions (basic types) C-function interfaces 18 core functions 6 utility functions no macros C-function name: <ModelIdentifier>_<name>, z.B. "Drive_fmiSetTime" Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 20 Example: // Set input arguments fmiSetTime(m, time); fmiSetReal(m, id_u1, u1, nu1); fmiSetContinuousStates(m, x, nx); // Get results fmiGetContinuousStates(m, derx, nx); fmiGetEventIndicators (m, z, nz); Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 21 Caching for efficient model evaluation Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 22 Clean Definition of State Events A state event occurs when an event indicator z changes its domain from z>0 to z≤0 or vice versa Always well defined! Usual definition z(ti)*z(ti-1) ≤ 0 is not always well-defined Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 23 7. Tool Support for FMI (planned for 2010 in MODELISAR) 7.1 FMU import and export AMESim (Modelica) CATIA Systems (CAD/Modelica) Dymola 7.4 (Modelica) already available Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 24 EXITE ACE (co-simulation of software/AUTOSAR) SimulationX (Modelica) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 25 7.2 FMU import EXITE (co-simulation) Silver/TestWeaver (FMU integration, cosimulation, testing) Simpack (multi-body) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 26 8. Comparison with SIMULINK S-Function Interface SIMULINK has two interfaces: S-Function for offline simulation Realtime Workshop for embedded Systems FMI is targeted for both offline simulation and embedded systems (one interface) Simulink and FMI have different goals and therefore have different solutions: S-function targeted to import models in SIMULINK: Main interface to implement an S-Functions. (many macros to fill S-Function data structure) Incomplete interface to call S-Functions. Whenever a small detail of the S-Function data structure is changed, existing DLLs must be newly build. If used in 3 simulation environments → 3 DLLs of the same model FMI targeted to import models in many simulation environments Only interface to call model in simulation environment. Model data structure is secret of model generation environment. If used in 3 simulation environments on same platform → 1 DLL Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 27 S-function not suited for embedded systems, due to large memory overhead since all information of a model is stored in the Model DLL (therefore separate code generation for embedded systems via Realtime Workshop) FMI: Only the minimum necessary part is stored in C source code or in Model DLL. All information not needed for execution, is provided in an XML file (which is needed on host, but not on target microprocessor) S-function has very complex definition (> 100 C-functions/macros) Generating S-function is fine. However, there is no simulator that can import all S-function models (with exception of SIMULINK). FMI: Simple definition (20 C-functions, no macros, XML schema file) S-function proprietary format, gives legal problems if used in other simulators FMI: Wikipedia license for specification, BSD license for schema/header Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 28 Technical issues that are missing in S-Function interface and are available in FMI: Reliable state event handling Event iteration over simulation model (not only component model) Request from submodel to reduce step-size (for non-linear equations in model that do not converge) Dynamic selection of states (as needed for order-reduced higer index systems) Alias variables (FMI: alias variables are marked; need to be stored only once, not several times; important for Modelica models, since many alias variables) Caching of computed results (FMI: more efficient solution) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 29 9. Outlook "FMI for Model Exchange" released at end of January 2010 (technical specification finalized; some discussion about precise license text) "FMI for Co-Simulation" in a good stage. Will be released in first half year: Support for: extrapolation/interpolation of interface variables, variable communication step-size, re-doing a step → step-size control possible). "FMI for Model Exchange" will be further developed. A lot of requirements available, such as: Sparse Jacobian Direct support for arrays and records in xml schema Improved sample time definition (for embedded systems) Online changeable parameters Saving/restoring model state Other tool vendors are encouraged to support FMI, especially: VHDL-AMS simulators Multi-Body simulators Note: Much simpler as SIMULINK S-Function interface and more powerful. Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 30 10. Acknowledgments FMI initiated and organized : Daimler AG (Bernd Relovsky, ....) Head of FMI development : Dietmar Neumerkel (Daimler AG) Head of FMI-for-Model-Exchange: Martin Otter (DLR-RM) FMI-for-Model-Exchange Core-Design by: Torsten Blochwitz (ITI) Hilding Elmqvist (Dassault Systèmes -Dynasim) Andreas Junghanns (QTronic) Jakob Mauss (QTronic) Hans Olsson (Dassault Systèmes -Dynasim) Martin Otter (DLR-RM) Other MODELISAR contributors: Ingrid Bausch-Gall, Bausch-Gall GmbH Alex Eichberger, SIMPACK AG Rainer Keppler, SIMPACK AG Gerd Kurzbach, ITI GmbH Carsten Kübler, TWT Johannes Mezger, TWT Thomas Neidhold, ITI GmbH Dietmar Neumerkel, Daimler AG Peter Nilsson, Dassault Systèmes-Dynasim Antoine Viel, LMS International Daniel Weil, Dassault Systèmes Other contributors: Johan Akesson, Lund University Joel Andersson, KU Leuven Roberto Parrotto, Politecnico di Milano Partially funded by: BMBF, VINNOVA, DGCIS, organized by ITEA2 Prototypes for FMI evaluation: Dymola by Peter Nilsson, Sven Erik Mattsson, Carl Fredrik Abelson, Dan Henriksson (Dassault Systèmes, Dynasim) JModelica.org by Tove Bergdahl (Modelon) Silver by Andreas Junghanns, Jakob Mauss (QTronic) Functional Mockup Interface > ASIM Workshop, 4.-5. März 2010 > Slide 31