In Modelica, global connectors are supported; this gives the user a convenient way to determine the cumulative amount of a given property throughout the model. In this blog post a simple example is worked through where the sum of all the masses in a model is determined.
What are connectors and connections?
Connectors in Modelica are a class that is used to transfer information between models. For example an electrical connector could contain the voltage and the current, and a battery model could contain two connectors, a positive and a negative electrical connector.
Two connectors are connected together using connections. For example a connection could connect the positive terminal of a battery to the positive pin of an LED (light emitting diode).
What is the Modelica code for a connector?
The Modelica code for the electrical connector can be seen in Figure 1:
Figure 1. Modelica code for an electrical connector
In Figure 1 there are two different types of values stored in the connector. There is a flow and an across variable, where the flow variable is the current and starts with the keyword flow. The across variable is the voltage and has no keyword in front of it.
Connecting connectors together
When multiple connectors are connected together the flow variables sum to zero. And the across variables are equal. The equations in Figure 2 describe this behaviour:
Figure 2. Equations describing across and flow variables . Taken from Modelica Specifications.
So in the example of the battery being connected to the LED the voltage at the positive terminal of the battery and the positive pin of the LED will be the same. And the current at the positive pin of the LED will be the negative amount of the current at the positive terminal of the battery. For a more detailed description of connectors see the Modelica Specifications.
A simple global connector example
Connectors can also be a global component; this gives the ability for components inside a model to connect to a common connector at the top level of the model. As in Figure 3 below:
Figure 3. Example of using a global connector. source1 and source2 are models that connect a current source to a global connector. This global connector is connected to the ground on the top level of the model.
In the example above inside the source1 and source2 models, current sources are connected to the global connector called globalConnector. At the top level of the model the globalConnector is connected to the ground.
So the current from sources in source1 and source2 will travel via the globalConnector to the ground on the top level. The current at the output connector of the current sources is –m (where m is a parameter of the source model).
As the connectors across variables, v, must be equal by the equation in Figure 2 we get:
ground.p.v = source1.constantCurrent.n.v = source2.constantCurrent.n.v = globalConnector.v
And as ground.p.v = 0, all these voltages are 0.
As the flow variables, i, must sum to zero the following equation holds:
It follows that the current in ground.p.i = source1.m+source2.m. The current in globalConnector.i = 0; this is because the current going into the connector and going out are equal.
Determine the total mass in a model
The mass properties of a model can be added to a global connector by modifying models that contains masses. So that the mass property is converted to a flow variable that is connected to a global connector, as is done in Figure 4.
Figure 4 is a model created by extending the Modelica Standard library model Modelica.Mechanics.MultiBody.Parts.BodyBox and adding the includeMass component. The includeMass component has the parameter m that is set to the parameter with the same in the BodyBox model. Then the constantCurrent component is used to create a flow equal to –m that is added to the global connector.
Figure 5. Double pendulum example with BodyBox classes replaced with the class in Figure 4 that adds the mass to the global connector. A global connector is also connected to the ground at the top level.
The Modelica Standard library double pendulum model is modified by using the BodyBox connector in Figure 5. Also at the top level a global connector is added and is connected to ground. When this model is simulated the current going to ground represents the total mass. Obviously one should not be using electrical components to do this and would create similar components with the correct units; the electrical components are used in this case as users may already be familiar with how these operate.
A method to calculate the sum of all of a property in a model is described. The example provided makes use of mass parameters however the value could be varying, for example it could be power usage by different components or many other things.
A modified version of this global connector method has been used in the Claytex 2022.1 libraries for calculating the total mass, center of mass and inertia within models.
The code used in the post can be obtained from here.
- Where inside flow variables have a + sign and outside flow variables have a – sign. See Generation of Connection Equations in the Modelica Specification.
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