When you have large data sets to parameterise your Dymola models, it can be tedious to enter all the data manually, especially if you have numerous data sets you want to switch between. If you have data stored in external data files you can use the ExternData Library to access the data from your Dymola models. In this blog post I will explain what ExternData is and how to make use of it.
What is ExternData?
This library can be used to access data stored in file formats:
- CSV (Comma-separated Value)
- MAT (MATLAB v4, v6, v7 and v7.3)
- XLS and XLSX (Excel Workbook)
- XML (Extensible Markup Language)
The data access is implemented using external Modelica functions. Interfaces to these functions are provided via Modelica records for each file format as shown in Figure 1.
Figure 1: ExternData Library package content
The Examples package contains experiments showing how to use the file format records in the library to access external data and link parameters to the data.
Using ExternData to Read External Data into a Tyre Model
1. To do this I first needed to specify the external tyre data file to be used at the top level of the wheel model:
- I dragged and dropped ExternData.TIRFile into the diagram layer of the wheel model as shown in Figure 2. In the text layer, you will see that the TIRFile record declaration is automatically declared as an inner parameter.
- I then opened the parameter dialog for this tirFile, and for the fileName parameter selected the TIR file containing the tyre data using the file browser.
2. The Pacejka tyre forces models in the VeSyMA – Suspensions Library to use a data record to organise the tyre data. I needed to link the parameters in the Pacejka tyre data record to the values in the TIR file:
- I first needed to add a declaration of the ExternData.TIRFile to my extension of the Pacejka tyre data record. In the text layer I made this an outer parameter declaration with the same name (tirFile) as the inner parameter in the tyre model, as shown in Figure 3.
Figure 3: The TIR file declaration in the Pacejka data record
- For each parameter in the Pacejka tyre data record I added a tirFile.getReal function call to read the relevant scalar Real value from the external data file, as shown in Figure 4.
The first argument in the function call is the variable name in the TIR file and the second argument is the section title where it is present, as highlighted in the TIR file example shown in Figure 5.
Figure 5: Section titles and variable names in a TIR external data file
The getReal function is defined in the ExternData.TIRFile; there are alternative functions to use if the data is not scalar Reals values but Integer, Boolean or String.
Having populated the Pacejka tyre data record, I then needed to redeclare the data record in the tyre forces component in the wheel model to use this new version. The wheel model was then ready to use. Now that the wheel model is set up to use an external data source, to use an alternative TIR file I would just need to update the fileName in the wheel model tirFile.
Written by: Hannah Hammond-Scott – Senior 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.