Importing FMU From Dymola
Contents
Workflow
We support importing Dymola FMU into SimWB. To run the FMU in SimWB, we need binary for Linux 64-bit or 32-bit depending on the SimWB server. Dymola is currently only available in Windows and they are working towards having a Linux version as well. Meanwhile we need to follow the steps below to get a working FMU in SimWB. Following steps assume you are using Dymola 2015.
Create FMU in Dymola
- Create Model in Dymola 2015
- Go to 'Simulation' Panel of Dymola
- Setup the model for FMU export
- Open Setup Panel by clicking the 'Setup' option in 'Simulation' menu
- This will show the 'General' Setup tab as shown below
- Click on the 'FMI' Setup tab. Make sure to select 'Cosimulation' mode, Version '2.0', 'Include source code' in the options as shown below. We also support version '1.0'.
- Generate FMU using the 'Translate' option in 'Simulation' menu.
- The generated FMU file is usually located in 'Documents' folder.
Create binary for Linux
- Move the generated FMU to SimWB server (RedHawk) system.
- Unzip the FMU in a temporary folder
unzip FilterPK_0Simple.fmu
- Navigate to the source folder in the unzipped folder
cd sources
- Edit 'fmiModelIdentifier.h' and comment the '#define FMI_MODULE_NAME FilterPK_0Simple.dll' (//#define FMI_MODULE_NAME FilterPK_0Simple.dll)
- Edit 'fmiModelIdentifier.h' and comment the '#define MODEL_IDENTIFIER FilterPK_0Simple' (//#define MODEL_IDENTIFIER FilterPK_0Simple)
- Edit the 'all.c' and comment the '#define DYMOLA_STATIC static' (//#define DYMOLA_STATIC static)
- Delete the 'fmiTypesPlatform_.h' and 'fmiPlatformTypes_.h' and create soft link to the files located in SimWB installation folder
rm fmiTypesPlatform_.h fmiPlatformTypes_.h ln -sf /usr/local/ccursim/FMIL/include/FMI2/fmiTypesPlatform.h fmiTypesPlatform_.h ln -sf /usr/local/ccursim/FMIL/include/FMI1/fmiPlatformTypes.h fmiPlatformTypes_.h
- Create a Makefile in the 'sources' directory. The 'MODEL' variable below should be changed to match the 'modelIdentifier' defined in 'modelDescription.xml' in the FMU file:
MODEL=FilterPK_0Simple FMILINSTALLPATH=/usr/local/ccursim/FMIL CFLAGS=-fPIC -g -O2 -DDYM2CCUR -I. -I\$(FMILINSTALLPATH)/include/FMI2 -I\$(FMILINSTALLPATH)/include/FMI -I\$(FMILINSTALLPATH)/include objects = all.o FMU=../binaries/linux64/$(MODEL).so fmulib:$(FMU) $(FMU): $(objects) mkdir -p ../binaries/linux64 ld -shared -o $(FMU) $(objects) $(LINKERUSEROPTIONS) -L/usr/local/ccursim/FMIL/lib64 -lfmilib -lrt -lm %.o:%.c $(CC) -fPIC -c $(CFLAGS) $< clean: rm -f *.o rm -f \$(FMU) zip: fmulib rm -f $(MODEL).fmu cd ../ && zip --exclude temp.fmu -q -r $(MODEL).fmu .
- Now let's generate FMU with Linux binary.
make zip
- Above step will create 'FilterPK_0Simple.fmu' in a folder where 'sources' folder is located. We can use this FMU file in SimWB.
Import FMU to SimWB
- Open the 'FMU Models' pane in SimWB
- Click on Select FMU file' button and navigate to the location of FMU created above.
- Click on 'Parse FMU' button. This will show the input, output, and parameter variables available in FMU to be mapped to RTDB. Inputs and Outputs are selected by default. You can select other variables as required.
- Click on 'New RTDB' button, provide a name for the RTDB to be created, and click 'Generate RTDB'
- Click on the 'Install FMU' button to install the FMU.
- Click on the 'Create FMU Model' to create a FMU model object in SimWB
- Now we are ready to use this object in any test like any other model