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?
How do you call dymosim.exe from the command line?
The simplest way is to just write:
in a Windows cmd and in a Linux terminal respectively .
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
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
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).
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
This example runs a model with a number of different solvers in parallel.
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.
 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:
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