Skip to content
Andreas Nicolai edited this page Mar 10, 2019 · 22 revisions

FMICodeGenerator wiki

User Guide

The readme.md file (see main project page) holds an introduction to the tool and the usage.

API

To use the FMUCodeGenerator functionality from other software, you can use the Python-API provided by the Python library. Basically, you create an instance of class FMIGenerator(), specify its attributes and call the member function generate(). As simple as that :-)

# import FMIGenerator class and data types
from FMIGenerator import *

# create instance of FMIGenerator class
fmiGen = FMIGenerator()

# specify attributes
fmiGen.modelName = "MyFirstFMU"
fmiGen.description = "My first auto-generated FMU. Awesome, right?"
fmiGen.targetDir = "../fmus" 
# 'targetDir' can be relative path to current working directory 
# or an absolute file path

# add variables to export
v = VarDef("InputVar1", "continuous", "input", "exact", "Real") 
# valueRef will be given automatically unless specified explicitely
v.startValue = 15
fmiGenerator.variables.append(v)

# now generate the FMU
fmiGen.generate()

FMU Compliance Checker Testing Procedure

The FMUs created by the FMIGenerator are only backbones and lack specific functionality. To test the correct export, we will follow this procedure:

  1. define an FMU with given parameters and variables according to the defined test scenario (see below)
  2. generate the FMU directory with the FMIGenerator
  3. add C++-Code into FMU source stub
  4. build and deploy .fmu file
  5. run file through compliance checker

Test Scenarios

Here is a list of test scenarios to test and demonstrate the functionality of the FMIGenerator.

  • stateless p-controller: Tests the very basic functionality (if FMU is well formed and modelDescription is syntactically correct). No serialization is needed, so there cannot be anything wrong with that.

State-less digital controller with dead-band

  • input var: real, continuous, T (temperature in K)
  • output var: real, continuous, P (heating power in W)
  • parameter: real, fixed, P_on (heating power in W)
  • parameter: real, fixed, T_low (heating on)
  • parameter: real, fixed, T_high (heating off)
  • parameter: real, fixed, delay (min time in [s] between switching events)

Logic:

 T < T_low and t_since_last_switch > delay:
     switch heating on, remember last switch time
 T > T_high and t_since_last_switch > delay:
     switch heating off, remember last switch time
Clone this wiki locally