Skip to content

Create an array of records


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 a number of ports or openings at different heights and of different diameters. Each of these ports are 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 record 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).


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

The aim is to equip above 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 > paste 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 = {

  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 are 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.


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