OpenMI components can be linked via a configuration utility such as e.g. the OpenMI editor.
However, once can also develop a linked system by calling the OpenMI interfaces. This page describes how to set up a hard-coded linked system, where the establishment of links and the deployment and execution of a combination of components is completely encapsulated in the source code.
When developing a hard-coded system, you usually know the underlying OpenMI components and their capabilities in terms of input and output. Hard-coding the system then comes down to the following steps:
- Instantiate the LinkableComponents and initialize them with the proper input data sets.
- Create the Quantity and ElementSet objects by querying ExchangeItems.
- Create the Link objects and populate them with the Quantity and ElementSet objects.
- Add the Link objects to the components and validate them.
- Prepare the event listener to catch events.
- Run the simulation (including preparation and finish).
- Dispose of the components.
You must also continuously catch exceptions on all steps.
Example to setup a hard-coded system
The sample below provides a (pseudo) C#-code example that includes all phases in the utilization of OpenMI components. Note that this example does not include data operations and associated validations, while the calendar conversion between the DateTime data type of C# and the OpenMI Time object is omitted.
Figure Sample Hard-coded system using OpenMI linkable components