Co-simulation using FMI

After the application of the first prototype (the Intercom library) for co-simulating the overture and EnergyPlus models of the case study, some limitations were identified. To overcome these limitations, the final prototype must

    • Be able to instantiate several instances of a control.
    • Be able to co-simulate different control parts developed as independent Overture projects.
    • Be able to co-simulate several tools and add the option of simulating models of other tools such as Modelica or Simulink.
    • Be able to connect to web services providing real data and use this data during the co-simulation.

To be able to comply with all the requisites, for the final prototype Functional Mock-up Interface (FMI) has been used to co-simulate. This standard allows using several instances of a model and coupling several tools. Also, the tools to be coupled already have FMI support developed.

Functional Mock-up Interface or FMI is a tool independent standard to support both model exchange and co-simulation of dynamic models using a combination of XML files and compiled C-code. For more information about this standard click here.

FMI is used to allow co-simulation. This standard allows using several instances of a model and coupling several tools. Overture and EnergyPlus already have FMI support.

1. FMI support for Overture

As a part of the project INTO-CPS (click here for more information about the project) FMI support for overture has been developed. How to install the tool and export a model from overture to FMU is explained here.

This support is based on Crescendo Tool and there is an automated export function from Overture for FMI 2.0.

1.1 Generating an Overture FMU for the Example

Starting from the overture project, first the FMI library must be added to the project.

In order to use this model sensor and actuator data variables must be changed. In the original model, the data coming from sensor and the data sent to the actuator are real, but for FMU a FMI port must be used, so for each sensor and actuator a class is created. The controller will work with instances of this classes. The constructor is also changed to pass the initial values of the sensor and actuator data.

Changes made in the Controller.vdmrt:

  • Change type of the instance variables TRoo, ISolExt and yShade
  • New constructor of the Controller passing the TRoo, ISolExt and yShade initial values
  • Changes to adapt GetTRoo, GetISolExt and SetY operations

New classes:

  • ShadeActuator.vdmrt
  • SolarSensor.vdmrt
  • TempSensor.vdmrt
  • HardwareInterface.vdmrt

Changes are also necessary in System.vdmrt

  • To obtain an instance of the HardwareInterface that define the interface of the FMU.
  • Change the way the instance controller is obtained (the call to the constructor), passing instances of sensors and actuators with the values of the interface.

To see the exact changes applied to the project click here.

In the Hardware interface some annotations have to be written to specify the inputs and outputs of the FMU.

The last step is to send to export the FMU. There are two options: to export the FMU including the source code or including the binaries.

Adding FMI library to project

Hardware interface class with annotations

Exporting FMU

2. FMI support for EnergyPlus

To export EnergyPlus models to FMU, EnergyPlusToFMU tool is used (to install this tool click here). EnergyPlusToFMU is a software package written in Python which allows to exports models of EnergyPlus 8.0 or newer versions to FMU.

2.1 Generating an EnergyPlus FMU for the Example

New information about the FMU interface must be added to the idf file of the EnergyPlus model. These three items must be included:

  • An object that instructs EnergyPlus to activate the external interface.
  • EnergyPlus objects that read inputs of the FMU and send the values to EnergyPlus.
  • EnergyPlus objects that read data from EnergyPlus and send the values to the outputs of the FMU.



To create a FMU, EnergyPlusToFMU python script has been executed with the appropriate parameters.

How to declare the variables in the idf

Python script to create FMU

3. Co-simulation tool: BCVTB

For co-simulating the generated FMUs, a tool or simulation environment is needed. Building Controls Virtual Test Bed (BCVTB) has been selected in this case. BCVTB offers support for Functional Mock-up Units (FMU) for co-simulation and model-exchange for the Functional Mock-up Interface (FMI) 1.0 and 2.0. It has a graphical interface for building models connecting imported FMUs.

3.1 Generation of the Overture FMU

As BCVTB does not support the FMI 2.0 in co-simulation, FMUs for version FMI 1.0 has to be created. The tool used is FMU SDK 2.0.4 (FMUSDK), a free software development kit provided by QTronic. To download this tool click here.

To install this tool Microsoft Visual Studio 2005 (VS8), 2008 (VS9), 2010 (VS10), or 2012 (VS11) must be installed. To compile with another compiler, you must adapt the batch files.

Steps to generate the Overture FMU:

  • To generate the Overture FMU, from the overture project the C code must be generated using the tool that Overture has for this.
  • To create the FMU with FMUSDK, a directory must be created (ShadeControl for example) in FMUSDK_HOME\fmu10\src\models and create the file ShadeControl.c there. The name of the new directory and the .c file must be the same. An image png file with an image has to be added for the model and the modelDescription.xml file. The XML file must not contain the <implementation> element and the closing tag <fmiModelDescription>, because this is automatically added in the construction.
  • When the file ShadeControl.c and the xml file (s) have already been edited, you must open a command shell in FMUSDK_HOME\fmu10\ src\models and execute the command build_fmu cs ShadeControl to build an FMU for co-simulation. This creates a 32-bit FMU named ShadeControl.fmu in the corresponding subdirectory of FMUSDK_HOME\fmu10. To create a 64-bit version of the FMU, you must add -win64 to the command.

The FMU examples provided by the tool are all in the same file, but in our case, many files have to be compiled, so the build_fmu.bat file has to be changed. This line has changed from:

  • cl /LD /nologo %DEF% ..\%2\%2.c /I ..\. /I ..\..\%FMI_DIR%\include

to:

  • cl /LD /nologo %DEF% ..\%2\%2.c /I ..\%2\include /I ..\. /I ..\..\%FMI_DIR%\include

4. Co-simulation with BCVTB

The Shading control example in BCVTB is opened and import the generated Overture FMU and replace the shadingController by the imported FMU.

Import the generated Overture FMU

Replace shadingController

FMIvideo.mp4