Using physical connectors with an FMU

This post has a look at how to interface with FMU blocks that make use of physical connectors. In this blog a simple electrical circuit is split into two FMUs that interface with electrical connectors.

What is a physical connector?

A connector that could be found on a physical system connecting sub-components together is a physical connector. For example an electrical wire, a pipe, a driveshaft, and the surface of a heatsink are a few examples of physical connectors.

What is the difference between physical connectors and signal connectors?

Physical connectors in Modelica are typically acausal. Signal connectors are causal (i.e. the signal connectors are all inputs or outputs). Take the example of an electrical connector on a resistor, the voltage at the connector could be seen as the input; in this case using Ohms law (V = IR) the current would be calculated as the voltage across the resistor divided by the resistance (i.e. I=V/R) and the current would be an output at the connector. However, if the current was selected to be the input then the voltage would be the output and be the current multiplied by the resistance (i.e. V=IR).

This acausal nature of connectors in Modelica is important as it allows Dymola to work with the models in a flexible way and being able to provide a range of different boundary conditions to the same component, and also to calculate the solution to the equations efficiently.

A closer look at the electrical connector

The electrical connector consists of the across variable, voltage, which is equal at all connectors connected together; and a flow variable, current, which is such that the sum of all the flow variables of all connectors connected together is zero.
Where the convention used by flow variables is that a flow going into a component is positive and a flow going out of a component is negative (see Modelica by Example for more details).

The simple electrical example

To demonstrate how electrical connectors can interface with a FMU, the simple electrical circuit in Figure 1 is used.

Figure 1. Simple electrical circuit, with two sections FMU 1 and FMU 2 that will be exported as FMUs and a new circuit created with these FMUs

Figure 1. Simple electrical circuit, with two sections FMU 1 and FMU 2 that will be exported as FMUs and a new circuit created with these FMUs.

In the figure above the two sections that are going to be exported as FMUs make use of electrical connectors to connect to each other and to the sineVoltage and ground components.

Causal connectors to electrical connectors adaptors

Dymola currently does not support acausal (physical) connectors with FMUs so causal input and output signals have to be connected to the electrical connector using adaptors; there are two ways this can be done as in Figure 2.

Figure 2. Causal adaptors to the electrical connectors

Figure 2. Causal adaptors to the electrical connectors

The equations for the two adaptors in Figure 2 are:

pin_n.v = Vin; pin_p.v = Vout;
pin_n.i = -Iout; pin_p.p = Iin;

In the Modelica equations above pin_n and pin_p are electrrical connectors with v as the across variable and i as the flow variable. In the first set of equations Vin is the input voltage to the adaptor and Iout is the output current of the adaptor; it has a negative sign as the current is flowing out of the component. The second set of equations has the voltage as an output and the current as an input.

Using the adaptors in the simple electrical circuit

The adaptors in Figure 2 are now used in the simple electrical circuit in Figure 1 so that the FMU sections have causal connectors as in Figure 3.

Figure 3. Simple electrical circuit with electrical connection adaptors

Figure 3. Simple electrical circuit with electrical connection adaptors

In Figure 3 it was decided that the voltage to the FMU components be inputs and the current be outputs. These FMU components are then connected to the voltage source and ground an adaptor with the voltage being an output and the current being the input.

Other combinations of adaptors are possible. For example in the FMU 2 section the adaptor to the resistor could use the voltage as an output adaptor; in this case the Modelica.Blocks.Math.InverseBlockConstraints block could be used so that the voltage at the resistor in the FMU2 section is equal to the voltage at the sine source.

Why would you want to create these FMUs?

The FMUs in this case are for demonstration purposes and are to show how exporting a model that interacts with physical connectors can be done. In a more realistic example there are a number of reasons you could want to create the FMU:

  • to export the model from Dymola and use it as an FMU in different software environment (typically you would be exporting a more complex model than the ones in this example).
  • to run the FMUs in parallel and at different sampling rates

Creating the models for the FMUs

Creating the models for the FMUs can be done by selecting the components of the FMUs by pressing shift and dragging, then selecting Split Model as in Figure 4.

Figure 4. Creating the FMU models using the Split Model tool
Figure 4. Creating the FMU models using the Split Model tool

Using the method in Figure 4 two models were created one called ResistorAndCapacitor and one called ResistorAndInductor.

The model with the FMUs

The ResistorAndCapacitor and ResistorAndInductor models are now exported as FMUs (see this blog post for more details) and imported into Dymola and a model making use of the FMUs is created as in Figure 5.

Figure 5. Simple electrical circuit where the resistor and capacitor, and resistor and inductor are replaced with Model Exchange FMUs

In Figure 5 Model Exchange FMUs have been used, Co-Simulation FMUs can also be used.

Using other physical connectors

Adaptors for other physical connectors can also be created. For example:

Modelica.Mechanics.Translational.Interfaces.Flange could have the position s as an output and the force f as an input.

Modelica.Mechanics.MultiBody.Interfaces.Frame could have the position r_0 and orientation R as the input and force f and torque t as the output.


Supplying derivatives of adaptor signals

In some cases when a model is exported as an FMU an error is generated:

The model requires derivatives of some inputs error

The error above is caused because the input signal u has to be differentiated during symbolic manipulation however the input u signal does not have a derivative.

If this issue occurs and the input is a signal going to a physical adaptor the workaround is to add the derivative signals to the adaptor as is done in the Modelica.Electrical.Analog.Basic.GeneralCurrentToVoltageAdaptor and the Modelica.Electrical.Analog.Basic.GeneralVoltageToCurrentAdaptor adaptors. How the derivatives are “merged” back into the input signal is not covered in this post so please check out how this is done by viewing the models above. Note that these adaptors should be used instead of the simple Causal connectors to electrical connectors adaptors created above, the simple adaptors are given as an easy way for users to create their own physical connectors.

Discussion

This post has described how physical connectors can be used with FMUs by using adaptors.

Care is needed when connecting co-simulation FMU’s together as this can introduce accuracy and stability issues. Two papers that look into ways to reduce these issues are Energy Conservation and Coupling Error Reduction
in Non-Iterative Co-Simulations
and Relaxing Stiff System Integration by Smoothing Techniques for Non-iterative Co-simulation.

Ideas to support acausal signals into the FMI standard (see Initiatives for acausal model connection using FMI in JSAE (Society of Automotive Engineers of Japan) (researchgate.net)) are being explored so how acausal connectors are interfaced with may change in the future.

Written by: Garron Fish – Chief 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

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-2024 Claytex Services Ltd All Rights Reserved

Log in with your credentials

Forgot your details?