Skip to content

Arrays of Records🔗

Description🔗

In some models, arrays of records are used for parameterization. An example of this is the tank model Modelica.Fluid.Vessels.OpenTank from the Modelica Standard Library. This tank model may have several ports or openings at different heights and of different diameters. Each of these ports is parameterized by a record and since the tank may have many openings these records are collected in an array i.e an array of records.

If the user wishes to have a different parameterization for each port in this example, then an array of records has to be created, as described below.

The figure above shows Modelica.Fluid.Vessels.OpenTank component from the Modelica Standard Library that has been modified to have an array of ports (3).

Instruction🔗

An example will be used to illustrate how to create the array of records.

The aim is to equip the tank with 3 ports, which can be connected to 3 different pipes.
To do this, we need to edit the Modelica code of the model after it has been dragged into the model canvas.

  1. Create a new model (link) and drag and drop Modelica.Fluid.Vessels.OpenTank on the canvas.1

  1. Check the parameter portsData[0] within the tank properties. This parameter can not be edited however, we can see that the parameters are scalars (one value).

  1. Right-click on the canvas and choose Edit source.

  1. Adjust the code as shown below to provide space to enter code for the array of records:

  1. Copy and paste the below text right next to the tank identifier. This piece of code adds a modifier to the tank component that does two things:
    • Sets use_portsData=true
    • Declares the parameter portsData to be an array of 3 VesselPortsData-records with individual parameterization.
    (use_portsData = true,portsData = {
    Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.1,height=0.1,zeta_out=0.5,zeta_in=0.5),
    Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.2,height=0.22,zeta_out=0.2,zeta_in=0.4),
    Modelica.Fluid.Vessels.BaseClasses.VesselPortsData(diameter=0.3,height=0.33,zeta_out=0.8,zeta_in=0.7)})

  1. Check the syntax and save the code.
  2. Close the editor.
  3. Check the tank ports as you did above, you will now see that the port is parameterized as an array of ports.

  1. Add 3 pipes Modelica.Fluid.Pipes.StaticPipe on the canvas and connect them to the tank as shown below. Each pipe will be connected to a different port.

Tip

The name Modelica.Fluid.Vessels.BaseClasses.VesselPortsData can be copied from the library tree by right-clicking on > Copy path.