-
Notifications
You must be signed in to change notification settings - Fork 26
Home
Andreas Nicolai edited this page Mar 9, 2019
·
22 revisions
The readme.md file (see main project page) holds an introduction to the tool and the usage.
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()
The FMUs created by the FMIGenerator are only backbones and lack specific functionality. To test the correct export, we will follow this procedure:
- define an FMU with given parameters and variables according to the defined test scenario (see below)
- generate the FMU directory with the FMIGenerator
- add C++-Code into FMU source stub
- build and deploy
.fmu
file - run file through compliance checker
tests/check/p_control
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.
- input: real, continuous, T (temperature in K)
- output: real, continuous, P (heating power in W)
- parameter: real, fixed, initial=exact, k_p (P-control constant)
Logic:
P = k_p * T
- 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