How to export a CoSim FMU with Inline Integration – Part 1

Model export is a commonly used function of Dymola. Exporting FMUs using the FMI interface is one of the most popular options, as it enables users to utilize the in-built FMI specified functionality for parametrization, time integration and other functions. Even though FMI was primarily developed to promote model re-use across platforms, we more commonly see FMI utilized as a stand alone simulation deployment mechanism.

Adhering to the FMI standard simplifies the code base required outside of Dymola, which is desirable for many model developers (especially those without appreciable Computer Science background). Various options exist within the FMI standard for creating FMUs. Previous blog posts have covered the basics in FMU export, progressing to more advanced topics such as inclusion of string parameters. In this blog post, we will look at how to export a Co-simulation FMU with inline integration.

Often, people need to deploy their Dymola simulation models to a broad audience. The inbuilt FMI functionality (along with the appropriate export license) incorporates 80% of what needs to be done for these applications. The additional 20% is often custom and must be added in what we generally refer to as a FMI wrapper.

When people first begin building their own FMI wrappers to help deploy their FMUs for use by a larger audience, they logically start with the most basic approach, Co-simulation. With model exchange, the FMU uses an external solver, whereas with co-simulation a solver is packaged within the FMU and used for integration. For this reason, Co-simulation FMUs are a great starting point for new users (and users with limited computer science background). Various solvers can be utilized in this type of FMU, with Cvode being one of the more commonly used options. With that said, if your model is suitable for a fixed step solver, inline integration can provide additional performance gains. This has been documented before on the Claytex tech blog, inline integration is one method of increasing model integration efficiency and reducing solve time. Faster solving simulations are always welcome, but there are often applications where simulation speed is of paramount importance. More options outside of harnessing inline integration do exist to speed up models, a wide range of which are covered in the Advanced Model Debugging and Improvement training offered by Claytex.

Let’s take a look at how to export a Co-simulation FMU with Inline Integration.

Procedure

STEP 1: Select inline solver settings

While in the Simulation tab, select the base solver type of Euler. Then set the desired inline integration option to be used via the Realtime tab in the Simulation Setup menu. Be sure to select the inline integration order if required by the selected inline integration method.

Figure 1: There are various types of Inline Integration methods to choose from, each with their own characteristics
Figure 1: There are various types of Inline Integration methods to choose from, each with their own characteristics

Be sure to run a few simulations within Dymola to verify the performance of the Inline method selected, and once you’re happy with the performance of your simulation, move on to exporting your model.

STEP 2: FMU type selection.

When exporting a FMU there are 4 basic types available; Model Exchange, Co-simulation using Cvode, Model exchange and Co-simulation using Cvode, and Co-simulation using Dymola solvers.

Figure 2: Using the GUI is the simplest way to take an overview of all the FMI export options available in Dymola
Figure 2: Using the GUI is the simplest way to take an overview of all the FMI export options available in Dymola

If you noticed that some of the Co-simulation options listed in step 2 mention Cvode (a variable step solver) in their descriptions, and the other is only Model exchange… then you probably came to the conclusion that there is only one export option available to export a Co-simulatin FMU with Inline Integration. This isn’t a problem, as that option can be used in this case, but technically this would not be correct. It turns out that any of the four options will adhere to your Inline Integration settings.

STEP 3: Verifying exported model

Since Cvode is mentioned in the export menu, it is common for users to assume that their inline integration solver settings would be ignored. In fact, they are not. It turns out that selecting any of the Co-Simulation methods will yield a FMU with the Co-simulation interface which utilizes the selected Inline Integration settings.

We can verify that our FMU has exported with a fixed step solver including inline integration by checking the generationTool property in the modelDescription.xml file (Simply rename the *.fmu file to be *.zip and view the contents of this zip file to find the modelDescription.xml file).

Figure 3: The modelDescritiption.xml file is located in the generated FMU.

The item boxed in red above indicates that the Explicit Euler inline integration method was built into this particular FMU.

Closing remarks

There are some powerful advanced features in Dymola which require a bit of prior knowledge to get the best out of the tool. Hopefully this blog post shines a little light on one of these features and helps you to build Co-simulation FMUs with improved performance.

In a later post, I will discuss and present the process for building source code versions of Co-simulation FMUs featuring inline integration, a task which at first glance appears not to be possible (but you may be surprised to find that it is!).

Nate Horn – Vice President

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

CONTACT US

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

Sending

© Copyright 2010-2023 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?