3 Steps to Reading XML Data into Modelica Models Using Data AccessJim Claesson, Michael Sielemann
Whether you’re already modeling within the Modelica environment, or simply considering how Modelica will work for your modeling and simulation needs, you’ve probably thought about how to read your existing data from different data formats into a Modelica model. Depending on the size of the file, manually reading data from a format such as XML and into another environment is often a time-consuming process with a large margin for error.
Data Access is a capability that comes with every Modelon Library Suite product to help users efficiently and thoroughly parse data from different file formats, including JSON, CSV, MAT and XML, into a Modelica model.
This blog will go through the process of using Data Access in Modelica to extract values from an XML file following three simple steps:
- Define inner access objects with file name reference
- Add outer access objects in components
- Add binding expressions to access values
To demonstrate the benefits of Data Access, this blog will include an open source CPACS* data definition for aircraft transportation systems as an example.
Step 1: Define inner access objects with file name reference
We start with an executable Modelica model which contains all the parts we want to simulate. As long as the XML-files are following the same standard, you can instantly switch between XML-data files by just changing the filename (see Figure 2).
Step 2: Add outer access objects in components
Next we need to declare the outer object, which is shown on the second line of Figure 3. This creates a link between to the first inner object – the data source- that is found when looking upwards in the hierarchical model structure. In this case it will find the inner object declared in Figure 2.
Step 3: Add binding expressions to extract values
Once outer and inner access objects have been defined, we’re now equipped to start extracting values from the XML file. In every component where the outer object is defined, the data can be queried with an array of convenient methods, such as getReal(). Usually, the code is most readable when using binding expressions. In Figure 3 it can be identified as “access.getReal(…)”.
As a result, values in the XML file are accessed using dot-notation, which is an easy way to parse through XML code. Data Access can then extract these values to be entered into the Modelica environment. Additionally, Data Access is not just limited to real values, but can also read other data types like strings, booleans, and integer values.
This functionality has been a critical enabler, for instance in the collaboration between industrial and academic partners in the design of hybrid electric aircraft. Here, addressing today’s growing need for improvements in aircraft fuel efficiency and emissions, gas turbines in an aircraft are replaced with turbo-electric propulsion or boosted turbofans. Read more about a research project in this area here.
Data Access allows users to easily declare values from an XML file to be extracted within the Modelica environment; thus allowing users to feel secure about making the jump from incumbent modeling platforms to modeling using Modelica. All libraries part of the Modelon Library Suite come equipped with the Data Access capability. To learn more about the various libraries we offer, visit the Modelon Library Suite page for more information. For further questions about data migration using Data Access or other Modelon products, please contact us below.
*The Common Parametric Aircraft Configuration Schema (CPACS) is a data definition for the air transportation system. CPACS enables engineers to exchange information between their tools. It is therefore a driver for multi-disciplinary and multi-fidelity design in distributed environments. CPACS describes the characteristics of aircraft, rotorcraft, engines, climate impact, fleets and mission in a structured, hierarchical manner. Not only product but also process information is stored in CPACS. The process information helps in setting up workflows for analysis modules. Due to the fact that CPACS follows a central model approach, the number of interfaces is reduced to a minimum.
B. Nagel, D. Böhnke, V. Gollnick, P. Schmollgruber, A. Rizzi, G. La Rocca, J.J. Alonso, Communication in Aircraft Design: Can we establish a Common Language?, 28th International Congress of the Aeronautical Sciences, Brisbane, Australia, 2012.