Functional Mockup Interface for Model Exchange and Co-Simulation Torsten Blochwitz (ITI Dresden, FMI MAP Project Leader) Members of the FMI Modelica Association Project
Motivation Problems / Needs Component development by supplier Integration by OEM Many simulation tools involved supplier1 supplier2 supplier3 supplier4 supplier5 OEM? Solution supplier1 supplier2 supplier3 supplier4 supplier5 Reuse of supplier models by OEM: DLL (model exchange) and/or Tool coupling (co-simulation) Protection of model IP of supplier tool 1 tool 2 tool 3 tool 4 tool 5 FMI OEM Added Value Early validation of design supplier1! OEM Increased process quality Higher efficiency and quality supplier2 slide from Nick Suyam, Daimler (adapted) supplier3 Modelisar ITEA 2 2
Motivation No standards available for: Model interface based on C or binaries Co-simulation between simulation tools Lots of proprietary interfaces: Simulink: S-function Modelica: external function, external object interface QTronic Silver: Silver-Module API SimulationX: External Model Interface NI LabVIEW: External Model Interface, Simulation Interface Toolkit Simpack: uforce routines ADAMS: user routines Modelisar ITEA 2 3
Modelisar Project Developed within EU project Modelisar (2008-2011) Cooperation of European tool vendors and users Proof of concept in industrial use cases Supported by ca. 27 tools (planned by 7) After 2011: Continue development as Modelica Association Project Modelica Association changed its bylaws in order to become an umbrella organization for projects related with modeling and simulation MODELISAR (ITEA 2 ~ 07006) Partners ARMINES Arsenal Research ATB AVL Berata Daimler Dassault Systèmes David DLR Dynasim Extessy FhG First, IIS EAS, SCAI Geensys Halle University IFP Imagine INSPIRE SIMPACK AG ITI LMS International QTronic Schneider Electric Trialog Triphase TWT Verhaert Volkswagen Volvo Modelisar ITEA 2 4
Agenda Motivation Modelisar Project FMI Main Design Idea XML Model Description C-Interface FMI for Model Exchange FMI for Co-Simulation History and Future Development process FMI 2.0 Organizational Future of FMI Conclusion Modelisar ITEA 2 5
FMI Main Design Idea FMI for Model Exchange Tool Solver FMI Slave FMU Model Model Solver Version 1.0: January 2010 FMI for Co-Simulation Tool Master FMI Slave FMU Model Solver Slave Version 1.0: October 2010 FMI 2.0 for Model Exchange and Co-Simulation is under development Modelisar ITEA 2 6
FMI Main Design Idea A component which implements the interface is called Functional Mockup Unit (FMU) Separation of: Description of interface data (XML file) Functionality (C code or binary) An FMU is a zipped file (*.fmu) containing: XML description file, Implementation in source and/or binary form Additional data and functionality can be included Interface specification: www.functional-mockup-interface.org Modelisar ITEA 2 7
XML Model Description Information not needed for execution is stored in one xml-file: Complex data structures give still simple interface. Reduced overhead in terms of memory. Definition of display units Definition of type defaults Default stop time, tolerances Tool specific data Variable names and attributes Modelisar ITEA 2 8
Example <?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="momentofinertia"> <RealType quantity="inertia" unit="kgm^2"/> </Type> </TypeDefinitions> <ModelVariables> <ScalarVariable name="inertia1.j" valuereference="16777217" description="moment of inertia" variability="parameter"> <Real declaredtype= "MomentOfInertia" start="1"/> </ScalarVariable>... </ModelVariables> </fmimodeldescription> Modelisar ITEA 2 9
C-Interface Two C-Header Files: Platform dependent definitions (basic types): C-Functions: 18 core functions 6 utility functions Modelisar ITEA 2 10
C-Interface Instantiation: fmicomponent fmiinstantiatexxx(fmistring instancename,...) Returns an instance of the FMU. Returned fmicomponent is an argument of the other interface functions. It is of type void* for the master. The FMU uses it to hold all necessary information. Functions for initialization, termination, destruction Support of real, integer, boolean, and string inputs, outputs, parameters Set and Get functions for each type: fmistatus fmisetreal (fmicomponent c, const fmivaluereference vr[], size_t nvr, const fmireal value[]) fmistatus fmisetinteger(fmicomponent c, const fmivaluereference vr[], size_t nvr, const fmiinteger value[]) Identification by valuereference, defined in the XML description file for each variable Modelisar ITEA 2 11
FMI for Model Exchange Features Model is described by differential-, algebraic-, discrete equations Interface for solution of Ordinary Differential Equations (ODE) Handling of: Time events State events Step events Event iteration Discarding of invalid inputs, state variables No explicit function call for computation of model algorithm FMU decides which part is to be computed, when an fmigetxxx function is called Allows efficient caching algorithms Modelisar ITEA 2 12
FMI for Model Exchange Signals For example: 10 input/output signals (u/y) for connection and 100000 local variables (v) for plotting Modelisar ITEA 2 13
FMI for Model Exchange C-Interface Model is described by differential-, algebraic-, discrete equations with events For each part of the model algorithm different function calls are defined: This complexity is necessary to express functionality which result from multi domain modeling languages like Modelica. Modelisar ITEA 2 14
Co-Simulation Definition: Coupling of several simulation tools Each tool treats one part of a modular coupled problem Data exchange is restricted to discrete communication points Subsystems are solved independently between communication points Motivation Simulation of heterogeneous systems Partitioning and parallelization of large systems Multirate integration Hardware-in-the-loop simulation slave A simula tor A slave B simulator A slave C simulator A simul ator A slave E master si mu lat or A slave G Master slave D slave F Modelisar ITEA 2 15
FMI for Co-Simulation Features State-of-the-Art Co-Simulation: Fixed communication step size To improve accuracy and robustness: Optional variable communication step size Optional higher order approximation of inputs and outputs Optional repetition of communication steps Capabilities of the slave are contained in the XML-file, for example: canhandlevariablecommunicationstepsize caninterpolateinputs Master can decide which coupling algorithm is applicable Asynchronous execution (allows parallel execution) Modelisar ITEA 2 16
FMI for Co-Simulation Signals Status information Derivatives of inputs, outputs w.r.t. time for support of higher order approximation Modelisar ITEA 2 17
FMI for Co-Simulation C-Interface Execution of a time step: fmistatus fmidostep(fmicomponent c, fmireal currentcommunicationpoint, fmireal communicationstepsize, fmiboolean newstep) communicationstepsize can be zero in case of event iteration newstep = fmitrue if last step was accepted by the master It depends on the capabilities of the slave which calling sequences are allowed. Depending on internal state of the slave and the function arguments, slave can decide which action is to be done before the computation Return values are fmiok, fmidiscard, fmierror, fmipending Asynchronous execution is possible Modelisar ITEA 2 18
FMI for Model Exchange and Co-Simulation Sample Code Model Exchange: (One evaluation) Co-Simulation: (One communication step) /* Set inputs*/ fmisetreal(m, id_u1, u1, nu1); fmisettime(m, time); fmisetcontinuousstates(m, x, nx); /* Get results */ fmigetderivatives(m, derx, nx); fmigeteventindicators (m, z, nz); fmigetreal(m, id_u1, u1, nu1); /* Set inputs arguments */ fmisetreal(s, id_u1, u1, nu1); /* Do computation*/ fmidostep(s, tc, hc, fmitrue); /* Get results */ fmigetreal(s, id_u1, u1, nu1); Modelisar ITEA 2 19
FMI for Co-Simulation Use Cases Standalone Execution: Tool Coupling: Modelisar ITEA 2 20
FMI for Co-Simulation Use Cases Distributed: With FMI 2.0 all use cases are possible using FMI for Model Exchange too. Modelisar ITEA 2 21
Berlin Munich Berlin Munich Munich Development Process FMI for Model Exchange Specification Prototypes FMI for Co-Simulation V 1.0 Berlin Bonn Munich Halle Dresden Munich Stuttgart Leuven Munich Dresden Specification Prototypes FMI for Model Exchange and Co-Simulation V 2.0 b 3 V 2.0 b 4 V 2.0 Berlin Dresden Munich V 1.0 Lund Munich Munich Munich Berlin Meeting Webmeeting Milestone Specification Prototypes 2008 2009 2010 2011 2012 Modelisar ITEA 2 22
Roadmap for FMI 2.0 Unification and Harmonization of Model Exchange and Co-Simulation Clarification, Improvements: Instantiation Classification of variables, unit handling Calling sequence New Features: Tunable parameters Save and restore FMU state Detailed dependency information (inputs, outputs, derivatives) Efficient interface to Jacobian matrices Contained in public Beta 3 Improved handling of time events Support of arrays Support of bus/physical connectors Hierarchical data Graphical appearance Under Discussion Modelisar ITEA 2 23
Organizational Future of FMI Modelisar Project ended on Dec, 31 st, 2011 FMI went under the hood of the Modelica Association Modelica Association changed its bylaws to become an umbrella organization hosting several Modelica Association Projects: Modelica Language Development Modelica Standard Library Functional Mockup Interface Modelisar ITEA 2 24
FMI Project Rules Purpose: Development, standardization and promoting the Functional Mockup Interface (FMI) definition. The intention is that dynamic system models of different software systems can be used together for software/model/hardwarein-the-loop simulation, for cyber physical systems, and other applications. Results (documents, C-headers, XML schemas): are published under a free license (similar to Wikipedia license). Project Members (need not to be a member of the Modelica Association): Companies, institutes, universities and other organizations Steering Committee: Voting rights Defines FMI policy, strategy, feature roadmap, and future FMI releases Advisory Committee: Organizational members that have no voting rights Contribute to the design of FMI Have Access to FMI infrastructure (svn, trac, mailing lists, meeting minutes, etc.) Modelisar ITEA 2 25
FMI Project Rules Advisory Committee is open for additional members that proofed to actively support FMI: must have participated at least at two FMI meetings in the last 24 months. Advisory Committee members can become Steering Committee members, if: they participated at least at two FMI meetings in the last 24 months, they either provided the FMI standard or part of it in a commercial or open source tool, and/or must actively use FMI in industrial projects, the members agree with qualified majority FMI meetings are open to the public. Initial Steering Committee: Atego, Daimler, Dassault Systèmes, IFP EN, ITI, LMS, Modelon, QTronic, SIMPACK Initial Advisory Committee: Armines, DLR, Fraunhofer (IIS/EAS First, SCAI), Open Modelica Consortium, TWT, University of Halle Modelisar ITEA 2 26
Conclusions FMI for Model Exchange and Co-Simulation is a promising concept 27 tools currently support FMI, 7 intend to Already used in industry FMI is continued after Modelisar project as Modelica Association project FMI 2.0 will improve: Compatibility of implementations (clarified specification) Usability (tunable parameters, bus and physical connectors) Efficiency and robustness for large models (dependency information, Jacobian matrix) Modelisar ITEA 2 27