Run dymosim.exe from the command line

In the Dymola compilation process the Modelica model is translated and a dymosim executable file is created.

This blog post looks at how this dymosim executable can be called directly from the Windows cmd or from the Linux terminal. This information is in the Full Dymola User Manual Section 5.4.4.; however, as many users are unaware of this useful functionality it is covered in this post.

Why call the dymosim executable from the command line?

There are multiple ways to interface with Dymola such as calling it from Matlab, Java, Python or JavaScript or just running it directly from Dymola; however, there are cases where running dymosim.exe directly is useful and the most practical solution. For example if you want to simulate a Dymola model on a different PC that does not contain a Dymola license, and in the extreme case you may want to simulate this Dymola model on a PC Cluster. The dymosim executable can be created, with a binary model export license, and this could be transferred to the other PCs or nodes and run. Running dymosim also gives you the ability to run adaptive batch runs in parallel. Or you may just not fancy using the Java, Python or JavaScript interface.

How do you call dymosim.exe from the command line?

The simplest way is to just write:

> dymosim.exe
$ ./dymosim
in a Windows cmd and in a Linux terminal respectively [1].

This will simulate the Dymola model and generate the dsres.mat result file which is the .mat trajectory file that is generated when you simulate the model in Dymola.

How does the dymosim.exe know what simulation settings should be used?

During translation a dsin.txt file is created which contains the simulation settings such as the solver settings, result file settings and the initial parameter settings. The dymosim executable uses the settings from this dsin.txt file. For example the experiment settings in Figure 1:

Figure 1. Experiment setup in dsin.txt

Figure 1. Experiment setup in dsin.txt

The experiment setup (Figure 1.) sets the stop time, the tolerance, the solver and more. There are a lot of other simulation and output setup settings in dsin.txt and the ability to set the initial values.

Figure 2.  Initial values in dsin.txt

Figure 2. Initial values in dsin.txt

The different columns of the initialisation value matrix are:

  • The 1st column supplies information about the initial value; for example, if the first column is -1 then the initial value is a fixed value. If column 1 is 0 then the initial value is a free (or desired value). There are further information about this column; see the dsin.txt file for more details.
  • The 2nd column is the initial or guess value for the variable or state.
  • The 3rd column is the minimum value
  • The 4th column is the maximum value
  • The 5th column is the category of the variable; these are represented as:
    1 for parameter
    2 for state
    3 for state derivative
    4 for output
    5 for input
    6 for auxiliary variable
  • Column 6 is the data type of the variable. The information of the data type is stored at the bit level. For example if the data type integer is masked with 3 (i.e. <value>&3) a result of 0 means the value is a Real, a 1 means the value is a Boolean, and a 2 means the value is an Integer. This variable also stores if the variable is protected and a lot more. By translating a model with different signals, it is possible to determine what information the different bit settings of this integer represent.

What are the different command line options?

The Dymola Full User Manual describes the different command line options that can be used with the dymosim executable in Section 5.4.4, as in Figure 3.

Figure 3.  dymosim command line options.  Image from the Dymola Full User Manual Section 5.4.4 (image from the Dymola User Manual).

Figure 3. dymosim command line options.

Image from the Dymola Full User Manual Section 5.4.4 (image from the Dymola User Manual).

There are a number of interesting commands above. For example the option to -ib file command stores the dsin.txt file as a binary file in the .mat format, which makes it easier to modify these settings. It is recommended not to use the -d option and rather modify the dsin.txt file or dsin.mat and call dymosim with these options:
dymosim dsin.txt result.mat
dymosim dsin.mat result.mat

An example

This example runs a model with a number of different solvers in parallel.

Figure 4. Function to simulate a model with different solvers

Figure 4. Function to simulate a model with different solvers

This function simulates the model, experimentName, with different solvers. The Modelica.Utilities.System.command is used to run commands from the Windows/Linux shell.

To run the models in parallel, the dymosim executables need to be run from separate directories so a directory with the same name as the solver is created from which the dymosim is run. The dsin.txt file is exported as a binary and stored as a dsin.mat using:
dymosim -ib dsin.mat

This generates a default dsin.mat file, which does not contain the models experiments settings, so the experiment settings will need to be set appropriately.

The DataFiles.readMATmatrix command is used to read the experiment settings and experiment settings are modified.

dymosim is run in parallel using:
start “” dymosim dsin.mat result.mat

This simulates the model with the different solvers, generates the log files and result files in the directory in which the model was simulated. This example was created with the purpose of demonstrating calling dymosim from the command line. A number of improvements are required to make this function robust.

You can download the function here


This post describes how the dymosim executable can be called from the command line.


[1] For Linux you need to make sure LD_LIBRARY_PATH includes the lib directories that are being utilised so you may need to type something like the following in the Terminal to add the Dymola /lib directory to LD_LIBRARY_PATH:
export DYMOLA=/opt/dymola-2022x-x86_64
export LD_LIBRARY_PATH=’/home/garron/rFpro/TerrainServer2020a_1′:$DYMOLA/bin/lib64:$DYMOLA/bin/lib:$LD_LIBRARY_PATH

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


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


© Copyright 2010-2024 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?