The Dymola Compilation Process in Action

This blog post describes the Dymola compilation process used to compile the C code generated during translation into an application file(s) that is used during simulation.

Figure 1 shows the Dymola translation and simulation process diagram in which a Modelica model passes through to generate the Simulation results.  Dymola translation and simulation process diagram-Dymola Compilation

Figure 1.  Dymola translation and simulation process diagram.

Step 2 of Figure 1 depicts how the C code is built into an application file(s). This build process is the focus of this blog post.

Please note that this blog post has used Dymola 2018 FD01 for demonstration purposes.

Generation of C code

Dymola converts (translates) a Modelica model into C code by using symbolic processing techniques as described in a recent blog post: ‘Exploring Translation Log Statistics’. The C code generated is stored as dsmodel.c and dsmodelext*.c files (where * represents a whole number).

Building options

There are a number of different compiler options supported in Dymola. However, the C code is built depending on the selected compiler and the translation methods.

Compiler options on the Dymola > Simulation > Setup...> Compiler tab

Figure 2.  Compiler options on the Dymola > Simulation > Setup…> Compiler tab

Figure 2 shows different compiler options supported in Dymola. This includes Microsoft Visual Studio (VS), Intel Parallel Studio XE and MinGW GCC compilers (see Dymola User Manual Volume 1 (Dymola 2018 FD01) page 624).  The C code can also be compiled and used with DDE or OPC embedded server. Alternatively, the Dymola model can be exported as a DLL with API option (see Section 6 of Dymola User Manual Volume 2). However, this option requires a Binary Model Export or Source Code Generation licence. Dymola Compilation 

Dymola models can also be exported as FMUs by using the Translate toolbar on Dymola Simulation window as shown in Figure 3.

Translate tab pull down option on Dymola Simulation window

Figure 3. Translate tab pull down option on Dymola Simulation window.

The Build process

Different compiling options use appropriate batch files to build the C code. These files are available in <Dymola installation directory>\bin:

build.bat                        – build commands for non-godess solvers with Visual Studio and Intel compilers
builddde.bat                 – build commands for models built with DDE embedded server
buildfmu.bat                 – build commands for FMU models, this will build the <model name>.dll and package it into an fmu
buildopc.bat                  – build commands for models built with OPC embedded server
dsbuild.bat                    – build commands for models compiled with MINGW
dsbuilddll.bat               – build commands to generate DLL as an output
Dymmex.bat                  – used for building sFunction used by DymolaBlock in Simulink
Dymmex4c.bat              – used for building sFunction used by DymolaBlock in Simulink with Matlab 4
Gccbuild.bat                   – build commands for models built with gcc
vgodbui.bat                    – build commands for godess solvers

When the build process is performed, an appropriate batch file(s) is called by Dymola based on the compiler option selected in the Simulation Setup in order to build the required application file(s).

On the one hand, if a Modelica model is translated (or a build process is executed), no detailed log of the commands that were used in the build process is displayed anywhere except a brief summary of this build process is stored in a buildlog.txt file. On the other hand, for viewing the commands used in the build process in detail, some modifications can be made to the appropriate build batch files. For this editing purpose, Notepad can be used. If you do not have editing permission, then modify these files as described in https://www.nibbleguru.com/67_remove-read-only-attribute-windows-10/.

An example using VS build.bat file is provided below; Dymola Compilation

Before proceeding the following steps, it is highly recommended to create a backup copy of the ‘<Dymola installation directory>\bin\build.bat’ file in your preferred location.

  • Open the build.bat file available in <Dymola installation directory>\bin using a Notepad.
  • In the first line change “echo off” to “echo on”.
  • Add “echo on” after running the VS setup batch files are called (see Figure 4).
  • Add a “pause” function to the end of this build file so that the cmd window stays open after the build is complete.

Original and modified VS build.bat files

Figure 4.  Original and modified VS build.bat files.

Now, please go through the following steps to see Dymola compilation processes in action;

  1. Open a Dymola window
  2. Select the Modelica.Blocks.Examples.PID_Controller model in the Dymola Package Browser
  3. Press Normal pull-down option from the Translate tab on the Dymola Simulation window as shown in Figure 3.

Once the model is translated, Windows cmd will appear that may look similar to Figure 5.

Build commands in action when translating Modelica.Blocks.Examples.PID_Controller in Dymola

Figure 5.  Build commands in action when translating Modelica.Blocks.Examples.PID_Controller in Dymola.

Figure 5 displays a cropped version of commands used by Dymola during translation and compilation of the C code in Windows command line. This cmd will stay open until a key is pressed.

Build files generated

The build process will generate a number of different files in the current working directory depending upon the build option used. A few of them are given below:

dymosim.exe Build generated when model is translated in Dymola or with the OPC server
dymosim.dll DLL generated when Export with DLL and DDE server are selected. (Please note:  dymosim.exe is also present with the DDE build and is used to run the dymosim.dll).
<model name>.fmu FMU dll generated with FMU export option, this is packaged inside the <model name>.fmu file.
<mex files> the mex files generated by dymmex.bat and dymmex4c.bat depend on the Matlab installation.

Remember to revert to the original version of the build.bat file in your ‘<Dymola installation directory>\bin folder.


Dymola Compilation Written by: Garron Fish – Chief Engineer 

 

Please get in touch if you have any questions or have got a topic in mind that you would like us to write about. You can submit your questions / topics via: Tech Blog Questions / Topic Suggestion

CONTACT US

Got a question? Just fill in this form and send it to us and we'll get back to you shortly.

Sending

© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?