Reading Dymola Results to Python without Dymola

There is a Python interface with Dymola shipped with every version of Dymola. Users can control Dymola with a wide variety of function calls that can load, create, simulate and read results from Dymola models. But when a limited number of licenses are available it can be very inefficient just using an instance of Dymola to read results when the .mat result file already exits.

Dymola result files are in a trajectory format, as described in a great post by Nate Horne. This means that you can use a common interface to read data files without the need of Dymola.


Python Code

There is a free SDF library available through PIP that reads and parses the Dymola result file. This means that reading data directly into Python is very easy.

The SDF library is able to access data related to each variable. Once a .mat file has been loaded the path is used to find its data. Each path will have associated data with it, with the key data being accessible. After simulating “Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum” in Dymola:

import sdf
sdfData = sdf.load("C:\Dymola Working\DoublePendulum.mat")

>>>First derivative of angle phi (relative angular velocity)

Below is an example of a simple function that reads data from a specified simulation result and outputs the data as a list:

import sdf
def readDymolaData(resultFile,variablePath):
  sdfData = sdf.load(resultFile)
  if len(splitPath)>1:
    for i in splitPath[1:]:

This can be used in the following way:

resultFile="C:\Dymola Working\DoublePendulum.mat"






Size Limit

Unfortunately Dymola uses a .mat version 4 that has a limit on the size of file that can be used. Dymola can output .mat files that are larger than that limit for simulations that have a large amount of data. Dymola is able to read those data files, but the SDF library cannot. Therefore using the Python-Dymola Interface to gain data is the best way.

Written by: David Briant – Project 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-2022 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?

Rolex Replica Watches Best Replica Watches